USB: serial: ti_usb_3410_5052: fix port-close races
Subsystems (3)
Johan Hovold
maintainerPATCH 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.
--- 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
@@ -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
Johan Hovold
maintainerPATCH 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
@@ -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
Johan Hovold
maintainerRe: [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
Signed-off-by Johan Hovold <[email protected]>--- 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
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