From: Liu Chao <liuc63@xiaopeng.com>
To: justinpopo6@gmail.com, alcooperx@gmail.com, gregkh@linuxfoundation.org
Cc: bcm-kernel-feedback-list@broadcom.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
liuwb@xiaopeng.com, Liu Chao <liuc63@xiaopeng.com>
Subject: [PATCH] usb: gadget: bdc: validate endpoint index in ep0 handlers
Date: Thu, 17 Sep 2026 16:18:58 +0800 [thread overview]
Message-ID: <20260917081859.190561-1-liuc63@xiaopeng.com> (raw)
ep0_handle_status() and ep0_handle_feature() derive an endpoint index
from the host-supplied wIndex field:
epnum = wIndex & USB_ENDPOINT_NUMBER_MASK; /* 0 .. 15 */
epnum = epnum * 2 + 1; /* up to 31 */
ep = bdc->bdc_ep_array[epnum];
bdc_ep_array[] is allocated with bdc->num_eps entries (typically 10-16
depending on the hardware). A malicious USB host can set wIndex to a
value that produces an epnum beyond num_eps, causing an out-of-bounds
read of a stale or uninitialized pointer, followed by a dereference.
Add a bounds check before the array access in both functions, matching
the same pattern already used in bdc_sr_xsf() since commit a402532ab855
("usb: gadget: bdc: validate status-report endpoint indices").
Fixes: efed421a94e6 ("usb: gadget: Add Broadcom BDC UDC driver")
Cc: stable@vger.kernel.org
Reviewed-by: Weibin Liu <liuwb@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
drivers/usb/gadget/udc/bdc/bdc_ep.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c
index a7a22e5ec..e5c203b9a 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
@@ -1286,6 +1286,10 @@ static int ep0_handle_feature(struct bdc *bdc,
return 0;
}
dev_dbg(bdc->dev, "epnum=%d\n", epnum);
+ if (epnum >= bdc->num_eps) {
+ dev_err(bdc->dev, "Invalid ep index %d\n", epnum);
+ return -EINVAL;
+ }
ep = bdc->bdc_ep_array[epnum];
if (!ep)
return -EINVAL;
@@ -1352,6 +1356,10 @@ static int ep0_handle_status(struct bdc *bdc,
epnum = 1; /* EP0 */
}
+ if (epnum >= bdc->num_eps) {
+ dev_err(bdc->dev, "Invalid ep index %d\n", epnum);
+ return -EINVAL;
+ }
ep = bdc->bdc_ep_array[epnum];
if (!ep) {
dev_err(bdc->dev, "ISSUE, GET_STATUS for invalid EP ?");
--
2.50.1
reply other threads:[~2026-09-17 8:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260917081859.190561-1-liuc63@xiaopeng.com \
--to=liuc63@xiaopeng.com \
--cc=alcooperx@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=justinpopo6@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=liuwb@xiaopeng.com \
--cc=stable@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
all inboxes | Powered by JetHome®