Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp105655pxb; Thu, 21 Jan 2021 02:29:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBfPbJ6wWsmdO7DN5d/jo6sQFLHYh5Ko7IN95SXpXQpjzijgr6XbAFmjjPqivioFJ906fL X-Received: by 2002:a17:906:e085:: with SMTP id gh5mr8838571ejb.418.1611224940669; Thu, 21 Jan 2021 02:29:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611224940; cv=none; d=google.com; s=arc-20160816; b=Sw4t/AHajaikZUQ+GLTBzlVdmFGxFZDL3105yHgRiOs9/klw+G2oLZROUi593SUg/C 53m2v4TAfj3jxyB0gtLMU7W+WXwRfoeHZhWb4qvGKx0htO5ciVaUFv4fpaGdDdaCTYNB h04qILq8dzJ68czV7SpxxkPlV3WiRPPalgWCcP2BoEZLVsOoV7AUnPxiCy8M2Aci/Gxt WDgezlqi1gAEk+3dV60Bz0q4+GsvANBq0REY8ZS/CFnE9V/CJS/DAi0SsSto3a4jsar3 oKVai3tMSTiX2O+1edbguRAPue1l7G6smNpM2+fdKl05LjtekIEZKe0QmNMonEdpoMwT Sb8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=+idL6gjBrOu33CgB3Ttj1mCJUhS74vedM0OgmRjzjxI=; b=ed2OPY1+sjvw6p6ALtInMPevnmfUBOYrYR9oEH4k0GAS4g/Vq6FSKH0BuwrNpmSXTg L0lkRO9hZxsormLzgkS8Tt6AH1fy+LJvRAYHHb5gkBVFGkxbBAimNNAP1cRW4b13keZH jLnnRZTPUWNpm/kPiISDMfnUHzbOjDZNhJ4zkXcOGGoNb6Yy+iGCxqkMkQBhsO8ZafIi LlHMvYU9LvPDpry5TPFG9E3LBYwRxh9acnlRRJ34hLiiIu5yUSCPRM87z9N9XQ2VkuV0 Pr6mmVodqKv5JiOve6Lmslx/Fgn8shgQIuJ+Gx5mFSqK2NlzzOpm6emtMmDtUi9NiH2o BZew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=elv1kMda; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v25si1913916edt.63.2021.01.21.02.28.36; Thu, 21 Jan 2021 02:29:00 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=elv1kMda; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729226AbhAUK1Y (ORCPT + 99 others); Thu, 21 Jan 2021 05:27:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:57854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729177AbhAUK0K (ORCPT ); Thu, 21 Jan 2021 05:26:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9AE1C233EF; Thu, 21 Jan 2021 10:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611224726; bh=1WqH3NdCK1Aq7P98SXwjbmM2Zdvym1uIUTpuB2RRcL8=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=elv1kMdaVzgDBRV2OScyEeuPivjIFBFpHBpelrYLvprzGAjfenBqWdqWe2I2hjNDn VQHCYP0vjYGkrCcY5aMc9UIpsDW5oQUCTUOB+DDsfN+0EjpiWX6JTWDoeiFDR4MwsR JdXiulX7C/RM13EtMBgRuu1yYCWTELFBTCXPylTNa9eTc+a9lmHUUzmh7y7ItXCMil pyTHGv/BDgL68Pi02rpYKc81dnoGwDGgjNsK1FcqPSAhdBRORZOR5uJPnY8o0fAyDe dXnKckQ4ArvULxO8b/nFzeh37e2T7HjztHNpIeG5wfFq4Dp7PFsPm8oD1pRv7dh4Yd xHw7akBcncUuA== Date: Thu, 21 Jan 2021 11:25:23 +0100 (CET) From: Jiri Kosina To: Denis Efremov cc: Jens Axboe , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Wim Osterholt Subject: Re: [PATCH RESEND] floppy: fix open(O_ACCMODE) for ioctl-only open In-Reply-To: <5cb57175-7f0b-5536-925d-337241bcda93@linux.com> Message-ID: 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> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)) { + UDRS->last_checked = 0; + clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags); + check_disk_change(bdev); + 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; -- Jiri Kosina SUSE Labs