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=1796490373; b=M3djNJvxr075WOCuSMasDJZVxFE6oEg4pGU74NLobYmRnEUhZdrkBv/M/Y1viMei1oVa aZH+hmzQXpveSqBWzfxkZJOFwPrJ2JC2u4FrM6F51OfWKBGJXMhOVeQpwUY6td4siIDZM m4MMEhyZz9X5J0EByP3XzmrdjXOvwmMMPld7VGAwrjXtZrrWdUVpP1UpNZ7PAlsldnBlO mx1kJvzsn7uIYcKuPVSUb72Ee9p5CuqXAAoQB2rdVrdqayYP+jBG37KLHo9/tb11nguCh BpcKSpJ9zkmpL6x5c8396uZ2COxbtvsujG/pWUgEhXBvnewAoKZwCBgfprggN2tUEFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796490373; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=YtgwMkeqiABEzIq649/gsAxV4gDo95aW/ZYpSW8bCDI=; b=OBcEos+Qetj5Emuff8nIv/rGN4Sik5udn6a4qNQ3fx+6aO+7WlZZu6bWQ9nGiLByBLSh xvDrrBRTGP7m369ldT2hjzZpyESa9+pu4xGjSGzZqKZ76evU8o+nYNpLsw7tIYtUVf3RM +dM+GdettBF4BcXcLKAjF7AU/hXRUzfr+FvdqMPZTljHpL6gbu8jEvUkcBMM8uBbZE8g3 wYwxGdHd9oafX+H623f3rZgFe8RtNOAO905fr5+lgSOsQcngtJi0OgTrmL6tKW78TYf7Q zzxr1M4fRUupkveq6g2raJ3nrioL6Aimq4p8m7M5z5ADSl+BGYM9xcfMVCJmOqKguag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jGDr3ILf; 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 99C71606A31F for ; Sat, 5 Dec 2026 17:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jGDr3ILf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 214011F0092B; Sat, 5 Dec 2026 17:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796490373; bh=YtgwMkeqiABEzIq649/gsAxV4gDo95aW/ZYpSW8bCDI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jGDr3ILf39jvLofqPA0dJU9DICicVvKU990dvgeod8hIoMiD8V34cNPBq9jshtHlM 57/cWubLQaEn25Glrxx+2Eci4ZO4yezqp0Tb77runneXKkOMp5cDRAhEhBhu2wWqg3 qG1ucUCXjcksVpY9+2QYIBjkMyoJspXVnwO8yuEmZyPYrqA0RVN7F7pUOQ0/eafbgh gKkinDYJxGXCajvrSoUo5voaY5YZ5QCrSbJZYAzoUAQkMOPsjZzjWjrKjhbQWTWJ53 Y5dQHKPLD84tO8kvLSfrFBsjzM0UGbvks1RPesae2GbPP3mOD6XmKp1fUnT8/LnUt0 AH9QnPT5ssIRg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: usx2y: Fix use-after-free of playback URBs at close Reply-To: sashiko-reviews@lists.linux.dev To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn> Cc: linux-sound@vger.kernel.org In-Reply-To: <20261205164316.3665-1-25031212351@stu.xidian.edu.cn> References: <20261205164316.3665-1-25031212351@stu.xidian.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 17:06:12 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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/usbusx2yau= dio.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_sub= stream *substream) > =20 > if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK) { > cap_subs =3D 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) =3D=3D 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 >=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205164316.3665= -1-25031212351@stu.xidian.edu.cn?part=3D1