Skip to contentSkip to conversation

usb: musb: Fix musb_gadget.c rxstate may cause request->buf overflow problems

PATCH In review Andy Guo (郭卫斌) 2 participants 5 messages Jul 27, 2022 – Jul 28, 2022

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

PATCH v2 1/1 usb: musb: Fix musb_gadget.c rxstate may cause request->buf overflow problems

From: guoweibin <[email protected]>

when the rxstate function executes the 'goto buffer_aint_mapped' code branch, it will always copy the fifocnt bytes data to request->buf, which may cause request->buf out of bounds. for Ethernet-over-USB will cause skb_over_panic when a packet larger than mtu is recived.

Fix it by add the length check :
fifocnt = min_t(unsigned, request->length - request->actual, fifocnt);

---
v2:
-fix format error

 drivers/usb/musb/musb_gadget.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/musb/musb_gadget.c +1 -0
index 51274b87f46c..4ad5a1f31d7e 100644
@@ -760,6 +760,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
 			musb_writew(epio, MUSB_RXCSR, csr);
 
 buffer_aint_mapped:
+			fifo_count = min_t(unsigned, request->length - request->actual, fifo_count);
 			musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *)
 					(request->buf + request->actual));
 			request->actual += fifo_count;
#1 lore raw
Quoted 1 line · Andy Guo (郭卫斌)

From: guoweibin <[email protected]>

Your From: in your email has your real name, why not use that instead of just putting your email alias here?

Quoted 5 lines

when the rxstate function executes the 'goto buffer_aint_mapped' code branch, it will always copy the fifocnt bytes data to request->buf, which may cause request->buf out of bounds. for Ethernet-over-USB will cause skb_over_panic when a packet larger than mtu is recived.

How can we get a bigger packet than mtu?

Quoted 5 lines

Fix it by add the length check :
fifocnt = min_t(unsigned, request->length - request->actual, fifocnt);

Same here.

Quoted 11 lines

---
v2:

(quoted diff) +0 -1
-fix format error
 drivers/usb/musb/musb_gadget.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/musb/musb_gadget.c +0 -0
index 51274b87f46c..4ad5a1f31d7e 100644

drivers/usb/musb/musb_gadget.c static void rxstate(struct musb *musb, struct musb_request *req) · line 763

Quoted 4 lines
drivers/usb/musb/musb_gadget.c +1 -0
@@ -760,6 +760,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
 			musb_writew(epio, MUSB_RXCSR, csr);
 
 buffer_aint_mapped:
+			fifo_count = min_t(unsigned, request->length - request->actual, fifo_count);

Why the case to "unsigned"?

And if we get a too big packet, shouldn't we drop it?

And what does this have to do with a usb-ethernet device, this is in the generic musb code, not an ethernet driver.

thanks,

greg k-h

#4 lore raw

I'm sorroy,
I use Enterprise mailbox doesn't work very well.
I will send this patch through another mailbox.

Thanks

guoweibin

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, July 28, 2022 2:57 PM
To: Andy Guo (郭卫斌) <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: 答复: [vger.kernel.org代发]Re: [PATCH v2] usb: musb: Fix musb_gadget.c rxstate may cause request->buf overflow problems

On Thu, Jul 28, 2022 at 01:14:17AM +0000, Andy Guo (郭卫斌) wrote:

As can be seen in the archives:

	https://lore.kernel.org/all/[email protected]/

this message could not be decoded, sorry.

Please resend in plain text format.

thanks,

greg k-h