Archive-only list for syzbot
 help / color / mirror / Atom feed
* [PATCH] usb: usbtest: fix NULL pointer dereference in usbtest_probe
@ 2026-07-29  9:19 syzbot
  2026-08-03 15:13 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2026-07-29  9:19 UTC (permalink / raw)
  To: syzkaller-bugs, Aleksandr Nogikh, Greg Kroah-Hartman, linux-usb,
	Greg Kroah-Hartman
  Cc: kees, linux-kernel, syzbot

From: Aleksandr Nogikh <nogikh@google.com>

The usbtest driver relies on the driver_info field of the usb_device_id
structure to hold a pointer to a struct usbtest_info, which contains
necessary configuration for the device. When a new device ID is dynamically
added via the sysfs new_id interface without specifying a reference device,
the driver_info field defaults to 0. When the USB core binds the device
using this dynamic ID, usbtest_probe() unconditionally casts the 0 to a
pointer, resulting in a NULL pointer dereference when attempting to access
the autoconf bitfield (at offset 0xa) of the struct usbtest_info.

This leads to the following crash:

Oops: general protection fault, probably for non-canonical address
0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
RIP: 0010:usbtest_probe+0x522/0xcc0 drivers/usb/misc/usbtest.c:2822
Call Trace:
 <TASK>
 usb_probe_interface+0x653/0xc60 drivers/usb/core/driver.c:396
 call_driver_probe drivers/base/dd.c:-1 [inline]
 really_probe+0x254/0xae0 drivers/base/dd.c:706
 __driver_probe_device+0x1e8/0x360 drivers/base/dd.c:868
 driver_probe_device+0x4f/0x240 drivers/base/dd.c:898
 __device_attach_driver+0x270/0x410 drivers/base/dd.c:1026
 bus_for_each_drv+0x258/0x2f0 drivers/base/bus.c:500
 __device_attach+0x2c4/0x450 drivers/base/dd.c:1098
 device_initial_probe+0xa1/0xd0 drivers/base/dd.c:1153
 bus_probe_device+0x12a/0x220 drivers/base/bus.c:620
 device_add+0x7d7/0xb80 drivers/base/core.c:3772
 usb_set_configuration+0x1ad8/0x2180 drivers/usb/core/message.c:2268
 usb_generic_driver_probe+0x8d/0x150 drivers/usb/core/generic.c:250
 usb_probe_device+0x1c3/0x3b0 drivers/usb/core/driver.c:291

To fix this, validate that id->driver_info is not NULL before proceeding
with the probe. If it is NULL, gracefully return -ENODEV. The check is
placed before any memory allocation to avoid unnecessary work and simplify
error handling.

Fixes: 733260ff9c45 ("[PATCH] USB: add dynamic id functionality to USB core")
Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot
Reported-by: syzbot+7e1e5911f9eac50bedc7@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7e1e5911f9eac50bedc7
Link: https://syzkaller.appspot.com/ai_job?id=9e476ca5-99d1-47d2-b9d1-f3b501897179
Signed-off-by: Aleksandr Nogikh <nogikh@google.com>

---
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 98071b25a..6410b3e26 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -2786,10 +2786,13 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	}
 #endif
 
+	info = (struct usbtest_info *) id->driver_info;
+	if (!info)
+		return -ENODEV;
+
 	dev = kzalloc_obj(*dev);
 	if (!dev)
 		return -ENOMEM;
-	info = (struct usbtest_info *) id->driver_info;
 	dev->info = info;
 	mutex_init(&dev->lock);
 


base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff
-- 
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at syzkaller@googlegroups.com.

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

* Re: [PATCH] usb: usbtest: fix NULL pointer dereference in usbtest_probe
  2026-07-29  9:19 [PATCH] usb: usbtest: fix NULL pointer dereference in usbtest_probe syzbot
