Re: [PATCH v6] ALSA: line6: Stop URBs synchronously via sync_stop callback
From: Takashi Iwai
Date: Mon Nov 23 2026 - 03:59:10 EST
On Sun, 22 Nov 2026 11:40:39 +0100,
YuanZhe Liu wrote:
>
> line6_buffer_release() frees the stream buffer after
> line6_wait_clear_audio_urbs() gave up waiting for the URBs that are still
> active. The buffer is still referenced by those URBs, and the completion
> callback of such an URB resubmits it from submit_audio_out_urb() with
> line6pcm->out.buffer already set to NULL, which ends up in a NULL pointer
> dereference in the memset() in submit_audio_out_urb().
>
> While the URBs remain queued, the host controller can also write the
> received isochronous data into the freed buffer. Such a write does not go
> through the KASAN checks, so it silently corrupts the freed slab object;
> the corruption was observed as a bogus KASAN quarantine entry that later
> led to a general protection fault in qlist_free_all().
>
> The active_urbs bitmap cannot prove that the URBs are gone:
> line6_unlink_audio_urbs() is called outside the stream lock and only marks
> the URBs that are active at that moment, so an URB resubmitted by a
> completion callback right after the scan is never unlinked and keeps being
> resubmitted after the stream was stopped.
>
> Stop the URBs synchronously instead of polling for them: mark the URBs
> that are currently active under the stream lock, so that the completion
> callbacks cannot resubmit them, and kill them with usb_kill_urb(), which
> waits for the giveback. Expose this through the sync_stop PCM op, which
> ALSA core invokes before hw_free(), hw_params() and prepare() once the
> stream was stopped, so the buffer is guaranteed to be unused when it is
> released.
>
> The URBs are marked and killed only while no stream is running on that
> stream, and only those that are active at that moment, so neither a
> stream started concurrently nor another stream type still running
> (software monitoring, impulse or the capture helper) is stopped.
> Unlink marks left on already completed URBs are dropped afterwards, while
> those of still active URBs are kept, so that a later stream start can
> submit the URBs again.
>
> line6_pcm_acquire() and snd_line6_prepare() keep a synchronous stop for
> an idle stream as well: sync_stop() is invoked only when the substream
> itself was stopped, while the other stream types sharing the same stream
> never set that, and their unlinking URBs would make
> line6_stream_start() skip the submission. line6_pcm_disconnect() and
> line6_buffer_release() stop the URBs unconditionally, as the device may
> be gone already and the buffer is about to be freed.
>
> The helper skips the loop when the URBs were not created, as
> line6_pcm_disconnect() may run after a failed probe.
>
> Fixes: 63e20df1e5b2 ("ALSA: line6: Reorganize PCM stream handling")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
> Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
> Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
Applied to for-next branch now. If you have further fix, please give
an incremental fix.
thanks,
Takashi