diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2019-10-28 10:54:26 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-10-29 04:56:18 -0400 |
commit | 54f83b8c8ea9b22082a496deadf90447a326954e (patch) | |
tree | 30a32b3dfab1c350d4a957cdef6979abe05edcd2 | |
parent | 1186f86a71130a7635a20843e355bb880c7349b2 (diff) |
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 <stern@rowland.harvard.edu>
Reported-and-tested-by: syzbot+8ab8bf161038a8768553@syzkaller.appspotmail.com
CC: <stable@vger.kernel.org>
Acked-by: Felipe Balbi <balbi@kernel.org>
Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.1910281052370.1485-100000@iolanthe.rowland.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/gadget/udc/core.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 92af8dc98c3d..51fa614b4079 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c | |||
@@ -98,6 +98,17 @@ int usb_ep_enable(struct usb_ep *ep) | |||
98 | if (ep->enabled) | 98 | if (ep->enabled) |
99 | goto out; | 99 | goto out; |
100 | 100 | ||
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 | |||
101 | ret = ep->ops->enable(ep, ep->desc); | 112 | ret = ep->ops->enable(ep, ep->desc); |
102 | if (ret) | 113 | if (ret) |
103 | goto out; | 114 | goto out; |