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=1796327563; b=AgBLL+QhLrTMPNI6Fll8lIpEDbPguMx2z1GFw11xAHKDKatGZKdUzJJQmUdSvKK79c/h 5Zse4qPgMf1AHEzEaCDbos5oWEorrRcsU95c5R8t6d+dGlBbxPLmaono61rYYGsmpNmjI uZp6GJ5LG8VblvppMgDnWksD/zqtDgGyHbG1BTy5opY0lbz1vfv7ha5RTjCj+b53RUy1H 44U3AOIKsew5kl78rFmWYhEZfqv2lBl2ssKW4lKXF2j9ZC0zYbZQWPXgfqsLtQ8N8d7HD P0nWIa3JsXE1kmSBOO7mA21XRBXhf2Ai9iepEl4wuf/yX3sr8RMrCTjwTc8tzd5Zl1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796327563; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=upVBPd7QdB368Wn55fPh4fA7a67qT7qXQX75v7Ct6DA=; b=2sZMniHQkuA/v0aZGHoGaB4JG5hkrfOP3ZVfz/8gh0SCLSvRqV0DvhjqfB77DVMgP5WA XJkvALwZFpvKT9ze6XqoujitRRd3ZczVyqLrUsx3Wc+t1e/n8dMc4ol+5kuL/cDA/fxyf DRcoUfb6Kt+gaV+dPZSpE9MVA6HyYvxs4vry9RaKzYwUm5CNCDEBIfbWlAupFbDvW3ghY AfEbpfl+nh7Unvxpc6eVLbZEipl71WTogbpKsM1hQUTpKM4dZTXAqFMhi4SARp58XqEsC SdOg4fmwgeAiu+txdRaEbeZPFZRxPE48RsaaBeerCaln6lu/pZ8LftDAbWgmHgVnDBA== 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=A2mP6xrn; 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 BB344606A322 for ; Thu, 3 Dec 2026 19:52:43 +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=A2mP6xrn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87B061F00931; Thu, 3 Dec 2026 19:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796327563; bh=upVBPd7QdB368Wn55fPh4fA7a67qT7qXQX75v7Ct6DA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=A2mP6xrn7Ux+DfyUBdLO3KTZki/2PxHSXq7cR/BclT5H5o3bs83PHJnvWAm4hMzzY x1XIuI0Vk/JoeQPQekwDZMTMYSLWmHaoWYuyKqhUgNtPnnwA9kHClX6SjfgBYr0ccG pWgHd4wdtRIf8SsU8wWp73R8Ql5crry37Mpt5KdN9OmhuDLNWOiVv15ZGqk8juRLfy J+OsizZ0jbtHhU8wV0d13NVVALdQfojJJygbRFdOwoK+vbVQnZiOR5mVl+lSace5e+ JfX1XRDLhaJvmzSwin8LwaHFALMTxxWEO4hCttf67oAAQ63FRRBeaYCuJhEJEkW5g1 rsVEVgXJEQKcw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 4/4] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak Reply-To: sashiko-reviews@lists.linux.dev To: "Vineet Thakran" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261203193217.465889-5-vineet789thakran@gmail.com> References: <20261203193217.465889-1-vineet789thakran@gmail.com> <20261203193217.465889-5-vineet789thakran@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 19:52:43 +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_uac1: concurrent f_audio_bind() UAF and double-free on globals -- commit 20d563ef92940baa4fb226b974c5c6ad509ae61d Author: Vineet Thakran usb: gadget: f_uac1: fix feature unit and AC header descriptor leak This commit frees the file-scope AC header and feature unit descriptors on every exit path of f_audio_bind(), including normal success, and removes the kfree() calls from f_audio_unbind(). > diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/fu= nction/f_uac1.c > index 6a5c00d3a8e63..2c892db84c656 100644 > --- a/drivers/usb/gadget/function/f_uac1.c > +++ b/drivers/usb/gadget/function/f_uac1.c [ ... ] > @@ -1480,18 +1480,19 @@ static int f_audio_bind(struct usb_configuration = *c, struct usb_function *f) > =20 > status =3D g_audio_setup(audio, "UAC1_PCM", "UAC1_Gadget"); > if (status) > - goto err_card_register; > + usb_free_all_descriptors(f); > =20 > - return 0; > - > -err_card_register: > - usb_free_all_descriptors(f); > -err_free_fu: > +free_fu: > + /* > + * The feature unit and AC header 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); > in_feature_unit_desc =3D NULL; > -fail: > +free_ac_header: > kfree(ac_header_desc); > ac_header_desc =3D NULL; > return status; [Severity: Medium] Can freeing ac_header_desc, out_feature_unit_desc, and in_feature_unit_desc on the normal exit path of f_audio_bind() cause a use-after-free, NULL pointer dereference, or double free when two gadgets bind concurrently on separate UDCs? Multi-UDC binding is not globally serialized: gadget_dev_desc_UDC_store() only holds the per-gadget gi->lock, and gadget_bind_driver() releases udc_lock before calling driver->bind(). With f_audio_bind() now freeing these globals after sleeping in g_audio_setup(), two binds can race: CPU0 CPU1 f_audio_bind() ac_header_desc =3D build_ac_...() ... g_audio_setup() (sleeps) f_audio_bind() ac_header_desc =3D build_ac_...() out_feature_unit_desc =3D ... kfree(out_feature_unit_desc) out_feature_unit_desc =3D NULL kfree(ac_header_desc) ac_header_desc =3D NULL setup_descriptor(...) <-- NULL deref / use-after-free CPU0 frees and clears the descriptors allocated by CPU1 while CPU1 is still using them, causing a use-after-free or NULL pointer dereference. If both CPUs enter free_fu before either writes NULL, both pass the same pointer to kfree() and trigger a double free. Making ac_header_desc, out_feature_unit_desc, and in_feature_unit_desc local variables in f_audio_bind() (passed to setup_descriptor()) removes their shared lifetime, and a file-scope mutex around descriptor setup would serialize the remaining shared static descriptors. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203193217.4658= 89-1-vineet789thakran@gmail.com?part=3D4