From patchwork Mon Sep 23 20:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Arkhipov X-Patchwork-Id: 830322 Received: from mail.rosa.ru (mail.rosa.ru [176.109.80.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F35415E88; Mon, 23 Sep 2024 20:20:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=176.109.80.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727122829; cv=none; b=UBbogO+cBCpiLaFqSpQDB8LI1bahcRegS10mfecXHkChz6enD3AAPo63U49Vme1A0uia45RNoeATHtnoqKWm9ewVHd0wXgX4qT+DjcB5AjKZlWH9CGWJ83mJgqqGoAIXSRbaFoTx1FkQcE48JfF218pB7FmB0ezl6asz4WVi460= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727122829; c=relaxed/simple; bh=lGwAoI+n9Yo4xnfmF+vllGL8FK8LhqfP38H5u6NnS6I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=PZIbk9udHm+YwYZlbEWM1bZZ49XYcqHJ6NaXYXdO/s7i0ZSoLosMd2oIhas0yZJScwwhugDUV1MzbeuxiEbRrRv36BzJqC9JeEn17zSk2fVkNubMzda0w5b00H1rCrmtan3NdnA99Vo0MQc8TPXMJX773KzUaoDfCaI3TmCP8yc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rosa.ru; spf=pass smtp.mailfrom=rosa.ru; dkim=pass (1024-bit key) header.d=rosa.ru header.i=@rosa.ru header.b=HMrNRSep; arc=none smtp.client-ip=176.109.80.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rosa.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rosa.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=rosa.ru header.i=@rosa.ru header.b="HMrNRSep" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=rosa.ru; s=mail; bh=lGwAoI+n9Yo4xnfmF+vllGL8FK8LhqfP38H5u6NnS6I=; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From; b=HMrNRSepcaCMaLVvg7L2bfmUgxUNGnRd65MhvZXu5PfDK6P0SSiAbV8vfms7rUQOfT3lrgWRAzb nbVDJGcEvrqgJYchQ80bOclSeZ2U1xKKg1SuIMXO8SB2HOVUOumbCuoBQOOGe+e7uFiye1AJDSgn3 mzt5Kfb6nODlHrrdpQ4= Received: from [194.9.26.89] (account m.arhipov@rosa.ru HELO localhost.localdomain) by mail.rosa.ru (CommuniGate Pro SMTP 6.4.1j) with ESMTPSA id 135313; Mon, 23 Sep 2024 23:20:21 +0300 From: Mikhail Arkhipov To: Greg Kroah-Hartman Cc: Mikhail Arkhipov , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Felipe Balbi , Mike Frysinger , Sebastian Andrzej Siewior , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2] usb: gadget: r8a66597-udc: Fix double free in r8a66597_probe Date: Mon, 23 Sep 2024 23:20:19 +0300 Message-Id: <20240923202019.37875-1-m.arhipov@rosa.ru> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The function r8a66597_free_request is already called in the err_add_udc block, and freeing r8a66597->ep0_req twice may lead to a double free error. 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. Remove the redundant call to r8a66597_free_request in the clean_up2 block. 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 Reviewed-by: Sebastian Andrzej Siewior --- v2: Remove redundant call to r8a66597_free_request in clean_up2 block instead of assigning r8a66597->ep0_req to NULL, as suggested by Sebastian Andrzej Siewior . drivers/usb/gadget/udc/r8a66597-udc.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c index db4a10a979f9..a9b82f371abb 100644 --- a/drivers/usb/gadget/udc/r8a66597-udc.c +++ b/drivers/usb/gadget/udc/r8a66597-udc.c @@ -1956,9 +1956,6 @@ static int r8a66597_probe(struct platform_device *pdev) if (r8a66597->pdata->on_chip) clk_disable_unprepare(r8a66597->clk); - if (r8a66597->ep0_req) - r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); - return ret; }