Commit fa1e11d5 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: ch341: fix use-after-free in TIOCMIWAIT

Use the port wait queue and make sure to check the serial disconnected
flag before accessing private port data after waking up.

This is is needed as the private port data (including the wait queue
itself) can be gone when waking up after a disconnect.

Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 50188603
...@@ -80,7 +80,6 @@ MODULE_DEVICE_TABLE(usb, id_table); ...@@ -80,7 +80,6 @@ MODULE_DEVICE_TABLE(usb, id_table);
struct ch341_private { struct ch341_private {
spinlock_t lock; /* access lock */ spinlock_t lock; /* access lock */
wait_queue_head_t delta_msr_wait; /* wait queue for modem status */
unsigned baud_rate; /* set baud rate */ unsigned baud_rate; /* set baud rate */
u8 line_control; /* set line control value RTS/DTR */ u8 line_control; /* set line control value RTS/DTR */
u8 line_status; /* active status of modem control inputs */ u8 line_status; /* active status of modem control inputs */
...@@ -252,7 +251,6 @@ static int ch341_port_probe(struct usb_serial_port *port) ...@@ -252,7 +251,6 @@ static int ch341_port_probe(struct usb_serial_port *port)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
init_waitqueue_head(&priv->delta_msr_wait);
priv->baud_rate = DEFAULT_BAUD_RATE; priv->baud_rate = DEFAULT_BAUD_RATE;
priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR; priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
...@@ -298,7 +296,7 @@ static void ch341_dtr_rts(struct usb_serial_port *port, int on) ...@@ -298,7 +296,7 @@ static void ch341_dtr_rts(struct usb_serial_port *port, int on)
priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR); priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR);
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
ch341_set_handshake(port->serial->dev, priv->line_control); ch341_set_handshake(port->serial->dev, priv->line_control);
wake_up_interruptible(&priv->delta_msr_wait); wake_up_interruptible(&port->delta_msr_wait);
} }
static void ch341_close(struct usb_serial_port *port) static void ch341_close(struct usb_serial_port *port)
...@@ -491,7 +489,7 @@ static void ch341_read_int_callback(struct urb *urb) ...@@ -491,7 +489,7 @@ static void ch341_read_int_callback(struct urb *urb)
tty_kref_put(tty); tty_kref_put(tty);
} }
wake_up_interruptible(&priv->delta_msr_wait); wake_up_interruptible(&port->delta_msr_wait);
} }
exit: exit:
...@@ -517,11 +515,14 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) ...@@ -517,11 +515,14 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
while (!multi_change) { while (!multi_change) {
interruptible_sleep_on(&priv->delta_msr_wait); interruptible_sleep_on(&port->delta_msr_wait);
/* see if a signal did it */ /* see if a signal did it */
if (signal_pending(current)) if (signal_pending(current))
return -ERESTARTSYS; return -ERESTARTSYS;
if (port->serial->disconnected)
return -EIO;
spin_lock_irqsave(&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
status = priv->line_status; status = priv->line_status;
multi_change = priv->multi_status_change; multi_change = priv->multi_status_change;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment