From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796556824; b=0B4/KRWtB1HgkQficmg2RHzqpQ9w48MyC7aF2GG816W+Tg04JtoP6sKVKMuulMB8uy0h a1AlgDPPpThTMAwZFJS6BWQRws11abljSb+/AlDI0v4w+/xwQBGDc+AFPI/rSxkCoX7Tz FIfEVtJlLJbLDC6CPVExUrkHJlMnxIqWQzSNvnhBlqRIwN0JZ37SRtqLgmHFEZHSBbeTZ mWanEGkYQaDE07AQ7ar/PvA+PPOcPJ6ng8m+2if8bZFFDx5OL7PG77MpLexey+0OHkOlr SzHPlZzaRhfDMIg1ce3THsy/RWf9A7PdGWPfThOGTpy5j94BwvbC1LvXTiOzBqFvdWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796556824; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=NSlQSHBaE0SpwCqU6hLtk4tOzGtLT4kMVvb5LU8ksZ4=; b=y3IeUJi9ZCHcb1fVSiCU9gC2FXSSsbVxyXH1xi1uB6jBnhZKdeDu91b0HC+ZcuKQ7tYy pc7KMTqmb4YF6avrNi+xgr5Rt9xAbPbtYrT6oHxEMtGKS+MONk5WDfn4y/okGGeGtKr30 1sDcOhr5Fy4xcPIgUUQfx+dzJtsko64Rhr18JAEeEjo0g/LDwgG/YQtBKTTxSb3ZtQqQK lRmF3u9e6PCVO6jo4Te5q9D8aiDbZQ1kuT+PWqreLOQvStyUXpYdquYSkLZRsNfQVId3T mXblNLmMAjMfc5r2J7smjdAhFkUMojAQNo8MgFovAEY6DxGy5updjp9JUvsHYXgFVwA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=FxtQpHvA; arc=none smtp.remote-ip=74.125.82.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B5C9606A321 for ; Sun, 6 Dec 2026 11:33:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B5C9606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=FxtQpHvA Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-15ea896ddc8so3165538c88.0 for ; Sun, 06 Dec 2026 03:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796556823; x=1797161623; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NSlQSHBaE0SpwCqU6hLtk4tOzGtLT4kMVvb5LU8ksZ4=; b=FxtQpHvA48tZdylrIpOgyKnXJNtnVaZD4V06rWH5grNtpmaWPKiHK9Ud/9hIUWJA/Z Bl+mVJJ+dJWM96/bk46fM0bkytIMXbVxf/p8oeWxU8PuYE24etmJYL6PFjhnK+wHcSHI 0iA6gv9+4AaPH+L+paSj7f0WXnbehqPyVp6LImdPX00LhxjMcVz7Pp5EGFVLMg0+rpGP wUuh/wrURNTHeS5bAOTc7jOFG6LL9a5Xypoqn/Y4qbKOymuMuQG2GaBkA+9BkMN3wwLx hkV/2p8UZqHYN8DapI676Et8oEurMbIba8Irfdxa2DewAKWzAEwhbh12qZNy4FlxD2EN m3TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796556823; x=1797161623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NSlQSHBaE0SpwCqU6hLtk4tOzGtLT4kMVvb5LU8ksZ4=; b=qDenQy5O6AdBzITGnuhBAWZDCA5oGJMBrNeeZPcxSSh9AvM1ugvPoB/ntLJDvJqzjl SVJatz1C1pb764CQCzXnzxLvF//0sWPlYRX5HwDGQdE+iEzWJv6+gOzSRUXS/6r5PL63 64q4MVe8fPuRObxc+mgsImDOv5Mv6xZ1e7GNGGmBmbKDKUVEag4bf7Hx8fTfZYi+s69p uEQxCs0Yq+wF5t0COHZGa7FV43r503VH8nvxYWIKZmkMjWQo9N4NOu/+rcUj/JsDU4Jv Ar7TnkyHIbOWY2EDENQer0Ll7KkRnmlyNd5vdnaN9Lh1DXR1kpF74ARIpqbOr/DPLUop v+AQ== X-Forwarded-Encrypted: i=1; AL+hErE0+4weIoEQO0OigO0TnLwLudRvqIOatAVsJRIh0Q6NHSHIORj+kQs32ZkfFtq8cI0GA5ud39m42Ks=@vger.kernel.org X-Gm-Message-State: APuU4Z/BmnGDquS6i1LrbkRNMbkX01MyG+JwWFRegJdefIA96DkPBeZI 9MjFsuPxXQQyChM8XDxCqUDQedNpcYhkJIw+lvt+RAO0S1W3tBeOrhfN X-Gm-Gg: AZFdTZd+g5Px9kB/v9y1VrPZDCmAWNhKE7UTspQyPsnV5Zb/YfWemHd+Ggu147ft3gL Xa09UnDvQxvZtMNAjCCNdZBgRCNQruECALWHGtSQbtuLvbKylrJQpts2R3tUFTJVR8rvZeFLCNd 0oaw9mGKnRfGIHx6Y75HBK1MxEYKYVjsUCs17c+1KUwNsBgdXpCUuZmZUduf3L6XEeOsmWQC7/C NAyCS5t9sY+skGmGpmtIyFclCP24BgzwAs2jYLF+jqqimGNNGNGT30WJqkld4i0Wct3TrobkGqv KpCTFJQyHGnMA7JefwqGsiX9S0nidmC/mCtFRl9ML5bhL6b2/hj4I9Pxe5t99N6hSAQTR+LBZ5K tNSI7VPfrVY9jWap6mHrUyZ+JsZ8KFATP46ml2fhdQnDdaKyxI+BlFJV3TkELSw7qkqNZki9OsG 5KjAb+aKSTIbNkfbAgKvYi+yq+SxpHyxsDWdC6MEU3lbl9vfRP4K65C03cJN4cwX4xx6iy1tZ9z SHeRoyMEHoWHboy999+UEIAO/DoKvnYAxVuvIqMBrV0GYg95ocK5B1vI25tUBL2+Z+MtQy4IogV 2uHJhm41ABhhXRGhCgogxTinH/QPRKpE+BN3rid0 X-Received: by 2002:a05:701a:8458:10b0:1b5:3616:59a1 with SMTP id a92af1059eb24-1b5d70c50e7mr8330778c88.8.1796556823452; Sun, 06 Dec 2026 03:33:43 -0800 (PST) Received: from vineet-kernel.. ([106.51.245.14]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d6480265sm26512724c88.14.2026.12.06.03.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 03:33:42 -0800 (PST) From: Vineet Thakran To: Greg Kroah-Hartman , Neill Kapron Cc: Ruslan Bilovol , Pavel Hofman , linux-usb@vger.kernel.org, Vineet Thakran , syzbot+da5ce3f4a00c8cbe0d4e@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH v3 3/6] usb: gadget: f_uac2: fix feature unit descriptor leak Date: Sun, 6 Dec 2026 11:32:52 +0000 Message-ID: <20261206113255.91550-4-vineet789thakran@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261206113255.91550-1-vineet789thakran@gmail.com> References: <20261206113255.91550-1-vineet789thakran@gmail.com> X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit afunc_bind() allocates the feature unit descriptors and stores them in the file-scope in_feature_unit_desc/out_feature_unit_desc pointers, which are freed only in afunc_unbind(). When a configuration contains more than one f_uac2 instance, each bind overwrites the pointers left by the previous one, and those descriptors are leaked: unreferenced object 0xffff888111d43640 (size 32): build_fu_desc+0x3f/0x70 drivers/usb/gadget/function/f_uac2.c:773 afunc_bind+0x1414/0x16a0 drivers/usb/gadget/function/f_uac2.c:1062 usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333 configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1803 usb_assign_descriptors() copies the descriptors into the function, and since the per-instance feature unit ID change nothing uses them after afunc_bind(). Free them on every exit path of afunc_bind(), including success, and drop the now redundant kfree() calls from afunc_unbind(). The set_ep_max_packet_size_bint() error paths also returned without freeing the descriptors. They cannot trigger today, as that function only fails for an unknown speed, but route them through the same cleanup so that every exit path releases the descriptors. Reported-by: syzbot+da5ce3f4a00c8cbe0d4e@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=da5ce3f4a00c8cbe0d4e Fixes: eaf6cbe09920 ("usb: gadget: f_uac2: add volume and mute support") Cc: stable@vger.kernel.org Signed-off-by: Vineet Thakran --- drivers/usb/gadget/function/f_uac2.c | 54 +++++++++++++--------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 7a3179ad8f97..4bc876512ffb 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -1101,7 +1101,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) in_feature_unit_desc = build_fu_desc(p_channels); if (!in_feature_unit_desc) { ret = -ENOMEM; - goto err_free_fu; + goto free_fu; } } @@ -1169,7 +1169,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ret = usb_interface_id(cfg, fn); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - goto err_free_fu; + goto free_fu; } iad_desc.bFirstInterface = ret; @@ -1181,7 +1181,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ret = usb_interface_id(cfg, fn); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - goto err_free_fu; + goto free_fu; } std_as_out_if0_desc.bInterfaceNumber = ret; std_as_out_if1_desc.bInterfaceNumber = ret; @@ -1211,7 +1211,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ret = usb_interface_id(cfg, fn); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - goto err_free_fu; + goto free_fu; } std_as_in_if0_desc.bInterfaceNumber = ret; std_as_in_if1_desc.bInterfaceNumber = ret; @@ -1225,7 +1225,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) if (!uac2->int_ep) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); ret = -ENODEV; - goto err_free_fu; + goto free_fu; } std_ac_if_desc.bNumEndpoints = 1; @@ -1241,42 +1241,42 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) USB_SPEED_FULL, true); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - return ret; + goto free_fu; } ret = set_ep_max_packet_size_bint(dev, uac2_opts, &fs_epout_desc, USB_SPEED_FULL, false); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - return ret; + goto free_fu; } ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epin_desc, USB_SPEED_HIGH, true); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - return ret; + goto free_fu; } ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epout_desc, USB_SPEED_HIGH, false); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - return ret; + goto free_fu; } ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epin_desc, USB_SPEED_SUPER, true); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - return ret; + goto free_fu; } ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epout_desc, USB_SPEED_SUPER, false); if (ret < 0) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); - return ret; + goto free_fu; } if (EPOUT_EN(uac2_opts)) { @@ -1284,7 +1284,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) if (!agdev->out_ep) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); ret = -ENODEV; - goto err_free_fu; + goto free_fu; } if (EPOUT_FBACK_IN_EN(uac2_opts)) { agdev->in_ep_fback = usb_ep_autoconfig(gadget, @@ -1293,7 +1293,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); ret = -ENODEV; - goto err_free_fu; + goto free_fu; } } } @@ -1303,7 +1303,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) if (!agdev->in_ep) { dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); ret = -ENODEV; - goto err_free_fu; + goto free_fu; } } @@ -1337,7 +1337,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, ss_audio_desc, ss_audio_desc); if (ret) - goto err_free_fu; + goto free_fu; agdev->gadget = gadget; @@ -1372,15 +1372,17 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) agdev->notify = afunc_notify; ret = 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 = NULL; + } -err_free_descs: - usb_free_all_descriptors(fn); - agdev->gadget = 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 = NULL; kfree(in_feature_unit_desc); @@ -2311,12 +2313,6 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) usb_free_all_descriptors(f); agdev->gadget = NULL; - - guard(mutex)(&f_uac2_desc_mutex); - kfree(out_feature_unit_desc); - out_feature_unit_desc = NULL; - kfree(in_feature_unit_desc); - in_feature_unit_desc = NULL; } static struct usb_function *afunc_alloc(struct usb_function_instance *fi) -- 2.43.0