From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796556807; b=QT3ODq+34PJMZAGoN6gplS4SxnKDLaGsxApkN9IqY+lCMRTK9mPSBmlfRWtw6j0LLcKY /zD9fF5qJ8gNe60RzcstU8TTW3m0QY8DHbTheKFSD89gHVdnxPbjJZnRu1G0wPVH5jdXs sSM5oogOgV9odZI+HFdE0g34xQ7EwOBGKKW56wW/KtfY9oGLP1YqyDNyYXtHw34vwJWdY 9RwTEQyAF9S5fUBk0nS3eveu/H1lSBsBDD+bEo/hVKd6JDRbeAqWRJBBrHG0BkHvEeW4Q doXSbX3bjDkcHR0pfvMkYFIw6cGSoFd/dLI+PlAO6ffkDzGXx8UKG6paYHkm3A3+cMg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796556807; 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:MIME-Version: Content-Transfer-Encoding; bh=0zGsMoqJe6Aqzu/6FGnPp5jAKJQPw2Wzv81DoBNs2vc=; b=Tv9a0RfNntl9LXllGdCaefFriRlHYw+FclO19NetNgr8zqCdGsXYh5xKPT8IuAS9VceO LgnPheRSpYzpq7CGp9wDZ+66jRbxWU4BmPwf6Qvu9gve4O67xlrt0R8j1JmOa0eAqBtHN 86w+Sl+Hwqowray0ROcNB38uY1jXkH9v4CFdrer070QyA45XdN/ZVUlqNVbWqIGDHdMUH VW9vjq7Cv8QgRdfR+2RGeEE7J8O2KiY0VsUHaYytYDaBpqGyY8GHw9zXQLFjoSdu6Q78J otCyjWs/TLldPaa/IDZQTOHteLODC/Hen2Y4pqtpN7b58zfO9sOa3c62peBE2S/wLNw== 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=pRgvYX21; arc=none smtp.remote-ip=74.125.82.52 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (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 E793E606A31F for ; Sun, 6 Dec 2026 11:33:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E793E606A31F 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pRgvYX21 Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1b5d5f3d5b8so2476038c88.0 for ; Sun, 06 Dec 2026 03:33:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796556806; x=1797161606; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=0zGsMoqJe6Aqzu/6FGnPp5jAKJQPw2Wzv81DoBNs2vc=; b=pRgvYX21xuP8ReU58GlGZYt10D5CL42zag1rNBSXsF1IWaWaM5Q6w+7SKArjNTEhdE 4ra1bzdRndxq/lh7sbXS/BLumIsd7TV6LfyoyB/HIIh3SamMfNz1kfHMJgUW3X6nsJE3 AwN5qQl7PF9uHj1cvo/ndgsmWzg3clataV2b11wQ5QL/xCTYNKLObDb/+K7gM10QLrH8 QfUqZhUDyXJcVZxyBz52+1ea+NGigXCrvfC7AHAT8V4tt/dH7b08a+esd5ESJr2cap4J XH1GW0O9VGT4tY/k9L5EN58fzIZsCC7C/5XXpj9QYFU4z1nXVhMzEOpH1ryBm+Ut/gg/ PEfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796556806; x=1797161606; h=content-transfer-encoding:mime-version: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=0zGsMoqJe6Aqzu/6FGnPp5jAKJQPw2Wzv81DoBNs2vc=; b=ODzXjFPKnwuXH5/6Q8rgwAMwvE5OnlF38AhlVbeeBj7bJpUSOGkj7mk7a0Ht3G+mxn ufARI4oLWQJVrwf4Gr7DOZQpepfXRTkd/Ggfia5NJRXYS0wT2xHWNQQmn+9M+lsQHNds H5PbLR8hw0Ve0urWbbmlaxlAwIBjElgS6Qc/cBuy9ndUP7aZaAXFwVfYhMsWbmj/wGdN p8N+Tm6UAQZVn/zfDit9GjhX/2KcwzB/hLIYY6RJf3E8EV7FCNP+3VxP5ufp5gfTe941 ehCKSlvp7GeLEdOyZrKYNm3oL/mibtmdo8HR9O1pLHNHNvgv52GoSqNr5uHptN7Ipdhv aCNQ== X-Forwarded-Encrypted: i=1; AL+hErGxzVgOMPSN2Hfzzg5++upeQjpIT7RWbXfmKUZFUqvniHIcwa4FpLXZ0NykV8rcZfpjEZ2s79ejY6E=@vger.kernel.org X-Gm-Message-State: APuU4Z92ab8RfzYVz7LLzn/2wY3/l0s8F9/6IZsV0NSnLMSaColtGQHd fUZijtt7f4z4SRYvWCjBVwBg8UQUaKb0Kb8P9POEtURknUEIyAy1WDBU X-Gm-Gg: AZFdTZc0GgtqTh6yoKHLbYPs89rCF/Q9JGqSpEOXmL2vJF1QJA2eYBIuZBsBhwJAAJL JSeWbj+4Q9qfkUjMDASLXlgZZGgX/takwrHvtISLQU5TfOofPa93xwFu+pd29bKki1wFUhomJGd bNx99W/ltHoaGLP9HKvbvH7aeCAmWOk7KwYrzCenOEacjqSUB8ePU1X+J6OL7/obWlar5KkAtdu THbUFyBck87vXjCkQOPmfxVQ3RYQOwisc37PGm9770n4qs3sQ89qOe6S03K23M+SH0ysoBxYRrQ WoSSkx2syqW6y4cAz5+JlgHilvSrJcu50GffHAQPLLgIzVbHbX2rUaehbtXH0wQHBq+US6mgj86 j7H08VXXuRvyuvAGEGp4muJQA9ftUPM0whWTQIg7SAvinEZmWUJka0ou18hVgojlsp7V56NjkNx xQ596GTshrBsxrwjEkyDH/vudMQkJHzLBWCIPIWYd7GdOA/S/kOmdYSmJ8Hc5u2TZVxL0HF4Ced yw4YDZe69MZMCI35ABSlq4YLvY/5kTDeUswklUo1Z67TUZhUevLSzMMUj+kECHmMVKcabmshoAD wfGIZfInbSVAkpNiwr0RT0z6vi1IbvMRK01eobue X-Received: by 2002:a05:7022:b1c2:20b0:1b5:8f22:9803 with SMTP id a92af1059eb24-1b5d705e42bmr6334851c88.1.1796556805830; Sun, 06 Dec 2026 03:33:25 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 03:33:25 -0800 (PST) From: Vineet Thakran To: Greg Kroah-Hartman , Neill Kapron Cc: Ruslan Bilovol , Pavel Hofman , linux-usb@vger.kernel.org, Vineet Thakran Subject: [PATCH v3 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Date: Sun, 6 Dec 2026 11:32:49 +0000 Message-ID: <20261206113255.91550-1-vineet789thakran@gmail.com> X-Mailer: git-send-email 2.43.0 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_uac1 and f_uac2 keep the dynamically allocated feature unit (and, in f_uac1, AC header) descriptors in file-scope pointers shared by all instances. With more than one instance this leaks descriptors on every bind (reported by syzbot for f_uac2), and once one instance unbinds, a feature unit control request to any other bound instance dereferences a NULL pointer. Binds of gadgets on different UDCs are also not serialized, so they race on these shared descriptors. Patches 1 and 4 make the control request handlers use the unit IDs already stored per instance. Patches 2 and 5 serialize bind with a file-scope mutex, as f_midi2 does. Patches 3 and 6 then free the descriptors at the end of bind, as usb_assign_descriptors() has copied them by then; in f_uac1 they also become local variables of f_audio_bind(). The mutex patches use guard() and scoped_guard(), so older stable trees will need a manual backport of them. Testing (next-20261127, arm64 QEMU, usbip-vudc as UDC): - syzbot's C reproducer (kmemleak on): reports the build_fu_desc leak before the series; runs for 180 s without any leak after it. - Two uac2 and two uac1 instances in one config, bound/unbound for 3 cycles: kmemleak reports 10 leaked objects before the series and none after. - Two gadgets on two vudc instances, unbinding the first and attaching the second to vhci-hcd: both drivers oops on the first feature unit control request before the series. After it, snd-usb-audio enumerates the device and creates all volume/mute controls. - Two gadgets on two vudc instances bound and unbound in parallel loops, 300 iterations each, on 2 CPUs with KASAN and PROVE_LOCKING: before the series, KASAN reports a double-free in afunc_unbind() (uac2) and a slab-use-after-free in f_audio_bind() (uac1). With the series, there are no KASAN or lockdep reports. Changes in v3: - Patch 6: add Fixes: b8fb6db6cb04, as patch 6 also fixes the AC header entry of f_audio_ss_desc that it introduced (Sashiko) - Link to v2: https://lore.kernel.org/linux-usb/20261205110831.204588-1-vineet789thakran@gmail.com/ Changes in v2: - Add patches 2 and 5 to serialize bind with a mutex (Sashiko) - Patch 6: make the f_uac1 AC header and feature unit descriptors local variables of f_audio_bind() (Sashiko) - Link to v1: https://lore.kernel.org/linux-usb/20261203193217.465889-1-vineet789thakran@gmail.com/ Vineet Thakran (6): usb: gadget: f_uac2: use per-instance feature unit IDs in control requests usb: gadget: f_uac2: serialize bind with a mutex usb: gadget: f_uac2: fix feature unit descriptor leak usb: gadget: f_uac1: use per-instance feature unit IDs in control requests usb: gadget: f_uac1: serialize bind with a mutex usb: gadget: f_uac1: fix feature unit and AC header descriptor leak drivers/usb/gadget/function/f_uac1.c | 116 +++++++++++++-------------- drivers/usb/gadget/function/f_uac2.c | 89 ++++++++++---------- 2 files changed, 103 insertions(+), 102 deletions(-) base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d -- 2.43.0