USB: gadget: max3420: validate endpoint index for max3420 udc
PATCH 1/1 USB: gadget: max3420: validate endpoint index for max3420 udc
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.
--- drivers/usb/gadget/udc/max3420_udc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/max3420_udc.c +5 -1
@@ -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;
Signature · 1 line
2.34.1
Greg KH
maintainerQuoted 39 lines · 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_STATUSrequest 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 <[email protected]>--- drivers/usb/gadget/udc/max3420_udc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/gadget/udc/max3420_udc.c +5
-1@@ -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;Signature · 1 line
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/[email protected]
thanks,
greg k-h