FAILED: patch "[PATCH] USB: serial: fix ioctl hangup race" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x ae0e61d95677efa778379853e495d748e6efbf95
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100508-radish-overtone-e471@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ae0e61d95677efa778379853e495d748e6efbf95 Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Thu, 3 Sep 2026 18:31:46 +0200
Subject: [PATCH] USB: serial: fix ioctl hangup race
The tty ioctls can race with hangup and end up calling into a tty driver for a device that is already gone or powered down.
Serialise the callbacks using the tty port mutex and add the missing checks to make sure the port has not been hung up before accessing port driver data or hardware.
This specifically avoids dereferencing a NULL-pointer if a device is disconnected during lengthy break signalling.
Note that TIOCGICOUNT and TIOCMIWAIT do not access port driver data or hardware and are therefore not affected by the race.
drivers/usb/serial/generic.c +9 -1
@@ -266,6 +266,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);void usb_serial_generic_wait_until_sent (struct tty_struct *tty,long timeout) {struct usb_serial_port *port = tty->driver_data; +struct tty_port *tport = &port->port;unsigned int bps;unsigned long period;unsigned long expire;
@@ -285,7 +286,14 @@ void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout) __func__,jiffies_to_msecs (timeout), jiffies_to_msecs(period)); expire = jiffies + timeout; -while (!port->serial->type->tx_empty (port)) { +for (;;) { +mutex_lock (&tport->mutex); +if (tty_io_error (tty) || port->serial->type->tx_empty (port)) { +mutex_unlock (&tport->mutex); +break ; + } +mutex_unlock (&tport->mutex); +schedule_timeout_interruptible (period);if (signal_pending (current))break ;
drivers/usb/serial/usb-serial.c +74 -20
178 lines not on this page · raw message
drivers/usb/serial/xr_serial.c +3 -7
@@ -850,12 +850,9 @@ static int xr_get_rs485_config(struct tty_struct *tty,struct usb_serial_port *port = tty->driver_data;struct xr_data *data =usb_get_serial_port_data (port); -down_read (&tty->termios_rwsem); -if (copy_to_user (argp, &data->rs485,sizeof (data->rs485))) { -up_read (&tty->termios_rwsem); +/* core holds port mutex */ +if (copy_to_user (argp, &data->rs485,sizeof (data->rs485)))return -EFAULT ; - } -up_read (&tty->termios_rwsem);return 0 ; }
@@ -871,10 +868,9 @@ static int xr_set_rs485_config(struct tty_struct *tty,return -EFAULT ;xr_sanitize_serial_rs485 (&rs485); -down_write (&tty->termios_rwsem); +/* core holds termios rwsem and port mutex */ data->rs485 = rs485;xr_set_flow_mode (tty, port,NULL ); -up_write (&tty->termios_rwsem);if (copy_to_user (argp, &rs485,sizeof (rs485)))return -EFAULT ;
Sasha Levin
maintainerPATCH 1/1 USB: serial: fix ioctl hangup race
From: Johan Hovold <[email protected]>
[ Upstream commit ae0e61d95677efa778379853e495d748e6efbf95 ]
The tty ioctls can race with hangup and end up calling into a tty driver for a device that is already gone or powered down.
Serialise the callbacks using the tty port mutex and add the missing checks to make sure the port has not been hung up before accessing port driver data or hardware.
This specifically avoids dereferencing a NULL-pointer if a device is disconnected during lengthy break signalling.
Note that TIOCGICOUNT and TIOCMIWAIT do not access port driver data or hardware and are therefore not affected by the race.
--- drivers/usb/serial/generic.c | 10 ++- drivers/usb/serial/usb-serial.c | 111 +++++++++++++++++++++++++------- drivers/usb/serial/usb_wwan.c | 6 +- 3 files changed, 99 insertions(+), 28 deletions(-)
drivers/usb/serial/generic.c +9 -1
@@ -268,6 +268,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);void usb_serial_generic_wait_until_sent (struct tty_struct *tty,long timeout) {struct usb_serial_port *port = tty->driver_data; +struct tty_port *tport = &port->port;unsigned int bps;unsigned long period;unsigned long expire;
@@ -287,7 +288,14 @@ void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout) __func__,jiffies_to_msecs (timeout), jiffies_to_msecs(period)); expire = jiffies + timeout; -while (!port->serial->type->tx_empty (port)) { +for (;;) { +mutex_lock (&tport->mutex); +if (tty_io_error (tty) || port->serial->type->tx_empty (port)) { +mutex_unlock (&tport->mutex); +break ; + } +mutex_unlock (&tport->mutex); +schedule_timeout_interruptible (period);if (signal_pending (current))break ;
drivers/usb/serial/usb-serial.c +88 -23
187 lines not on this page · raw message
drivers/usb/serial/usb_wwan.c +2 -4
@@ -139,7 +139,7 @@ int usb_wwan_get_serial_info(struct tty_struct *tty, ss->line = port->minor; ss->port = port->port_number; - ss->baud_base =tty_get_baud_rate (port->port.tty); + ss->baud_base =tty_get_baud_rate (tty); ss->close_delay =jiffies_to_msecs (port->port.close_delay) /10 ; ss->closing_wait = port->port.closing_wait ==ASYNC_CLOSING_WAIT_NONE ? ASYNC_CLOSING_WAIT_NONE :
@@ -160,8 +160,7 @@ int usb_wwan_set_serial_info(struct tty_struct *tty, ASYNC_CLOSING_WAIT_NONE :msecs_to_jiffies (ss->closing_wait *10 ); -mutex_lock (&port->port.mutex); - +/* core holds the port mutex */ if (!capable (CAP_SYS_ADMIN )) {if ((close_delay != port->port.close_delay) || (closing_wait != port->port.closing_wait))
@@ -173,7 +172,6 @@ int usb_wwan_set_serial_info(struct tty_struct *tty, port->port.closing_wait = closing_wait; } -mutex_unlock (&port->port.mutex);return retval; }EXPORT_SYMBOL (usb_wwan_set_serial_info);
Signature · 1 line
2.53.0