From: Szymon Heidrich <szymon.heidrich@gmail.com>
To: u-boot@lists.denx.de
Cc: Szymon Heidrich <szymon.heidrich@gmail.com>
Subject: [PATCH] Prevent buffer overflow on USB control endpoint
Date: Thu, 17 Nov 2022 10:48:47 +0100 [thread overview]
Message-ID: <20221117094847.60409-1-szymon.heidrich@gmail.com> (raw)
In-Reply-To: <CAOMZO5CXJos1Ms=uxfhZ15T9SQhCziz1jgWNtD5QXq2F8=JNZQ@mail.gmail.com>
Assure that the control endpoint buffer of size USB_BUFSIZ (4096)
can not be overflown during handling of USB control transfer
requests with wLength greater than USB_BUFSIZ.
Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com>
---
drivers/usb/gadget/composite.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 2a309e624e..cb89f6dca9 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1019,6 +1019,17 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
u8 endp;
struct usb_configuration *c;
+ if (w_length > USB_BUFSIZ) {
+ if (ctrl->bRequestType & USB_DIR_IN) {
+ /* Cast away the const, we are going to overwrite on purpose. */
+ __le16 *temp = (__le16 *)&ctrl->wLength;
+ *temp = cpu_to_le16(USB_BUFSIZ);
+ w_length = USB_BUFSIZ;
+ } else {
+ goto done;
+ }
+ }
+
/*
* partial re-init of the response message; the function or the
* gadget might need to intercept e.g. a control-OUT completion
--
2.38.1
next prev parent reply other threads:[~2022-11-17 9:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 20:00 USB Device buffer overflow Szymon Heidrich
2022-11-17 0:43 ` Sultan Khan
2022-11-17 0:56 ` Fabio Estevam
2022-11-17 9:48 ` Szymon Heidrich [this message]
2022-11-17 11:50 ` [PATCH] Prevent buffer overflow on USB control endpoint Fabio Estevam
2022-11-20 14:43 ` Marek Vasut
2022-11-20 15:29 ` Szymon Heidrich
2022-11-20 17:25 ` Marek Vasut
2022-11-20 17:42 ` Szymon Heidrich
2022-12-16 3:22 ` Marek Vasut
2022-12-19 18:52 ` Szymon Heidrich
2022-12-19 19:46 ` Marek Vasut
2022-11-28 9:21 ` Szymon Heidrich
2022-11-28 9:27 ` Marek Vasut
2022-12-12 9:55 ` Szymon Heidrich
2022-12-12 13:24 ` Marek Vasut
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=20221117094847.60409-1-szymon.heidrich@gmail.com \
--to=szymon.heidrich@gmail.com \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.