Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3560304pxb; Mon, 1 Mar 2021 13:21:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzDbN0gpj5rIRxAYbuyOEUF9EbLFTbAnxzwQ/J/Sytca+oWGmxAf/d+iyTvl1mlqeDdlRm X-Received: by 2002:a05:6402:203:: with SMTP id t3mr18225032edv.306.1614633705926; Mon, 01 Mar 2021 13:21:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614633705; cv=none; d=google.com; s=arc-20160816; b=u8L1g1Ou5qTtFZ0cIlh9HK6RoVVoGEYtA8+EFa3Rd3EN1UjIP8uM6Fn9uwigbiO7F+ 3aj60b7o3ph5xPOR65S5CBDXOTdjjjGPwv/imawX5lsmixTS8frMmAMpgLEyACHwCrtt EJJLQuDW8x0nYse1sFIPvWRFC1vvNZCX67bgqGdn2LuVB8U79lzB/0+MLz/G53mydDQS iugFVZuo72tHt4+QHijeDpaB+oAL2UsbdCHF5WZSDMEUVPrQiC86XqCWiyj4GKMSPYzw Ck7GO2Ssg/1vyq0VBgseHA1YVVdeYgjD24FbY1Ds2jSDWjyPBgFkf+mvup5fDg08YIz2 I9gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oo/VQKrn4dNK7ou7v9ivbrxeHQ3jhM7suf7FKj49w3A=; b=0wlqdf/YH2+w3IUV4MBrNy/f/ZUfBR1NGh4/rflecC9oETS+LyeTFEd1OHjVzYd7GS WaPmto24r2S/aRYwvWLDnu9cpN7BR2EGbu6y3pTBHUzrW25akDvXW7z0eVDHhPRPuWCB ono+6r8Hc0c6huHmU8buSFx4zF6qn17IWRNvQhDEMA4cIm7KzJ0AlscJQ6mWyOPtO0u0 bb9cXTn/idZe3am5bYGIe5AGoA6/bg62tShjFYlGFVewqZuh63mz58aQetFDVbSfY4dT hyHffCTw8XSn0klroxI5HlPxBP9bMzN5pWv57hJaYThjKsvESLNQY2nwsbyCTbXreOba A5wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O+JL4piL; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si5079119edv.488.2021.03.01.13.21.23; Mon, 01 Mar 2021 13:21:45 -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=@linuxfoundation.org header.s=korg header.b=O+JL4piL; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244035AbhCAVRs (ORCPT + 99 others); Mon, 1 Mar 2021 16:17:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:52684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235234AbhCAROD (ORCPT ); Mon, 1 Mar 2021 12:14:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7284065037; Mon, 1 Mar 2021 16:45:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617135; bh=L9axuymLvZZRk+y/Eh2UbVJTEYHiwU1vYwcseXf5DHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O+JL4piLnFMTRzwAKj8pJmp14A8664sB0teoUbgmLmV5ca/bhFOIIitr2cNzrL9uh s6GMo1oGi61SobWkz/ZYplDo1KOGGeewPY2H3Gz3sgf2cEh5fTgfC9qhTl+wBe6JcN 8TS8a2ZbvR6twWKZzzvOXAd2C8Mx8aFa2MeoVkpI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wim Osterholt , Jiri Kosina , Denis Efremov , Kurt Garloff Subject: [PATCH 4.19 214/247] floppy: reintroduce O_NDELAY fix Date: Mon, 1 Mar 2021 17:13:54 +0100 Message-Id: <20210301161042.147410184@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Kosina commit 8a0c014cd20516ade9654fc13b51345ec58e7be8 upstream. This issue was originally fixed in 09954bad4 ("floppy: refactor open() flags handling"). The fix as a side-effect, however, introduce issue for open(O_ACCMODE) that is being used for ioctl-only open. I wrote a fix for that, but instead of it being merged, full revert of 09954bad4 was performed, re-introducing the O_NDELAY / O_NONBLOCK issue, and it strikes again. This is a forward-port of the original fix to current codebase; the original submission 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. Link: https://lore.kernel.org/r/nycvar.YFH.7.76.2101221209060.5622@cbobk.fhfr.pm Cc: stable@vger.kernel.org Reported-by: Wim Osterholt Tested-by: Wim Osterholt Reported-and-tested-by: Kurt Garloff Fixes: 09954bad4 ("floppy: refactor open() flags handling") Fixes: f2791e7ead ("Revert "floppy: refactor open() flags handling"") Signed-off-by: Jiri Kosina Signed-off-by: Denis Efremov Signed-off-by: Greg Kroah-Hartman --- drivers/block/floppy.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4074,21 +4074,22 @@ static int floppy_open(struct block_devi if (UFDCS->rawcmd == 1) UFDCS->rawcmd = 2; - if (!(mode & FMODE_NDELAY)) { - if (mode & (FMODE_READ|FMODE_WRITE)) { - UDRS->last_checked = 0; - clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); - check_disk_change(bdev); - if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags)) - goto out; - if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags)) - goto out; - } - res = -EROFS; - if ((mode & FMODE_WRITE) && - !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags)) + if (mode & (FMODE_READ|FMODE_WRITE)) { + UDRS->last_checked = 0; + clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags); + check_disk_change(bdev); + if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags)) + goto out; + if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags)) goto out; } + + res = -EROFS; + + if ((mode & FMODE_WRITE) && + !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags)) + goto out; + mutex_unlock(&open_lock); mutex_unlock(&floppy_mutex); return 0;