@ 2026-08-03 15:13 ` Greg Kroah-Hartman
  2026-08-03 15:14   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-08-03 15:13 UTC (permalink / raw)
  To: syzbot
  Cc: syzkaller-bugs, Aleksandr Nogikh, linux-usb, Greg Kroah-Hartman,
	kees, linux-kernel, syzbot

On Wed, Jul 29, 2026 at 09:19:54AM +0000, syzbot wrote:
> From: Aleksandr Nogikh <nogikh@google.com>
> 
> The usbtest driver relies on the driver_info field of the usb_device_id
> structure to hold a pointer to a struct usbtest_info, which contains
> necessary configuration for the device. When a new device ID is dynamically
> added via the sysfs new_id interface without specifying a reference device,
> the driver_info field defaults to 0. When the USB core binds the device
> using this dynamic ID, usbtest_probe() unconditionally casts the 0 to a
> pointer, resulting in a NULL pointer dereference when attempting to access
> the autoconf bitfield (at offset 0xa) of the struct usbtest_info.
> 
> This leads to the following crash:
> 
> Oops: general protection fault, probably for non-canonical address
> 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI
> KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
> RIP: 0010:usbtest_probe+0x522/0xcc0 drivers/usb/misc/usbtest.c:2822
> Call Trace:
>  <TASK>
>  usb_probe_interface+0x653/0xc60 drivers/usb/core/driver.c:396
>  call_driver_probe drivers/base/dd.c:-1 [inline]
>  really_probe+0x254/0xae0 drivers/base/dd.c:706
>  __driver_probe_device+0x1e8/0x360 drivers/base/dd.c:868
>  driver_probe_device+0x4f/0x240 drivers/base/dd.c:898
>  __device_attach_driver+0x270/0x410 drivers/base/dd.c:1026
>  bus_for_each_drv+0x258/0x2f0 drivers/base/bus.c:500
>  __device_attach+0x2c4/0x450 drivers/base/dd.c:1098
>  device_initial_probe+0xa1/0xd0 drivers/base/dd.c:1153
>  bus_probe_device+0x12a/0x220 drivers/base/bus.c:620
>  device_add+0x7d7/0xb80 drivers/base/core.c:3772
>  usb_set_configuration+0x1ad8/0x2180 drivers/usb/core/message.c:2268
>  usb_generic_driver_probe+0x8d/0x150 drivers/usb/core/generic.c:250
>  usb_probe_device+0x1c3/0x3b0 drivers/usb/core/driver.c:291
> 
> To fix this, validate that id->driver_info is not NULL before proceeding
> with the probe. If it is NULL, gracefully return -ENODEV. The check is
> placed before any memory allocation to avoid unnecessary work and simplify
> error handling.
> 
> Fixes: 733260ff9c45 ("[PATCH] USB: add dynamic id functionality to USB core")
> Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot
> Reported-by: syzbot+7e1e5911f9eac50bedc7@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=7e1e5911f9eac50bedc7
> Link: https://syzkaller.appspot.com/ai_job?id=9e476ca5-99d1-47d2-b9d1-f3b501897179
> Signed-off-by: Aleksandr Nogikh <nogikh@google.com>
> 
> ---
> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> index 98071b25a..6410b3e26 100644
> --- a/drivers/usb/misc/usbtest.c
> +++ b/drivers/usb/misc/usbtest.c
> @@ -2786,10 +2786,13 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
>  	}
>  #endif
>  
> +	info = (struct usbtest_info *) id->driver_info;

Extra space there, right?  Didn't checkpatch catch that?

And this really isn't the proper solution, just don't allow dynamic
binding for this driver.  That should resolve it, right?

thanks,

greg k-h

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

* Re: [PATCH] usb: usbtest: fix NULL pointer dereference in usbtest_probe
  2026-08-03 15:13 ` Greg Kroah-Hartman
@ 2026-08-03 15:14   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-08-03 15:14 UTC (permalink / raw)
  To: syzbot
  Cc: syzkaller-bugs, Aleksandr Nogikh, linux-usb, Greg Kroah-Hartman,
	kees, linux-kernel, syzbot

