[SRU][J][PATCH 1/1] memstick/mspro_block: fix handling of read-only devices
Cengiz Can
cengiz.can at canonical.com
Tue Sep 8 21:17:57 UTC 2026
From: Christoph Hellwig <hch at lst.de>
Use set_disk_ro to propagate the read-only state to the block layer
instead of checking for it in ->open and leaking a reference in case
of a read-only device.
Signed-off-by: Christoph Hellwig <hch at lst.de>
Link: https://lore.kernel.org/r/20220215094514.3828912-4-hch@lst.de
Signed-off-by: Jens Axboe <axboe at kernel.dk>
(backported from commit 6dab421bfe06a59bf8f212a72e34673e8acf2018)
[bot_kybele: Added only the set_disk_ro block; kept this tree's void-style
device_add_disk() call (no rc check / no out_cleanup_disk label), since that
error handling is pre-existing upstream context absent here, not part of this
commit.]
CVE-2022-49178
Assisted-by: kybele:claude-opus-4.8
Signed-off-by: Cengiz Can <cengiz.can at canonical.com>
---
drivers/memstick/core/mspro_block.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 22778d0e24f5..3a87b40d9967 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
mutex_lock(&mspro_block_disk_lock);
- if (msb && msb->card) {
+ if (msb && msb->card)
msb->usage_count++;
- if ((mode & FMODE_WRITE) && msb->read_only)
- rc = -EROFS;
- else
- rc = 0;
- }
mutex_unlock(&mspro_block_disk_lock);
@@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card)
set_capacity(msb->disk, capacity);
dev_dbg(&card->dev, "capacity set %ld\n", capacity);
+ if (msb->read_only)
+ set_disk_ro(msb->disk, true);
+
device_add_disk(&card->dev, msb->disk, NULL);
msb->active = 1;
return 0;
--
2.53.0
More information about the kernel-team
mailing list