From: sashiko-bot@kernel.org
To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ALSA: usx2y: Fix use-after-free of playback URBs at close
Date: Sat, 05 Dec 2026 17:06:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-251753@kernel.org> (raw)
In-Reply-To: <20261205164316.3665-1-25031212351@stu.xidian.edu.cn>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ALSA: usx2y: UAF of capture URBs in snd_usx2y_pcm_hw_free()
- [High] ALSA: usx2y: playback hw_free() unconditionally kills active
capture
- [High] ALSA: usx2y: hw_free() vs trigger() race deadlocks
pcm_prepare()
--
commit 829b732cac6599f15afd45198cef24c7c11ba1e6
Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
ALSA: usx2y: Fix use-after-free of playback URBs at close
This commit ignores playbacksubs->completed_urb in usx2y_usbframe_complete()
once the playback stream is stopped, and changes playback
snd_usx2y_pcm_hw_free() to unconditionally stop and release the capture URBs
before releasing the playback URBs.
> diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
> index ef24c3ec690f5..6cee877833a98 100644
> --- a/sound/usb/usx2y/usbusx2yaudio.c
> +++ b/sound/usb/usx2y/usbusx2yaudio.c
[ ... ]
> @@ -824,14 +826,14 @@ static int snd_usx2y_pcm_hw_free(struct snd_pcm_substream *substream)
>
> if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
> cap_subs = subs->usx2y->subs[SNDRV_PCM_STREAM_CAPTURE];
> + /*
> + * The capture completion feeds the playback URBs; release
> + * the capture stream first so usb_kill_urb() waits for it.
> + */
> atomic_set(&subs->state, STATE_STOPPED);
> + atomic_set(&cap_subs->state, STATE_STOPPED);
> + usx2y_urbs_release(cap_subs);
> usx2y_urbs_release(subs);
> - if (!cap_subs->pcm_substream ||
> - !cap_subs->pcm_substream->runtime ||
> - cap_subs->pcm_substream->runtime->state < SNDRV_PCM_STATE_PREPARED) {
> - atomic_set(&cap_subs->state, STATE_STOPPED);
> - usx2y_urbs_release(cap_subs);
> - }
[Severity: High]
Can releasing cap_subs before subs cause a use-after-free of capture URBs?
Both capture and playback URBs share i_usx2y_urb_complete(). When a
capture URB completes before its paired playback URB, it stores itself in
capsubs->completed_urb and returns, so its use_count drops to zero. If
playback snd_usx2y_pcm_hw_free() then races with the playback URB
completion, usb_kill_urb() on the idle capture URB returns immediately and
usx2y_urbs_release(cap_subs) frees it while the playback completion is
still using it:
CPU0 CPU1
i_usx2y_urb_complete(play_urb)
usx2y_usbframe_complete()
read playbacksubs->state
snd_usx2y_pcm_hw_free()
set subs/cap_subs STATE_STOPPED
usx2y_urbs_release(cap_subs)
usb_kill_urb(cap_urb)
kfree(cap_urb->transfer_buffer)
usb_free_urb(cap_urb)
usx2y_urb_play_prepare()
cap_urb->iso_frame_desc[] <-- use-after-free
Because capture and playback completions cross-reference both streams,
killing all URBs on both streams before freeing any URB or transfer buffer
would avoid the use-after-free in either direction.
[Severity: High]
Does removing the capture state check break active full-duplex capture
streams?
Unconditionally setting cap_subs->state to STATE_STOPPED and calling
usx2y_urbs_release(cap_subs) tears down capture URBs whenever playback
closes or fails hw_params(), since snd_pcm_hw_params() calls hw_free() on
error. A running capture stream then silently stalls with no further URB
completions or xrun notification, and a prepared capture stream fails
SNDRV_PCM_TRIGGER_START with -EPIPE in snd_usx2y_pcm_trigger().
[Severity: High]
Can racing playback snd_usx2y_pcm_hw_free() with capture
snd_usx2y_pcm_trigger() deadlock snd_usx2y_pcm_prepare()?
snd_usx2y_pcm_trigger() does not hold usx2y->pcm_mutex and updates
cap_subs->state with a non-atomic read-then-set. Now that playback
hw_free() unconditionally stops and frees capture URBs even while capture
is prepared or running, a concurrent capture trigger can overwrite
STATE_STOPPED back to STATE_PRERUNNING or STATE_PREPARED after the capture
URBs have been freed:
CPU0 CPU1
snd_usx2y_pcm_trigger(capture)
atomic_read(&subs->state)
== STATE_PREPARED
snd_usx2y_pcm_hw_free(playback)
atomic_set(&cap_subs->state,
STATE_STOPPED)
usx2y_urbs_release(cap_subs)
atomic_set(&subs->state,
STATE_PRERUNNING)
snd_usx2y_pcm_prepare(playback)
capsubs->state >= STATE_PREPARED
usx2y_urbs_start(playback)
wait_event(prepare_wait_queue, ...)
<-- hangs forever
Because no capture URBs exist to drive playback startup and wake
prepare_wait_queue, usx2y_urbs_start() blocks permanently in
uninterruptible sleep while holding usx2y->pcm_mutex, wedging all
subsequent PCM operations on the card.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205164316.3665-1-25031212351@stu.xidian.edu.cn?part=1
prev parent reply other threads:[~2026-12-05 17:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 16:43 [PATCH] ALSA: usx2y: Fix use-after-free of playback URBs at close YuanZhe Liu
2026-12-05 17:06 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251753@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=25031212351@stu.xidian.edu.cn \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.