USB: serial: sierra: validate URB length in instat callback
Subsystems (3)
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.
--- drivers/usb/serial/sierra.c | 5 +++++ 1 file changed, 5 insertions(+)
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 ; + }if ((req_pkt->bRequestType ==0xA1 ) && (req_pkt->bRequest ==0x20 )) {int old_dcd_state;
Signature · 1 line
2.47.3
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Tristan Madani <[email protected]>
sierra_instat_callback()reads one byte past theusb_ctrlrequestheader at offsetsizeof(struct usb_ctrlrequest)without first checking thaturb->actual_lengthis 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")Signed-off-by Tristan Madani <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Johan Hovold
maintainerQuoted 23 lines · Tristan Madani
From: Tristan Madani <[email protected]>
sierra_instat_callback()reads one byte past theusb_ctrlrequestheader at offsetsizeof(struct usb_ctrlrequest)without first checking thaturb->actual_lengthis 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")Signed-off-by Tristan Madani <[email protected]>--- drivers/usb/serial/sierra.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/serial/sierra.c +0
-0
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
-0if ((req_pkt->bRequestType ==0xA1 ) && (req_pkt->bRequest ==0x20 )) {int old_dcd_state;
Johan