Skip to contentSkip to conversation

USB: serial: ti_usb_3410_5052: fix port-close races

PATCH In review Johan Hovold 1 participant 3 messages Oct 11, 2019

Subsystems (3)
lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

PATCH 1/2 USB: serial: ti_usb_3410_5052: fix port-close races

Fix races between closing a port and opening or closing another port on the same device which could lead to a failure to start or stop the shared interrupt URB. The latter could potentially cause a use-after-free or worse in the completion handler on driver unbind.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>
---
 drivers/usb/serial/ti_usb_3410_5052.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/usb/serial/ti_usb_3410_5052.c +3 -7
index dd0ad67aa71e..9174ba2e06da 100644
@@ -776,7 +776,6 @@ static void ti_close(struct usb_serial_port *port)
 	struct ti_port *tport;
 	int port_number;
 	int status;
-	int do_unlock;
 	unsigned long flags;
 
 	tdev = usb_get_serial_data(port->serial);
@@ -800,16 +799,13 @@ static void ti_close(struct usb_serial_port *port)
 			"%s - cannot send close port command, %d\n"
 							, __func__, status);
 
-	/* if mutex_lock is interrupted, continue anyway */
-	do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock);
+	mutex_lock(&tdev->td_open_close_lock);
 	--tport->tp_tdev->td_open_port_count;
-	if (tport->tp_tdev->td_open_port_count <= 0) {
+	if (tport->tp_tdev->td_open_port_count == 0) {
 		/* last port is closed, shut down interrupt urb */
 		usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
-		tport->tp_tdev->td_open_port_count = 0;
 	}
-	if (do_unlock)
-		mutex_unlock(&tdev->td_open_close_lock);
+	mutex_unlock(&tdev->td_open_close_lock);
 }
 
 
Signature · 1 line
2.23.0
author maintainer
#1 lore raw

PATCH 2/2 USB: serial: ti_usb_3410_5052: clean up serial data access

Use the tdev pointer directly instead of going through the port data when accessing the serial data in open().

---
 drivers/usb/serial/ti_usb_3410_5052.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/ti_usb_3410_5052.c +2 -2
index 9174ba2e06da..ef23acc9b9ce 100644
@@ -800,8 +800,8 @@ static void ti_close(struct usb_serial_port *port)
 							, __func__, status);
 
 	mutex_lock(&tdev->td_open_close_lock);
-	--tport->tp_tdev->td_open_port_count;
-	if (tport->tp_tdev->td_open_port_count == 0) {
+	--tdev->td_open_port_count;
+	if (tdev->td_open_port_count == 0) {
 		/* last port is closed, shut down interrupt urb */
 		usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
 	}
Signature · 1 line
2.23.0
author maintainer
#2 lore raw

Re: [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access

Quoted 2 lines · Johan Hovold

Use the tdev pointer directly instead of going through the port data when accessing the serial data in open().

hmm, s/open/close/.

Quoted 10 lines
---
 drivers/usb/serial/ti_usb_3410_5052.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/ti_usb_3410_5052.c +0 -0
index 9174ba2e06da..ef23acc9b9ce 100644

drivers/usb/serial/ti_usb_3410_5052.c static void ti_close(struct usb_serial_port *port) · line 807

Quoted 10 lines
drivers/usb/serial/ti_usb_3410_5052.c +2 -2
@@ -800,8 +800,8 @@ static void ti_close(struct usb_serial_port *port)
 							, __func__, status);
 
 	mutex_lock(&tdev->td_open_close_lock);
-	--tport->tp_tdev->td_open_port_count;
-	if (tport->tp_tdev->td_open_port_count == 0) {
+	--tdev->td_open_port_count;
+	if (tdev->td_open_port_count == 0) {
 		/* last port is closed, shut down interrupt urb */
 		usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
 	}

Johan