From: Ho Jie Feng <hjf3108@gmail.com>
To: Ulf Hansson <ulfh@kernel.org>
Cc: Maxim Levitsky <maximlevitsky@gmail.com>,
Alex Dubov <oakad@yahoo.com>,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
Ho Jie Feng <hjf3108@gmail.com>,
Maoyi Xie <maoyixie.tju@gmail.com>,
Yifei Gao <gyf161023@gmail.com>,
Hemanth Selam <hemanth.selam@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 3/5] memstick: ms_block: don't erase the old block of an unmapped LBA
Date: Mon, 9 Nov 2026 23:38:02 +0800 [thread overview]
Message-ID: <20261109153832.7377-3-hjf3108@gmail.com> (raw)
In-Reply-To: <20261109153510.7161-1-hjf3108@gmail.com>
msb_update_block() checks for MS_BLOCK_INVALID before it sets the update
flag on the old block, but then erases the old block unconditionally. For
an LBA without a block, this tries to erase block 65535.
msb_erase_block() then calls msb_mark_block_unused() and sets the bit in
erased_blocks_bitmap with pba 65535, so used_blocks_bitmap,
free_block_count[] and erased_blocks_bitmap are accessed out of bounds.
UBSAN reported free_block_count[127] on the int[16] array.
Only erase the old block if there is one.
Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
Signed-off-by: Ho Jie Feng <hjf3108@gmail.com>
---
drivers/memstick/core/ms_block.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index cd4ff1b79a6da..e373eaf92530f 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -1149,8 +1149,10 @@ static int msb_update_block(struct msb_data *msb, u16 lba,
if (error)
goto out;
- dbg_verbose("block update: erasing the old block");
- msb_erase_block(msb, pba);
+ if (pba != MS_BLOCK_INVALID) {
+ dbg_verbose("block update: erasing the old block");
+ msb_erase_block(msb, pba);
+ }
msb->lba_to_pba_table[lba] = new_pba;
return 0;
}
--
2.56.0
next prev parent reply other threads:[~2026-11-09 15:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 15:34 [PATCH 0/5] memstick: fixes for mspro_block and ms_block Ho Jie Feng
2026-11-09 15:38 ` [PATCH 1/5] memstick: mspro_block: don't hand a finished request back to the host Ho Jie Feng
2026-11-09 15:38 ` [PATCH 2/5] memstick: mspro_block: wait for running dispatches in mspro_block_stop() Ho Jie Feng
2026-11-09 15:38 ` Ho Jie Feng [this message]
2026-11-09 15:38 ` [PATCH 4/5] memstick: ms_block: keep the power off during a full msb_reset() Ho Jie Feng
2026-11-09 15:38 ` [PATCH 5/5] memstick: ms_block: add the missing newline to the parallel switch error Ho Jie Feng
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=20261109153832.7377-3-hjf3108@gmail.com \
--to=hjf3108@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=gyf161023@gmail.com \
--cc=hemanth.selam@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=maoyixie.tju@gmail.com \
--cc=maximlevitsky@gmail.com \
--cc=oakad@yahoo.com \
--cc=ulfh@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
all inboxes | Powered by JetHome®