Skip to contentSkip to conversation

patch "usb: core: fix slab-out-of-bounds Read in read_descriptors" added to usb-linus

PATCH [email protected] 1 participant 1 message Sep 4, 2020

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

usb: core: fix slab-out-of-bounds Read in read_descriptors

to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.

The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)

The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.

If you have any questions about this process, please let me know.

From a18cd6c9b6bc73dc17e8b7e9bd07decaa8833c97 Mon Sep 17 00:00:00 2001
From: Zeng Tao <[email protected]>
Date: Fri, 4 Sep 2020 14:37:44 +0800
Subject: 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 217a9081d8e6 ("USB: add all configs to the "descriptors" attribute")
---
 drivers/usb/core/sysfs.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/core/sysfs.c +5 -0
index a2ca38e25e0c..8d134193fa0c 100644
@@ -889,7 +889,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).
@@ -914,6 +918,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
 			off -= srclen;
 		}
 	}
+	usb_unlock_device(udev);
 	return count - nleft;
 }
 
Signature · 1 line
2.28.0