Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: uac1_legacy: fix double-close of sound device files
@ 2026-11-23 13:48 Shuai Liu
  2026-11-23 14:01 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Shuai Liu @ 2026-11-23 13:48 UTC (permalink / raw)
  To: Neill Kapron; +Cc: Greg Kroah-Hartman, linux-usb, syzbot+592c653b056459925299

syzbot reports:

  VFS: Close: file count is 0 (f_op=snd_ctl_f_ops)
  kernel BUG at fs/open.c
  ...
  Call Trace:
   filp_flush+0x...
   filp_close+0x...
   gaudio_close_snd_dev
   gaudio_cleanup
   f_audio_bind
   usb_add_function

gaudio_close_snd_dev() closes the control/playback/capture device
files but does not clear the file pointers afterwards, so it is not
idempotent.  gaudio_cleanup() is invoked both from the f_audio_bind()
failure path and from f_audio_free().  When a bind attempt fails after
gaudio_setup() has opened the sound device files (e.g. because
usb_ep_autoconfig() cannot find an isochronous endpoint), the files
get closed while audio_opts->bound stays true and the stale file
pointers remain set.  A subsequent bind of the same function instance
skips gaudio_setup() and closes the already freed struct files again,
triggering the file count corruption check in filp_flush().

Make gaudio_close_snd_dev() clear the file pointer (and the PCM
substream) after each close, and reset audio_opts->bound to false on
the bind failure path so that a subsequent bind reopens the sound
devices instead of reusing stale ones.

Verified with a QEMU setup (dummy UDC provides no isochronous
endpoints, so every bind fails): without the patch the second bind
attempt hits "VFS: Close: file count is 0 ... kernel BUG at
fs/open.c"; with the patch ten consecutive bind attempts complete
cleanly.

Reported-by: syzbot+592c653b056459925299@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=592c653b056459925299
Signed-off-by: Shuai Liu <847807867@qq.com>
---
 drivers/usb/gadget/function/f_uac1_legacy.c |  1 +
 drivers/usb/gadget/function/u_uac1_legacy.c | 14 +++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c
index 7c8d60c7e87d1..56b9cf8fbe92e 100644
--- a/drivers/usb/gadget/function/f_uac1_legacy.c
+++ b/drivers/usb/gadget/function/f_uac1_legacy.c
@@ -790,6 +790,7 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f)
 
 fail:
 	gaudio_cleanup(&audio->card);
+	audio_opts->bound = false;
 	return status;
 }
 
diff --git a/drivers/usb/gadget/function/u_uac1_legacy.c b/drivers/usb/gadget/function/u_uac1_legacy.c
index 01016102fa172..f074804bba59a 100644
--- a/drivers/usb/gadget/function/u_uac1_legacy.c
+++ b/drivers/usb/gadget/function/u_uac1_legacy.c
@@ -259,18 +259,26 @@ static int gaudio_close_snd_dev(struct gaudio *gau)
 
 	/* Close control device */
 	snd = &gau->control;
-	if (snd->filp)
+	if (snd->filp) {
 		filp_close(snd->filp, NULL);
+		snd->filp = 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;
+	}
 
 	/* 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;
+	}
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: gadget: uac1_legacy: fix double-close of sound device files
  2026-11-23 13:48 [PATCH] usb: gadget: uac1_legacy: fix double-close of sound device files Shuai Liu
@ 2026-11-23 14:01 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 14:01 UTC (permalink / raw)
  To: Shuai Liu; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: uac1_legacy: missing Fixes: trailer in commit
  message
--

commit 3da4b8607e9ed8f8aab229a9303b5baa05b42d1a
Author: Shuai Liu <847807867@qq.com>

> usb: gadget: uac1_legacy: fix double-close of sound device files
>
> syzbot reports:
>
>   VFS: Close: file count is 0 (f_op=snd_ctl_f_ops)
>   kernel BUG at fs/open.c
>   ...
>   Call Trace:
>    filp_flush+0x...
>    filp_close+0x...
>    gaudio_close_snd_dev
>    gaudio_cleanup
>    f_audio_bind
>    usb_add_function
>
> gaudio_close_snd_dev() closes the control/playback/capture device
> files but does not clear the file pointers afterwards, so it is not
> idempotent.  gaudio_cleanup() is invoked both from the f_audio_bind()
> failure path and from f_audio_free().  When a bind attempt fails after
> gaudio_setup() has opened the sound device files (e.g. because
> usb_ep_autoconfig() cannot find an isochronous endpoint), the files
> get closed while audio_opts->bound stays true and the stale file
> pointers remain set.  A subsequent bind of the same function instance
> skips gaudio_setup() and closes the already freed struct files again,
> triggering the file count corruption check in filp_flush().
>
> Make gaudio_close_snd_dev() clear the file pointer (and the PCM
> substream) after each close, and reset audio_opts->bound to false on
> the bind failure path so that a subsequent bind reopens the sound
> devices instead of reusing stale ones.
>
> Verified with a QEMU setup (dummy UDC provides no isochronous
> endpoints, so every bind fails): without the patch the second bind
> attempt hits "VFS: Close: file count is 0 ... kernel BUG at
> fs/open.c"; with the patch ten consecutive bind attempts complete
> cleanly.
>
> Reported-by: syzbot+592c653b056459925299@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=592c653b056459925299
> Signed-off-by: Shuai Liu <847807867@qq.com>

[Severity: Low]
Commit f3a3406b3f56 ("usb: gadget: f_uac1: convert to new function interface
with backward compatibility") added the audio_opts->bound guard around
gaudio_setup() in f_audio_bind() while calling gaudio_cleanup() on both the
bind failure path and function teardown.  Should this include a Fixes: tag?

  Fixes: f3a3406b3f56 ("usb: gadget: f_uac1: convert to new function interface with backward compatibility")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_7C654BDEA5891337506C7242C8FD481A9E05@qq.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 13:48 [PATCH] usb: gadget: uac1_legacy: fix double-close of sound device files Shuai Liu
2026-11-23 14:01 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox