* [PATCH] block: drop the claim on a rejected write open by path
@ 2026-11-26 10:27 Gleb Chesnokov
0 siblings, 0 replies; only message in thread
From: Gleb Chesnokov @ 2026-11-26 10:27 UTC (permalink / raw)
To: linux-block; +Cc: Jens Axboe, Christian Brauner
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-26 10:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 10:27 [PATCH] block: drop the claim on a rejected write open by path Gleb Chesnokov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox