mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: TAKANO Mitsuhiro via B4 Relay <devnull+takano32.gmail.com@kernel.org>
To: Neal Liu <neal_liu@aspeedtech.com>,
	Neill Kapron <nkapron@google.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Joel Stanley <joel@jms.id.au>,
	 Andrew Jeffery <andrew@codeconstruct.com.au>,
	 Ryan Chen <ryan_chen@aspeedtech.com>,
	 Billy Tsai <billy_tsai@aspeedtech.com>,
	linux-aspeed@lists.ozlabs.org,  linux-usb@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	 linux-kernel@vger.kernel.org,
	TAKANO Mitsuhiro <takano32@gmail.com>
Subject: [PATCH] usb: gadget: aspeed_udc: validate pointers before dereferencing in ast_udc_ep_enable()
Date: Sat, 28 Nov 2026 22:21:06 +0000	[thread overview]
Message-ID: <20261128-b4-aspeed-udc-ep-enable-null-v1-1-26e41e0cd96b@gmail.com> (raw)

From: TAKANO Mitsuhiro <takano32@gmail.com>

In ast_udc_ep_enable(), desc and ep are dereferenced in local variable
initializers (usb_endpoint_maxp(desc), ep->udc, and usb_endpoint_num(desc))
before checking whether _ep or desc is NULL. In addition, the error path
calls EP_DBG(ep, ...), which dereferences ep->udc and ep->ep.name when
AST_EP_DEBUG is enabled.

Check _ep and desc for NULL first, then derive ep, udc, maxpacket, and
epnum. Since _ep is already verified non-NULL, the redundant !ep check
after container_of() is also removed.

Fixes: 055276c13205 ("usb: gadget: add Aspeed ast2600 udc driver")
Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com>
---
Verification: compile-tested on x86_64 with CONFIG_COMPILE_TEST=y and
CONFIG_USB_ASPEED_UDC=m (make W=1 drivers/usb/gadget/udc/aspeed_udc.o;
0 warnings) and checked with scripts/checkpatch.pl --strict. Checked
against linux-next (next-20261127) and lore.kernel.org for duplicates.
Not runtime-tested on Aspeed hardware.

The change and the changelog text were produced with an AI coding
assistant (Gemini) working from the tree; I reviewed the diff and the
reasoning, and I am responsible for the submission.
---
 drivers/usb/gadget/udc/aspeed_udc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c
index 10214232c..38817d99c 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -341,16 +341,24 @@ static void ast_udc_stop_activity(struct ast_udc_dev *udc)
 static int ast_udc_ep_enable(struct usb_ep *_ep,
 			     const struct usb_endpoint_descriptor *desc)
 {
-	u16 maxpacket = usb_endpoint_maxp(desc);
-	struct ast_udc_ep *ep = to_ast_ep(_ep);
-	struct ast_udc_dev *udc = ep->udc;
-	u8 epnum = usb_endpoint_num(desc);
+	struct ast_udc_ep *ep;
+	struct ast_udc_dev *udc;
 	unsigned long flags;
 	u32 ep_conf = 0;
+	u16 maxpacket;
+	u8 epnum;
 	u8 dir_in;
 	u8 type;
 
-	if (!_ep || !ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT ||
+	if (!_ep || !desc)
+		return -EINVAL;
+
+	ep = to_ast_ep(_ep);
+	udc = ep->udc;
+	maxpacket = usb_endpoint_maxp(desc);
+	epnum = usb_endpoint_num(desc);
+
+	if (desc->bDescriptorType != USB_DT_ENDPOINT ||
 	    maxpacket == 0 || maxpacket > ep->ep.maxpacket) {
 		EP_DBG(ep, "Failed, invalid EP enable param\n");
 		return -EINVAL;

---
base-commit: f93eb7cfc4bfa5d46340f360873726e3e77f2365
change-id: 20261128-b4-aspeed-udc-ep-enable-null-76fee6aa38e4

Best regards,
--  
TAKANO Mitsuhiro <takano32@gmail.com>



                 reply	other threads:[~2026-11-28 22:21 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=20261128-b4-aspeed-udc-ep-enable-null-v1-1-26e41e0cd96b@gmail.com \
    --to=devnull+takano32.gmail.com@kernel.org \
    --cc=andrew@codeconstruct.com.au \
    --cc=billy_tsai@aspeedtech.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@jms.id.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-aspeed@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neal_liu@aspeedtech.com \
    --cc=nkapron@google.com \
    --cc=ryan_chen@aspeedtech.com \
    --cc=takano32@gmail.com \
    /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®