* [PATCH 1/2] USB: serial: ti_usb_3410_5052: fix port-close races
@ 2019-10-11 9:57 Johan Hovold
2019-10-11 9:57 ` [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access Johan Hovold
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2019-10-11 9:57 UTC (permalink / raw)
To: linux-usb; +Cc: Greg Kroah-Hartman, Johan Hovold, stable
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 <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/ti_usb_3410_5052.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index dd0ad67aa71e..9174ba2e06da 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -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);
}
--
2.23.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access
2019-10-11 9:57 [PATCH 1/2] USB: serial: ti_usb_3410_5052: fix port-close races Johan Hovold
@ 2019-10-11 9:57 ` Johan Hovold
2019-10-11 10:00 ` Johan Hovold
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2019-10-11 9:57 UTC (permalink / raw)
To: linux-usb; +Cc: Greg Kroah-Hartman, Johan Hovold
Use the tdev pointer directly instead of going through the port data
when accessing the serial data in open().
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/ti_usb_3410_5052.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 9174ba2e06da..ef23acc9b9ce 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -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);
}
--
2.23.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access
2019-10-11 9:57 ` [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access Johan Hovold
@ 2019-10-11 10:00 ` Johan Hovold
0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2019-10-11 10:00 UTC (permalink / raw)
To: linux-usb; +Cc: Greg Kroah-Hartman, Johan Hovold
On Fri, Oct 11, 2019 at 11:57:36AM +0200, Johan Hovold wrote:
> Use the tdev pointer directly instead of going through the port data
> when accessing the serial data in open().
hmm, s/open/close/.
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/usb/serial/ti_usb_3410_5052.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
> index 9174ba2e06da..ef23acc9b9ce 100644
> --- a/drivers/usb/serial/ti_usb_3410_5052.c
> +++ b/drivers/usb/serial/ti_usb_3410_5052.c
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-11 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 9:57 [PATCH 1/2] USB: serial: ti_usb_3410_5052: fix port-close races Johan Hovold
2019-10-11 9:57 ` [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access Johan Hovold
2019-10-11 10:00 ` Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).