Skip to content

Commit

Permalink
USB: core: Avoid WARNings for 0-length descriptor requests
Browse files Browse the repository at this point in the history
[ Upstream commit 60dfe48 ]

The USB core has utility routines to retrieve various types of
descriptors.  These routines will now provoke a WARN if they are asked
to retrieve 0 bytes (USB "receive" requests must not have zero
length), so avert this by checking the size argument at the start.

CC: Johan Hovold <johan@kernel.org>
Reported-and-tested-by: syzbot+7dbcd9ff34dc4ed45240@syzkaller.appspotmail.com
Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20210607152307.GD1768031@rowland.harvard.edu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
AlanStern authored and Sasha Levin committed Aug 26, 2021
1 parent 8e100c7 commit ba6c1b0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/usb/core/message.c
Expand Up @@ -785,6 +785,9 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type,
int i;
int result;

if (size <= 0) /* No point in asking for no data */
return -EINVAL;

memset(buf, 0, size); /* Make sure we parse really received data */

for (i = 0; i < 3; ++i) {
Expand Down Expand Up @@ -833,6 +836,9 @@ static int usb_get_string(struct usb_device *dev, unsigned short langid,
int i;
int result;

if (size <= 0) /* No point in asking for no data */
return -EINVAL;

for (i = 0; i < 3; ++i) {
/* retry on length 0 or stall; some devices are flakey */
result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
Expand Down

0 comments on commit ba6c1b0

Please sign in to comment.