* [PATCH] memstick: ms_block: reject an invalid bad block table size
@ 2026-11-27 6:35 Maoyi Xie
0 siblings, 0 replies; only message in thread
From: Maoyi Xie @ 2026-11-27 6:35 UTC (permalink / raw)
To: Maxim Levitsky; +Cc: Alex Dubov, Ulf Hansson, linux-mmc
msb_read_bad_block_table() stores the u32 table size from the card boot
page in an int and checks it only for zero. A size of 0xffffffff
becomes -1. size_to_read is then 0 or one page, but the loop bound
data_size / sizeof(u16) becomes huge. The loop faults on ZERO_SIZE_PTR
or reads past the buffer.
The table is stored in the boot block. Reject a size that is negative
or larger than the block.
Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer. Not tested on
hardware.
Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.
drivers/memstick/core/ms_block.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index d4143a871d69..37b810760642 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -1274,6 +1274,11 @@ static int msb_read_bad_block_table(struct msb_data *msb, int block_nr)
if (!data_size)
return 0;
+ if (data_size < 0 || data_size > msb->block_size) {
+ pr_err("Invalid bad block table size: %d\n", data_size);
+ return -EINVAL;
+ }
+
page = data_offset / msb->page_size;
page_offset = data_offset % msb->page_size;
size_to_read =
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-27 6:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 6:35 [PATCH] memstick: ms_block: reject an invalid bad block table size Maoyi Xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox