Skip to content

Commit a18cd6c

Browse files
prime-zenggregkh
authored andcommitted
usb: core: fix slab-out-of-bounds Read in read_descriptors
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]>
1 parent a6498d5 commit a18cd6c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/usb/core/sysfs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,11 @@ read_descriptors(struct file *filp, struct kobject *kobj,
889889
size_t srclen, n;
890890
int cfgno;
891891
void *src;
892+
int retval;
892893

894+
retval = usb_lock_device_interruptible(udev);
895+
if (retval < 0)
896+
return -EINTR;
893897
/* The binary attribute begins with the device descriptor.
894898
* Following that are the raw descriptor entries for all the
895899
* configurations (config plus subsidiary descriptors).
@@ -914,6 +918,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
914918
off -= srclen;
915919
}
916920
}
921+
usb_unlock_device(udev);
917922
return count - nleft;
918923
}
919924

0 commit comments

Comments
 (0)