Skip to contentSkip to conversation

USB: serial: garmin_gps: queue the device reset

PATCH In review Greg Kroah-Hartman 3 participants 5 messages Oct 27 – Oct 29

Subsystems (2)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 USB: serial: garmin_gps: queue the device reset

From: Josef Bacik <[email protected]>

A private packet with the ID PRIV_PKTID_RESET_REQ that is written to the port makes garmin_write() call usb_kill_urb() and usb_reset_device(). Both sleep, but the write operation of a tty driver must not: a line discipline may call it in atomic context, synchronous PPP for one under a spinlock with bottom halves disabled. In addition usb_reset_device() has to be called with the device locked, which it is not here.

The reset also unbinds the driver inside the write: the disconnect hangs the tty up, ppp_sync_close() calls ppp_unregister_channel(), and that spins on pch->downl, which the writer holds. The CPU is lost.

Unlink the URB and use usb_queue_reset_device(), which locks the device and resets it from a work item.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>

---
Johan, this was sent to me, but I really don't know if PPP is used for this device to talk to the port or not. If not, this isn't a real issue, but if it is, then maybe it is? I can't tell so I'm tossing it to you :)

 drivers/usb/serial/garmin_gps.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/usb/serial/garmin_gps.c +5 -9
index 8020149f5658..c2b29a7a6674 100644
@@ -818,10 +818,9 @@ static void priv_status_resp(struct usb_serial_port *port)
  * Garmin specific driver functions
  ******************************************************************************/
 
-static int process_resetdev_request(struct usb_serial_port *port)
+static void process_resetdev_request(struct usb_serial_port *port)
 {
 	unsigned long flags;
-	int status;
 	struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
 
 	spin_lock_irqsave(&garmin_data_p->lock, flags);
@@ -830,13 +829,10 @@ static int process_resetdev_request(struct usb_serial_port *port)
 	garmin_data_p->serial_num = 0;
 	spin_unlock_irqrestore(&garmin_data_p->lock, flags);
 
-	usb_kill_urb(port->interrupt_in_urb);
-	dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__);
-	status = usb_reset_device(port->serial->dev);
-	if (status)
-		dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n",
-			__func__, status);
-	return status;
+	/* This is called by the write operation, which must not sleep */
+	usb_unlink_urb(port->interrupt_in_urb);
+	dev_dbg(&port->dev, "%s - usb_queue_reset_device\n", __func__);
+	usb_queue_reset_device(port->serial->interface);
 }
 
 
Signature · 1 line
2.56.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

From: Josef Bacik <[email protected]>

A private packet with the ID PRIV_PKTID_RESET_REQ that is written to the port makes garmin_write() call usb_kill_urb() and usb_reset_device(). Both sleep, but the write operation of a tty driver must not: a line discipline may call it in atomic context, synchronous PPP for one under a spinlock with bottom halves disabled. In addition usb_reset_device() has to be called with the device locked, which it is not here.

The reset also unbinds the driver inside the write: the disconnect hangs the tty up, ppp_sync_close() calls ppp_unregister_channel(), and that spins on pch->downl, which the writer holds. The CPU is lost.

Quoted 7 lines

Unlink the URB and use usb_queue_reset_device(), which locks the device and resets it from a work item.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/2026102733-prayer-drainer-56f3@gregkh?part=1
maintainer
#2 lore raw
In reply to Greg Kroah-Hartman
Quoted 20 lines · Greg Kroah-Hartman

From: Josef Bacik <[email protected]>

A private packet with the ID PRIV_PKTID_RESET_REQ that is written to the port makes garmin_write() call usb_kill_urb() and usb_reset_device(). Both sleep, but the write operation of a tty driver must not: a line discipline may call it in atomic context, synchronous PPP for one under a spinlock with bottom halves disabled. In addition usb_reset_device() has to be called with the device locked, which it is not here.

The reset also unbinds the driver inside the write: the disconnect hangs the tty up, ppp_sync_close() calls ppp_unregister_channel(), and that spins on pch->downl, which the writer holds. The CPU is lost.

Unlink the URB and use usb_queue_reset_device(), which locks the device and resets it from a work item.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>
Quoted 5 lines

---
Johan, this was sent to me, but I really don't know if PPP is used for this device to talk to the port or not. If not, this isn't a real issue, but if it is, then maybe it is? I can't tell so I'm tossing it to you :)

