Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp947612pxb; Fri, 22 Jan 2021 03:25:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaAITX7laCFH9SCbKlqWEHQ3/zj6lsfs119LRdlqSx+scF0kLR4CXlIv43KFSJVDPcDp/q X-Received: by 2002:a05:6402:b6f:: with SMTP id cb15mr2762696edb.277.1611314722595; Fri, 22 Jan 2021 03:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611314722; cv=none; d=google.com; s=arc-20160816; b=ycZbW47e2CwBrRRESq4UmhWJPSV/RXbjxO77Tqq5lroG1j968OxD7R+2L+c1X7bmmF TKpNbLcMidIHcKtI0Xd3tfWHBu7sWwIjgKzob5ZDOEoF93xY4sG43mr3UhhpIVgriToy ImIw7gucDZRWrxf3i1RWhXFA1qQU2ytSEETBIZfVecNv4jfFp6FA0AxUbyDHQbDUIaag Cc0aDbuxH0a8kfDO3A7V3s4mKUeLTby5x4LOi0vgdGv0j9wpTKqkNrSS9WoLsw9E+DMB GkwSlMlaZ1kZsLWCi8qAvnA3bMnyvxVErwGybvAnKqUTWYlazLhhWGJTfFCq/JuybzmI tyNQ== 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=Droq4DFWZSWtfSMJppev0zYaZRCz/zX2TsHe3Yli9Pg=; b=FOFfEuJkmQy+2pRbGm82WYTJJEUaVpqSnG3g9CFg5gL342ZsXREeRXw81SxXT/FFNi 6ebZQWcj1orIfffrBCwlabw//quX2JB/5RR76O2ho0pHQVpxhsHQwT4o2cOnJkjPAwpn GZRowCZNdDg8Yo+D2YyN78CODOYiGdPuo6oJ6zV8L4sj3nlsAHfRoWSnIBt3GyBJ5u/0 CuJAZ7JNWkXvpHAzMoHSigkLp/WqtacK8bbnjGRujbtOhfaZoSx12Qi4vOeZOYtNk/ka hYbhpZrVuewyl+A8tUrYtq1kQqTAqFOIvfXVAhxDhShFdDga9N8gEswP4GYqtI7GgcQ5 LhpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=llYcg9it; 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 gx11si2859154ejb.357.2021.01.22.03.24.57; Fri, 22 Jan 2021 03:25:22 -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=llYcg9it; 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 S1728216AbhAVLUo (ORCPT + 99 others); Fri, 22 Jan 2021 06:20:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:55864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbhAVLOH (ORCPT ); Fri, 22 Jan 2021 06:14:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B9A752246B; Fri, 22 Jan 2021 11:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611314004; bh=qKaCrMSE3znTlxna118B4y/k0MOaw8ankwk0D2+SXQ8=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=llYcg9itg23JAsDCeIqdGYyxPEo5HgCT4RdQmnUFBA5MVHQ/S/i6pfDgF29sf8JOo e14YJUHO+KVoU/rW8UKt9tZe7mAo5EkNjCLqp42Mp21D+9haLizwcU1Yvi3vz1qh3O oxbMFmiMLL0f0FdcgtAO5Po+1TD0WbL8zIGSC8Ksf2t3003gAIAR13ge0e4JXhFeSX ehSIq6JHblCjuhm0k9dpBaisBIwzI+KcGSK6KDqjcgqj+m0KEmM9VNwuVyyiQWfblw 7VG9P8iC2aR2Thdciscfr33/ewYyPLmQv8J2aGIa+X5IhJmHVUuO/cn5D40WdB/z73 pwFezGuVl9FqQ== Date: Fri, 22 Jan 2021 12:13:20 +0100 (CET) From: Jiri Kosina To: Denis Efremov , Jens Axboe cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Wim Osterholt , Kurt Garloff Subject: [PATCH] floppy: reintroduce O_NDELAY fix In-Reply-To: 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 From: Jiri Kosina 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. 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 --- drivers/block/floppy.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index dfe1dfc901cc..0b71292d9d5a 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4121,23 +4121,23 @@ 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)) { + 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; -- Jiri Kosina SUSE Labs