diff options
author | Christian Brauner <brauner@kernel.org> | 2024-03-23 17:11:20 +0100 |
---|---|---|
committer | Christian Brauner <brauner@kernel.org> | 2024-03-27 12:59:25 +0100 |
commit | 3ff56e285de5a375fbfab3c3f1af81bbd23db36d (patch) | |
tree | afb41f5c9994aa19e82e9d893d79d9ca7a385ac4 /drivers/phy | |
parent | block: handle BLK_OPEN_RESTRICT_WRITES correctly (diff) | |
download | linux-3ff56e285de5a375fbfab3c3f1af81bbd23db36d.tar.xz linux-3ff56e285de5a375fbfab3c3f1af81bbd23db36d.zip |
block: count BLK_OPEN_RESTRICT_WRITES openers
The original changes in v6.8 do allow for a block device to be reopened
with BLK_OPEN_RESTRICT_WRITES provided the same holder is used as per
bdev_may_open(). I think this has a bug.
The first opener @f1 of that block device will set bdev->bd_writers to
-1. The second opener @f2 using the same holder will pass the check in
bdev_may_open() that bdev->bd_writers must not be greater than zero.
The first opener @f1 now closes the block device and in bdev_release()
will end up calling bdev_yield_write_access() which calls
bdev_writes_blocked() and sets bdev->bd_writers to 0 again.
Now @f2 holds a file to that block device which was opened with
exclusive write access but bdev->bd_writers has been reset to 0.
So now @f3 comes along and succeeds in opening the block device with
BLK_OPEN_WRITE betraying @f2's request to have exclusive write access.
This isn't a practical issue yet because afaict there's no codepath
inside the kernel that reopenes the same block device with
BLK_OPEN_RESTRICT_WRITES but it will be if there is.
Fix this by counting the number of BLK_OPEN_RESTRICT_WRITES openers. So
we only allow writes again once all BLK_OPEN_RESTRICT_WRITES openers are
done.
Link: https://lore.kernel.org/r/20240323-abtauchen-klauen-c2953810082d@brauner
Fixes: ed5cc702d311 ("block: Add config option to not allow writing to mounted devices")
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'drivers/phy')
0 files changed, 0 insertions, 0 deletions