From: 徐晗翔 <xuhx@hust.edu.cn>
To: perex@perex.cz, tiwai@suse.com
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized (probe-window NULL deref via MISC_MODE ioctl)
Date: Tue, 1 Dec 2026 11:25:38 +0800 (GMT+08:00) [thread overview]
Message-ID: <111775f5.43a9.1a22fa2f3b8.Coremail.xuhx@hust.edu.cn> (raw)
In-Reply-To: <2026102727-data-sequel-ce41@gregkh>
[-- Attachment #1: Type: text/plain, Size: 9469 bytes --]
Opening /dev/snd/hwC*D* on an emux wavetable (emu10k1/emu8000 synth
sub-driver) pins only the base-card module (try_module_get of
hw->card->module in snd_hwdep_open()); the emux sub-driver module is
not pinned, and removing the sub-driver (rmmod snd_emu10k1_synth, or
sysfs unbind which bypasses module refcounts) runs snd_emux_free(),
which unconditionally kfree()s the struct snd_hwdep, the whole soundfont
list (snd_sf_free()) and the struct snd_emux itself -- while the fd
stays open with file->private_data pointing at the freed hwdep and
in-flight snd_emux_hwdep_ioctl() calls still executing (snd_hwdep_ioctl
holds no open_mutex, and snd_hwdep_dev_disconnect() checks neither
hwdep->used nor replaces f_op the way a whole-card disconnect does).
Verified on mainline 7.3 with a KASAN kernel and the real in-tree
snd-emux-synth module (harness attached): one hundred slab-use-after-free
reports while a hwdep fd hammers VERSION/MEM_AVAIL/MISC_MODE ioctls
across snd_emux_free() -- snd_emux_hwdep_ioctl() at five distinct
dereference points (emu->sflist, emu->memhdr, emu->portptrs including a
UAF write, hw->private_data) plus snd_hwdep_ioctl() reading hw->ops --
and, with rmmod, the module text can additionally be unloaded while
those callbacks are still running (snd_hwdep_f_ops.owner pins the
snd-hwdep module, not the emux one). Needs the synth sub-driver
probed; triggering the in-flight overlap needs only /dev/snd access.
Consequences: multi-object UAF read/write (function pointer tables,
mutex objects) and execution of unloaded module text -- crashes and a
controlled indirect-call surface.
The detailed description:
* Test environment / affected version
Linux version 7.3.0 (gcc 13.3.0, GNU ld 2.42) #6 SMP PREEMPT_DYNAMIC
-- vanilla mainline 7.3 tree, unmodified sources; KASAN enabled,
QEMU/KVM x86_64 guest. sound/core/hwdep.c, sound/synth/emux/* and
sound/core/rawmidi.c are byte-identical between the tested tree and
the report baseline.
* Mechanism
- snd_hwdep_open() (hwdep.c:88) pins hw->card->module only; the emux
hwdep registers no ops.open/ops.release hooks
(emux_hwdep.c:126-131), so nothing increments snd_emux usage for
hwdep fds (contrast: sequencer port subscribe and OSS-sequencer
open both go through snd_emux_inc_count(), which also pins
emu->ops.owner -- the sub-driver module).
- snd_hwdep_ioctl() (hwdep.c:236-254) dispatches hw->ops.ioctl
without holding hw->open_mutex; the emux ioctl touches
hw->private_data, emu->sflist, emu->memhdr and emu->portptrs.
- The sub-driver removal path snd_emux_free() (emux.c:124-143)
performs snd_emux_delete_hwdep() -> snd_device_free() ->
snd_hwdep_dev_disconnect() (which does not consult hwdep->used and
does not revoke f_op for open fds) -> snd_hwdep_free() -> kfree
(hwdep), then snd_sf_free() -> kfree(sflist), kfree(emu->voices),
kfree(emu) -- none of it waits for hwdep->used to drop.
- Whole-card snd_card_free() is NOT affected: snd_card_disconnect()
replaces open fds' f_op with snd_shutdown_f_ops and the teardown
waits for all files to close before the free sequence runs. The
sub-driver independent removal bypasses that protocol entirely --
that bypass is the defect.
The same shape exists for the emux virtual rawmidi devices
(snd_emux_delete_virmidi() -> snd_device_free() of RAWMIDI devices;
snd_rawmidi_open() likewise only pins the card module and
snd_rawmidi_free() kfrees unconditionally), and for the probe error
path of snd_emux_register() (init_hwdep registers the device, then a
later init_seq failure frees everything through snd_emux_free()).
This patch fixes the hwdep fd face; the rawmidi face is mentioned
for completeness and needs the equivalent treatment.
* Trigger model
emu10k1/emu8000 hardware with the synth sub-driver probed
(hwC*D2 fixed for emu10k1). One process holds the exclusive hwdep
fd open and issues ioctls; another (root, or hot-unplug hardware
event) runs `rmmod snd_emu10k1_synth` (works: hwdep fds contribute
no sub-driver module refcount) or writes the driver's unbind file.
Consequence: UAF read/write on struct snd_hwdep (function pointer
table hw->ops, hw->used decrement), struct snd_emux, struct
snd_sf_list (presets_mutex operations on freed memory) and the
portptrs targets, plus execution of already-unloaded module text in
the rmmod case.
* Reproducer and results on 7.3
synthrace.c registers the real in-tree emux on a virtual card
(snd_emux_new/snd_emux_register, backend ops mirroring emu10k1);
synth_test holds /dev/snd/hwC0D0 open and loops the three ioctls;
writing 1 to the module's "free" parameter runs the real
snd_emux_free() (the sub-driver remove body) under the hammer.
Results (7.3, KASAN, 2 vCPU): 100 slab-use-after-free reports:
snd_emux_hwdep_ioctl+0x73/0x15d/0x1bd/0x2be/0x2d6 (emu/sflist/memhdr/
portptrs accesses, including a UAF write) and
snd_hwdep_ioctl+0x11f (hw->ops read). A harness run with the free
disabled stays clean.
* Fix
Give hwdep fds the same user accounting the sequencer and OSS paths
already have, and make the sub-driver removal wait for them:
- register hw->ops.open / hw->ops.release calling
snd_emux_inc_count() / snd_emux_dec_count(). inc_count already
try_module_get()s emu->ops.owner (the sub-driver module), so an
open hwdep fd now blocks rmmod exactly like a sequencer/OSS user;
- count open fds additionally in a new atomic emu->hwdep_users and
make snd_emux_free() wait for it to drain (at the top, before any
sub-structure is torn down, so in-flight ioctls cannot observe
partially freed state either).
sysfs unbind bypasses module refcounts, which is why the drain wait
is needed in addition to the refcount. This matches the semantics
the whole-card path already provides (snd_card_disconnect() waits
for open files before anything is freed).
The patch is a suggested direction, written against 7.3 and reviewed
by inspection; it has not been runtime-validated (the reported
reproduction used the unpatched kernel). Happy to test any
counter-proposal.
* Patch
[PATCH] ALSA: emux: drain open hwdep users before freeing emux
structures
snd_emux_free() (the sub-driver remove path, reachable via
rmmod snd_emu10k1_synth or sysfs unbind) kfrees the struct snd_hwdep,
the soundfont list and the struct snd_emux without waiting for open
hwdep file descriptors: hwdep fds pin only the base-card module, the
emux hwdep registers no open/release hooks, and an in-flight
snd_emux_hwdep_ioctl() (which does not hold open_mutex) plus every
later operation on the stale fd hits freed memory. KASAN on 7.3 shows
100 UAF reports in snd_emux_hwdep_ioctl/snd_hwdep_ioctl for this
interleave.
Register hwdep open/release hooks that take snd_emux_inc_count()
(also pinning emu->ops.owner against rmmod, like the sequencer and
OSS-sequencer paths already do), count them in a new emu->hwdep_users,
and make snd_emux_free() wait for that count to drain before tearing
anything down -- mirroring the drain that snd_card_disconnect()
performs for whole-card removal. Note that sysfs unbind is not
covered by module refcounts, which is why the drain wait is required
in addition to the refcount.
--- a/include/sound/emux_synth.h
+++ b/include/sound/emux_synth.h
@@ -99,6 +99,8 @@ struct snd_emux {
int use_time; /* allocation counter */
spinlock_t voice_lock; /* Lock for voice access */
struct mutex register_mutex;
+ atomic_t hwdep_users; /* open hwdep fds */
+ wait_queue_head_t free_wait; /* sub-driver removal waits for hwdep_users */
int client; /* For the sequencer client */
int ports[SNDRV_EMUX_MAX_PORTS]; /* The ports for this device */
--- a/sound/synth/emux/emux.c
+++ b/sound/synth/emux/emux.c
@@ -32,6 +32,8 @@ int snd_emux_new(struct snd_emux **remu)
spin_lock_init(&emu->voice_lock);
mutex_init(&emu->register_mutex);
+ atomic_set(&emu->hwdep_users, 0);
+ init_waitqueue_head(&emu->free_wait);
emu->client = -1;
@@ -126,6 +130,19 @@ int snd_emux_free(struct snd_emux *emu)
if (! emu)
return -EINVAL;
timer_shutdown_sync(&emu->tlist);
+
+ wait_event(emu->free_wait, !atomic_read(&emu->hwdep_users));
snd_emux_proc_free(emu);
snd_emux_delete_virmidi(emu);
--- a/sound/synth/emux/emux_hwdep.c
+++ b/sound/synth/emux/emux_hwdep.c
@@ (before snd_emux_hwdep_ioctl)
+static int
+snd_emux_hwdep_open(struct snd_hwdep *hw, struct file *file)
+{
+ struct snd_emux *emu = hw->private_data;
+
+ if (!snd_emux_inc_count(emu))
+ return -EFAULT;
+ atomic_inc(&emu->hwdep_users);
+ return 0;
+}
+
+static int
+snd_emux_hwdep_release(struct snd_hwdep *hw, struct file *file)
+{
+ struct snd_emux *emu = hw->private_data;
+
+ atomic_dec(&emu->hwdep_users);
+ wake_up(&emu->free_wait);
+ snd_emux_dec_count(emu);
+ return 0;
+}
+
+
/*
* ioctl
*/
static int
snd_emux_hwdep_ioctl(struct snd_hwdep * hw, struct file *file,
@@ -120,6 +166,9 @@ int
hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE;
hw->ops.ioctl = snd_emux_hwdep_ioctl;
/* The ioctl parameter types are compatible between 32- and
* 64-bit architectures, so use the same function. */
hw->ops.ioctl_compat = snd_emux_hwdep_ioctl;
+ hw->ops.open = snd_emux_hwdep_open;
+ hw->ops.release = snd_emux_hwdep_release;
hw->exclusive = 1;
hw->private_data = emu;
--
2.47.1
Please keep me in Cc; I am not subscribed to the lists.
Regards,
Hanxiang Xu
xuhx@hust.edu.cn
[-- Attachment #2: synth_test.c --]
[-- Type: text/plain, Size: 8705 bytes --]
// SPDX-License-Identifier: GPL-2.0
/*
* synth_test.c - userspace driver for the emux race verification harness.
*
* Plans:
* load [secs] - open /dev/snd/hwC0D0 and load a soundfont through the
* REAL hwdep SNDRV_EMUX_IOCTL_LOAD_PATCH path
* (OPEN_PATCH + LOAD_DATA + LOAD_INFO), then keep the
* fd open. Writes /tmp/synth_loaded when done.
* reload [secs] - same, but keeps re-issuing LOAD_DATA+LOAD_INFO in a
* loop (font gets eaten by the kernel-side removal
* hammer in plan mr01nat).
* mr03 [iters] - open hwdep and hammer ioctls (VERSION / MEM_AVAIL /
* MISC_MODE) - the in-flight side of SYNTH-MR-03.
* mr04 [iters] - hammer open+read+close on
* /proc/asound/card0/wavetableD0 - the reader side of
* SYNTH-MR-04.
* mr04hold - open the proc file, print "HOLD", sleep 3s (the host
* script frees emux in between), then read again -
* delayed-UAF variant of SYNTH-MR-04.
* mr05 - poll for /dev/snd/hwC0D0 (probe-window race), open it
* and issue SNDRV_EMUX_IOCTL_MISC_MODE - the NULL-deref
* side of SYNTH-MR-05.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sound/asound.h>
#include "include/sound/sfnt_info.h"
/* ---- soundfont binary construction (wire format of
* sound/synth/emux/soundfont.c) ---- */
static void patch_hdr(unsigned char *p, int type, int len, int optarg)
{
struct soundfont_patch_info h;
memset(&h, 0, sizeof(h));
h.key = SNDRV_OSS_SOUNDFONT_PATCH;
h.device_no = 0;
h.sf_id = 0;
h.optarg = optarg;
h.len = len;
h.type = type;
memcpy(p, &h, sizeof(h));
}
static int sf_load(int fd)
{
unsigned char buf[512];
struct soundfont_open_parm parm;
struct soundfont_sample_info si;
struct soundfont_voice_rec_hdr rh;
struct soundfont_voice_info vi;
int rc;
/* OPEN_PATCH */
memset(&parm, 0, sizeof(parm));
parm.type = SNDRV_SFNT_PAT_TYPE_MISC | SNDRV_SFNT_PAT_SHARED;
strcpy(parm.name, "synthrace");
patch_hdr(buf, SNDRV_SFNT_OPEN_PATCH, sizeof(parm), 0);
memcpy(buf + sizeof(struct soundfont_patch_info), &parm, sizeof(parm));
rc = ioctl(fd, SNDRV_EMUX_IOCTL_LOAD_PATCH, buf);
if (rc < 0) {
/* font already open from an earlier round */
if (errno == EBUSY)
return 0;
fprintf(stderr, "LOAD_PATCH OPEN: %s\n", strerror(errno));
return -1;
}
/* LOAD_DATA: 1 sample, 64 s16le frames */
memset(&si, 0, sizeof(si));
si.sample = 1;
si.start = 0;
si.end = 64;
si.loopstart = 8;
si.loopend = 56;
si.size = 64;
si.mode_flags = SNDRV_SFNT_SAMPLE_NO_BLANK;
patch_hdr(buf, SNDRV_SFNT_LOAD_DATA, sizeof(si) + si.size * 2, 0);
memcpy(buf + sizeof(struct soundfont_patch_info), &si, sizeof(si));
memset(buf + sizeof(struct soundfont_patch_info) + sizeof(si), 0x7f,
si.size * 2);
rc = ioctl(fd, SNDRV_EMUX_IOCTL_LOAD_PATCH, buf);
if (rc < 0) {
fprintf(stderr, "LOAD_PATCH DATA: %s\n", strerror(errno));
return -1;
}
/* LOAD_INFO: one zone, bank 0 / instr 0, note 0..127, vel 0..127,
* exclusiveClass = 1, tied to sample 1 */
memset(&vi, 0, sizeof(vi));
vi.sf_id = 0;
vi.sample = 1;
vi.root = 60;
vi.high = 127;
vi.velhigh = 127;
vi.fixkey = -1;
vi.fixvel = -1;
vi.fixpan = -1;
vi.pan = -1;
vi.amplitude = 127;
vi.scaleTuning = 100;
vi.exclusiveClass = 1;
memset(&rh, 0, sizeof(rh));
rh.bank = 0;
rh.instr = 0;
rh.nvoices = 1;
rh.write_mode = SNDRV_SFNT_WR_APPEND;
patch_hdr(buf, SNDRV_SFNT_LOAD_INFO,
sizeof(rh) + sizeof(vi), 0);
memcpy(buf + sizeof(struct soundfont_patch_info), &rh, sizeof(rh));
memcpy(buf + sizeof(struct soundfont_patch_info) + sizeof(rh),
&vi, sizeof(vi));
rc = ioctl(fd, SNDRV_EMUX_IOCTL_LOAD_PATCH, buf);
if (rc < 0) {
fprintf(stderr, "LOAD_PATCH INFO: %s\n", strerror(errno));
return -1;
}
/* CLOSE_PATCH -> close_patch() -> rebuild_presets(): zones loaded via
* LOAD_INFO only enter the preset table at close time (this is the
* real sfxload sequence), so note_on's search_zones() can find them */
patch_hdr(buf, SNDRV_SFNT_CLOSE_PATCH, 0, 0);
rc = ioctl(fd, SNDRV_EMUX_IOCTL_LOAD_PATCH, buf);
if (rc < 0) {
fprintf(stderr, "LOAD_PATCH CLOSE: %s\n", strerror(errno));
return -1;
}
return 0;
}
static int plan_load(int secs, int reload)
{
int fd, n = 0;
unsigned long until = (unsigned long)time(NULL) + (secs > 0 ? secs : 30);
fd = open("/dev/snd/hwC0D0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "open hwC0D0: %s\n", strerror(errno));
return 1;
}
if (sf_load(fd) < 0) {
close(fd);
return 1;
}
printf("LOAD: font ready\n");
fflush(stdout);
int tf = open("/tmp/synth_loaded", O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (tf >= 0)
close(tf);
while (reload && (unsigned long)time(NULL) < until) {
/* re-load data+info; kernel-side hammer eats the font */
if (sf_load(fd) < 0)
break;
n++;
usleep(2000);
}
printf("LOAD: done (%d reloads)\n", n);
/* keep the fd open until the plan ends (exclusive hwdep) */
sleep(secs > 0 ? secs : 30);
close(fd);
return 0;
}
static int plan_mr03(int iters)
{
int fd, i;
struct snd_emux_misc_mode mm;
unsigned int ver = 0;
int avail = 0;
fd = open("/dev/snd/hwC0D0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "open hwC0D0: %s\n", strerror(errno));
return 1;
}
printf("MR03: hammering %d ioctl iterations\n", iters);
fflush(stdout);
for (i = 0; i < iters; i++) {
ioctl(fd, SNDRV_EMUX_IOCTL_VERSION, &ver);
ioctl(fd, SNDRV_EMUX_IOCTL_MEM_AVAIL, &avail);
memset(&mm, 0, sizeof(mm));
mm.port = -1;
mm.mode = 0;
mm.value = 0;
ioctl(fd, SNDRV_EMUX_IOCTL_MISC_MODE, &mm);
if ((i % 128) == 0) {
printf("MR03: iter %d\n", i);
fflush(stdout);
}
usleep(100);
}
printf("MR03: closing\n");
fflush(stdout);
close(fd);
sleep(2);
close(open("/dev/snd/hwC0D0", O_RDWR)); /* delayed variant: reopen */
printf("MR03: done\n");
return 0;
}
static int plan_mr04(int iters)
{
int i;
printf("MR04: hammering %d proc-read iterations\n", iters);
fflush(stdout);
for (i = 0; i < iters; i++) {
char buf[4096];
int fd = open("/proc/asound/card0/wavetableD0", O_RDONLY);
if (fd >= 0) {
ssize_t r = read(fd, buf, sizeof(buf));
(void)r;
close(fd);
}
if ((i % 128) == 0) {
printf("MR04: iter %d\n", i);
fflush(stdout);
}
usleep(500);
}
printf("MR04: done\n");
return 0;
}
static int plan_mr04hold(void)
{
char buf[4096];
int fd;
fd = open("/proc/asound/card0/wavetableD0", O_RDONLY);
if (fd < 0) {
fprintf(stderr, "open proc: %s\n", strerror(errno));
return 1;
}
printf("MR04HOLD: fd open, reading once\n");
fflush(stdout);
read(fd, buf, sizeof(buf));
printf("MR04HOLD: holding fd for 4s (free happens now)\n");
fflush(stdout);
sleep(4);
off_t ls = lseek(fd, 0, SEEK_SET);
printf("MR04HOLD: delayed read on stale fd (lseek=%ld)\n", (long)ls);
fflush(stdout);
ssize_t rr = read(fd, buf, sizeof(buf));
printf("MR04HOLD: stale read rc=%zd errno=%d\n", rr, rr < 0 ? errno : 0);
fflush(stdout);
printf("MR04HOLD: done\n");
close(fd);
return 0;
}
static int plan_mr05(void)
{
int fd, tries;
struct snd_emux_misc_mode mm;
for (tries = 0; tries < 5000; tries++) {
struct stat st;
if (stat("/dev/snd/hwC0D0", &st) == 0)
break;
usleep(1000);
}
if (tries >= 5000) {
fprintf(stderr, "MR05: hwC0D0 never appeared\n");
return 1;
}
fd = open("/dev/snd/hwC0D0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "MR05: open: %s\n", strerror(errno));
return 1;
}
printf("MR05: opened inside probe window, issuing MISC_MODE\n");
fflush(stdout);
memset(&mm, 0, sizeof(mm));
mm.port = -1;
mm.mode = 0;
mm.value = 0;
ioctl(fd, SNDRV_EMUX_IOCTL_MISC_MODE, &mm);
printf("MR05: ioctl returned rc=%d (%s)\n", fd, strerror(errno));
fflush(stdout);
close(fd);
return 0;
}
int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "usage: synth_test <plan> [arg]\n");
return 2;
}
if (!strcmp(argv[1], "load"))
return plan_load(argc > 2 ? atoi(argv[2]) : 30, 0);
if (!strcmp(argv[1], "reload"))
return plan_load(argc > 2 ? atoi(argv[2]) : 30, 1);
if (!strcmp(argv[1], "mr03"))
return plan_mr03(argc > 2 ? atoi(argv[2]) : 3000);
if (!strcmp(argv[1], "mr04"))
return plan_mr04(argc > 2 ? atoi(argv[2]) : 2000);
if (!strcmp(argv[1], "mr04hold"))
return plan_mr04hold();
if (!strcmp(argv[1], "mr05"))
return plan_mr05();
fprintf(stderr, "unknown plan %s\n", argv[1]);
return 2;
}
[-- Attachment #3: synthmr05.c --]
[-- Type: text/plain, Size: 4983 bytes --]
// SPDX-License-Identifier: GPL-2.0
/*
* synthmr05.c - controlled-window verification for SYNTH-MR-05
* (docs/manual-review-sound-synth-2026-11-26.md §2.5):
*
* snd_emux_register() calls snd_emux_init_hwdep() FIRST, whose
* snd_card_register() publishes /dev/snd/hwC*D* to userspace, and only then
* snd_emux_init_seq() fills emu->portptrs[] (kzalloc'd NULL until then).
* A user opening the hwdep node inside that window and issuing
* SNDRV_EMUX_IOCTL_MISC_MODE hits snd_emux_hwdep_misc_mode() ->
* emu->portptrs[i]->ctrls[..] with portptrs[i] == NULL -> NULL-pointer
* WRITE -> oops.
*
* Controlled window: kprobe on snd_emux_init_seq() stalls the (single-caller)
* probe thread at its entry - i.e., exactly after the hwdep node is exposed
* and before portptrs[] is filled. Userspace polls for the node, opens it,
* issues the ioctl -> deterministic NULL deref. After the stall expires the
* registration completes.
*/
#define pr_fmt(fmt) "SYNTHMR05: " fmt
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/kprobes.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/completion.h>
#include <linux/device.h>
#include <sound/core.h>
#include <sound/emux_synth.h>
#include <sound/util_mem.h>
static struct device *parent;
static struct snd_card *card;
static struct snd_emux *emu;
static struct kprobe mr5_kp;
static struct completion reg_done;
static unsigned int stall_ms = 4000;
module_param(stall_ms, uint, 0400);
static int mr5_start(struct snd_emux_voice *vp) { return 0; }
static void mr5_void1(struct snd_emux_voice *vp) {}
static void mr5_void2(struct snd_emux_voice *vp, int u) {}
static struct snd_emux_voice *mr5_get_voice(struct snd_emux *e,
struct snd_emux_port *port)
{
return NULL;
}
static int mr5_snew(struct snd_emux *e, struct snd_sf_sample *sp,
struct snd_util_memhdr *h, const void __user *d, long c)
{
sp->block = snd_util_mem_alloc(h, 256);
return sp->block ? 0 : -ENOMEM;
}
static int mr5_sfree(struct snd_emux *e, struct snd_sf_sample *sp,
struct snd_util_memhdr *h)
{
if (sp->block) {
snd_util_mem_free(h, sp->block);
sp->block = NULL;
}
return 0;
}
static const struct snd_emux_operators mr5_ops = {
.owner = THIS_MODULE,
.get_voice = mr5_get_voice,
.prepare = mr5_start,
.trigger = mr5_void1,
.release = mr5_void1,
.update = mr5_void2,
.terminate = mr5_void1,
.sample_new = mr5_snew,
.sample_free = mr5_sfree,
};
static int mr5_reg_pre(struct kprobe *p, struct pt_regs *regs)
{
pr_info("probe thread stalled at snd_emux_init_seq() entry: "
"hwC0D0 exposed, portptrs[] still NULL (window open)\n");
mdelay(stall_ms);
pr_info("probe thread resuming snd_emux_init_seq()\n");
return 0;
}
static int mr5_reg_thread(void *arg)
{
int err;
err = snd_emux_new(&emu);
if (err < 0) {
complete(®_done);
return 0;
}
emu->ops = mr5_ops;
emu->hw = card;
emu->max_voices = 8;
emu->num_ports = 1; /* > 0: drives the buggy loop bound */
emu->midi_ports = 0;
emu->hwdep_idx = 0; /* /dev/snd/hwC0D0 */
emu->memhdr = snd_util_memhdr_new(0x100000);
/* registers hwdep (exposes hwC0D0 via snd_card_register) and then
* enters snd_emux_init_seq() -> stalled by the kprobe */
err = snd_emux_register(emu, card, 0, "synthmr05");
pr_info("snd_emux_register returned %d\n", err);
if (err < 0) {
snd_emux_free(emu);
emu = NULL;
}
complete(®_done);
return 0;
}
static int arm_set(const char *val, const struct kernel_param *kparam)
{
struct task_struct *t;
int ret;
if (!card)
return -ENODEV;
memset(&mr5_kp, 0, sizeof(mr5_kp));
mr5_kp.symbol_name = "snd_emux_init_seq";
mr5_kp.pre_handler = mr5_reg_pre;
ret = register_kprobe(&mr5_kp);
if (ret) {
pr_err("register_kprobe(snd_emux_init_seq) failed: %d\n", ret);
return ret;
}
init_completion(®_done);
t = kthread_run(mr5_reg_thread, NULL, "synthmr05_reg");
if (IS_ERR(t)) {
unregister_kprobe(&mr5_kp);
return PTR_ERR(t);
}
pr_info("armed: probe thread started, window open for ~%ums\n",
stall_ms);
return 0;
}
static const struct kernel_param_ops arm_ops = { .set = arm_set };
module_param_cb(arm, &arm_ops, NULL, 0200);
static int __init synthmr05_init(void)
{
int err;
init_completion(®_done);
parent = root_device_register("synthmr05");
if (IS_ERR(parent))
return PTR_ERR(parent);
err = snd_card_new(parent, 0, "synthmr05", THIS_MODULE, 0, &card);
if (err < 0) {
root_device_unregister(parent);
parent = NULL;
return err;
}
return 0;
}
static void __exit synthmr05_exit(void)
{
wait_for_completion_timeout(®_done, msecs_to_jiffies(30000));
unregister_kprobe(&mr5_kp);
if (emu) {
snd_emux_free(emu);
emu = NULL;
}
if (card) {
snd_card_free(card);
card = NULL;
}
if (parent) {
root_device_unregister(parent);
parent = NULL;
}
}
module_init(synthmr05_init);
module_exit(synthmr05_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SYNTH-MR-05 probe-window race verification harness");
next prev parent reply other threads:[~2026-12-01 3:25 UTC|newest]
Thread overview: 151+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 12:35 usb: devio: usbdev_release() has no barrier against an in-flight async_completed() callback (use-after-free window on struct usb_dev_state)gregkh@linuxfoundation.org 徐晗翔
2026-10-27 14:12 ` Greg KH
2026-11-03 11:21 ` mm/slub: has_pcs_used() reads remote per-CPU sheaf state from flush_all_cpus_locked() without synchronization (data race; KCSAN blind spot: slub.o is uninstrumented) 徐晗翔
2026-11-04 9:41 ` Qing Wang
2026-11-04 10:07 ` Qing Wang
2026-11-03 11:30 ` futex/hrtimer: hrtimer_sleeper::task is read unsynchronized in 16 places on v7.3 -- the accessor series that fixes this is not in 7.3; please make sure it reaches the affected trees (backport nudge + stock-kernel KCSAN evidence) 徐晗翔
2026-11-03 11:48 ` cgroup: fork vs cgroup.procs write race in favordynmods mode -- v7.3 is affected; please make sure bf6fbf46b5ff reaches the stable trees (repro incl. uninstrumented natural hit) 徐晗翔
2026-11-03 14:51 ` Sasha Levin
2026-11-03 11:57 ` net: rtnetlink: rtnl_link_unregister() vs in-flight RTM_GETLINK dump readers -- v7.3 lacks the synchronize_rcu() fix (Fixes: 6b57ff21a310 family); A/B reproduction on stock 7.3 徐晗翔
2026-11-03 15:49 ` Eric Dumazet
2026-11-04 15:03 ` Sasha Levin
2026-11-03 12:07 ` wifi: wilc1000: SDIO/SPI remove destroys the srcu_struct before wiphy_unregister() -- late cfg80211 callbacks write through dangling srcu state (unfixed upstream; controlled + natural Oops) 徐晗翔
2026-11-03 12:10 ` gpio: gpiolib: final put of the gpio_device happens inside the SRCU read critical section on the setup-failure path -- deterministic use-after-free read at guard release (unfixed upstream) 徐晗翔
2026-11-05 8:52 ` Linus Walleij
2026-11-04 12:54 ` soc: qcom: pmic_glink_altmode: fix use-after-free on unbind (no cancel_work_sync for port work and enable_work) 徐晗翔
2026-11-04 13:04 ` Greg KH
2026-11-04 12:57 ` usb: typec: anx7411: unregister partner/altmodes before stopping the IRQ work -- use-after-free, double unregister, orphan partner on remove 徐晗翔
2026-11-04 13:28 ` Greg KH
2026-11-04 12:58 ` usb: typec: ucsi: deadlock on cros_ec unbind -- connector lock held across cancel_delayed_work_sync vs the mode-selection work's unbounded trylock polling 徐晗翔
2026-11-04 13:00 ` usb: typec: stusb160x/rt1719/hd3ss3220: IRQ thread vs remove -- double unregister / use-after-free on the partner and port 徐晗翔
2026-11-04 13:01 ` usb: typec: ucsi: displayport: data race on dp->header/ vdo_data/vdo_size -- work reads them unlocked while writers hold con->lock (VDM mismatch) 徐晗翔
2026-11-04 13:02 ` usb: typec: class: three lifetime/locking gaps around the mux/switch handles and mode_selection (drvdata UAF after provider unbind; no concurrent protocol for set/put; unlocked state_update vs delete) 徐晗翔
2026-11-10 12:56 ` driver core: uevent: netns teardown frees uevent_sock while a tagged uevent is still being broadcast (UAF) 徐晗翔
2026-11-10 13:00 ` 徐晗翔
2026-11-10 18:48 ` Greg KH
2026-11-10 13:05 ` ACPI: CPPC: per-CPU cpc_desc is freed on processor unbind without clearing the published pointer, causing UAF in cpufreq accessors 徐晗翔
2026-11-10 13:07 ` ACPI: CPPC: shared PCC subspace data can be freed while another CPU probes, reads, or tears it down 徐晗翔
2026-11-10 14:47 ` Christian Loehle
2026-11-10 13:11 ` ACPI: ACPICA: Reset can delete an event semaphore while another thread is blocked in Wait 徐晗翔
2026-11-10 13:14 ` power: supply: bq25890: pump-express work can call power_supply_changed after the psy is unregistered 徐晗翔
2026-11-10 13:17 ` power: supply: core: get/set property callbacks can run after unregister and read freed driver data 徐晗翔
2026-11-10 13:18 ` power: supply: core: system-battery enumeration can return an unregistered battery 徐晗翔
2026-11-10 13:21 ` power: supply: core: changed work can run after unregister and use freed LED triggers 徐晗翔
2026-11-10 13:23 ` power: supply: bq24190: IRQ handler can call power_supply_changed after the psy is unregistered 徐晗翔
2026-11-10 13:34 ` 徐晗翔
2026-11-11 7:17 ` genirq: NMI dispatch reads struct irqaction with no quiescence -- use-after-free across free_nmi()'s kfree (x86 verification on the arch-independent core path) 徐晗翔
2026-11-11 7:26 ` genirq: NMI API lacks the request_mutex / dev_id matching / idempotency semantics that free_irq() has -- double free_nmi releases chip PM and module references twice (verified) 徐晗翔
2026-11-11 7:30 ` kernfs: kernfs_drain()'s fast-path decision reads the active count without acquire ordering -- on weakly-ordered architectures the forced ->release()/unmap can be skipped 徐晗翔
2026-11-11 13:41 ` Greg KH
2026-11-13 11:58 ` ALSA: ctxfi: free atimer only after the timer IRQ is quiesced 徐晗翔
2026-11-13 16:30 ` Takashi Iwai
2026-11-25 12:51 ` [PATCH] Re: " 徐晗翔
2026-11-25 14:33 ` Takashi Iwai
2026-11-13 12:03 ` ALSA: ctxfi: do not free a running system timer when timer_delete_sync_try() returns -1 (UAF) 徐晗翔
2026-11-25 12:51 ` [PATCH] " 徐晗翔
2026-11-25 14:35 ` Takashi Iwai
2026-11-26 2:13 ` 徐晗翔
2026-11-26 7:54 ` Takashi Iwai
2026-11-13 12:04 ` ALSA: asihpi: free IRQ before snd_card_free()/HPI delete on HPI6205 removal (UAF) 徐晗翔
2026-11-25 12:50 ` [PATCH] " 徐晗翔
2026-11-25 14:43 ` Takashi Iwai
2026-11-13 12:06 ` ALSA: asihpi: quiesce PCM timer and IRQ before freeing dpcm on close (UAF) 徐晗翔
2026-11-25 12:50 ` [PATCH] " 徐晗翔
2026-11-25 14:46 ` Takashi Iwai
2026-11-13 12:15 ` ALSA: pcm: link-group walk in timer callback can use a closed substream's freed runtime (UAF) 徐晗翔
2026-11-25 12:55 ` [PATCH] " 徐晗翔
2026-11-25 13:27 ` Takashi Iwai
2026-11-13 12:28 ` ALSA: usb-audio: us144mkii: PCM close frees runtime while playback/feedback URB completion and capture work still use it (UAF) 徐晗翔
2026-11-25 12:48 ` [PATCH] " 徐晗翔
2026-11-25 16:25 ` Takashi Iwai
2026-11-13 12:29 ` ALSA: usb-audio: us144mkii: queued stop_pcm_work calls snd_pcm_stop() after PCM close and dereferences NULL runtime 徐晗翔
2026-11-25 12:49 ` [PATCH] " 徐晗翔
2026-11-13 12:33 ` sched/topology: old domain chains are queued for RCU freeing before the per-CPU pointers are updated, so a late reader can still dereference a freed sched_domain and sched_domain_shared (UAF) 徐晗翔
2026-11-13 12:47 ` xfs: use-after-free in stats_clear sysctl handler during module unload 徐晗翔
2026-11-13 12:48 ` xfs: data races on xfs_params and xfs_globals tunables 徐晗翔
2026-11-17 12:32 ` jbd2: fix unsynchronized read of j_average_commit_time in procfs stats (KCSAN data race) 徐晗翔
2026-11-17 12:33 ` jbd2: read j_stats.ts_tid under j_history_lock in fast commit path " 徐晗翔
2026-11-17 12:35 ` jbd2: fix unlocked read/write of j_last_sync_writer in jbd2_journal_stop " 徐晗翔
2026-11-17 12:38 ` btrfs: compression: data race on compr_pool.count between shrinker scan and folio alloc/free " 徐晗翔
2026-11-17 12:47 ` fs/ceph: debugfs mdsmap_show() can dereference a freed MDS map after a concurrent map update (UAF) 徐晗翔
2026-11-17 12:48 ` fs/ceph: ceph_statfs() can dereference a freed MDS map (double evaluation of mdsc->mdsmap) (UAF) 徐晗翔
2026-11-17 12:49 ` fs/ceph: ceph_get_tree() out_splat path walks mdsc->mdsmap without mdsc->mutex (UAF) 徐晗翔
2026-11-17 12:50 ` fs/ceph: __ceph_setxattr() reads mdsmap->m_max_xattr_size " 徐晗翔
2026-11-17 12:51 ` fs/ceph: MDS reconnect paths read mdsc->mdsmap " 徐晗翔
2026-11-17 12:52 ` fs/ceph: caps renew paths read mdsmap->m_session_timeout " 徐晗翔
2026-11-24 14:53 ` Krzysztof Kozlowski
2026-11-17 12:53 ` fs/ceph: MDS connections can deliver CEPH_MSG_MDS_MAP and re-enter ceph_mdsc_handle_mdsmap() (UAF) 徐晗翔
2026-11-22 7:37 ` mm/hugetlb: a min_size-only hugetlbfs subpool is kfree()d before its last pinned page is released, so free_huge_folio() takes a spinlock on freed memory (UAF) 徐晗翔
2026-11-22 15:58 ` David Hildenbrand (Arm)
2026-11-25 12:05 ` David Hildenbrand (Arm)
2026-11-26 5:52 ` Ackerley Tng
2026-11-26 6:39 ` David Hildenbrand (Arm)
2026-11-22 7:39 ` io_uring/zcrx: copy statistics lose updates when one ifq is shared by multiple rings (Data race) 徐晗翔
2026-11-23 13:50 ` Pavel Begunkov
2026-11-24 17:17 ` Clément Léger
2026-11-22 7:43 ` sound: core: compress offload fd does not pin card or module, so card removal leaves a live fd pointing at freed snd_compr (KASAN UAF) 徐晗翔
2026-11-22 8:07 ` Takashi Iwai
2026-11-25 12:44 ` [PATCH] Re: " 徐晗翔
2026-11-25 14:21 ` Takashi Iwai
2026-11-22 7:48 ` sound: core: jack kcontrol is published before jack_kctl allocation, and the failure path frees it without removing it from card->controls (null-ptr-deref) 徐晗翔
2026-11-24 9:39 ` Sreeraj S Kurup
2026-11-25 12:43 ` 徐晗翔
2026-11-22 7:50 ` sound: core: rawmidi input close can re-queue event_work after cancel_work_sync() (UAF) 徐晗翔
2026-11-24 14:52 ` Krzysztof Kozlowski
2026-11-25 12:45 ` [PATCH] Re: " 徐晗翔
2026-11-25 14:37 ` Takashi Iwai
2026-11-22 7:52 ` sound: core: hwdep DSP_LOAD check-then-act is unlocked, allowing concurrent DSP_LOAD callbacks (UAF) 徐晗翔
2026-11-25 12:46 ` [PATCH] " 徐晗翔
2026-11-25 14:14 ` Takashi Iwai
2026-11-22 7:55 ` sound: core: get_available_index() calls snd_ctl_find_id() without controls_rwsem (UAF risk) 徐晗翔
2026-11-25 12:46 ` [PATCH] " 徐晗翔
2026-11-25 14:18 ` Takashi Iwai
2026-11-22 7:56 ` sound: core: OSS mixer notify callback is invoked without module pin or mutex, racing with rmmod 徐晗翔
2026-11-25 12:47 ` [PATCH] " 徐晗翔
2026-11-25 14:16 ` Takashi Iwai
2026-11-22 7:57 ` sound: timer: snd_utimer_fops lacks .owner, so an open user timer fd does not pin snd-timer 徐晗翔
2026-11-25 12:48 ` [PATCH] " 徐晗翔
2026-11-25 14:17 ` Takashi Iwai
2026-11-26 12:49 ` SUNRPC: rpc_new_client() kfree()s a fully published client on the auth-creation failure path -- use-after-free via concurrent rpc_pipefs mount notifications and via open debugfs/pipefs files (UAF) 徐晗翔
2026-11-26 12:52 ` SUNRPC: cache_read() serialises readers with a per-open inode lock, but every open() gets a fresh inode: concurrent formatting of the shared upcall buffer and unsynchronised rq->len (Data Race KCSAN-confirmed) 徐晗翔
2026-11-26 12:55 ` SUNRPC: rpc_switch_client_transport() removes the client pipedir without pipefs_sb_lock, racing the RPC_PIPEFS_UMOUNT notification chain into a double removal (UAF) 徐晗翔
2026-12-01 3:22 ` [PATCH 0/2] ALSA: emux: fix use-after-free of soundfont zones/samples between snd_emux_note_on() and soundfont removal paths (UAF) 徐晗翔
2026-12-01 6:37 ` Takashi Iwai
2026-12-01 11:56 ` 徐晗翔
2026-12-01 12:15 ` Takashi Iwai
2026-12-01 3:23 ` [PATCH] ALSA: emux: drain open hwdep users before freeing the emux structures(UAF) 徐晗翔
2026-12-01 11:57 ` 徐晗翔
2026-12-01 12:58 ` Takashi Iwai
2026-12-01 3:25 ` 徐晗翔 [this message]
2026-12-01 11:56 ` [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized (probe-window NULL deref via MISC_MODE ioctl) 徐晗翔
2026-12-01 3:27 ` [PATCH] ALSA: core: protect card->devices against concurrent disconnect/free -- snd_device UAF with split sub-driver removal (UAF) 徐晗翔
2026-12-01 11:56 ` 徐晗翔
2026-12-01 4:28 ` ALSA: jack: snd_jack_kctl_new() frees a published snd_kcontrol when the jack private-part allocation fails (UAF/double-free) 徐晗翔
2026-12-01 12:00 ` 徐晗翔
2026-12-01 4:31 ` ALSA: hwdep: struct snd_hwdep is kfree()d while open files, an in-flight ioctl and delayed close() still use it (UAF) 徐晗翔
2026-12-01 12:00 ` 徐晗翔
2026-12-01 4:32 ` ALSA: rawmidi: struct snd_rawmidi and its substreams are kfree()d while open files, delayed close() and a queued highpri work item still use them (UAF) 徐晗翔
2026-12-01 12:01 ` 徐晗翔
2026-12-01 4:33 ` ALSA: pcm: struct snd_pcm and its substreams are kfree()d while open fds and in-flight ioctls " 徐晗翔
2026-12-01 12:01 ` 徐晗翔
2026-12-01 4:36 ` ALSA: emu8000: the self-rearming emu8k_pcm timer survives trigger-stop and fires on freed memory after close (UAF) 徐晗翔
2026-12-01 12:01 ` 徐晗翔
2026-12-01 4:39 ` ALSA: control: find_id()/find_numid() kerneldoc claims they take controls_rwlock internally; the FAST_LOOKUP implementation is a lockless, unreferenced xa_load and several in-tree callers use it unlocked (UAF) 徐晗翔
2026-12-01 12:01 ` 徐晗翔
2026-12-01 4:42 ` ALSA: aoa/i2sbus: unlocked codec_list / dev->pcm check-and-free in i2sbus_detach_codec() can double-free the pcm under concurrent codec detaches (Double free) 徐晗翔
2026-12-01 12:02 ` 徐晗翔
2026-12-01 12:12 ` ASoC: intel: atom: SST: synchronize the DSP threaded IRQ against the PCM close path (UAF) 徐晗翔
2026-12-01 12:15 ` 徐晗翔
2026-12-01 12:19 ` ASoC: intel: atom: SST: clear the compress drain callbacks on close and gate them on the stream status (UAF) 徐晗翔
2026-12-01 12:22 ` ASoC: intel: atom: SST: log the byte-stream message header before handing it to the dispatch queue (UAF) 徐晗翔
2026-12-01 12:25 ` ALSA: emu8000: pin the module while an emu8k PCM runtime exists (UAF) 徐晗翔
2026-12-01 13:13 ` Takashi Iwai
2026-12-01 12:28 ` ALSA: emu8000: sync the PCM emulation timer before freeing snd_emu8k_pcm and gate the callback re-arm on timer_running (UAF) 徐晗翔
2026-12-01 12:37 ` ALSA: opl3: patch_table lookup/clear/load run lock-free against the voice_lock readers (UAF) 徐晗翔
2026-12-01 12:39 ` ALSA: core: card->devices list is managed lock-free -- struct snd_device UAF and LIST_POISON2 crash between card disconnect and independent sub-driver removal (UAF) 徐晗翔
2026-12-01 12:43 ` ALSA: hwdep: single-device teardown kfrees snd_hwdep while user space still holds the node open (UAF) 徐晗翔
2026-12-01 12:45 ` ALSA: rawmidi: snd_rawmidi_free() tears down substreams and the private data while fds are still open and the virmidi output work is queued (UAF) 徐晗翔
2026-12-01 12:47 ` ALSA: pcm: snd_emu8000_remove() frees a pcm with open fds and an armed period timer (UAF) 徐晗翔
2026-12-01 12:48 ` ALSA: vx: vx_free_pipe() kfrees pipes with no lock common to the threaded IRQ pipe walker (UAF) 徐晗翔
2026-12-01 12:51 ` ALSA: sb: emu8k frees the pcm private data without syncing the self-rearming period timer (UAF) 徐晗翔
2026-12-01 13:12 ` ALSA: core: serialize card disconnect/free and quiesce codecs before device release (UAF) 徐晗翔
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=111775f5.43a9.1a22fa2f3b8.Coremail.xuhx@hust.edu.cn \
--to=xuhx@hust.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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®