No, you would not use PPP with this device, but if someone tried to I don't believe they would be able to trigger the reset due the PPP packet framing not matching the garmin_gps header format.

So basically the patch is fine but the commit message is misleading.

You will still get a deadlock with the default line discipline however so that's enough of a motivation to fix this (even if that doesn't wedge a CPU).

drivers/usb/serial/garmin_gps.c static int process_resetdev_request(struct usb_serial_port *port) · line 833

Quoted 9 lines
drivers/usb/serial/garmin_gps.c +2 -7
-	usb_kill_urb(port->interrupt_in_urb);
-	dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__);
-	status = usb_reset_device(port->serial->dev);
-	if (status)
-		dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n",
-			__func__, status);
-	return status;
+	/* This is called by the write operation, which must not sleep */
+	usb_unlink_urb(port->interrupt_in_urb);

USB core will unlink (and the driver will kill) all three URBs as part of disconnect so I think we can just drop the interrupt-in unlink here.

drivers/usb/serial/garmin_gps.c static int process_resetdev_request(struct usb_serial_port *port) · line 836

Quoted 3 lines
drivers/usb/serial/garmin_gps.c +2 -0
+	dev_dbg(&port->dev, "%s - usb_queue_reset_device\n", __func__);
+	usb_queue_reset_device(port->serial->interface);
 }

Josef, do you want a send a v2 of this or shall I treat this patch as a bug report and fix it up myself?

Johan

author maintainer
#3 lore raw
Quoted 50 lines · Johan Hovold
Quoted 20 lines · Greg Kroah-Hartman

From: Josef Bacik <[email protected]>

A private packet with the ID PRIV_PKTID_RESET_REQ that is written to the port makes garmin_write() call usb_kill_urb() and usb_reset_device(). Both sleep, but the write operation of a tty driver must not: a line discipline may call it in atomic context, synchronous PPP for one under a spinlock with bottom halves disabled. In addition usb_reset_device() has to be called with the device locked, which it is not here.

The reset also unbinds the driver inside the write: the disconnect hangs the tty up, ppp_sync_close() calls ppp_unregister_channel(), and that spins on pch->downl, which the writer holds. The CPU is lost.

Unlink the URB and use usb_queue_reset_device(), which locks the device and resets it from a work item.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>
Quoted 5 lines

---
Johan, this was sent to me, but I really don't know if PPP is used for this device to talk to the port or not. If not, this isn't a real issue, but if it is, then maybe it is? I can't tell so I'm tossing it to you :)

No, you would not use PPP with this device, but if someone tried to I don't believe they would be able to trigger the reset due the PPP packet framing not matching the garmin_gps header format.

So basically the patch is fine but the commit message is misleading.

You will still get a deadlock with the default line discipline however so that's enough of a motivation to fix this (even if that doesn't wedge a CPU).

drivers/usb/serial/garmin_gps.c static int process_resetdev_request(struct usb_serial_port *port) · line 833

Quoted 9 lines
drivers/usb/serial/garmin_gps.c +2 -7
-	usb_kill_urb(port->interrupt_in_urb);
-	dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__);
-	status = usb_reset_device(port->serial->dev);
-	if (status)
-		dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n",
-			__func__, status);
-	return status;
+	/* This is called by the write operation, which must not sleep */
+	usb_unlink_urb(port->interrupt_in_urb);

USB core will unlink (and the driver will kill) all three URBs as part of disconnect so I think we can just drop the interrupt-in unlink here.

Quoted 6 lines

drivers/usb/serial/garmin_gps.c static int process_resetdev_request(struct usb_serial_port *port) · line 836

Quoted 3 lines
drivers/usb/serial/garmin_gps.c +2 -0
+	dev_dbg(&port->dev, "%s - usb_queue_reset_device\n", __func__);
+	usb_queue_reset_device(port->serial->interface);
 }

Josef, do you want a send a v2 of this or shall I treat this patch as a bug report and fix it up myself?

I'm guessing at Josef's current load, so it might just be faster for you to fix it up yourself :)

thanks,

greg k-h

maintainer
#4 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 2 lines · Johan Hovold

Josef, do you want a send a v2 of this or shall I treat this patch as a bug report and fix it up myself?

I'm guessing at Josef's current load, so it might just be faster for you to fix it up yourself :)

That was my guess as well. I'll do so.

Johan