[LTP] [PATCH v1] sound/snd_timer02: Detect CVE-2026-74503 from the fallback timer
Stephen Bertram
sbertram@redhat.com
Tue Nov 17 14:37:20 CET 2026
From: Stephen Bertram <sbertram@redhat.com>
Open HRTIMER instances until SELECT returns EBUSY, move the queue to
the system timer, then drop one slot and switch the queue back to
HRTIMER. The matching slave makes snd_timer_check_master() fail, so
snd_seq_timer_open() reuses the instance for the system-timer fallback.
snd_timer_start1() rejects the start while SNDRV_TIMER_IFLG_DEAD is
set, so an unfixed kernel leaves the queue stopped. Point linux-git
at c2744d5f3aea.
Signed-off-by: Stephen Bertram <sbertram@redhat.com>
---
runtest/cve | 1 +
testcases/kernel/sound/.gitignore | 1 +
testcases/kernel/sound/snd_timer02.c | 292 +++++++++++++++++++++++++++
3 files changed, 294 insertions(+)
create mode 100644 testcases/kernel/sound/snd_timer02.c
diff --git a/runtest/cve b/runtest/cve
index 0fe25cd83..71d8e3bce 100644
--- a/runtest/cve
+++ b/runtest/cve
@@ -91,6 +91,7 @@ cve-2023-52879 fanotify25
cve-2026-43499 ghostlock
cve-2026-53362 setsockopt11
cve-2026-64600 refluxfs
+cve-2026-74503 snd_timer02
cve-2026-99999 pwnescape
# Tests below may cause kernel memory leak
cve-2020-25704 perf_event_open03
diff --git a/testcases/kernel/sound/.gitignore b/testcases/kernel/sound/.gitignore
index e33480fb6..b2e4041df 100644
--- a/testcases/kernel/sound/.gitignore
+++ b/testcases/kernel/sound/.gitignore
@@ -1,2 +1,3 @@
snd_timer01
+snd_timer02
/snd_seq01
diff --git a/testcases/kernel/sound/snd_timer02.c b/testcases/kernel/sound/snd_timer02.c
new file mode 100644
index 000000000..673ea96b6
--- /dev/null
+++ b/testcases/kernel/sound/snd_timer02.c
@@ -0,0 +1,292 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+
+/*\
+ * Test for CVE-2026-74503.
+ *
+ * snd_timer_close_locked() sets SNDRV_TIMER_IFLG_DEAD and returns
+ * immediately when that flag is already set. remove_slave_links() used
+ * to leave the flag set, so snd_seq_timer_open() could reuse the same
+ * instance for its fallback open and a later close would free an object
+ * that was still on timer->open_list_head.
+ *
+ * Fill the HRTIMER global timer to one below its instance limit and
+ * register a pending slave whose key matches the sequencer queue. Switching
+ * the queue onto HRTIMER then fails in snd_timer_check_master() and the
+ * fallback opens the system timer on that same instance. A fixed kernel
+ * clears SNDRV_TIMER_IFLG_DEAD, so the queue timer starts. An unfixed
+ * kernel still has the flag set, and snd_timer_start1() rejects the start.
+ *
+ * Fixed by c2744d5f3aea ("ALSA: timer: Clear SNDRV_TIMER_IFLG_DEAD once the
+ * close completes").
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+
+#include <sound/asound.h>
+#include <sound/asequencer.h>
+
+#define TIMER_DEV "/dev/snd/timer"
+#define SEQ_DEV "/dev/snd/seq"
+#define PROC_TIMERS "/proc/asound/timers"
+
+static int seq_fd = -1;
+static int slave_fd = -1;
+static int *fill_fds;
+static unsigned int fill_n;
+static int queue_id = -1;
+
+static int open_snd(const char *path)
+{
+ int fd = open(path, O_RDWR);
+
+ if (fd >= 0)
+ return fd;
+
+ if (errno == ENOENT || errno == ENODEV || errno == EACCES)
+ tst_brk(TCONF | TERRNO, "open(%s)", path);
+
+ tst_brk(TBROK | TERRNO, "open(%s)", path);
+ return -1;
+}
+
+static void raise_nofile(void)
+{
+ struct rlimit rl;
+
+ SAFE_GETRLIMIT(RLIMIT_NOFILE, &rl);
+ if (rl.rlim_cur >= rl.rlim_max) {
+ tst_brk(TCONF, "RLIMIT_NOFILE %llu cannot hold the HRTIMER instances",
+ (unsigned long long)rl.rlim_cur);
+ }
+
+ rl.rlim_cur = rl.rlim_max;
+ SAFE_SETRLIMIT(RLIMIT_NOFILE, &rl);
+}
+
+static int select_timer(int fd, int dev_class, int dev_sclass, int device)
+{
+ struct snd_timer_select ts = {
+ .id.dev_class = dev_class,
+ .id.dev_sclass = dev_sclass,
+ .id.card = -1,
+ .id.device = device,
+ };
+
+ return ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &ts);
+}
+
+/*
+ * Open HRTIMER instances until SELECT returns EBUSY, which is
+ * num_instances >= max_instances in snd_timer_open(). The caller drops
+ * one so the sequencer open is the one that reaches the limit.
+ */
+static void fill_hrtimer(void)
+{
+ int raised = 0;
+ struct snd_timer_select ts = {
+ .id.dev_class = SNDRV_TIMER_CLASS_GLOBAL,
+ .id.dev_sclass = SNDRV_TIMER_SCLASS_NONE,
+ .id.card = -1,
+ .id.device = SNDRV_TIMER_GLOBAL_HRTIMER,
+ };
+
+ for (;;) {
+ int fd = open(TIMER_DEV, O_RDWR);
+
+ if (fd < 0) {
+ if (errno == EMFILE && !raised) {
+ raise_nofile();
+ raised = 1;
+ continue;
+ }
+ tst_brk(TBROK | TERRNO, "open(%s)", TIMER_DEV);
+ }
+
+ if (ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &ts) < 0) {
+ int err = errno;
+
+ SAFE_CLOSE(fd);
+ errno = err;
+ if (err == EBUSY)
+ break;
+ if (!fill_n)
+ tst_brk(TCONF | TERRNO, "HRTIMER global timer not available");
+ tst_brk(TBROK | TERRNO, "SNDRV_TIMER_IOCTL_SELECT");
+ }
+
+ fill_fds = SAFE_REALLOC(fill_fds, (fill_n + 1) * sizeof(*fill_fds));
+ fill_fds[fill_n++] = fd;
+ }
+
+ if (!fill_n)
+ tst_brk(TCONF, "HRTIMER global timer is already at max_instances");
+
+ tst_res(TINFO, "opened %u HRTIMER instances before EBUSY", fill_n);
+}
+
+static void release_hrtimer(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < fill_n; i++)
+ SAFE_CLOSE(fill_fds[i]);
+ free(fill_fds);
+ fill_fds = NULL;
+ fill_n = 0;
+}
+
+static void set_queue_timer(int device)
+{
+ struct snd_seq_queue_timer qt = {
+ .queue = queue_id,
+ .type = SNDRV_SEQ_TIMER_ALSA,
+ .u.alsa.id.dev_class = SNDRV_TIMER_CLASS_GLOBAL,
+ .u.alsa.id.dev_sclass = SNDRV_TIMER_SCLASS_NONE,
+ .u.alsa.id.card = -1,
+ .u.alsa.id.device = device,
+ };
+
+ SAFE_IOCTL(seq_fd, SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER, &qt);
+}
+
+static void setup(void)
+{
+ struct snd_seq_queue_info qinfo = {};
+
+ if (access(TIMER_DEV, F_OK) && errno == ENOENT)
+ tst_brk(TCONF, "%s not present", TIMER_DEV);
+ if (access(SEQ_DEV, F_OK) && errno == ENOENT)
+ tst_brk(TCONF, "%s not present", SEQ_DEV);
+
+ seq_fd = open_snd(SEQ_DEV);
+ SAFE_IOCTL(seq_fd, SNDRV_SEQ_IOCTL_CREATE_QUEUE, &qinfo);
+ queue_id = qinfo.queue;
+
+ /*
+ * The default queue timer is often HRTIMER. Move it off that timer
+ * before filling, or SET_QUEUE_TIMER closes the queue's own slot and
+ * the following open is no longer the one that reaches the limit.
+ *
+ * snd_timer_user keeps a slave's dev_sclass. snd_seq_timer_open()
+ * forces the master slave_class to SNDRV_TIMER_SCLASS_SEQUENCER and
+ * passes the queue id as slave_id.
+ */
+ set_queue_timer(SNDRV_TIMER_GLOBAL_SYSTEM);
+
+ slave_fd = open_snd(TIMER_DEV);
+ if (select_timer(slave_fd, SNDRV_TIMER_CLASS_SLAVE,
+ SNDRV_TIMER_SCLASS_SEQUENCER, queue_id) < 0)
+ tst_brk(TBROK | TERRNO, "SNDRV_TIMER_IOCTL_SELECT slave");
+}
+
+static void start_queue(void)
+{
+ struct snd_seq_event ev = {
+ .type = SNDRV_SEQ_EVENT_START,
+ .flags = SNDRV_SEQ_EVENT_LENGTH_FIXED,
+ .queue = SNDRV_SEQ_QUEUE_DIRECT,
+ .dest.client = SNDRV_SEQ_CLIENT_SYSTEM,
+ .dest.port = SNDRV_SEQ_PORT_SYSTEM_TIMER,
+ .data.queue.queue = queue_id,
+ };
+
+ SAFE_WRITE(SAFE_WRITE_ALL, seq_fd, &ev, sizeof(ev));
+}
+
+static void check_queue_timer(void)
+{
+ char buf[256];
+ char expect[64];
+ FILE *fp;
+ int dev = -1;
+ int found = 0;
+ int running = 0;
+
+ snprintf(expect, sizeof(expect), "sequencer queue %d :", queue_id);
+ fp = SAFE_FOPEN(PROC_TIMERS, "r");
+
+ while (fgets(buf, sizeof(buf), fp)) {
+ int gdev;
+
+ if (sscanf(buf, "G%d:", &gdev) == 1) {
+ dev = gdev;
+ continue;
+ }
+
+ if (!strstr(buf, expect))
+ continue;
+
+ found = 1;
+ running = strstr(buf, "running") != NULL;
+ break;
+ }
+ SAFE_FCLOSE(fp);
+
+ if (!found) {
+ tst_brk(TBROK, "queue %d timer missing from %s",
+ queue_id, PROC_TIMERS);
+ }
+
+ if (dev != SNDRV_TIMER_GLOBAL_SYSTEM) {
+ tst_brk(TBROK,
+ "queue %d is on timer G%d, fallback to the system timer did not run",
+ queue_id, dev);
+ }
+
+ if (!running) {
+ tst_res(TFAIL, "queue %d timer did not start", queue_id);
+ return;
+ }
+
+ if (tst_taint_check())
+ tst_res(TFAIL, "kernel tainted after the queue timer started");
+ else
+ tst_res(TPASS, "queue %d timer is running", queue_id);
+}
+
+static void run(void)
+{
+ /*
+ * Fill HRTIMER to its instance limit, drop one, then point the
+ * queue at it. The open passes the max_instances check and
+ * snd_timer_check_master() fails while adopting the matching
+ * slave. That close sets IFLG_DEAD and the fallback open reuses
+ * the instance on the system timer.
+ */
+ fill_hrtimer();
+ SAFE_CLOSE(fill_fds[--fill_n]);
+ set_queue_timer(SNDRV_TIMER_GLOBAL_HRTIMER);
+ start_queue();
+ check_queue_timer();
+}
+
+static void cleanup(void)
+{
+ if (slave_fd >= 0)
+ SAFE_CLOSE(slave_fd);
+
+ release_hrtimer();
+
+ if (seq_fd >= 0)
+ SAFE_CLOSE(seq_fd);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run,
+ .taint_check = TST_TAINT_W | TST_TAINT_D,
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "c2744d5f3aea474513fd2298daecb94a952ce441"},
+ {"CVE", "2026-74503"},
+ {}
+ },
+};
--
2.56.0
More information about the ltp
mailing list