mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Becholey <alex@becholey.ch>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Hanxiang Xu" <xuhx@hust.edu.cn>,
	"Šerif Rami" <ramiserifpersia@gmail.com>,
	"Alexandre Becholey" <alex@becholey.ch>
Subject: [PATCH 0/5] ALSA: usx2y: us144mkii: fix PCM stream lifetime bugs
Date: Sat, 14 Nov 2026 17:28:30 +0000	[thread overview]
Message-ID: <20261114172806.88710-1-alex@becholey.ch> (raw)

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. This series is 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.

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

 sound/usb/usx2y/us144mkii.c          |   5 +-
 sound/usb/usx2y/us144mkii.h          |   2 +
 sound/usb/usx2y/us144mkii_capture.c  |  22 ++++-
 sound/usb/usx2y/us144mkii_pcm.c      | 162 +++++++++++++++++++----------------
 sound/usb/usx2y/us144mkii_pcm.h      |   8 ++
 sound/usb/usx2y/us144mkii_playback.c |  65 ++++++++++----
 6 files changed, 170 insertions(+), 94 deletions(-)


             reply	other threads:[~2026-11-14 17:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 17:28 Alexandre Becholey [this message]
2026-11-14 17:28 ` [PATCH 1/5] ALSA: usx2y: us144mkii: fix stop_pcm_work race with PCM close Alexandre Becholey
2026-11-14 17:28 ` [PATCH 2/5] ALSA: usx2y: us144mkii: wait for the capture work on capture close Alexandre Becholey
2026-11-14 17:28 ` [PATCH 3/5] ALSA: usx2y: us144mkii: only touch the buffer of a running PCM stream Alexandre Becholey
2026-11-14 17:29 ` [PATCH 4/5] ALSA: usx2y: us144mkii: wait for the URB completion handlers on stop and close Alexandre Becholey
2026-11-14 17:29 ` [PATCH 5/5] ALSA: usx2y: us144mkii: do not restart the stream while stop_work runs Alexandre Becholey

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=20261114172806.88710-1-alex@becholey.ch \
    --to=alex@becholey.ch \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=ramiserifpersia@gmail.com \
    --cc=tiwai@suse.com \
    --cc=xuhx@hust.edu.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®