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=1796382852; b=3xSIcpzNFBgmjt513Ggr7Dv7uSUO+iLLVNLkScrSzZMFmtpYIfhgfIdw5ueQUDxsTN16 8C0j3wsYiV/ODtJcAJWGHstiueGKOhTUBRsAdLB6iBIrgts5ZTHxR9P1zMC4gIWwxkKSW oqZyxy4zg+5qjyDN1i0xsoxNktT4Yr3aMK9QcnXvh/VCirYe+dCzUpcRF7nYbMvJi4ylr g5YV78VyfIiw+tOLwXABAD3wHhRUZtLZwXwoT6YWbzQR9leBr6UjgTpgK7wf0mNYNAFWA Ump1iB+CVQdg2NQoQ2ncLmLLdsqssr2AeNRGtqnXxmTtMN1sjFrEHM/WEYq3yuwPT1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382852; 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=rFCdARUFawzZk6xMA223DuMKm43FhC+Bzu+IQAHkU7o=; b=c8WApoLEu2WaVYwd+5fWTk7xxV5JCQvFt/ni87q3JZqsMkplBlmNuRKh41o6nJE1Vs/D 9GKv7987cCVvxEtTDfnBM3GROivRz9eFhIISBX9YeIOx/Q05fTFnyG+0mZB1CW6IOQmXs dpSm696OyWkljmpvD9nF13g952cG6lnLa8AXvL2VfbrDw5gQFoy1/opYQTEQgB+GgmxkI GggCp3AYC2rtowi04YABeFGVUl2H9WkKyo+3pbHp2m3ER1tmNGp59seZrNd0RpwGOocwc JuYejOfbBXYids4YVlrBes61+u5zWcgH2ayJqG5i6TT/gPkPk3+ip+1CL2143c24Oqg== 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=CvU0Dqoh; 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 EAC06606A32C; Fri, 4 Dec 2026 11:14:11 +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=CvU0Dqoh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DC811F00934; Fri, 4 Dec 2026 11:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382851; bh=rFCdARUFawzZk6xMA223DuMKm43FhC+Bzu+IQAHkU7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CvU0DqohXYNjmtukmiORKxHXAbgDbWA6fq0Z6Jv7DuuWDvVMV/ie1/jzOpXAckqXL DJelVGhEip0RqdUF84CNy48HXY2K5THJhPBLS6a/Vd7OaEWuVDi5wR2EczeaQFrVbE V8H0RHqEyauO0IONgPYCY4SNR1q4OKoSiQVNJv0A= 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.18 621/703] usb: gadget: f_uac1_legacy: fix double close of the ALSA devices Date: Fri, 4 Dec 2026 19:08:40 +0900 Message-ID: <20261204100644.304379032@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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; }