Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp271903pxb; Thu, 21 Jan 2021 06:50:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxs3qvwMJnlF0atxOyVrpSc96IG4M/5ai3b+okQNdt260gjDWFciw8hMqOdekaKEOwhGYIg X-Received: by 2002:aa7:db49:: with SMTP id n9mr11881427edt.73.1611240629612; Thu, 21 Jan 2021 06:50:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611240629; cv=none; d=google.com; s=arc-20160816; b=0J3prLQnYSbps/F0PsK7RmRrinjC8vXR38XyQQuU92aqao4DPzbtW8N/rpDpqWkTSr i30IzLWGHNbNoqSdmmXRLunm8nuO7+apq3ND4aPiAaLABEtnmMp4bt2cIYi5Sj3M6zR+ mNj9IxZGy8LnwlhUK8NxkOI7NAJkf2zoGuRUQokb7iDM87isbKkcBqdghZISGue+wRLM kV7UB/Vxou/oZXZAXH5XsmwaO92X+ceXzi/S9h4JNgor9it4mETBHx5VMsLmtgvOK4N/ mN3/Y24kPoYhFoIXuL3+wJtcqtvBZPGsmkZXeRrqSf4fzzsJ56a10T0+EzlGsFTP2F/z WxPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:reply-to; bh=405oyctWCF4c6HZyWVXh37+hz6ooySr8zjsgVJNe27I=; b=0O11yBBRsQVm65SxVbSQPpAzllZa5RcxLMGg2bBh6kFIQ/gtYkRaS1iwNAzowrRWyg gavSMiiXgINj9TikN+JPrrCt6end3QbOFMCEIDL3kKtVBrUIBf4gu3P4aZjNmMO15vft 4jC7WjlB0YTronuJ9NTJ4oCWVsWcPQGcRbdJueNdaMXvQb0f6yopxxtCsvPucYVBL4g5 pVGLeSC1bsS9vAm8nipeYvOXLnK37IMaMW/koHhKwpDEGLnb4Nxx/fZo2ifSzw/F4fO5 vVtoweRmffqR/XeUno/E3/hB2Xao3xGasUMASdb509+qM1WL8p0RJOrOIeU0ezECoQim m+5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si2246374edt.265.2021.01.21.06.49.40; Thu, 21 Jan 2021 06:50:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729589AbhAUOrh (ORCPT + 99 others); Thu, 21 Jan 2021 09:47:37 -0500 Received: from mail-lj1-f177.google.com ([209.85.208.177]:35325 "EHLO mail-lj1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732093AbhAUOqR (ORCPT ); Thu, 21 Jan 2021 09:46:17 -0500 Received: by mail-lj1-f177.google.com with SMTP id p13so2784945ljg.2; Thu, 21 Jan 2021 06:46:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:to:cc:references:from:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=405oyctWCF4c6HZyWVXh37+hz6ooySr8zjsgVJNe27I=; b=MbcXA4JOY7+mctDWKy0oxqnrunp19dret4nkIZQOx4P7hj0RIBeS20CyarWVL6MVLH 5Bln9dxZpDmD6vMSX6QoesQnULK4k5UxDcHeIyJdSe6hq1RKqBmjF8RZ72j4kVfMEZ6/ EIZ74Ed/bmpQ5HUr5TIehw6V6HQ1isIlAW2BaPctvm/vzfQLjYxAfk6ZpfatrE5G0efj 1Qu/57xFwB/xlx8qc3mL9ZnH9OPGtU9P6aXuOuhQ7ScD+3xG0UTUIQadzvx697Cmgc42 21SlemIVUZNikPVoMvjlvRTAg/F3l01QEYPLha5S1doMbS1HSSQ5LmuJzxyTfbcQNbqY 0K1A== X-Gm-Message-State: AOAM533EGtLnY5fReEwGbany/VzjygxpcRiJQLvnl/kZJojzFJX9eNlg NZ+NxjwNlxYH0A2XP2LCN3k7y1QrrPI= X-Received: by 2002:a05:651c:1254:: with SMTP id h20mr7069162ljh.211.1611240334966; Thu, 21 Jan 2021 06:45:34 -0800 (PST) Received: from [10.68.32.148] (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.gmail.com with ESMTPSA id 132sm546867lff.197.2021.01.21.06.45.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jan 2021 06:45:34 -0800 (PST) Reply-To: efremov@linux.com To: Jiri Kosina Cc: Jens Axboe , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Wim Osterholt References: <20160610230255.GA27770@djo.tudelft.nl> <20160614184308.GA6188@djo.tudelft.nl> <20160615132040.GZ14480@ZenIV.linux.org.uk> <20160615224722.GA9545@djo.tudelft.nl> <9c713fa8-9da1-47b5-0d5d-92f4cd13493a@kernel.dk> <5cb57175-7f0b-5536-925d-337241bcda93@linux.com> From: Denis Efremov Subject: Re: [PATCH RESEND] floppy: fix open(O_ACCMODE) for ioctl-only open Message-ID: <08c74fa2-ecbf-3c1d-be09-2447bb009bcb@linux.com> Date: Thu, 21 Jan 2021 17:45:33 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/21/21 1:25 PM, Jiri Kosina wrote: > On Thu, 21 Jan 2021, Denis Efremov wrote: > >> I think it's hard to recall the exact reasons after so many years. > > Yeah, I guess so :) > >> I'll send a patch today based on this one. > > I am currently waiting for confirmation by the original reporter that the > patch below fixes the issue. > > > > From: Jiri Kosina > Subject: [PATCH] floppy: reintroduce O_NDELAY fix > > Originally fixed in 09954bad4 ("floppy: refactor open() flags handling") > then reverted for unknown reason in f2791e7eadf437 instead of taking > the open(O_ACCMODE) for ioctl-only open fix, which had the changelog below > > ==== > Commit 09954bad4 ("floppy: refactor open() flags handling"), as a > side-effect, causes open(/dev/fdX, O_ACCMODE) to fail. It turns out that > this is being used setfdprm userspace for ioctl-only open(). > > Reintroduce back the original behavior wrt !(FMODE_READ|FMODE_WRITE) > modes, while still keeping the original O_NDELAY bug fixed. > > Cc: stable@vger.kernel.org # v4.5+ > Reported-by: Wim Osterholt > Tested-by: Wim Osterholt > Signed-off-by: Jiri Kosina > ===== > > Fixes: 09954bad4 ("floppy: refactor open() flags handling") > Fixes: f2791e7ead ("Revert "floppy: refactor open() flags handling"") > Signed-off-by: Jiri Kosina > --- > drivers/block/floppy.c | 29 ++++++++++++++--------------- > 1 file changed, 14 insertions(+), 15 deletions(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index dfe1dfc901cc..bda9417aa0a8 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -4121,23 +4121,22 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) > if (fdc_state[FDC(drive)].rawcmd == 1) > fdc_state[FDC(drive)].rawcmd = 2; > > - if (!(mode & FMODE_NDELAY)) { > - if (mode & (FMODE_READ|FMODE_WRITE)) { > - drive_state[drive].last_checked = 0; > - clear_bit(FD_OPEN_SHOULD_FAIL_BIT, > - &drive_state[drive].flags); > - if (bdev_check_media_change(bdev)) > - floppy_revalidate(bdev->bd_disk); > - if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags)) > - goto out; > - if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags)) > - goto out; > - } > - res = -EROFS; > - if ((mode & FMODE_WRITE) && > - !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags)) > + if (mode & (FMODE_READ|FMODE_WRITE)) { As the bot points out this was refactored a bit in: 8d9d34e25a37 ("floppy: cleanup: expand macro UDRS") 4a6f3d480edc ("floppy: use bdev_check_media_change") Should be something like: + drive_state[drive].last_checked = 0; + clear_bit(FD_OPEN_SHOULD_FAIL_BIT, + &drive_state[drive].flags); + if (bdev_check_media_change(bdev)) + floppy_revalidate(bdev->bd_disk); > + if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags)) > + goto out; > + if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags)) > goto out; > } > + > + res = -EROFS; > + > + if ((mode & FMODE_WRITE) && > + !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags)) > + goto out; > + > mutex_unlock(&open_lock); > mutex_unlock(&floppy_mutex); > return 0; >