* [PATCH] USB: gadget: max3420: validate endpoint index for max3420 udc
@ 2026-01-05 8:02 Kery Qi
2026-01-16 15:27 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Kery Qi @ 2026-01-05 8:02 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Kery Qi
Assure that the host may not manipulate the index to point past the
endpoint array.
In max3420_getstatus(), the driver uses the wIndex value from the
setup packet to obtain the endpoint index. However, there is no
check to ensure this index is within the valid bounds of the
udc->ep[] array.
A malicious host could send a USB_REQ_GET_STATUS request with a
large endpoint index, leading to an out-of-bounds memory access.
This patch adds a validation check against MAX3420_MAX_EPS. If the
endpoint index is invalid, the request is stalled.
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
drivers/usb/gadget/udc/max3420_udc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c
index 7349ea774adf..ac11ddf3fcbc 100644
--- a/drivers/usb/gadget/udc/max3420_udc.c
+++ b/drivers/usb/gadget/udc/max3420_udc.c
@@ -548,7 +548,11 @@ static void max3420_getstatus(struct max3420_udc *udc)
goto stall;
break;
case USB_RECIP_ENDPOINT:
- ep = &udc->ep[udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK];
+ u8 epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK;
+
+ if (epnum >= MAX3420_MAX_EPS)
+ goto stall;
+ ep = &udc->ep[epnum];
if (udc->setup.wIndex & USB_DIR_IN) {
if (!ep->ep_usb.caps.dir_in)
goto stall;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] USB: gadget: max3420: validate endpoint index for max3420 udc
2026-01-05 8:02 [PATCH] USB: gadget: max3420: validate endpoint index for max3420 udc Kery Qi
@ 2026-01-16 15:27 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-01-16 15:27 UTC (permalink / raw)
To: Kery Qi; +Cc: linux-kernel
On Mon, Jan 05, 2026 at 04:02:43PM +0800, Kery Qi wrote:
> Assure that the host may not manipulate the index to point past the
> endpoint array.
>
> In max3420_getstatus(), the driver uses the wIndex value from the
> setup packet to obtain the endpoint index. However, there is no
> check to ensure this index is within the valid bounds of the
> udc->ep[] array.
>
> A malicious host could send a USB_REQ_GET_STATUS request with a
> large endpoint index, leading to an out-of-bounds memory access.
>
> This patch adds a validation check against MAX3420_MAX_EPS. If the
> endpoint index is invalid, the request is stalled.
>
> Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
> ---
> drivers/usb/gadget/udc/max3420_udc.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c
> index 7349ea774adf..ac11ddf3fcbc 100644
> --- a/drivers/usb/gadget/udc/max3420_udc.c
> +++ b/drivers/usb/gadget/udc/max3420_udc.c
> @@ -548,7 +548,11 @@ static void max3420_getstatus(struct max3420_udc *udc)
> goto stall;
> break;
> case USB_RECIP_ENDPOINT:
> - ep = &udc->ep[udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK];
> + u8 epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK;
> +
> + if (epnum >= MAX3420_MAX_EPS)
> + goto stall;
> + ep = &udc->ep[epnum];
> if (udc->setup.wIndex & USB_DIR_IN) {
> if (!ep->ep_usb.caps.dir_in)
> goto stall;
> --
> 2.34.1
>
You didn't use scripts/get_maintainer.pl to determine what list to send
this to :(
Anyway, if you have a malicious USB host, then don't bind to it, we
implicitly trust hosts in the kernel. Also, I don't think that this
will protect anything here, see the thread on the linux-usb list in the
past when this has come up:
https://lore.kernel.org/r/20250629201324.30726-4-eeodqql09@gmail.com
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-16 15:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-05 8:02 [PATCH] USB: gadget: max3420: validate endpoint index for max3420 udc Kery Qi
2026-01-16 15:27 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox