aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2020-07-15 11:02:45 +0200
committerJohan Hovold <johan@kernel.org>2020-07-16 10:20:21 +0200
commite7b931bee739e8a77ae216e613d3b99342b6dec0 (patch)
tree12acbe9e68c39c3c42f05159a818c0c3bf994e52
parentda6902e5b6dbca9081e3d377f9802d4fd0c5ea59 (diff)
downloadmvebu-e7b931bee739e8a77ae216e613d3b99342b6dec0.tar.gz
USB: serial: iuu_phoenix: fix memory corruption
The driver would happily overwrite its write buffer with user data in 256 byte increments due to a removed buffer-space sanity check. Fixes: 5fcf62b0f1f2 ("tty: iuu_phoenix: fix locking.") Cc: stable <stable@vger.kernel.org> # 2.6.31 Signed-off-by: Johan Hovold <johan@kernel.org>
-rw-r--r--drivers/usb/serial/iuu_phoenix.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index d5bff69b1769b2..b8dfeb4fb2ed6e 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -697,14 +697,16 @@ static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port,
struct iuu_private *priv = usb_get_serial_port_data(port);
unsigned long flags;
- if (count > 256)
- return -ENOMEM;
-
spin_lock_irqsave(&priv->lock, flags);
+ count = min(count, 256 - priv->writelen);
+ if (count == 0)
+ goto out;
+
/* fill the buffer */
memcpy(priv->writebuf + priv->writelen, buf, count);
priv->writelen += count;
+out:
spin_unlock_irqrestore(&priv->lock, flags);
return count;