Skip to content

Commit afdcfd3

Browse files
oneukumgregkh
authored andcommitted
usb: vhci-hcd: Do not drop references before new references are gained
At a few places the driver carries stale pointers to references that can still be used. Make sure that does not happen. This strictly speaking closes ZDI-CAN-22273, though there may be similar races in the driver. Signed-off-by: Oliver Neukum <[email protected]> Cc: stable <[email protected]> Acked-by: Shuah Khan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 76a7bfc commit afdcfd3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/usbip/vhci_hcd.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
745745
*
746746
*/
747747
if (usb_pipedevice(urb->pipe) == 0) {
748+
struct usb_device *old;
748749
__u8 type = usb_pipetype(urb->pipe);
749750
struct usb_ctrlrequest *ctrlreq =
750751
(struct usb_ctrlrequest *) urb->setup_packet;
@@ -755,14 +756,15 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
755756
goto no_need_xmit;
756757
}
757758

759+
old = vdev->udev;
758760
switch (ctrlreq->bRequest) {
759761
case USB_REQ_SET_ADDRESS:
760762
/* set_address may come when a device is reset */
761763
dev_info(dev, "SetAddress Request (%d) to port %d\n",
762764
ctrlreq->wValue, vdev->rhport);
763765

764-
usb_put_dev(vdev->udev);
765766
vdev->udev = usb_get_dev(urb->dev);
767+
usb_put_dev(old);
766768

767769
spin_lock(&vdev->ud.lock);
768770
vdev->ud.status = VDEV_ST_USED;
@@ -781,8 +783,8 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
781783
usbip_dbg_vhci_hc(
782784
"Not yet?:Get_Descriptor to device 0 (get max pipe size)\n");
783785

784-
usb_put_dev(vdev->udev);
785786
vdev->udev = usb_get_dev(urb->dev);
787+
usb_put_dev(old);
786788
goto out;
787789

788790
default:
@@ -1067,15 +1069,16 @@ static void vhci_shutdown_connection(struct usbip_device *ud)
10671069
static void vhci_device_reset(struct usbip_device *ud)
10681070
{
10691071
struct vhci_device *vdev = container_of(ud, struct vhci_device, ud);
1072+
struct usb_device *old = vdev->udev;
10701073
unsigned long flags;
10711074

10721075
spin_lock_irqsave(&ud->lock, flags);
10731076

10741077
vdev->speed = 0;
10751078
vdev->devid = 0;
10761079

1077-
usb_put_dev(vdev->udev);
10781080
vdev->udev = NULL;
1081+
usb_put_dev(old);
10791082

10801083
if (ud->tcp_socket) {
10811084
sockfd_put(ud->tcp_socket);

0 commit comments

Comments
 (0)