From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384177; b=oBE3E/vQBEmTRdheqQ6y2P3dMsglh/iyQ7Hb4fSkm9DhFdkrtlO6Ctd7/6w4hkGzlVa5 23ukztLe053tFgNfHsZO130K/1FrmafV2xjAJYg+LlLbDfkRAi/RtuM4U5tV8U1BheUnv lh+jkmfWd4rDbjzkVwHN4zUB/5jTRcLbw2RO85mnybVPSPGxQIfKUuWonahqntleqwKrH NS+FzhZRzyx3p2zie5mrH3XnONXrgkxyX42dtIF9v080/FLvhndGDULRlbPMgEcK2g5Cw uRKCiVz3xAwtzcY1zCqe/wKUBoMCwv+sLETLo0VuA6aFlYLhyNQdE58YzZSsZ430IVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384177; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=aviXpsgVRPMBhzD3MA3X4GXZJyvHkvDHC97EgXtMLQY=; b=PKkXsje4QuON/lVpZpAF4mA4yc6R4k8iJI4pMTPCRJaKz/LPrHGKccLacyQwsXhqTeYd ybn+1/R3bgv7heYN4vc6wVQ5RowkaMVODWhGYpAXT3uQkqVqQWH+pNhoae2OIWpMHvrIR 711hMbgvmWQgFaPivwFeJtiGWucmERnzfez3gGoZEfgGpIQGWOTNuKaPxZkzSkW7mjKBM w7f10MKqokyuumcgdfc94a9YZ5MLmr5+kZYpVoA5/p3elhQTdFTiDfFqIjfcNP2FYfx8e h+DO9KITLdnGcoZ2DpL65zgY3QviYyeuB6AtN/roj4te+hBQSDOkhphZlJIVyQN76fg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=X4JZFG9z; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38278606A32D; Fri, 4 Dec 2026 11:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=X4JZFG9z Received: by smtp.kernel.org (Postfix) with ESMTPSA id A72B51F000CE; Fri, 4 Dec 2026 11:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384177; bh=aviXpsgVRPMBhzD3MA3X4GXZJyvHkvDHC97EgXtMLQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X4JZFG9zNnBq0jVm8O72dz1NKG+oxoZwObGhU7laO4+58nkMpUeCDLSvczayGkdvY Gf0764zkfCoacfm1LJKR2YnuKGd+PoyJVvmJEJZzk1HR7to4cTxQ7V6PXXGu+C5ZnW lMiu6smR3r1IAElFUUwGHZueEwjzhatq2y8DQfA0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , syzbot+df868600fe111c5ff79f@syzkaller.appspotmail.com, Vasileios Almpanis Subject: [PATCH 6.12 529/555] usb: gadget: f_uac1_legacy: fix double close of the ALSA devices Date: Fri, 4 Dec 2026 19:09:32 +0900 Message-ID: <20261204100628.871013196@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vasileios Almpanis commit ba4bbac98e65c6998cac4ea2b63baf2159d00a8c upstream. f_audio_bind() records that the ALSA files are open in the function instance flag opts->bound, but keeps the file pointers in the per-function gaudio card. Its error path calls gaudio_cleanup(), which closes the files without clearing the filp pointers or opts->bound. A failed bind does not destroy the usb_function, configfs_composite_bind() puts it back on cfg->func_list, so the next write to UDC binds the same f_audio, skips gaudio_setup() because opts->bound is still set, and on failure closes the files a second time. Dropping the config symlink after a failed bind closes them again via f_audio_free(). BUG: KASAN: slab-use-after-free in filp_flush+0x31/0x190 fs/open.c:1464 Read of size 8 at addr ffff888045f01990 by task syz-executor659/5617 Call Trace: filp_close+0x1d/0x40 fs/open.c:1484 gaudio_close_snd_dev drivers/usb/gadget/function/u_uac1_legacy.c:263 [inline] gaudio_cleanup+0x54/0xf0 drivers/usb/gadget/function/u_uac1_legacy.c:305 f_audio_bind+0x4a0/0x630 drivers/usb/gadget/function/f_uac1_legacy.c:792 usb_add_function+0x290/0x930 drivers/usb/gadget/composite.c:333 configfs_composite_bind+0xde0/0x1410 drivers/usb/gadget/configfs.c:1802 gadget_bind_driver+0x2ca/0x9e0 drivers/usb/gadget/udc/core.c:1662 gadget_dev_desc_UDC_store+0x1c9/0x2f0 drivers/usb/gadget/configfs.c:300 Clear filp, substream and card in gaudio_close_snd_dev() so cleanup is idempotent, and close the devices on the bind error path only if that bind opened them, resetting opts->bound as well. Fixes: f3a3406b3f56 ("usb: gadget: f_uac1: convert to new function interface with backward compatibility") Cc: stable Reported-by: syzbot+df868600fe111c5ff79f@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=df868600fe111c5ff79f Signed-off-by: Vasileios Almpanis Link: https://patch.msgid.link/20260731-alsa-v1-1-95eb93ba32ec@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_uac1_legacy.c | 8 +++++++- drivers/usb/gadget/function/u_uac1_legacy.c | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) --- a/drivers/usb/gadget/function/f_uac1_legacy.c +++ b/drivers/usb/gadget/function/f_uac1_legacy.c @@ -732,6 +732,7 @@ f_audio_bind(struct usb_configuration *c int status; struct usb_ep *ep = NULL; struct f_uac1_legacy_opts *audio_opts; + bool bound_here = false; audio_opts = container_of(f->fi, struct f_uac1_legacy_opts, func_inst); audio->card.gadget = c->cdev->gadget; @@ -741,6 +742,7 @@ f_audio_bind(struct usb_configuration *c if (status < 0) return status; audio_opts->bound = true; + bound_here = true; } us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); if (IS_ERR(us)) @@ -789,7 +791,11 @@ f_audio_bind(struct usb_configuration *c return 0; fail: - gaudio_cleanup(&audio->card); + /* Only tear down the ALSA devices if this bind opened them; the */ + if (bound_here) { + gaudio_cleanup(&audio->card); + audio_opts->bound = false; + } return status; } --- a/drivers/usb/gadget/function/u_uac1_legacy.c +++ b/drivers/usb/gadget/function/u_uac1_legacy.c @@ -259,18 +259,29 @@ static int gaudio_close_snd_dev(struct g /* Close control device */ snd = &gau->control; - if (snd->filp) + if (snd->filp) { filp_close(snd->filp, NULL); + snd->filp = NULL; + snd->card = NULL; + } /* Close PCM playback device and setup substream */ snd = &gau->playback; - if (snd->filp) + if (snd->filp) { filp_close(snd->filp, NULL); + snd->filp = NULL; + snd->substream = NULL; + snd->card = NULL; + } /* Close PCM capture device and setup substream */ snd = &gau->capture; - if (snd->filp) + if (snd->filp) { filp_close(snd->filp, NULL); + snd->filp = NULL; + snd->substream = NULL; + snd->card = NULL; + } return 0; }