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=1796381413; b=FqEcUGf5kAENEUPFb032Zm6pGVWcIkrwvEuxVpbtQXvQZMSw3Auk6x+4ieLBWaWH+Cst RLCsCU6nSB5zQbs1jMnDH2DDqcB8bW05KXPN6ieufOGASBcojZFlPEKFSjYwdTNSZE/Eg z0YrYVe9pRFV00LmJnzvjRHaCA9+AyJlouGdfD4hCui4vna8CgSocnZPDpQYxAy/12M6x 52FLZUxNwnFDjnR/IVxQhfeICgrk82YIvHTXyzhyYgxG65wfdKHXuqJUV2QkYHWOiR/HK K5ySMmgz1ich028sQZAygOu08ZtYYoYU4c+UEXB4+AY4/FcwNhI8al81btrvR+BQYZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381413; 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=0IKN9atnj1cqcsi9+f8TlmEXjHXLzsKRNjPgMZKN2qQ=; b=joeViPcpMercYPxEYjKe5Y6Dvldf0h8glW0Qxe2cHVkQyi32ewcCDUE81tKVuEt2eI+X m2P5dJpedyDEl+UaMOIMbCnym58NkMuk1JlBaXABsDmeJxTgN7mhAYcoJ2jcxKsaWTS2a elyeFZh4vm1jFeDVv4FZgJfckKfXCR3lq1d+6pI4b6aYSjtROGzMTUvm8+tGl/PpNNAdg WMZZ6Mgk2nC5s0+7yW5ur/amVWHAyJiUvLPZgrBXl0EQY6ETqf2QMByunQCxCtXyqMq/Y aBsYj4ZfcemRaZnVPztz+XkU1DS5n163psNxWs3XW9sj6c5QnSNggfp19QqnCJKkq4w== 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=X6T1px2K; 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 951FF606A32D; Fri, 4 Dec 2026 10:50:13 +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=X6T1px2K Received: by smtp.kernel.org (Postfix) with ESMTPSA id B26991F00936; Fri, 4 Dec 2026 10:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381413; bh=0IKN9atnj1cqcsi9+f8TlmEXjHXLzsKRNjPgMZKN2qQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X6T1px2K907qawujd/ZqA8dghHhN1fmTfFEA1x7aykMFBkbKReLhgE0OR7dxsSbhK VgZjoh3kUX+8whwXBh5Qm9qls+3s5YA+PS5m3+SkNRLPXsosvcvVZ05d3C6LduVIrD ZbP7FkWKdYMhxLEgJyf5VXs0iN4s1cZ7bD4RIFSs= 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 7.3 692/742] usb: gadget: f_uac1_legacy: fix double close of the ALSA devices Date: Fri, 4 Dec 2026 19:09:16 +0900 Message-ID: <20261204100653.439508855@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 7.3-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; }