Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb-storage: alauda: track media_initialized per port
@ 2026-11-21 17:19 Arbab Haider
  2026-11-21 17:29 ` sashiko-bot
  2026-11-21 20:54 ` Alan Stern
  0 siblings, 2 replies; 6+ messages in thread
From: Arbab Haider @ 2026-11-21 17:19 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman
  Cc: Shichao Lai, linux-usb, usb-storage, linux-kernel,
	syzbot+dc208a8cf8d37cf3e5ac, stable, Arbab Haider

Commit 16637fea001a ("usb-storage: alauda: Check whether the media is
initialized") added a media_initialized flag to struct alauda_info to
prevent divide-by-zero errors when alauda_init_media() has not succeeded.

However, Alauda devices expose two LUNs (us->max_lun = 1) backed by
info->port[0] (xD) and info->port[1] (SmartMedia). Storing
media_initialized in struct alauda_info shares it across both ports: once
port 0 initializes, media_initialized becomes true, allowing port 1 to
skip alauda_init_media() when its media-change bit is clear and divide by
port[1].uzonesize == 0 in alauda_read_data() or alauda_write_lba():

  Oops: divide error: 0000 [#1] SMP KASAN NOPTI
  RIP: 0010:alauda_read_data drivers/usb/storage/alauda.c:953 [inline]
  RIP: 0010:alauda_transport+0xe5a/0x35c0 drivers/usb/storage/alauda.c:1187

Additionally, alauda_check_media() never cleared media_initialized when
media was removed or before re-initializing on media change, leaving it
true if a subsequent re-initialization failed.

Move media_initialized into struct alauda_media_info so each port tracks
its own initialization state, and clear it when media is absent or before
re-initializing on media change.

Reported-by: syzbot+dc208a8cf8d37cf3e5ac@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=dc208a8cf8d37cf3e5ac
Fixes: 16637fea001a ("usb-storage: alauda: Check whether the media is initialized")
Cc: stable@vger.kernel.org
Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
---
 drivers/usb/storage/alauda.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index 5e7f99ba8..5493f25a7 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -96,6 +96,8 @@ struct alauda_media_info {
 
 	u16 **lba_to_pba;		/* logical to physical block map */
 	u16 **pba_to_lba;		/* physical to logical block map */
+
+	bool media_initialized;
 };
 
 struct alauda_info {
@@ -105,8 +107,6 @@ struct alauda_info {
 	unsigned char sense_key;
 	unsigned long sense_asc;	/* additional sense code */
 	unsigned long sense_ascq;	/* additional sense code qualifier */
-
-	bool media_initialized;
 };
 
 #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
@@ -471,6 +471,7 @@ static int alauda_check_media(struct us_data *us)
 		|| ((status[1] & 0x01) == 0)) {
 		usb_stor_dbg(us, "No media, or door open\n");
 		alauda_free_maps(&MEDIA_INFO(us));
+		MEDIA_INFO(us).media_initialized = false;
 		info->sense_key = 0x02;
 		info->sense_asc = 0x3A;
 		info->sense_ascq = 0x00;
@@ -478,12 +479,13 @@ static int alauda_check_media(struct us_data *us)
 	}
 
 	/* Check for media change */
-	if (status[0] & 0x08 || !info->media_initialized) {
+	if (status[0] & 0x08 || !MEDIA_INFO(us).media_initialized) {
 		usb_stor_dbg(us, "Media change detected\n");
 		alauda_free_maps(&MEDIA_INFO(us));
+		MEDIA_INFO(us).media_initialized = false;
 		rc = alauda_init_media(us);
 		if (rc == USB_STOR_TRANSPORT_GOOD)
-			info->media_initialized = true;
+			MEDIA_INFO(us).media_initialized = true;
 		info->sense_key = UNIT_ATTENTION;
 		info->sense_asc = 0x28;
 		info->sense_ascq = 0x00;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-storage: alauda: track media_initialized per port
  2026-11-21 17:19 [PATCH] usb-storage: alauda: track media_initialized per port Arbab Haider
@ 2026-11-21 17:29 ` sashiko-bot
  2026-11-21 20:54 ` Alan Stern
  1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-21 17:29 UTC (permalink / raw)
  To: Arbab Haider; +Cc: linux-usb

> Commit 16637fea001a ("usb-storage: alauda: Check whether the media is
> initialized") added a media_initialized flag to struct alauda_info to
> prevent divide-by-zero errors when alauda_init_media() has not succeeded.
> 
> However, Alauda devices expose two LUNs (us->max_lun = 1) backed by
> info->port[0] (xD) and info->port[1] (SmartMedia). Storing
> media_initialized in struct alauda_info shares it across both ports: once
> port 0 initializes, media_initialized becomes true, allowing port 1 to
> skip alauda_init_media() when its media-change bit is clear and divide by
> port[1].uzonesize == 0 in alauda_read_data() or alauda_write_lba():
> 
>   Oops: divide error: 0000 [#1] SMP KASAN NOPTI
>   RIP: 0010:alauda_read_data drivers/usb/storage/alauda.c:953 [inline]
>   RIP: 0010:alauda_transport+0xe5a/0x35c0 drivers/usb/storage/alauda.c:1187
> 
> Additionally, alauda_check_media() never cleared media_initialized when
> media was removed or before re-initializing on media change, leaving it
> true if a subsequent re-initialization failed.
> 
> Move media_initialized into struct alauda_media_info so each port tracks
> its own initialization state, and clear it when media is absent or before
> re-initializing on media change.
> 
> Reported-by: syzbot+dc208a8cf8d37cf3e5ac@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=dc208a8cf8d37cf3e5ac
> Fixes: 16637fea001a ("usb-storage: alauda: Check whether the media is initialized")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261121171956.1455-1-arbabhaider649@gmail.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-storage: alauda: track media_initialized per port
  2026-11-21 17:19 [PATCH] usb-storage: alauda: track media_initialized per port Arbab Haider
  2026-11-21 17:29 ` sashiko-bot
@ 2026-11-21 20:54 ` Alan Stern
  2026-11-22  8:05   ` Arbab Haider
  1 sibling, 1 reply; 6+ messages in thread
From: Alan Stern @ 2026-11-21 20:54 UTC (permalink / raw)
  To: Arbab Haider
  Cc: Greg Kroah-Hartman, Shichao Lai, linux-usb, usb-storage,
	linux-kernel, syzbot+dc208a8cf8d37cf3e5ac, stable

On Sat, Nov 21, 2026 at 10:19:56PM +0500, Arbab Haider wrote:
> Commit 16637fea001a ("usb-storage: alauda: Check whether the media is
> initialized") added a media_initialized flag to struct alauda_info to
> prevent divide-by-zero errors when alauda_init_media() has not succeeded.
> 
> However, Alauda devices expose two LUNs (us->max_lun = 1) backed by
> info->port[0] (xD) and info->port[1] (SmartMedia). Storing
> media_initialized in struct alauda_info shares it across both ports: once
> port 0 initializes, media_initialized becomes true, allowing port 1 to
> skip alauda_init_media() when its media-change bit is clear and divide by
> port[1].uzonesize == 0 in alauda_read_data() or alauda_write_lba():
> 
>   Oops: divide error: 0000 [#1] SMP KASAN NOPTI
>   RIP: 0010:alauda_read_data drivers/usb/storage/alauda.c:953 [inline]
>   RIP: 0010:alauda_transport+0xe5a/0x35c0 drivers/usb/storage/alauda.c:1187
> 
> Additionally, alauda_check_media() never cleared media_initialized when
> media was removed or before re-initializing on media change, leaving it
> true if a subsequent re-initialization failed.
> 
> Move media_initialized into struct alauda_media_info so each port tracks
> its own initialization state, and clear it when media is absent or before
> re-initializing on media change.
> 
> Reported-by: syzbot+dc208a8cf8d37cf3e5ac@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=dc208a8cf8d37cf3e5ac
> Fixes: 16637fea001a ("usb-storage: alauda: Check whether the media is initialized")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
> ---

Has this patch been tested?

Alan Stern

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-storage: alauda: track media_initialized per port
  2026-11-21 20:54 ` Alan Stern
@ 2026-11-22  8:05   ` Arbab Haider
  2026-11-22 14:53     ` [usb-storage] " Alan Stern
  0 siblings, 1 reply; 6+ messages in thread
From: Arbab Haider @ 2026-11-22  8:05 UTC (permalink / raw)
  To: Alan Stern
  Cc: Greg Kroah-Hartman, Shichao Lai, linux-usb, usb-storage,
	linux-kernel, syzbot+dc208a8cf8d37cf3e5ac, stable, Arbab Haider

On Sat, Nov 21, 2026 at 03:54:57PM -0500, Alan Stern wrote:
> Has this patch been tested?

Yes, tested in QEMU (x86_64, v7.4-rc3 with KASAN, UBSAN, dummy_hcd,
raw_gadget, and usb-storage alauda enabled). I do not have physical
Alauda hardware, so testing was done via dummy_hcd + raw_gadget:

- Before the patch: running the syzbot C reproducer reproduced the
  UBSAN division-overflow / divide error in alauda_read_data()
  (drivers/usb/storage/alauda.c:986) on LUN 1.

- After the patch: the syzbot reproducer passes with no UBSAN, KASAN,
  or divide errors. I also verified additional raw_gadget scenarios:
  * READ_CAPACITY and READ_10 on both LUN 0 and LUN 1
  * Media removal (status 0x80) followed by re-insertion without the
    0x08 media-change bit and READ_10
  * Media change with a failing alauda_init_media() (unrecognized media
    signature) followed by READ_10 and WRITE_10
  * Recovery back to a valid media signature with TEST_UNIT_READY,
    READ_CAPACITY, and READ_10

Regards,
Arbab

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [usb-storage] Re: [PATCH] usb-storage: alauda: track media_initialized per port
  2026-11-22  8:05   ` Arbab Haider
@ 2026-11-22 14:53     ` Alan Stern
  2026-11-22 17:58       ` Arbab Haider
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Stern @ 2026-11-22 14:53 UTC (permalink / raw)
  To: Arbab Haider
  Cc: Greg Kroah-Hartman, Shichao Lai, linux-usb, usb-storage,
	linux-kernel, syzbot+dc208a8cf8d37cf3e5ac, stable

On Sun, Nov 22, 2026 at 01:05:51PM +0500, Arbab Haider wrote:
> On Sat, Nov 21, 2026 at 03:54:57PM -0500, Alan Stern wrote:
> > Has this patch been tested?
> 
> Yes, tested in QEMU (x86_64, v7.4-rc3 with KASAN, UBSAN, dummy_hcd,
> raw_gadget, and usb-storage alauda enabled). I do not have physical
> Alauda hardware, so testing was done via dummy_hcd + raw_gadget:
> 
> - Before the patch: running the syzbot C reproducer reproduced the
>   UBSAN division-overflow / divide error in alauda_read_data()
>   (drivers/usb/storage/alauda.c:986) on LUN 1.
> 
> - After the patch: the syzbot reproducer passes with no UBSAN, KASAN,
>   or divide errors. I also verified additional raw_gadget scenarios:
>   * READ_CAPACITY and READ_10 on both LUN 0 and LUN 1
>   * Media removal (status 0x80) followed by re-insertion without the
>     0x08 media-change bit and READ_10
>   * Media change with a failing alauda_init_media() (unrecognized media
>     signature) followed by READ_10 and WRITE_10
>   * Recovery back to a valid media signature with TEST_UNIT_READY,
>     READ_CAPACITY, and READ_10

I asked because when syzbot tests a patch successfully, it provides a 
Tested-by: tag and asks to have the tag included in the final patch 
submission -- but you didn't do this.  Did you run the reproducer 
locally, without using the bot?

Alan Stern

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [usb-storage] Re: [PATCH] usb-storage: alauda: track media_initialized per port
  2026-11-22 14:53     ` [usb-storage] " Alan Stern
@ 2026-11-22 17:58       ` Arbab Haider
  0 siblings, 0 replies; 6+ messages in thread
From: Arbab Haider @ 2026-11-22 17:58 UTC (permalink / raw)
  To: Alan Stern
  Cc: Greg Kroah-Hartman, Shichao Lai, linux-usb, usb-storage,
	linux-kernel, syzbot+dc208a8cf8d37cf3e5ac, stable, Arbab Haider

On Sun, Nov 22, 2026 at 09:53:25AM -0500, Alan Stern wrote:
> I asked because when syzbot tests a patch successfully, it provides a
> Tested-by: tag and asks to have the tag included in the final patch
> submission -- but you didn't do this.  Did you run the reproducer
> locally, without using the bot?

Yes, I ran the syzbot C reproducer locally in QEMU without using syzbot.
I also just tried sending "#syz test" to syzbot, and it replied that
patch testing via "#syz test" is currently disabled:

  Patch testing via #syz test is temporarily disabled.
  See https://github.com/google/syzkaller/issues/8122 for details.

Also, while checking lore.kernel.org, I noticed that syzbot previously
posted a similar AI-generated patch from Aleksandr Nogikh on 2026-08-28
that never received a reply. Please let me know if you prefer taking
that earlier patch instead, or if this submission looks good to you.

Regards,
Arbab

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-22 17:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 17:19 [PATCH] usb-storage: alauda: track media_initialized per port Arbab Haider
2026-11-21 17:29 ` sashiko-bot
2026-11-21 20:54 ` Alan Stern
2026-11-22  8:05   ` Arbab Haider
2026-11-22 14:53     ` [usb-storage] " Alan Stern
2026-11-22 17:58       ` Arbab Haider

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox