Re: [PATCH v2 0/5] ALSA: usx2y: us144mkii: fix PCM stream lifetime bugs

From: Alexandre Becholey

Date: Mon Nov 16 2026 - 08:05:18 EST


On Monday, November 16th, 2026 at 1:14 PM, Takashi Iwai <tiwai@xxxxxxx> wrote:

> On Mon, 16 Nov 2026 08:17:25 +0100,
> Alexandre Becholey wrote:
> >
> > Hi,
> >
> > Five bugs in the snd-usb-us144mkii PCM code, all reproduced with an
> > emulated US-144MKII under KASAN on torvalds/master and v7.3.1:
> >
> > 1/5 stop_pcm_work calls snd_pcm_stop() on a substream that is being
> > closed (use-after-free of the runtime); the device can schedule
> > the work at any time by sending bad feedback.
> > 2/5 capture_work keeps using the capture runtime after the capture
> > PCM is closed while playback is running (use-after-free).
> > 3/5 the capture work and the playback URB completion use the buffer
> > of a substream that was never started (NULL dma_area), because
> > the URBs of both directions always run together.
> > 4/5 the playback and feedback URB completions use the substream
> > runtime and buffer without waiting for close (use-after-free).
> > 5/5 a START retried while stop_work runs submits URBs that are still
> > in flight (URB submitted while active, anchor list corruption).
> >
> > The patches depend on each other and are meant to be applied in this
> > order: 2/5 builds on the close callback of 1/5, the check added in 3/5
> > is only safe once 2/5 guarantees that the capture work does not outlive
> > the substream, and 4/5 and 5/5 apply on top of the first three. In
> > testing, 3/5 without 2/5 crashed in the new check, and 1/5 + 2/5
> > without 3/5 still crashed on the NULL dma_area. Each patch has its
> > testing notes below its '---' line.
> >
> > Hanxiang Xu reported the bugs fixed by 1/5, 2/5 and 4/5 on this list
> > on 2026-11-13, from source inspection and without a patch; we found
> > them independently with emulated devices. v1 was sent as a reply
> > to that report, and 1/5, 2/5 and 4/5 carry Closes: tags for the two
> > messages. The reports also mention close racing with disconnect:
> > that concerns a fix that kills URBs in .close, which this series does
> > not do (the .close callbacks only touch the card private data), so
> > nothing is changed for it.
> >
> > Changes in v2, both from the Sashiko reviews of v1:
> > - 3/5: also count the hardware position and the elapsed periods in
> > feedback_urb_complete() only while the substream is running, so that
> > a substream started after the other one starts at the beginning of
> > its buffer.
> > https://lore.kernel.org/all/sashiko-outbox-214859@xxxxxxxxxx/
> > - 4/5: make playback_substream and capture_substream __rcu pointers,
> > published with rcu_assign_pointer() and read with rcu_dereference();
> > the capture work now also uses the substream inside an RCU read-side
> > section.
> > https://lore.kernel.org/all/sashiko-outbox-214863@xxxxxxxxxx/
> > - 1/5, 2/5: no change; 5/5: rebased, no change.
> >
> > v2 was tested on v7.3.1 and on torvalds/master 97d73c825122 with the
> > reproducers of all five patches, with KASAN, PROVE_LOCKING and
> > PROVE_RCU: no us144mkii report in 84 runs (the same reproducers
> > crashed unpatched v7.3.1 in 8 of 8 runs).
> >
> > v1: https://lore.kernel.org/all/20261114172806.88710-1-alex@xxxxxxxxxxx/
> >
> > How we found it: the bugs were found, and the reproducers and these
> > patches were written, by AI agents (Claude Mythos and Claude Opus
> > models), in QEMU with emulated USB devices (raw-gadget/dummy_hcd,
> > emulated xHCI, USB/IP).
> > A human reviewed the analysis and the patches. The reproducers are
> > available on request.
> >
> > Thanks,
> > Alexandre Becholey
> >
> > Alexandre Becholey (5):
> > ALSA: usx2y: us144mkii: fix stop_pcm_work race with PCM close
> > ALSA: usx2y: us144mkii: wait for the capture work on capture close
> > ALSA: usx2y: us144mkii: only touch the buffer of a running PCM stream
> > ALSA: usx2y: us144mkii: wait for the URB completion handlers on stop and close
> > ALSA: usx2y: us144mkii: do not restart the stream while stop_work runs
>
> Thanks for the patch.
>
> But, I believe that we should rather address the whole us144mkii
> driver issues differently: this kind of duct-tape fixes won't work
> well for this driver simply because the current code isn't designed
> well for the concurrent playback / capture changes at all. That is,
> it needs a redesign about how to keeping the streaming for full duplex
> and concurrent open/close or parameter changes.
>
> And, those patches generated by AI often make the same mistake.
> Basically, at the close callback, we shouldn't deal with the cleanup
> for work, etc. At the time of close callback, all streams must have
> been already turned down and cleaned up. The work stop and sync
> should have been done at PCM trigger and sync_stop callbacks, instead.
>
> I guess AI has been trained more with the older code changes that
> didn't use the sync_stop, so it tends to produce a quite old-fashioned
> code. You can give hints about the above point, I suppose.
>
>
> thanks,
>
> Takashi
>

Hi Takashi,

Thanks for the review. Yes AI have a tendency to go down rabbit holes instead of taking a step back to see the bigger picture. I also tried to run the Sashiko bot locally but with the models I have access to, they wouldn't find those issues consistently.

We don't have a real US-144MKII, which matters for a redesign of the streaming. What we can do is to send the reproducers and our analysis of the five bugs to whoever takes it on.

Thanks,
Alexandre