From: Gleb Chesnokov <gleb.chesnokov@scst.dev>
To: linux-block@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>, Christian Brauner <brauner@kernel.org>
Subject: [PATCH] block: drop the claim on a rejected write open by path
Date: Thu, 26 Nov 2026 13:27:00 +0300 [thread overview]
Message-ID: <b520c362-c26f-4796-847e-b982383582b0@scst.dev> (raw)
bdev_file_open_by_path() checks whether the device is read-only after
bdev_file_open_by_dev() has already claimed it for the caller's holder.
On this error path, fput() can defer ->release() until after the caller
gets -EACCES. A different holder can still get -EBUSY, and the block
layer can still call ->mark_dead() after the caller has freed its holder
state. The caller receives no file with which to release the claim.
Use bdev_fput() to drop the claim acquired by this open before returning
-EACCES. The final file release can still be deferred.
Fixes: f3a608827d1f ("bdev: open block device as files")
Signed-off-by: Gleb Chesnokov <gleb.chesnokov@scst.dev>
---
Tested in QEMU with two back-to-back opens of a read-only RAM disk from
the same task. The read/write open returned -EACCES on both kernels.
The read open with a different holder returned -EBUSY before the fix
and succeeded with it.
OpenAI Codex assisted with testing.
block/bdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/bdev.c b/block/bdev.c
index f20f91b3176e..add1a69f2f4a 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -1127,7 +1127,7 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode,
file = bdev_file_open_by_dev(dev, mode, holder, hops);
if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) {
if (bdev_read_only(file_bdev(file))) {
- fput(file);
+ bdev_fput(file);
file = ERR_PTR(-EACCES);
}
}
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
--
2.56.1
reply other threads:[~2026-11-26 10:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b520c362-c26f-4796-847e-b982383582b0@scst.dev \
--to=gleb.chesnokov@scst.dev \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox