Skip to content

Commit

Permalink
usb: core: fix slab-out-of-bounds Read in read_descriptors
Browse files Browse the repository at this point in the history
commit a18cd6c9b6bc73dc17e8b7e9bd07decaa8833c97 upstream.

The USB device descriptor may get changed between two consecutive
enumerations on the same device for some reason, such as DFU or
malicius device.
In that case, we may access the changing descriptor if we don't take
the device lock here.

The issue is reported:
https://syzkaller.appspot.com/bug?id=901a0d9e6519ef8dc7acab25344bd287dd3c7be9

Cc: stable <[email protected]>
Cc: Alan Stern <[email protected]>
Reported-by: [email protected]
Fixes: 217a908 ("USB: add all configs to the "descriptors" attribute")
Signed-off-by: Zeng Tao <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
prime-zeng authored and gregkh committed Sep 23, 2020
1 parent 8b7e718 commit d2a6d70
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/usb/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,11 @@ read_descriptors(struct file *filp, struct kobject *kobj,
size_t srclen, n;
int cfgno;
void *src;
int retval;

retval = usb_lock_device_interruptible(udev);
if (retval < 0)
return -EINTR;
/* The binary attribute begins with the device descriptor.
* Following that are the raw descriptor entries for all the
* configurations (config plus subsidiary descriptors).
Expand All @@ -873,6 +877,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
off -= srclen;
}
}
usb_unlock_device(udev);
return count - nleft;
}

Expand Down

0 comments on commit d2a6d70

Please sign in to comment.