Skip to contentSkip to conversation

USB: serial: spcp8x5: fix modem-status handling

PATCH New Johan Hovold 1 participant 3 messages Jan 12, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Johan Hovold

author maintainer
#1 lore raw

PATCH 1/15 USB: serial: ark3116: fix register-accessor error handling

The current implementation failed to detect short transfers, something which could lead to bits of the uninitialised heap transfer buffer leaking to user space.

Fixes 149fc791a452 ("USB: ark3116: Setup some basic infrastructure for

new ark3116 driver.")

Fixes f4c1e8d597d1 ("USB: ark3116: Make existing functions 16450-aware

and add close and release functions.")

---
 drivers/usb/serial/ark3116.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/usb/serial/ark3116.c +10 -3
index 1532cde8a437..7812052dc700 100644
@@ -99,10 +99,17 @@ static int ark3116_read_reg(struct usb_serial *serial,
 				 usb_rcvctrlpipe(serial->dev, 0),
 				 0xfe, 0xc0, 0, reg,
 				 buf, 1, ARK_TIMEOUT);
-	if (result < 0)
+	if (result < 1) {
+		dev_err(&serial->interface->dev,
+				"failed to read register %u: %d\n",
+				reg, result);
+		if (result >= 0)
+			result = -EIO;
+
 		return result;
-	else
-		return buf[0];
+	}
+
+	return buf[0];
 }
 
 static inline int calc_divisor(int bps)
Signature · 1 line
2.10.2
author maintainer
#2 lore raw

PATCH 3/15 USB: serial: ftdi_sio: fix modem-status error handling

In reply to a message not in the archive

Make sure to detect short responses when fetching the modem status in order to avoid parsing uninitialised buffer data and having bits of it leak to user space.

Note that we still allow for short 1-byte responses.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>
---
 drivers/usb/serial/ftdi_sio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/serial/ftdi_sio.c +5 -1
index 23d14b98ae2a..6dee20fc7e45 100644
@@ -2428,8 +2428,12 @@ static int ftdi_get_modem_status(struct usb_serial_port *port,
 			FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
 			0, priv->interface,
 			buf, len, WDR_TIMEOUT);
-	if (ret < 0) {
+
+	/* NOTE: We allow short responses and handle that below. */
+	if (ret < 1) {
 		dev_err(&port->dev, "failed to get modem status: %d\n", ret);
+		if (ret >= 0)
+			ret = -EIO;
 		ret = usb_translate_errors(ret);
 		goto out;
 	}
Signature · 1 line
2.10.2
author maintainer
#3 lore raw

PATCH 13/15 USB: serial: spcp8x5: fix modem-status handling

In reply to a message not in the archive

Make sure to detect short control transfers and return zero on success when retrieving the modem status.

This fixes the TIOCMGET implementation which since e1ed212d8593 ("USB:
spcp8x5: add proper modem-status support") has returned TIOCM_LE on successful retrieval, and avoids leaking bits from the stack on short transfers.

This also fixes the carrier-detect implementation which since the above mentioned commit unconditionally has returned true.

Fixes e1ed212d8593 ("USB: spcp8x5: add proper modem-status support")
Cc stable <[email protected]>
---
 drivers/usb/serial/spcp8x5.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/usb/serial/spcp8x5.c +7 -1
index 475e6c31b266..ddfd787c461c 100644
@@ -232,11 +232,17 @@ static int spcp8x5_get_msr(struct usb_serial_port *port, u8 *status)
 	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
 			      GET_UART_STATUS, GET_UART_STATUS_TYPE,
 			      0, GET_UART_STATUS_MSR, buf, 1, 100);
-	if (ret < 0)
+	if (ret < 1) {
 		dev_err(&port->dev, "failed to get modem status: %d\n", ret);
+		if (ret >= 0)
+			ret = -EIO;
+		goto out;
+	}
 
 	dev_dbg(&port->dev, "0xc0:0x22:0:6  %d - 0x02%x\n", ret, *buf);
 	*status = *buf;
+	ret = 0;
+out:
 	kfree(buf);
 
 	return ret;
Signature · 1 line
2.10.2