Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: aspeed_udc: validate pointers before dereferencing in ast_udc_ep_enable()
@ 2026-11-28 22:21 TAKANO Mitsuhiro via B4 Relay
  2026-11-28 22:27 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: TAKANO Mitsuhiro via B4 Relay @ 2026-11-28 22:21 UTC (permalink / raw)
  To: Neal Liu, Neill Kapron, Greg Kroah-Hartman
  Cc: Joel Stanley, Andrew Jeffery, Ryan Chen, Billy Tsai, linux-aspeed,
	linux-usb, linux-arm-kernel, linux-kernel, TAKANO Mitsuhiro

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>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: gadget: aspeed_udc: validate pointers before dereferencing in ast_udc_ep_enable()
  2026-11-28 22:21 [PATCH] usb: gadget: aspeed_udc: validate pointers before dereferencing in ast_udc_ep_enable() TAKANO Mitsuhiro via B4 Relay
@ 2026-11-28 22:27 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-28 22:27 UTC (permalink / raw)
  To: TAKANO Mitsuhiro; +Cc: linux-usb

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-aspeed-udc-ep-enable-null-v1-1-26e41e0cd96b@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 22:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 22:21 [PATCH] usb: gadget: aspeed_udc: validate pointers before dereferencing in ast_udc_ep_enable() TAKANO Mitsuhiro via B4 Relay
2026-11-28 22:27 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox