Skip to contentSkip to conversation

USB: serial: sierra: validate URB length in instat callback

PATCH Superseded Tristan Madani 3 participants 3 messages Oct 18 – Oct 19

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: serial: sierra: validate URB length in instat callback

From: Tristan Madani <[email protected]>

sierra_instat_callback() reads one byte past the usb_ctrlrequest header at offset sizeof(struct usb_ctrlrequest) without first checking that urb->actual_length is large enough to contain it. A short USB interrupt transfer could cause an out-of-bounds read.

Add a length check matching the pattern already present in the option driver (option_instat_callback), which validates the same field access.

Fixes 033a3fb980b041 ("USB: Sierra Wireless driver update")
---
 drivers/usb/serial/sierra.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/serial/sierra.c +5 -0
index 6e443aacae07d..8f800cde25229 100644
@@ -575,6 +575,11 @@ static void sierra_instat_callback(struct urb *urb)
 				__func__);
 			return;
 		}
+		if (urb->actual_length < sizeof(*req_pkt) + 1) {
+			dev_dbg(&port->dev, "%s: short interrupt transfer\n",
+				__func__);
+			return;
+		}
 		if ((req_pkt->bRequestType == 0xA1) &&
 				(req_pkt->bRequest == 0x20)) {
 			int old_dcd_state;
Signature · 1 line
2.47.3
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

From: Tristan Madani <[email protected]>

sierra_instat_callback() reads one byte past the usb_ctrlrequest header at offset sizeof(struct usb_ctrlrequest) without first checking that urb->actual_length is large enough to contain it. A short USB interrupt transfer could cause an out-of-bounds read.

Quoted 7 lines

Add a length check matching the pattern already present in the option driver (option_instat_callback), which validates the same field access.

Fixes 033a3fb980b041 ("USB: Sierra Wireless driver update")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Tristan Madani
Quoted 23 lines · Tristan Madani

From: Tristan Madani <[email protected]>

sierra_instat_callback() reads one byte past the usb_ctrlrequest header at offset sizeof(struct usb_ctrlrequest) without first checking that urb->actual_length is large enough to contain it. A short USB interrupt transfer could cause an out-of-bounds read.

Add a length check matching the pattern already present in the option driver (option_instat_callback), which validates the same field access.

Fixes 033a3fb980b041 ("USB: Sierra Wireless driver update")
---
 drivers/usb/serial/sierra.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/serial/sierra.c +0 -0
index 6e443aacae07d..8f800cde25229 100644

drivers/usb/serial/sierra.c static void sierra_instat_callback(struct urb *urb) · line 582

Quoted 8 lines
drivers/usb/serial/sierra.c +5 -0
@@ -575,6 +575,11 @@ static void sierra_instat_callback(struct urb *urb)
 				__func__);
 			return;
 		}
+		if (urb->actual_length < sizeof(*req_pkt) + 1) {
+			dev_dbg(&port->dev, "%s: short interrupt transfer\n",
+				__func__);
+			return;
+		}

This silently breaks a theoretical device that submits requests without payload not yet handled by the driver (the else branch below).

Please split this up in two checks; one for the header and one for the line state data as in the option driver.

And since you prevent any further interrupts if you ever hit this, you should use dev_err().

drivers/usb/serial/sierra.c static void sierra_instat_callback(struct urb *urb) · line 585

Quoted 3 lines
drivers/usb/serial/sierra.c +0 -0
 		if ((req_pkt->bRequestType == 0xA1) &&
 				(req_pkt->bRequest == 0x20)) {
 			int old_dcd_state;

Johan