Skip to contentSkip to conversation

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

PATCH In review Tristan Madani 3 participants 3 messages Oct 19 – Oct 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

From: Tristan Madani <[email protected]>

sierra_instat_callback() reads request fields and one byte past the usb_ctrlrequest header without first checking that urb->actual_length is large enough. A short USB interrupt transfer could cause an out-of-bounds read.

Add two length checks matching the pattern already present in the option driver (option_instat_callback): one for the request header before accessing bRequestType, and one for the line-state data byte inside the serial-state notification handler. Use dev_err() since failing these checks causes the interrupt URB not to be resubmitted.

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

---
Changes in v2 (Johan Hovold):
- Split into two checks: one for the header before accessing bRequestType, and one for the line-state data byte inside the serial-state handler, matching the option driver pattern
- Use dev_err() instead of dev_dbg() since early return prevents further interrupts

 drivers/usb/serial/sierra.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/usb/serial/sierra.c +14 -1
index 6e443aacae07d..03ed76dfbb2e3 100644
@@ -575,10 +575,23 @@ static void sierra_instat_callback(struct urb *urb)
 				__func__);
 			return;
 		}
+		if (urb->actual_length < sizeof(*req_pkt)) {
+			dev_err(&port->dev, "%s: short transfer\n",
+				__func__);
+			return;
+		}
 		if ((req_pkt->bRequestType == 0xA1) &&
 				(req_pkt->bRequest == 0x20)) {
 			int old_dcd_state;
-			unsigned char signals = *((unsigned char *)
+			unsigned char signals;
+
+			if (urb->actual_length < sizeof(*req_pkt) + 1) {
+				dev_err(&port->dev,
+					"%s: short interrupt transfer\n",
+					__func__);
+				return;
+			}
+			signals = *((unsigned char *)
 					urb->transfer_buffer +
 					sizeof(struct usb_ctrlrequest));
 
Signature · 1 line
2.47.3
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

From: Tristan Madani <[email protected]>

sierra_instat_callback() reads request fields and one byte past the usb_ctrlrequest header without first checking that urb->actual_length is large enough. A short USB interrupt transfer could cause an out-of-bounds read.

Add two length checks matching the pattern already present in the option driver (option_instat_callback): one for the request header before accessing bRequestType, and one for the line-state data byte inside the serial-state notification handler. Use dev_err() since failing these checks causes the interrupt URB not to be resubmitted.

Quoted 3 lines
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 16 lines · Tristan Madani

From: Tristan Madani <[email protected]>

sierra_instat_callback() reads request fields and one byte past the usb_ctrlrequest header without first checking that urb->actual_length is large enough. A short USB interrupt transfer could cause an out-of-bounds read.

Add two length checks matching the pattern already present in the option driver (option_instat_callback): one for the request header before accessing bRequestType, and one for the line-state data byte inside the serial-state notification handler. Use dev_err() since failing these checks causes the interrupt URB not to be resubmitted.

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

---
Changes in v2 (Johan Hovold):
- Split into two checks: one for the header before accessing bRequestType, and one for the line-state data byte inside the serial-state handler, matching the option driver pattern
- Use dev_err() instead of dev_dbg() since early return prevents further interrupts

Thanks for the update.

Now applied, with one change below.

Quoted 21 lines
 drivers/usb/serial/sierra.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/usb/serial/sierra.c +6 -1
index 6e443aacae07d..03ed76dfbb2e3 100644
@@ -575,10 +575,23 @@ static void sierra_instat_callback(struct urb *urb)
 				__func__);
 			return;
 		}
+		if (urb->actual_length < sizeof(*req_pkt)) {
+			dev_err(&port->dev, "%s: short transfer\n",
+				__func__);
+			return;
+		}
 		if ((req_pkt->bRequestType == 0xA1) &&
 				(req_pkt->bRequest == 0x20)) {
 			int old_dcd_state;
-			unsigned char signals = *((unsigned char *)
+			unsigned char signals;

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

Quoted 10 lines
drivers/usb/serial/sierra.c +8 -0
+
+			if (urb->actual_length < sizeof(*req_pkt) + 1) {
+				dev_err(&port->dev,
+					"%s: short interrupt transfer\n",
+					__func__);
+				return;
+			}
+			signals = *((unsigned char *)
 					urb->transfer_buffer +
 					sizeof(struct usb_ctrlrequest));

I used sizeof(*req_pkt) here too for consistency.

Johan