From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796327704; b=lWzuu9Nr9AAVFmJIj2EOi2o0V6r5cCFZNMg60sVDG5bvlYc64tIfWd2KSjuPR0Z7oShy ymt3HlKu5hZUXxrTbgE73X7WkM4R3cs+ZbSdgs/CEaXb2eZ4JLPlImMpgrsq/2cmiy2Vb bj/SzSd7JueH7tizmRy0t3Ba9vexs4j5956gSw0Vn47T5bMCEBrN1odRu2L/RUvKG8KA2 aI3UnpmASULxhe0nWls+l8EHD/uQl8vWg1SLB+drio2knhBSUOpqs1WbcnKTzJ4H0u27W QTGLiIpJW1o0YXQcSMhba7ioZNSgQcXpidKkwYv6SifNtRU9LTMZuyZoLx5KRXdsGmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796327704; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=k8eFlXSRK8/9p9/ZsRS1iQjg3/ixt5Y55IgI+sC0UFw=; b=BElkpQRN5Tl5JnXmnjBQ66pozEhkDSHzyHwbspCzD68Q0Z3g3KkhjtTiArXwcXGDncJq 9PZ8xJ+eycrD5yK+CDQ+9cCaglS8Y9tfljyjtFBNY3GAmESAlKLk0IvxHZRLPgT9gN3Aj dywc+aUcAGtlLDTyMyT5MsKIByu91KbuIdjeR73/5qVkHDy4HiTvBCx2WujLGKCbOWu9E 0wsjHxUaVp0qUzxUR4dMDoy4SUDF/RTtmGKVfcbMPjkUWswfAznjBtDLYIsdpVNZ0RbAQ hOtCA87ZZVf+xh6rSZUDYRknr8RAaa5Wo7pumzJAHFbFJzbhxW2Nc0v40l3cmJk3FcA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UEpHAlj0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2D4A606A322 for ; Thu, 3 Dec 2026 19:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UEpHAlj0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7854E1F000CE; Thu, 3 Dec 2026 19:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796327704; bh=k8eFlXSRK8/9p9/ZsRS1iQjg3/ixt5Y55IgI+sC0UFw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UEpHAlj0DPyyCuFBwdW/DukXfm3ejZrT07tR+e/nl63qfXgHwTT56LmoIMR14Ogac C+Uh4ZlKqdaHtEjrxuk5Yj1fMcBhoGb9bKtV7dLhzwldbmAgqIRiQgwRctPmxYR874 I4XDIV8b1zj62A4FRpQxCDYcSnFqVBtD2bR2SgInZjVyU7AbFESbvvNtwZRtQC3BDQ jMpXUUuT3EbJcGOeOF50u3ejCXTl70KziczZ8yazFiupalyuKMPi4Ss2Li7h0Fm8G1 JRAz3RB4kz7SA2AiWgr77QgWCl0SIbI2v417TbDXGfgRjPpdKwZLfp7dLS40wcRSm6 rLQ2lE2srDdSQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/4] usb: gadget: f_uac2: fix feature unit descriptor leak Reply-To: sashiko-reviews@lists.linux.dev To: "Vineet Thakran" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261203193217.465889-3-vineet789thakran@gmail.com> References: <20261203193217.465889-1-vineet789thakran@gmail.com> <20261203193217.465889-3-vineet789thakran@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 19:54:56 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] usb: gadget: f_uac2: concurrent afunc_bind() race on feature unit descriptors -- commit b460ba36b386cc9343677b189193698795073c6a Author: Vineet Thakran usb: gadget: f_uac2: fix feature unit descriptor leak This commit frees the file-scope in_feature_unit_desc and out_feature_unit_desc pointers on every exit path of afunc_bind(), including normal return, and removes the kfree() calls from afunc_unbind(). > diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/fu= nction/f_uac2.c > index dca8c6d7640c6..6851832ca7d07 100644 > --- a/drivers/usb/gadget/function/f_uac2.c > +++ b/drivers/usb/gadget/function/f_uac2.c [ ... ] > @@ -1366,15 +1366,17 @@ afunc_bind(struct usb_configuration *cfg, struct = usb_function *fn) > agdev->notify =3D afunc_notify; > =20 > ret =3D g_audio_setup(agdev, "UAC2 PCM", "UAC2_Gadget"); > - if (ret) > - goto err_free_descs; > - > - return 0; > + if (ret) { > + usb_free_all_descriptors(fn); > + agdev->gadget =3D NULL; > + } > =20 > -err_free_descs: > - usb_free_all_descriptors(fn); > - agdev->gadget =3D NULL; > -err_free_fu: > +free_fu: > + /* > + * The feature unit descriptors are shared by all instances and only > + * needed until usb_assign_descriptors() has copied them, so release > + * them on every exit path. > + */ > kfree(out_feature_unit_desc); > out_feature_unit_desc =3D NULL; > kfree(in_feature_unit_desc); [Severity: Medium] Can concurrent afunc_bind() calls race on out_feature_unit_desc and in_feature_unit_desc now that every exit path frees and clears them? Two separate configfs gadgets binding to distinct UDCs can run afunc_bind() concurrently: gadget_dev_desc_UDC_store() only holds the per-gadget gi->lock, and gadget_bind_driver() drops udc_lock before invoking driver->bind(). CPU0 CPU1 afunc_bind() out_feature_unit_desc =3D P1 usb_assign_descriptors() g_audio_setup() (sleeps) afunc_bind() out_feature_unit_desc =3D P2 setup_descriptor() free_fu: kfree(out_feature_unit_desc) out_feature_unit_desc =3D NULL usb_assign_descriptors() <-- use-after-free on P2 Because afunc_bind() sleeps in g_audio_setup() before reaching free_fu, the race window is wide. Depending on timing, CPU1 hits a use-after-free or NULL pointer dereference, both CPUs can double free P2 at free_fu, and P1 is still leaked when overwritten. Serializing descriptor setup and usb_assign_descriptors() in afunc_bind() with a file-scope mutex (as f_midi2_desc_mutex does in drivers/usb/gadget/function/f_midi2.c) would prevent both the race and the concurrent leak. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203193217.4658= 89-1-vineet789thakran@gmail.com?part=3D2