From: Ma Ke <make24@iscas.ac.cn>
To: gregkh@linuxfoundation.org, u.kleine-koenig@pengutronix.de,
make24@iscas.ac.cn
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: gadget: r8a66597-udc: validate endpoint index for r8a66597 udc
Date: Sat, 22 Jun 2024 22:23:08 +0800 [thread overview]
Message-ID: <20240622142308.1929531-1-make24@iscas.ac.cn> (raw)
We should verify the bound of the array to assure that host
may not manipulate the index to point past endpoint array.
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/usb/gadget/udc/r8a66597-udc.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index db4a10a979f9..93fc4201c0ae 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -1173,7 +1173,11 @@ __acquires(r8a66597->lock)
status = 0;
break;
case USB_RECIP_ENDPOINT:
- ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+ int pipe = w_index & USB_ENDPOINT_NUMBER_MASK;
+
+ if (pipe >= USB_MAX_ENDPOINTS)
+ break;
+ ep = r8a66597->epaddr2ep[pipe];
pid = control_reg_get_pid(r8a66597, ep->pipenum);
if (pid == PID_STALL)
status = 1 << USB_ENDPOINT_HALT;
@@ -1208,8 +1212,11 @@ static void clear_feature(struct r8a66597 *r8a66597,
struct r8a66597_ep *ep;
struct r8a66597_request *req;
u16 w_index = le16_to_cpu(ctrl->wIndex);
+ int pipe = w_index & USB_ENDPOINT_NUMBER_MASK;
- ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+ if (pipe >= USB_MAX_ENDPOINTS)
+ break;
+ ep = r8a66597->epaddr2ep[pipe];
if (!ep->wedge) {
pipe_stop(r8a66597, ep->pipenum);
control_reg_sqclr(r8a66597, ep->pipenum);
@@ -1268,8 +1275,11 @@ static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
case USB_RECIP_ENDPOINT: {
struct r8a66597_ep *ep;
u16 w_index = le16_to_cpu(ctrl->wIndex);
+ int pipe = w_index & USB_ENDPOINT_NUMBER_MASK;
- ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+ if (pipe >= USB_MAX_ENDPOINTS)
+ break;
+ ep = r8a66597->epaddr2ep[pipe];
pipe_stall(r8a66597, ep->pipenum);
control_end(r8a66597, 1);
--
2.25.1
next reply other threads:[~2024-06-22 14:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-22 14:23 Ma Ke [this message]
2024-06-22 15:30 ` [PATCH] usb: gadget: r8a66597-udc: validate endpoint index for r8a66597 udc Markus Elfring
2024-06-26 4:32 ` kernel test robot
2024-06-26 5:34 ` kernel test robot
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=20240622142308.1929531-1-make24@iscas.ac.cn \
--to=make24@iscas.ac.cn \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox