From: TAKANO Mitsuhiro Date: Sat, 28 Nov 2026 22:21:06 +0000 Subject: [PATCH] usb: gadget: aspeed_udc: validate pointers before dereferencing in ast_udc_ep_enable() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261128-b4-aspeed-udc-ep-enable-null-v1-1-26e41e0cd96b@gmail.com> X-B4-Tracking: v=1; b=H4sIANFTC2sC/yXMQQ7CIBAF0Ks0s3YSwQYbr2JcDPCrGIIExJg0v XuxLt/mLVRRAipdhoUKPqGGV+pQh4HcQ9IdHHw36aM2SumJ7chSM+C5ecfIjCQ2glOLkc9mBoz IacJIvcgFc/ju/fX2d232Cff+nbSuG7G2meeAAAAA X-Change-ID: 20261128-b4-aspeed-udc-ep-enable-null-76fee6aa38e4 To: Neal Liu , Neill Kapron , Greg Kroah-Hartman Cc: Joel Stanley , Andrew Jeffery , Ryan Chen , Billy Tsai , linux-aspeed@lists.ozlabs.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, TAKANO Mitsuhiro X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795904465; l=2602; i=takano32@gmail.com; s=20261128; h=from:subject:message-id; bh=hcvHTQ6F2wMbzfbaW5W4RNDZ0gjobLsb675NENMCyVI=; b=iZhkV21Yfbx1j7MSGFdvPXTQLi07UpvoM8pSg3LLuRqgXMhIzxERGYTlj6fPzraKlhBB0Eoiz abXiQewEZwcCyt9xVmEZ2Ofavc3f0iTdr7GD6k88enkjJIhwCdcwu74 X-Developer-Key: i=takano32@gmail.com; a=ed25519; pk=TRagOzwhUH617+mf3t6zOBDec87yxkHafrF76srBcI8= X-Endpoint-Received: by B4 Relay for takano32@gmail.com/20261128 with auth_id=1682 List-Id: B4 Relay Submissions 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 --- 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