Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] usb: gadget: uac1_legacy: fix double-close of sound device files
       [not found] <20261123134853.1589732-1-847807867@qq.com>
@ 2026-11-24  8:34 ` Shuai Liu
  2026-11-24  8:47   ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Shuai Liu @ 2026-11-24  8:34 UTC (permalink / raw)
  To: Neill Kapron
  Cc: Greg Kroah-Hartman, linux-usb, syzbot+592c653b056459925299,
	sashiko-bot

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
Fixes: f3a3406b3f56 ("usb: gadget: f_uac1: convert to new function interface with backward compatibility")
Signed-off-by: Shuai Liu <847807867@qq.com>
---
Changes in v2:
 - add Fixes tag: f3a3406b3f56 converted f_uac1 to the new function
   interface and made gaudio_cleanup() run on every bind failure and
   instance free, which opened the double-close window fixed here
   (before that commit gaudio_setup()/gaudio_cleanup() were module
   init/exit and could only run once).

 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 v2] usb: gadget: uac1_legacy: fix double-close of sound device files
  2026-11-24  8:34 ` [PATCH v2] usb: gadget: uac1_legacy: fix double-close of sound device files Shuai Liu
@ 2026-11-24  8:47   ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-24  8:47 UTC (permalink / raw)
  To: Shuai Liu; +Cc: linux-usb

> 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
> [ ... ]
> 
> Reported-by: syzbot+592c653b056459925299@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=592c653b056459925299
> Fixes: f3a3406b3f56 ("usb: gadget: f_uac1: convert to new function interface with backward compatibility")
> Signed-off-by: Shuai Liu <847807867@qq.com>

Sashiko has reviewed this patch and found no issues.

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

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

end of thread, other threads:[~2026-11-24  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261123134853.1589732-1-847807867@qq.com>
2026-11-24  8:34 ` [PATCH v2] usb: gadget: uac1_legacy: fix double-close of sound device files Shuai Liu
2026-11-24  8:47   ` sashiko-bot

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