From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796326760; b=gWbVAcRnkMNEQrYNiaPnek8EV4utLn7oT19VN+xkRgNmgrp6Nm2OyXGMYnyX0Rgc4AFD Ol6ZZPWuKuhLzrG0iC3axWn+oCWBvWALr6unclSjn5QBiV2BS4664U8tVk1U6ktkrnxBY 2ir9jGYvXqHe0uvx4my6mkDhMFTUVdhri0WTWm1Bl82AlS2FUHlChEnVigtC7BlRvLeWi 9eKxS4VAxIjKVMz2qsI3TV1fsQPCnlVK9CjLeiwcbyaE7KbQmdJvw1gnCwZDh1fqv+S1W jFhSynk8Sycc6l/mUpday0E4rHjHElpxkzGSPNlQxKUgnbYN2E6SsXQVgx47pxJ41CA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326760; 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=Y5l/f5kdCxx7fsX/qukL5bDFJuAPh2r97dVIcztZc2g=; b=hvyLDQmcAmzYfGfQU49v75bduxLtRPmmyukEGaf3DSwAg1bwjQ9VrLSXXyfFnU3+H0UU PXV25XSwYS8AHYutX3ErhnKTGPF5wRKgbrER9eJ/nlDXX0AyJVeMnId58PCRH3nIn9CGL yRnTBUIn2EvmbE7BQLLzZzBcSDJC60AhYRHeIgniVSc0TGO7ifh/Y7kDgCNpTWbBylwt1 O8afHchcVGwhAt1/mmyEzZMudkLf8gy4987sOFoaLh6fK1EzgFjkdk5iAOnEqBDiZJj22 wDI0x13RYZSC6U0fEfoBardADIHHe0ATsMb1VqhVcPcQRz7p4Q4JgkrKVC/GZ9cGStA== 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=br3s7pnj; arc=none smtp.remote-ip=209.85.222.171 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 8F58460A3808 for ; Thu, 3 Dec 2026 19:39:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8F58460A3808 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=br3s7pnj Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-93a40a9a01aso157715585a.0 for ; Thu, 03 Dec 2026 11:39:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796326759; x=1796931559; 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=Y5l/f5kdCxx7fsX/qukL5bDFJuAPh2r97dVIcztZc2g=; b=br3s7pnj/Mocsj+96v9CWaVJS3U4WexCeuqe+nKDuLW97mif7Cal904WXKf71zJc1b ZOJdUWmmZlV6DB0grypdE2Eco7v41h1axgr03EJbo6bDGVCiCuXzS8xH/AvLz/rTJ4WW 2qkXltbw9tXl8wm1XhH/f//WpsXsPmtYmW+sj/nb4YGBx0KBGHppfq9cOuVwYErc8wL9 68l8/fyRU9+Um1gTAk6+ZQ5R5B7Rg5llGI1Kb0WVpdMdgXUzEebiVHaLjZusjAcCDwEm PdzAavc0NRjkvzjLHiJY5jZRZq0t3boOoxzJuT9L35NFkbblmC3brZrtq7tQ1nJHxk/v gaIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796326759; x=1796931559; 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=Y5l/f5kdCxx7fsX/qukL5bDFJuAPh2r97dVIcztZc2g=; b=KEEz62mUloRYc6pE/CG2KXs4oxUS0M21izNI3ogYK/dGSaqcW9VVqk2Xk3iT/qlG6D ol+NaMIqxjsu7wUeQnhB6qNIT5WygcFIdkiapI/B24ghd3089V3nop6lRXjsm6HvTBVs DbFq4/TJX25aWtvn0vr5++MP3/CFjV+sEykzbwxoBN26nfNRRxAallgtnuqh/IbYCsqM Bfs/+VwTXu4yviFjWdreX0EeaLZmYMgSmXrJImBB2rKPhGX8sK9IPs5pkH+AAZW9otd2 6RSd3q79643IY++EZ4U6sAU7gq0TWLatoETCZPSf/ZDFGJJeY0UEI/TRyoPpWXl9lYF+ 4VNw== X-Forwarded-Encrypted: i=1; AL+hErEMSMB9eYIsHxKcuPZ4gtZzXgUI+PbWit/0P1H/eBfS8I3/fuKSCoEvVqzVR0ffoa2SQHZxVdkOeX8=@vger.kernel.org X-Gm-Message-State: APuU4Z8zHL+zNZUxu7cdjYJ7/dSKAwHOHggKzrLIgvG7EfZNaiXAhnwr IXTaX2sRb8HkkDFD/01hyCUa59AwVytIyJmRAVVJqW7Sx5Kn3f5+9KdTqXX0jDKL X-Gm-Gg: AZFdTZf6i5mBCnGNmTUZutmdwiz4vmVyzssCeXDcc90uCUHL7Z6+n7cbPTvVksrsHiT +p/3Pq6gEuiV9pvSmvnObL10ys1sFFG2HIGkUU/LSpablY8irVI6TMySUQ8Ha9Yb9qiPdYzQ0Xs Gm2KMyyZDSupNSz/HDipshRGxFpcYj/Jl0W8k1pXek+KWkoydUGA8GYKXYLw0HX0yBiZUNXuALj 8lHXa54uJc2B0w4yJWqdvg+CGM6AHVZc4/GPRr341yHdMnG2IZ4WEf3phBImtNdU59pxAGVzXrX 0BDG2IgoVruqrY9PBQ1wo5L132V0rFd71zKpIPa7N0DeEvGAzRVVMg//94/71KYA1/OoiTiEeU3 eT7epfSC8wiUDQRSOHc4HSjtbOAMUC+kQZ8nDetXz4xkBdjJ/rEkInPkn7uuCfum4jxT3X4eNct b7jDNvImaTWWpCnKOBQT3ie61tf6yV2zsGvMM+gODvbxjfz1hA5tlrpxauprZ2htvh2ttWqHSeb /ugvVnxRtKfQwkFek0c/fDZjR42ZO9AbcBoxDW4iX4An2RXfWWvhtAA1fbrhdMpXkbK1LoNb7sF PbcqSuC2eNmDvR40za9SDsd6DdekM3am+/2+4gH0 X-Received: by 2002:a05:7300:d516:b0:385:2ea8:aac7 with SMTP id 5a478bee46e88-38742dd6f90mr4077106eec.23.1796326395509; Thu, 03 Dec 2026 11:33:15 -0800 (PST) Received: from vineet-kernel.. ([106.51.245.14]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385672ce402sm124002972eec.16.2026.12.03.11.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 11:33:15 -0800 (PST) From: Vineet Thakran To: Greg Kroah-Hartman , Neill Kapron Cc: Ruslan Bilovol , Pavel Hofman , linux-usb@vger.kernel.org, Vineet Thakran , stable@vger.kernel.org Subject: [PATCH 4/4] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak Date: Thu, 3 Dec 2026 19:32:17 +0000 Message-ID: <20261203193217.465889-5-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 f_audio_bind() allocates the AC header and feature unit descriptors and stores them in the file-scope ac_header_desc, in_feature_unit_desc and out_feature_unit_desc pointers, which are freed only in f_audio_unbind(). When a configuration contains more than one f_uac1 instance, each bind overwrites the pointers left by the previous one, and those descriptors are leaked. This is the same problem syzbot reported for f_uac2. usb_assign_descriptors() copies the descriptors into the function, and since the previous patch nothing uses them after f_audio_bind(). Free them on every exit path of f_audio_bind(), including success, and drop the now redundant kfree() calls from f_audio_unbind(). Fixes: 254cb1e0d78c ("usb: gadget: f_uac1: disable IN/OUT ep if unused") Fixes: 0356e6283c71 ("usb: gadget: f_uac1: add volume and mute support") Cc: stable@vger.kernel.org Signed-off-by: Vineet Thakran --- drivers/usb/gadget/function/f_uac1.c | 41 ++++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 6a5c00d3a8e6..2c892db84c65 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -1277,14 +1277,14 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) out_feature_unit_desc = build_fu_desc(audio_opts->c_chmask); if (!out_feature_unit_desc) { status = -ENOMEM; - goto fail; + goto free_ac_header; } } if (FUIN_EN(audio_opts)) { in_feature_unit_desc = build_fu_desc(audio_opts->p_chmask); if (!in_feature_unit_desc) { status = -ENOMEM; - goto err_free_fu; + goto free_fu; } } @@ -1372,7 +1372,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) /* allocate instance-specific interface IDs, and patch descriptors */ status = usb_interface_id(c, f); if (status < 0) - goto err_free_fu; + goto free_fu; ac_interface_desc.bInterfaceNumber = status; uac1->ac_intf = status; uac1->ac_alt = 0; @@ -1382,7 +1382,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (EPOUT_EN(audio_opts)) { status = usb_interface_id(c, f); if (status < 0) - goto err_free_fu; + goto free_fu; as_out_interface_alt_0_desc.bInterfaceNumber = status; as_out_interface_alt_1_desc.bInterfaceNumber = status; ac_header_desc->baInterfaceNr[ba_iface_id++] = status; @@ -1393,7 +1393,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (EPIN_EN(audio_opts)) { status = usb_interface_id(c, f); if (status < 0) - goto err_free_fu; + goto free_fu; as_in_interface_alt_0_desc.bInterfaceNumber = status; as_in_interface_alt_1_desc.bInterfaceNumber = status; ac_header_desc->baInterfaceNr[ba_iface_id++] = status; @@ -1411,7 +1411,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (FUOUT_EN(audio_opts) || FUIN_EN(audio_opts)) { ep = usb_ep_autoconfig(cdev->gadget, &ac_int_ep_desc); if (!ep) - goto err_free_fu; + goto free_fu; uac1->int_ep = ep; uac1->int_ep->desc = &ac_int_ep_desc; @@ -1422,7 +1422,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (EPOUT_EN(audio_opts)) { ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc); if (!ep) - goto err_free_fu; + goto free_fu; ss_as_out_ep_desc.bEndpointAddress = as_out_ep_desc.bEndpointAddress; audio->out_ep = ep; audio->out_ep->desc = &as_out_ep_desc; @@ -1431,7 +1431,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) if (EPIN_EN(audio_opts)) { ep = usb_ep_autoconfig(cdev->gadget, &as_in_ep_desc); if (!ep) - goto err_free_fu; + goto free_fu; ss_as_in_ep_desc.bEndpointAddress = as_in_ep_desc.bEndpointAddress; audio->in_ep = ep; audio->in_ep->desc = &as_in_ep_desc; @@ -1443,7 +1443,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, f_audio_ss_desc, f_audio_ss_desc); if (status) - goto err_free_fu; + goto free_fu; audio->out_ep_maxpsize = le16_to_cpu(as_out_ep_desc.wMaxPacketSize); audio->in_ep_maxpsize = le16_to_cpu(as_in_ep_desc.wMaxPacketSize); @@ -1480,18 +1480,19 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f) status = g_audio_setup(audio, "UAC1_PCM", "UAC1_Gadget"); if (status) - goto err_card_register; + usb_free_all_descriptors(f); - 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 = NULL; kfree(in_feature_unit_desc); in_feature_unit_desc = NULL; -fail: +free_ac_header: kfree(ac_header_desc); ac_header_desc = NULL; return status; @@ -1819,14 +1820,6 @@ static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f) g_audio_cleanup(audio); usb_free_all_descriptors(f); - kfree(out_feature_unit_desc); - out_feature_unit_desc = NULL; - kfree(in_feature_unit_desc); - in_feature_unit_desc = NULL; - - kfree(ac_header_desc); - ac_header_desc = NULL; - audio->gadget = NULL; } -- 2.43.0