USB: gadget: validate endpoint index for max3420 udc
PATCH 1/1 USB: gadget: validate endpoint index for max3420 udc
The max3420_getstatus() and max3420_set_clear_feature() functions use the endpoint index from USB setup packet's wIndex field to access the endpoint array. The index is masked with USB_ENDPOINT_NUMBER_MASK (0x0f), which allows values 0-15, but the endpoint array (udc->ep) only has MAX3420_MAX_EPS (4) elements.
A malicious USB host can send a specially crafted control request with an invalid endpoint index (>= 4) to trigger an out-of-bounds array access, potentially leading to information disclosure or kernel memory corruption.
Add validation to ensure the endpoint index is within bounds before accessing the endpoint array.
--- drivers/usb/gadget/udc/max3420_udc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/gadget/udc/max3420_udc.c +5 -0
@@ -548,6 +548,9 @@ static void max3420_getstatus(struct max3420_udc *udc) goto stall;break ;case USB_RECIP_ENDPOINT : +if ((udc->setup.wIndex &USB_ENDPOINT_NUMBER_MASK ) + >=MAX3420_MAX_EPS ) + goto stall; ep = &udc->ep[udc->setup.wIndex &USB_ENDPOINT_NUMBER_MASK ];if (udc->setup.wIndex &USB_DIR_IN ) {if (!ep->ep_usb.caps.dir_in)
@@ -596,6 +599,8 @@ static void max3420_set_clear_feature(struct max3420_udc *udc)break ; id = udc->setup.wIndex &USB_ENDPOINT_NUMBER_MASK ; +if (id >=MAX3420_MAX_EPS ) +break ; ep = &udc->ep[id];spin_lock_irqsave (&ep->lock, flags);
Signature · 1 line
2.34.1
Greg KH
maintainerQuoted 6 lines · Kery Qi
The
max3420_getstatus()andmax3420_set_clear_feature()functions use the endpoint index from USB setup packet's wIndex field to access the endpoint array. The index is masked withUSB_ENDPOINT_NUMBER_MASK(0x0f), which allows values 0-15, but the endpoint array (udc->ep) only hasMAX3420_MAX_EPS(4) elements.
Quoted 6 lines
A malicious USB host can send a specially crafted control request with an invalid endpoint index (>= 4) to trigger an out-of-bounds array access, potentially leading to information disclosure or kernel memory corruption.
Add validation to ensure the endpoint index is within bounds before accessing the endpoint array.
We've been through this before, please read the archives for the last time this was attempted to be submitted, and go and fix the tool you are using to find these.
thanks,
greg k-h
Hi greg k-h,
Thank you for your response.
I'd like to clarify that I found this issue by performing variant analysis based on commit 7f14c7227f342d9932f9b918893c8814f86d2a0d ("USB: gadget:
validate endpoint index for xilinx udc"). That commit fixed the missing endpoint index validation in udc-xilinx.c before accessing the endpoint array, and was accepted into the kernel. I searched for similar patterns in other UDC drivers and found that max3420_udc.c has the same issue - MAX3420_MAX_EPS is only 4 while USB_ENDPOINT_NUMBER_MASK allows values 0-15, so both max3420_getstatus() and max3420_set_clear_feature() can access udc->ep[] out of bounds without validation.
If there was a previous discussion about this specific driver that I missed, I would appreciate a pointer to that thread.
Thanks,
Kery
Quoted 22 lines · Greg KH <[email protected]> 于2026年1月22日周四 13:32写道:
Quoted 6 lines · Kery Qi
The
max3420_getstatus()andmax3420_set_clear_feature()functions use the endpoint index from USB setup packet's wIndex field to access the endpoint array. The index is masked withUSB_ENDPOINT_NUMBER_MASK(0x0f), which allows values 0-15, but the endpoint array (udc->ep) only hasMAX3420_MAX_EPS(4) elements.Quoted 6 lines
A malicious USB host can send a specially crafted control request with an invalid endpoint index (>= 4) to trigger an out-of-bounds array access, potentially leading to information disclosure or kernel memory corruption.
Add validation to ensure the endpoint index is within bounds before accessing the endpoint array.
We've been through this before, please read the archives for the last time this was attempted to be submitted, and go and fix the tool you are using to find these.
thanks,
greg k-h
Greg KH
maintainerQuoted 3 lines · Kery Qi
Hi greg k-h,
Thank you for your response.
Please do not top-post, you have lost the context in this message :(
Quoted 9 lines
I'd like to clarify that I found this issue by performing variant analysis based on commit
7f14c7227f342d9932f9b918893c8814f86d2a0d("USB: gadget:
validate endpoint index for xilinx udc"). That commit fixed the missing endpoint index validation inudc-xilinx.cbefore accessing the endpoint array, and was accepted into the kernel. I searched for similar patterns in other UDC drivers and found thatmax3420_udc.chas the same issue -MAX3420_MAX_EPSis only 4 whileUSB_ENDPOINT_NUMBER_MASKallows values 0-15, so bothmax3420_getstatus()andmax3420_set_clear_feature()can access udc->ep[] out of bounds without validation.
But can that ever actually happen? Remember, we trust the hardware here. if you wish to change the model where we do not trust the hardware of this device, then there is a lot more work that needs to be done than just attempting to add this single check.
How was this tested?
Quoted 2 lines
If there was a previous discussion about this specific driver that I missed, I would appreciate a pointer to that thread.
I think the archives have them for this type of change, a simple search brings up this thread:
https://lore.kernel.org/all/[email protected]/
It was rejected back then, please work with your teammates on coordinating this type of thing and do not send duplicate patches.
Also, you forgot to document the tools that you used to "find" this issue, as is required. For that reason alone this patch would not be acceptable, sorry.
thanks,
greg k-h