mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Alan Stern <stern@rowland.harvard.edu>,
	 "Cho, Yu-Chen" <acho@novell.com>
Cc: Josef Bacik <josef@toxicpanda.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	 linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net,
	 linux-kernel@vger.kernel.org,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 5/7] usb: storage: sddr09: bound the unused PBA search
Date: Tue, 27 Oct 2026 15:40:48 +0100	[thread overview]
Message-ID: <20261027-llm-usb-storage-v1-5-d1655e94ed10@linuxfoundation.org> (raw)
In-Reply-To: <20261027-llm-usb-storage-v1-0-d1655e94ed10@linuxfoundation.org>

From: Josef Bacik <josef@toxicpanda.com>

sddr09_find_unused_pba() can read past the end of pba_to_lba[] and hand
out a physical block that does not exist on the card, which is then
recorded in pba_to_lba[] past its end and written to.

The search resumes from lastpba, a function-local static shared by all
SDDR-09 readers and kept across card changes.  The first loop is bounded
by end, the number of blocks in the zone, but the wrap-around loop only
by lastpba:

    for (i = 0; i <= lastpba; i++) {
            if (info->pba_to_lba[zonestart+i] == UNDEF) {

After a write to a card with 1024 blocks per zone has left lastpba at,
say, 700, writing to a 1MB card (256 blocks) whose blocks are all in use
walks pba_to_lba[] from index 256 to 700.  If any of those out-of-bounds
words reads as UNDEF, sddr09_write_lba() stores into pba_to_lba[pba]
and goes on to program that bogus block.

The bug was found by code inspection and has not been reproduced.

Fix by also stopping the wrap-around loop at the end of the zone.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/storage/sddr09.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index 313313508bde..44197a3a545b 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -838,7 +838,7 @@ sddr09_find_unused_pba(struct sddr09_card_info *info, unsigned int lba) {
 			return zonestart+i;
 		}
 	}
-	for (i = 0; i <= lastpba; i++) {
+	for (i = 0; i <= lastpba && i < end; i++) {
 		if (info->pba_to_lba[zonestart+i] == UNDEF) {
 			lastpba = i;
 			return zonestart+i;

-- 
2.56.0


  parent reply	other threads:[~2026-10-27 14:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 14:40 [PATCH 0/7] usb: storage: some llm-found patches Greg Kroah-Hartman
2026-10-27 14:40 ` [PATCH 1/7] usb: storage: ene_ub6250: fail MS init on card errors Greg Kroah-Hartman
2026-10-27 14:40 ` [PATCH 2/7] usb: storage: ene_ub6250: report boot block errors Greg Kroah-Hartman
2026-10-27 14:40 ` [PATCH 3/7] usb: storage: ene_ub6250: fix write to unmapped MS block Greg Kroah-Hartman
2026-10-27 14:40 ` [PATCH 4/7] usb: storage: ene_ub6250: bound the disabled block walk Greg Kroah-Hartman
2026-10-27 14:40 ` Greg Kroah-Hartman [this message]
2026-10-27 14:40 ` [PATCH 6/7] usb: storage: shuttle_usbat: fix READ CD divide by zero Greg Kroah-Hartman
2026-10-27 14:40 ` [PATCH 7/7] usb: storage: shuttle_usbat: bound the READ chunk size Greg Kroah-Hartman

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=20261027-llm-usb-storage-v1-5-d1655e94ed10@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=acho@novell.com \
    --cc=gregkh@suse.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=usb-storage@lists.one-eyed-alien.net \
    /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®