[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20240911220923.13628-1-m.arhipov@rosa.ru>
Date: Thu, 12 Sep 2024 01:09:23 +0300
From: Mikhail Arkhipov <m.arhipov@...a.ru>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Mikhail Arkhipov <m.arhipov@...a.ru>,
linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org,
lvc-project@...uxtesting.org
Subject: [PATCH] usb: gadget: udc: net2280: Fix NULL pointer dereference in net2280_free_request
When the function net2280_free_request is called with a NULL _ep pointer,
the function still tries to dereference _ep before returning. This leads
to a NULL pointer dereference and possible kernel panic.
This bug can be triggered when a USB endpoint is removed unexpectedly
and the driver attempts to free resources associated with it.
Move the NULL check before calling container_of to ensure that the
function does not attempt to dereference a NULL pointer. This prevents
the kernel from crashing when either _ep or _req is NULL.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Mikhail Arkhipov <m.arhipov@...a.ru>
---
drivers/usb/gadget/udc/net2280.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index 1b929c519cd7..3e8280fa3207 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -582,13 +582,12 @@ static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req)
struct net2280_ep *ep;
struct net2280_request *req;
- ep = container_of(_ep, struct net2280_ep, ep);
if (!_ep || !_req) {
- dev_err(&ep->dev->pdev->dev, "%s: Invalid ep=%p or req=%p\n",
- __func__, _ep, _req);
+ dev_err(NULL, "%s: Invalid ep=%p or req=%p\n", __func__, _ep, _req);
return;
}
+ ep = container_of(_ep, struct net2280_ep, ep);
req = container_of(_req, struct net2280_request, req);
WARN_ON(!list_empty(&req->queue));
if (req->td)
--
2.39.3 (Apple Git-146)
Powered by blists - more mailing lists