Linux USB
 help / color / mirror / Atom feed
From: Liu Chao <liuc63@xiaopeng.com>
To: gregkh@linuxfoundation.org
Cc: 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: m66592: add NULL checks for epaddr2ep lookups
Date: Thu, 17 Sep 2026 20:31:55 +0800	[thread overview]
Message-ID: <20260917123155.3763038-1-liuc63@xiaopeng.com> (raw)

get_status(), clear_feature() and set_feature() look up an endpoint
via m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK] and
immediately dereference the result.

epaddr2ep[] is only populated for EP0 at probe time and for other
endpoints when they are enabled via m66592_ep_setting().  If a USB
host sends a GET_STATUS, CLEAR_FEATURE or SET_FEATURE request
targeting an endpoint number that has not been enabled, the lookup
returns NULL and the subsequent dereference causes a kernel oops.

Add a NULL check after each lookup and stall EP0 on invalid
endpoints, consistent with the error handling already used in the
default cases of these switch statements.

Fixes: 0f91349b89f3 ("usb: gadget: m66592-udc: Add support for M66592 USB peripheral controller")
Cc: stable@vger.kernel.org
Reviewed-by: Weibin Liu <liuwb@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
 drivers/usb/gadget/udc/m66592-udc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/usb/gadget/udc/m66592-udc.c b/drivers/usb/gadget/udc/m66592-udc.c
index d77c11c4e..1d0755f79 100644
--- a/drivers/usb/gadget/udc/m66592-udc.c
+++ b/drivers/usb/gadget/udc/m66592-udc.c
@@ -977,6 +977,10 @@ __acquires(m66592->lock)
 		break;
 	case USB_RECIP_ENDPOINT:
 		ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+		if (!ep) {
+			pipe_stall(m66592, 0);
+			return;		/* exit */
+		}
 		pid = control_reg_get_pid(m66592, ep->pipenum);
 		if (pid == M66592_PID_STALL)
 			status = 1 << USB_ENDPOINT_HALT;
@@ -1012,6 +1016,10 @@ static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
 		u16 w_index = le16_to_cpu(ctrl->wIndex);
 
 		ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+		if (!ep) {
+			pipe_stall(m66592, 0);
+			break;
+		}
 		pipe_stop(m66592, ep->pipenum);
 		control_reg_sqclr(m66592, ep->pipenum);
 
@@ -1069,6 +1077,10 @@ static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
 		u16 w_index = le16_to_cpu(ctrl->wIndex);
 
 		ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+		if (!ep) {
+			pipe_stall(m66592, 0);
+			break;
+		}
 		pipe_stall(m66592, ep->pipenum);
 
 		control_end(m66592, 1);
-- 
2.50.1


                 reply	other threads:[~2026-09-17 12:32 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=20260917123155.3763038-1-liuc63@xiaopeng.com \
    --to=liuc63@xiaopeng.com \
    --cc=gregkh@linuxfoundation.org \
    --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