* [PATCH v2] usb: gadget: f_mass_storage: fix null pointer dereference in fsg_common_set_num_buffers()
@ 2026-08-18 3:59 Jeffin Philip
2026-08-18 15:59 ` Alan Stern
0 siblings, 1 reply; 2+ messages in thread
From: Jeffin Philip @ 2026-08-18 3:59 UTC (permalink / raw)
To: gregkh
Cc: christophe.jaillet, festevam, jeffinphilip14, eeodqql09, kees,
felipe.balbi, linux-usb, linux-kernel,
syzbot+791be35f1fbcc85d06d7, stable
Previously fsg_num_buffers_validate() was removed as it was not
necessary due to Kconfig setting the limits for n from 2 to 256 with
default as 2. However, setting the page content in such a way that
kstrtou8() reflects n value as either 0 or 1 bypasses these
restrictions leading to a null pointer dereference if n is 0. Fix
this by adding a check for n < 2 and returning -EINVAL if n is
either 0 or 1 consistent with Kconfig logic.
Reported-by: syzbot+791be35f1fbcc85d06d7@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=791be35f1fbcc85d06d7
Fixes: fe5a6c48fd95 ("usb: gadget: storage: get rid of fsg_num_buffers_validate()")
Cc: stable@vger.kernel.org
Signed-off-by: Jeffin Philip <jeffinphilip14@gmail.com>
---
Changes in v2:
- Change check from n = 0 to n < 2 consistent with Kconfig logic
---
drivers/usb/gadget/function/f_mass_storage.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index a50743caf083..4e743be220cc 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -2747,6 +2747,9 @@ int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
struct fsg_buffhd *bh, *buffhds;
int i;
+ if (n < 2)
+ return -EINVAL;
+
buffhds = kzalloc_objs(*buffhds, n);
if (!buffhds)
return -ENOMEM;
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] usb: gadget: f_mass_storage: fix null pointer dereference in fsg_common_set_num_buffers()
2026-08-18 3:59 [PATCH v2] usb: gadget: f_mass_storage: fix null pointer dereference in fsg_common_set_num_buffers() Jeffin Philip
@ 2026-08-18 15:59 ` Alan Stern
0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2026-08-18 15:59 UTC (permalink / raw)
To: Jeffin Philip
Cc: gregkh, christophe.jaillet, festevam, eeodqql09, kees, linux-usb,
linux-kernel, syzbot+791be35f1fbcc85d06d7, stable
On Tue, Aug 18, 2026 at 09:29:04AM +0530, Jeffin Philip wrote:
> Previously fsg_num_buffers_validate() was removed as it was not
> necessary due to Kconfig setting the limits for n from 2 to 256 with
> default as 2. However, setting the page content in such a way that
> kstrtou8() reflects n value as either 0 or 1 bypasses these
> restrictions leading to a null pointer dereference if n is 0. Fix
> this by adding a check for n < 2 and returning -EINVAL if n is
> either 0 or 1 consistent with Kconfig logic.
>
> Reported-by: syzbot+791be35f1fbcc85d06d7@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=791be35f1fbcc85d06d7
> Fixes: fe5a6c48fd95 ("usb: gadget: storage: get rid of fsg_num_buffers_validate()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jeffin Philip <jeffinphilip14@gmail.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
> ---
> Changes in v2:
> - Change check from n = 0 to n < 2 consistent with Kconfig logic
> ---
> drivers/usb/gadget/function/f_mass_storage.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
> index a50743caf083..4e743be220cc 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.c
> +++ b/drivers/usb/gadget/function/f_mass_storage.c
> @@ -2747,6 +2747,9 @@ int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
> struct fsg_buffhd *bh, *buffhds;
> int i;
>
> + if (n < 2)
> + return -EINVAL;
> +
> buffhds = kzalloc_objs(*buffhds, n);
> if (!buffhds)
> return -ENOMEM;
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-18 15:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 3:59 [PATCH v2] usb: gadget: f_mass_storage: fix null pointer dereference in fsg_common_set_num_buffers() Jeffin Philip
2026-08-18 15:59 ` Alan Stern
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.