From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796326866; b=fqliC7hhq5j4EHXFbiss9MIHZoIqFEMm9g60ip3b45aMcyfORT91CMmE7lMBCH2aj3tv UGB96l0kLkR2phXKmtycI2B3LJLppzJMC4gZwYVMVTg0ZcuoiRhRTMQhJ6ZCEV/J0BX6D jwRGVHvZfRUjjmD/XqP8jRJVxTa30oxP53UYUDZT/xPMWPkv3/KBbRH9eTndr3cjErLxj IvDEG1Oy1ZieO7cl3dWy4/b52FGecJIuejdxOOczmrBAPHvb+cYhDaGhq8f+/kDmgSiD6 bWyHxAR7Dc219A72+jUFG5pPQt3Ugf6cwwlc6PvEDD2U80xtIV2OHyUaPfnt2nIKczQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326866; 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=e+l7Cix/j0zo5IJyL1D4N2f7z48pX9j8G3/V6GnoL3k=; b=V3fm5CTDu5gw/EjzrQjsYGKDUsxT+WWTJD7B3x+eGI21cKyVeSneEgEaec8JJUtAc3mz TLAs2qNd9QqoT4uI7+nfgz15E+Jhx14Btcof832Hxg+sj87mUh4WytRDIalAGKIM4bXHJ qzafDL3rjImfSlPYipaqGz52mOIUNbNKZDquieALtnKspPIT9Rx5Gc13qibiRBSVDgfLH WkDgKfWWK6Ej9n9vQJQmvOePCI/twcYMlSuovmXLayX2iAat5NVfGR/LmgQ07JybUg4E3 zHVPEY06sGic1qj7ex5BA6so+d7pPIC1pAX17SeFDCYrWu0gOjVIil71/GEx68+oSYA== 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=WANtBiju; arc=none smtp.remote-ip=209.85.210.182 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 E72F760A3808 for ; Thu, 3 Dec 2026 19:41:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E72F760A3808 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=WANtBiju Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8b4c8b51b58so144397b3a.1 for ; Thu, 03 Dec 2026 11:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796326865; x=1796931665; 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=e+l7Cix/j0zo5IJyL1D4N2f7z48pX9j8G3/V6GnoL3k=; b=WANtBijulUD61ycVZLQxcuJvvae2R9o26/RthbiNdbl1+FVX7bhyf3Q1yK1pPOOrhr we/zyjnsf20oJLLFBb2dKLVf4lfv8R6Bjxb7rt9EhB0EAin8N5mfsG1WK3IigpTNFlyq hUp7RZ6Wt2aQcZLvB0Xhh+Asgn7ncuRAOYzRkouQp9GjFDC2S/WMgONYCfJ+6J1IqHMf CiZep1Jp9dTEieZHRWyYmnERlH2aueByBE0zLercWhJfO6qrSxpMwmEeb1oUlNAshDC5 CPasEpbzNcn3bBzXdSvE1oqAnB3JoJITo0YRDnO5aoOu/DS2iHR2BfgZqJjel8046nX1 R9MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796326865; x=1796931665; 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=e+l7Cix/j0zo5IJyL1D4N2f7z48pX9j8G3/V6GnoL3k=; b=bg0UlI1NUhgPCuwrKbrk7Jpjfb8yzkqAs328Tu2/lYAC7q2oEkG6yQOKWnBUte6aZv cu1dRcx35fQmTzBd5Kk/JtKmzHzeah8mB0NcbVU1Q+GPjieX3DMLCiCJ+CInuh3Z8pLE iDIM+z/NFg3Mgavx3zfKwINrdC3ykaRJrBvZwDnTcpYwIoxJJCdnileoSOWaSQ23hJ9s 2pZzaOhxGCr/ELk2mTRQJdvnI9Q6t/FJF1AMAc2KDnI4ZlLW/8qn8Ue2CB1PQFkb4/dD /lTpz1GRR9CH+Zm1HMcfrBLSLRgbP/Z3gq6n5Y94D2BIoOmPdgDpUGTlDsvHJAF73R+D ZdSQ== X-Forwarded-Encrypted: i=1; AL+hErEzNw/+oMYmSsRhW4Qtb6HTHdpmgugmwwuOIpI8cYsH/oWZTcJqqNo6GfaIDqf7z+lImqqOVoxCpOM=@vger.kernel.org X-Gm-Message-State: APuU4Z8r1//gi+37LQr7hnbA1OECGBasJ4680Jms+MbxlFnBjeNY7LuJ Vf+CUVCH8EIF0tJr9Z9WIGgMrOtdBEHpSlgi1WZ6Kn/s3Ah4nU1DB1T40uLMrKyk X-Gm-Gg: AZFdTZcgijuFPkARIOJquDIC3vtKe05m2lwX9eF4059NmwFLO0cp+EmZ4CKVLBZznyf Su3R8ak2BwNagsBxWZgw5CRKBmrrAjPrfQdArmrTbvSWz1AO0Nr8Y8o4nO/6Ip53bBakT3Xwg11 vtAC7RuCAiKQ3+RLou93Djf2Y2nLh0IgSKMZ34BleTyadWagTLQMR9KS5p7DsDzSCWYbgKCeB41 0ccxtsRM2W6ct9c5PgYPbGTeATqUgF/vh9JHY5GDikSGv78ocVf+nyv3WwNCKui3i+im7CNY66I dWMSOQCk3KDojCNfYO0v0AtyIf2IskpyK6BKe4ilGZv3CrApmkofzXZp7iiYwczN6t1aX21yXoG wCRSw0fr6HTdyIRZXO2wUpfjQ7JeCRkZwD0DWorEgxicj402ZIbgSXAaElw05D0Tvul2pPpOnE+ /ogJRAE8Vq9K3VbcrLz8GxrKXh16p0iQBYlZdzUXnRCAzvs5hIbCuptT1pfgqmPrNM8B+QV0yCj dMOQquHjsd7drBcbCME/ecYVmwOyWs4TPt80lwIPTKsGE1FedHvF19/8cNVoCNWj6PRDeR71+mx P5eVeaRRCsptVoIm4QK7hPKHf6g+q5nZCQP+OH8D X-Received: by 2002:a05:693c:87d3:20b0:382:8358:9e03 with SMTP id 5a478bee46e88-3856ef457c4mr48212636eec.17.1796326380303; Thu, 03 Dec 2026 11:33:00 -0800 (PST) Received: from vineet-kernel.. ([106.51.245.14]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385672ce402sm124002972eec.16.2026.12.03.11.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 11:32:59 -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 2/4] usb: gadget: f_uac2: fix feature unit descriptor leak Date: Thu, 3 Dec 2026 19:32:15 +0000 Message-ID: <20261203193217.465889-3-vineet789thakran@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203193217.465889-1-vineet789thakran@gmail.com> References: <20261203193217.465889-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 previous patch 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 | 53 +++++++++++++--------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index dca8c6d7640c..6851832ca7d0 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -1095,7 +1095,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; } } @@ -1163,7 +1163,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; @@ -1175,7 +1175,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; @@ -1205,7 +1205,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; @@ -1219,7 +1219,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; @@ -1235,42 +1235,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)) { @@ -1278,7 +1278,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, @@ -1287,7 +1287,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; } } } @@ -1297,7 +1297,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; } } @@ -1331,7 +1331,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; @@ -1366,15 +1366,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); @@ -2305,11 +2307,6 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) usb_free_all_descriptors(f); agdev->gadget = NULL; - - 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