linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: tegra-xudc: check ep->desc before dereferencing
@ 2025-04-15 17:42 Alexey V. Vissarionov
  2025-04-16  7:43 ` Jon Hunter
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey V. Vissarionov @ 2025-04-15 17:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Thierry Reding, Jonathan Hunter, Uwe Kleine-König,
	Alexey V. Vissarionov, Felipe Balbi, Nagarjuna Kristam, linux-usb,
	linux-tegra, lvc-project

Check ep->desc before dereferencing it in tegra_xudc_req_done() call
and later in this function tegra_xudc_handle_transfer_completion()

Found by ALT Linux Team (altlinux.org) and Linux Verification Center
(linuxtesting.org)

Fixes: 49db427232fe ("usb: gadget: Add UDC driver for tegra XUSB device mode controller")
Signed-off-by: Alexey V. Vissarionov <gremlin@altlinux.org>
---
 drivers/usb/gadget/udc/tegra-xudc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c
index c7fdbc55fb0b97ed..0322e984e2c6fd91 100644
--- a/drivers/usb/gadget/udc/tegra-xudc.c
+++ b/drivers/usb/gadget/udc/tegra-xudc.c
@@ -2661,6 +2661,10 @@ static void tegra_xudc_handle_transfer_completion(struct tegra_xudc *xudc,
 	trb = trb_phys_to_virt(ep, trb_read_data_ptr(event));
 	req = trb_to_request(ep, trb);
 
+	/* tegra_xudc_req_done() dereferences ep->desc; check it here */
+	if (!ep || !ep->desc)
+		return;
+
 	/*
 	 * TDs are complete on short packet or when the completed TRB is the
 	 * last TRB in the TD (the CHAIN bit is unset).
@@ -2678,7 +2682,7 @@ static void tegra_xudc_handle_transfer_completion(struct tegra_xudc *xudc,
 
 		tegra_xudc_req_done(ep, req, 0);
 
-		if (ep->desc && usb_endpoint_xfer_control(ep->desc))
+		if (usb_endpoint_xfer_control(ep->desc))
 			tegra_xudc_ep0_req_done(xudc);
 
 		/*
@@ -2694,8 +2698,7 @@ static void tegra_xudc_handle_transfer_completion(struct tegra_xudc *xudc,
 		dev_warn(xudc->dev, "transfer event on dequeued request\n");
 	}
 
-	if (ep->desc)
-		tegra_xudc_ep_kick_queue(ep);
+	tegra_xudc_ep_kick_queue(ep);
 }
 
 static void tegra_xudc_handle_transfer_event(struct tegra_xudc *xudc,


-- 
Alexey V. Vissarionov
gremlin ПРИ altlinux ТЧК org; +vii-cmiii-ccxxix-lxxix-xlii
GPG: 0D92F19E1C0DC36E27F61A29CD17E2B43D879005 @ hkp://keys.gnupg.net

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

end of thread, other threads:[~2025-04-21 15:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 17:42 [PATCH] usb: tegra-xudc: check ep->desc before dereferencing Alexey V. Vissarionov
2025-04-16  7:43 ` Jon Hunter
2025-04-16  9:53   ` Alexey V. Vissarionov
2025-04-16  9:55   ` [PATCH v1] usb: tegra-xudc: check ep and ep->desc before deref Alexey V. Vissarionov
2025-04-16 10:20     ` Jon Hunter
2025-04-16 11:54       ` Alexey V. Vissarionov
2025-04-16 12:00       ` [PATCH v2] " Alexey V. Vissarionov
2025-04-16 14:13         ` Alan Stern
2025-04-21 15:07           ` Alexey V. Vissarionov
2025-04-21 15:41             ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).