On Mon, Aug 03, 2026 at 05:13:00PM +0200, Greg Kroah-Hartman wrote:
> On Wed, Jul 29, 2026 at 09:19:54AM +0000, syzbot wrote:
> > From: Aleksandr Nogikh <nogikh@google.com>
> > 
> > The usbtest driver relies on the driver_info field of the usb_device_id
> > structure to hold a pointer to a struct usbtest_info, which contains
> > necessary configuration for the device. When a new device ID is dynamically
> > added via the sysfs new_id interface without specifying a reference device,
> > the driver_info field defaults to 0. When the USB core binds the device
> > using this dynamic ID, usbtest_probe() unconditionally casts the 0 to a
> > pointer, resulting in a NULL pointer dereference when attempting to access
> > the autoconf bitfield (at offset 0xa) of the struct usbtest_info.
> > 
> > This leads to the following crash:
> > 
> > Oops: general protection fault, probably for non-canonical address
> > 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI
> > KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
> > RIP: 0010:usbtest_probe+0x522/0xcc0 drivers/usb/misc/usbtest.c:2822
> > Call Trace:
> >  <TASK>
> >  usb_probe_interface+0x653/0xc60 drivers/usb/core/driver.c:396
> >  call_driver_probe drivers/base/dd.c:-1 [inline]
> >  really_probe+0x254/0xae0 drivers/base/dd.c:706
> >  __driver_probe_device+0x1e8/0x360 drivers/base/dd.c:868
> >  driver_probe_device+0x4f/0x240 drivers/base/dd.c:898
> >  __device_attach_driver+0x270/0x410 drivers/base/dd.c:1026
> >  bus_for_each_drv+0x258/0x2f0 drivers/base/bus.c:500
> >  __device_attach+0x2c4/0x450 drivers/base/dd.c:1098
> >  device_initial_probe+0xa1/0xd0 drivers/base/dd.c:1153
> >  bus_probe_device+0x12a/0x220 drivers/base/bus.c:620
> >  device_add+0x7d7/0xb80 drivers/base/core.c:3772
> >  usb_set_configuration+0x1ad8/0x2180 drivers/usb/core/message.c:2268
> >  usb_generic_driver_probe+0x8d/0x150 drivers/usb/core/generic.c:250
> >  usb_probe_device+0x1c3/0x3b0 drivers/usb/core/driver.c:291
> > 
> > To fix this, validate that id->driver_info is not NULL before proceeding
> > with the probe. If it is NULL, gracefully return -ENODEV. The check is
> > placed before any memory allocation to avoid unnecessary work and simplify
> > error handling.
> > 
> > Fixes: 733260ff9c45 ("[PATCH] USB: add dynamic id functionality to USB core")

Not really, but I can see why the LLM thinks this.  It's "just how this
driver works" instead, right?

> > Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot
> > Reported-by: syzbot+7e1e5911f9eac50bedc7@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=7e1e5911f9eac50bedc7
> > Link: https://syzkaller.appspot.com/ai_job?id=9e476ca5-99d1-47d2-b9d1-f3b501897179
> > Signed-off-by: Aleksandr Nogikh <nogikh@google.com>
> > 
> > ---
> > diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> > index 98071b25a..6410b3e26 100644
> > --- a/drivers/usb/misc/usbtest.c
> > +++ b/drivers/usb/misc/usbtest.c
> > @@ -2786,10 +2786,13 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
> >  	}
> >  #endif
> >  
> > +	info = (struct usbtest_info *) id->driver_info;
> 
> Extra space there, right?  Didn't checkpatch catch that?
> 
> And this really isn't the proper solution, just don't allow dynamic
> binding for this driver.  That should resolve it, right?

If you don't want to do that, you need a BIG comment here as to what you
are trying to prevent, as a NULL check just looks like any other normal
check, while you are trying to prevent a specific use case from being
possible, and it WILL have user-visable affect.

thanks,

greg k-h

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

end of thread, other threads:[~2026-08-03 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29  9:19 [PATCH] usb: usbtest: fix NULL pointer dereference in usbtest_probe syzbot
2026-08-03 15:13 ` Greg Kroah-Hartman
2026-08-03 15:14   ` Greg Kroah-Hartman

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