From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796468957; b=SkIL7PClGEzkYu1b7zoAWf0BHFP64iAuYvf5HpZk/CFUQZ8TJg+F2nX2SMd4PTW1zqlz ZertoCWz9VEC4HXkiWdL8paxKExBHOafKlAAgVmkWi+CCzf6AKATwa3xTB0X0+JD3Os/d UNfFjMBqRaQ7rWZCdotgsmJuXjcfc5bdOpEkhnA94IA6Ij5WKzWn8BpTi55y28qfNjto7 eyDDS2cizoL35hitCC2GtXYcx1bWvC0iWpTqYEw0R6ytFzYRRVdHKc0QzArNvXxO6dIoa YEF0zhn5lH05g7ivIdgoRDbE6KHr2ehye7GQ/4o/p9IWZ4OndaSVopTog/u3m0y5+xg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796468957; 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=ji/ygGcUy3MNIrb3oGUasK11FEXUhxwnHbsVhi81aqG11WI9FcGeRpJnp/0BbjjXSEB4 /x/9Jiw4aHO9GyilV+CoTIVUUd0ylk6QtpuPVU0+ozuU7qLypatEn/pyPjczx0djTAlMV c77lEobRjP6aIE4ewKkzaoWpcvhauV/MHxBEnSSMd9JtSBwJ/5137G6bQoHTRnG8wMZbI KcXjQfQxB+ego+MLfm+V38rn+5fHMLTLFsOINOwFuGRIvxVqVNn+JHnqL2XNmTI2I/hgl MF7ck175H5gUL0beklcxRUOEZIscdRPJZ0dylPauKjpo2+Rg2Zp0FtItWTNgI8WEMQQ== 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=ekW4+0cu; arc=none smtp.remote-ip=74.125.82.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 8027A606A330 for ; Sat, 5 Dec 2026 11:09:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8027A606A330 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=ekW4+0cu Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-33fb4680717so267131eec.1 for ; Sat, 05 Dec 2026 03:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796468957; x=1797073757; 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=ekW4+0cu4j+th8U7wsLC+DcAUQEAdyF18MKioCPqI3zoVGYfBlvrDsfGBnestbe9LF H6xgqLBrc6IReAj4IbND2HNiftWSx0+bEYTUBdoQXtuQOTtupa6Vf8TyZp7OFbSoPvSf 9SNiolHuUmOtB+Rf1JVEW27qwqrIesySRg4yPJdo4bjil51I9baPZbx4SZf+wqRM6fZm F3nnApwPz6sI4O03A4K1KHPNowyr68Sy/58z229vEVgwRADcvDsxNcq4mCAqdvt/7QY2 11dEXNVzCeZK9B+gb263gbrC15Eawb+56msy+qvm00zLDGQAJOd0wngZ9W0WO+vu7THc jVNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796468957; x=1797073757; 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=G8UKQ+fWWhnDvTUTwt9Xw+WnkMGTHAJNiRLcaxjgoDNzZ84Wzi4sWTDOypeRa1mvBC bJUuyQ99l8r1yEXS5yNBF7MDwyfiMtCWEB2uzPHuIzWf7/q3TVuxso+AAsoAfjwwIlXn EFx855Olb6KNnChCq4uV+0cc/dFDGkCf9L8q0ubSS7rDqCy6GBeaHtZ1D0z+3KZQ4PQc 11wprPwW6/V6FD2+D4xFBhM2Z6fSnuujVCEZSb09UqlCFnu2+yo3qyVcShZzwll6+1FC lbqeNFcIOzrDmfLg3FnsBDPxxtgT1KaqMBs6Q6t+i2qugWPJwIXEDVgkWpx62qvA6ukc Z1nQ== X-Forwarded-Encrypted: i=1; AL+hErFhQ7d9dLM+WLHM0G32Pgm+ef0TaixF+rhWXX0cArhdIJW7hlGAo+rqzA7iNQJbSvTILfRRiZRdKn0=@vger.kernel.org X-Gm-Message-State: AB4q+uHOFGV+ML3c8IGG0H+iH8WuKAqJA3j8r0bqWCIYjiSkEwN7TZ8Q uXYtgVbZkMfNlFKTKAKzZdqi7dV7Irb1ESlgCWL2c7Lmnohe7mMGBUOi X-Gm-Gg: AZFdTZcQ6hXkbxUNsTMzoFbfqWszeV7oe9u8PhS726Wj3ttn4buVkJOJGVJEnk7t0zo UsF0onJ6KYsygZOewsTB6M6tr9G5rBI8i08aYYBfRiTVEWm9GD/UVGqnJFfqU5c9esKd98tBgG6 e9+JerIoqPvHHB1ANuhilbdMGuOc/UhJ75RZY5XRq0vf+VQO2s+jBkc5SEe2/US+NKbniXgVVr3 ZGu4dGdmviILeB6xLOQVDtlmKvHUjgfhGT1lhe15rS1llIS+JtgiJyR603h1Eok9ZH8I5rThG7t 1bpGOrYBgINfm8RtGfh8443TYW5WWR5CfJhg8Chbb/SR8m4cZ2NXGf3jfgq2ZOo5Y1MsDckSg+M V/FFktLQZzEZeHaBvbayP+j7O+w7QZnobR5f+SqF2ackRlqx1ERfhj07Yz4pH8DNooFyUuHuE7B N16Pl/9dHQZ9gIpZtJX2u0QDWbDMAElMOu5n3B0kaX81D4+lksLNsSVjQcr8Rg/PQwItsXNNaNL IRVvT9AQ22ezlKUNLjsVQopwmJXj7+NaieSMmuwI8YAvLRs+WQnBJu9AWmjqEHz4ZaYuUAhctR8 4v+AXb8e+O3zTutChdoJ+J7SU22joSDyKS5UO6/St/A= X-Received: by 2002:a05:693c:885a:b0:385:b8f4:756a with SMTP id 5a478bee46e88-387520dbf61mr4716903eec.12.1796468956616; Sat, 05 Dec 2026 03:09:16 -0800 (PST) Received: from vineet-kernel.. ([115.242.144.166]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875226fa94sm16929678eec.29.2026.12.05.03.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 03:09:16 -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 v2 3/6] usb: gadget: f_uac2: fix feature unit descriptor leak Date: Sat, 5 Dec 2026 11:08:28 +0000 Message-ID: <20261205110831.204588-4-vineet789thakran@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205110831.204588-1-vineet789thakran@gmail.com> References: <20261205110831.204588-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