]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
USB: gadget: Reject endpoints with 0 maxpacket value
authorAlan Stern <stern@rowland.harvard.edu>
Mon, 28 Oct 2019 14:54:26 +0000 (10:54 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 19 Dec 2019 15:58:49 +0000 (15:58 +0000)
commitd7e3f2fe01372eb914d0e451f0e7a46cbcb98f9e
tree906a46b5dc48210959e900b34f94b40bb181a8fd
parent690dfe5668bc3173d67b5a1b984baf368182e100
USB: gadget: Reject endpoints with 0 maxpacket value

commit 54f83b8c8ea9b22082a496deadf90447a326954e upstream.

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
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>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
include/linux/usb/gadget.h