Skip to content

Commit 54f83b8

Browse files
AlanSterngregkh
authored andcommitted
USB: gadget: Reject endpoints with 0 maxpacket value
Endpoints with a maxpacket length of 0 are probably useless. They can't transfer any data, and it's not at all unlikely that a UDC will crash or hang when trying to handle a non-zero-length usb_request for such an endpoint. Indeed, dummy-hcd gets a divide error when trying to calculate the remainder of a transfer length by the maxpacket value, as discovered by the syzbot fuzzer. Currently the gadget core does not check for endpoints having a maxpacket value of 0. This patch adds a check to usb_ep_enable(), preventing such endpoints from being used. As far as I know, none of the gadget drivers in the kernel tries to create an endpoint with maxpacket = 0, but until now there has been nothing to prevent userspace programs under gadgetfs or configfs from doing it. Signed-off-by: Alan Stern <[email protected]> Reported-and-tested-by: [email protected] CC: <[email protected]> Acked-by: Felipe Balbi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1186f86 commit 54f83b8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/usb/gadget/udc/core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ int usb_ep_enable(struct usb_ep *ep)
9898
if (ep->enabled)
9999
goto out;
100100

101+
/* UDC drivers can't handle endpoints with maxpacket size 0 */
102+
if (usb_endpoint_maxp(ep->desc) == 0) {
103+
/*
104+
* We should log an error message here, but we can't call
105+
* dev_err() because there's no way to find the gadget
106+
* given only ep.
107+
*/
108+
ret = -EINVAL;
109+
goto out;
110+
}
111+
101112
ret = ep->ops->enable(ep, ep->desc);
102113
if (ret)
103114
goto out;

0 commit comments

Comments
 (0)