USB: ssu100: 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: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Johan Hovold 2013-03-19 09:21:25 +01:00 committed by Greg Kroah-Hartman
parent dbcea7615d
commit 43a66b4c41
1 changed files with 7 additions and 5 deletions

View File

@ -61,7 +61,6 @@ struct ssu100_port_private {
spinlock_t status_lock; spinlock_t status_lock;
u8 shadowLSR; u8 shadowLSR;
u8 shadowMSR; u8 shadowMSR;
wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
struct async_icount icount; struct async_icount icount;
}; };
@ -355,8 +354,9 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
spin_unlock_irqrestore(&priv->status_lock, flags); spin_unlock_irqrestore(&priv->status_lock, flags);
while (1) { while (1) {
wait_event_interruptible(priv->delta_msr_wait, wait_event_interruptible(port->delta_msr_wait,
((priv->icount.rng != prev.rng) || (port->serial->disconnected ||
(priv->icount.rng != prev.rng) ||
(priv->icount.dsr != prev.dsr) || (priv->icount.dsr != prev.dsr) ||
(priv->icount.dcd != prev.dcd) || (priv->icount.dcd != prev.dcd) ||
(priv->icount.cts != prev.cts))); (priv->icount.cts != prev.cts)));
@ -364,6 +364,9 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
if (signal_pending(current)) if (signal_pending(current))
return -ERESTARTSYS; return -ERESTARTSYS;
if (port->serial->disconnected)
return -EIO;
spin_lock_irqsave(&priv->status_lock, flags); spin_lock_irqsave(&priv->status_lock, flags);
cur = priv->icount; cur = priv->icount;
spin_unlock_irqrestore(&priv->status_lock, flags); spin_unlock_irqrestore(&priv->status_lock, flags);
@ -445,7 +448,6 @@ static int ssu100_port_probe(struct usb_serial_port *port)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&priv->status_lock); spin_lock_init(&priv->status_lock);
init_waitqueue_head(&priv->delta_msr_wait);
usb_set_serial_port_data(port, priv); usb_set_serial_port_data(port, priv);
@ -537,7 +539,7 @@ static void ssu100_update_msr(struct usb_serial_port *port, u8 msr)
priv->icount.dcd++; priv->icount.dcd++;
if (msr & UART_MSR_TERI) if (msr & UART_MSR_TERI)
priv->icount.rng++; priv->icount.rng++;
wake_up_interruptible(&priv->delta_msr_wait); wake_up_interruptible(&port->delta_msr_wait);
} }
} }