Skip to content

Commit 12783c0

Browse files
Udipto Goswamigregkh
authored andcommitted
usb: core: Prevent null pointer dereference in update_port_device_state
Currently, the function update_port_device_state gets the usb_hub from udev->parent by calling usb_hub_to_struct_hub. However, in case the actconfig or the maxchild is 0, the usb_hub would be NULL and upon further accessing to get port_dev would result in null pointer dereference. Fix this by introducing an if check after the usb_hub is populated. Fixes: 83cb260 ("usb: core: add sysfs entry for usb device state") Cc: [email protected] Signed-off-by: Udipto Goswami <[email protected]> Reviewed-by: Alan Stern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7c4650d commit 12783c0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/usb/core/hub.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,9 +2053,19 @@ static void update_port_device_state(struct usb_device *udev)
20532053

20542054
if (udev->parent) {
20552055
hub = usb_hub_to_struct_hub(udev->parent);
2056-
port_dev = hub->ports[udev->portnum - 1];
2057-
WRITE_ONCE(port_dev->state, udev->state);
2058-
sysfs_notify_dirent(port_dev->state_kn);
2056+
2057+
/*
2058+
* The Link Layer Validation System Driver (lvstest)
2059+
* has a test step to unbind the hub before running the
2060+
* rest of the procedure. This triggers hub_disconnect
2061+
* which will set the hub's maxchild to 0, further
2062+
* resulting in usb_hub_to_struct_hub returning NULL.
2063+
*/
2064+
if (hub) {
2065+
port_dev = hub->ports[udev->portnum - 1];
2066+
WRITE_ONCE(port_dev->state, udev->state);
2067+
sysfs_notify_dirent(port_dev->state_kn);
2068+
}
20592069
}
20602070
}
20612071

0 commit comments

Comments
 (0)