public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Andy Guo (郭卫斌)" <guoweibin@inspur.com>
To: "b-liu@ti.com" <b-liu@ti.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Andy Guo (郭卫斌)" <guoweibin@inspur.com>
Subject: [PATCH v2] usb: musb: Fix musb_gadget.c rxstate may cause request->buf overflow problems
Date: Wed, 27 Jul 2022 08:43:34 +0000	[thread overview]
Message-ID: <200f38d3e3eb44ec8ec8f8e9f210f131@inspur.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]

From: guoweibin <guoweibin@inspur.com>

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);

Signed-off-by: guoweibin <guoweibin@inspur.com>
---
 v2:
-fix format error
 drivers/usb/musb/musb_gadget.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 51274b87f46c..4ad5a1f31d7e 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -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;

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3801 bytes --]

             reply	other threads:[~2022-07-27  8:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27  8:43 Andy Guo (郭卫斌) [this message]
2022-07-27  9:25 ` [PATCH v2] usb: musb: Fix musb_gadget.c rxstate may cause request->buf overflow problems gregkh
2022-07-28  1:14   ` 答复: [vger.kernel.org代发]Re: " Andy Guo (郭卫斌)
2022-07-28  6:56     ` gregkh
2022-07-28 12:24       ` Andy Guo (郭卫斌)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200f38d3e3eb44ec8ec8f8e9f210f131@inspur.com \
    --to=guoweibin@inspur.com \
    --cc=b-liu@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox