[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240916222937.12878-1-m.arhipov@rosa.ru>
Date: Tue, 17 Sep 2024 01:29:37 +0300
From: Mikhail Arkhipov <m.arhipov@...a.ru>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Mikhail Arkhipov <m.arhipov@...a.ru>,
Uwe Kleine-König <u.kleine-koenig@...gutronix.de>,
Felipe Balbi <balbi@...com>,
Ben Dooks <ben.dooks@...ethink.co.uk>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org,
lvc-project@...uxtesting.org
Subject: [PATCH] usb: gadget: r8a66597-udc: Fix double free in r8a66597_probe
The function r8a66597_free_request is called to free r8a66597->ep0_req,
but the pointer is not set to NULL afterward, which may lead to a double
free if the function is called again.
If the probe process fails and the r8a66597_probe function subsequently
goes through its error handling path. Since r8a66597_free_request is called
multiple times in different error handling sections, it leads to an attempt
to free the same memory twice.
Set r8a66597->ep0_req to NULL after calling r8a66597_free_request
to prevent any further attempts to free this pointer.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 0f91349b89f3 ("usb: gadget: convert all users to the new udc infrastructure")
Signed-off-by: Mikhail Arkhipov <m.arhipov@...a.ru>
---
drivers/usb/gadget/udc/r8a66597-udc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index db4a10a979f9..43b81cae7d17 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -1952,12 +1952,14 @@ static int r8a66597_probe(struct platform_device *pdev)
err_add_udc:
r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
+ r8a66597->ep0_req = NULL;
clean_up2:
if (r8a66597->pdata->on_chip)
clk_disable_unprepare(r8a66597->clk);
if (r8a66597->ep0_req)
r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
+ r8a66597->ep0_req = NULL;
return ret;
}
--
2.39.3 (Apple Git-146)
Powered by blists - more mailing lists