Skip to main content
Vulnerability Database/CVE-2026-78118

CVE-2026-78118: Zephyr RTOS Use-After-Free Vulnerability

CVE-2026-78118 is a use-after-free flaw in Zephyr RTOS kernel affecting multi-CPU systems that can lead to out-of-bounds writes and scheduler corruption. This post explains its impact, technical details, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-78118 Overview

CVE-2026-78118 is a race condition [CWE-362] in the Zephyr Real-Time Operating System (RTOS) kernel. The flaw resides in the z_waitq_head() helper in kernel/include/wait_q.h, which reads the head of a thread wait queue without holding the scheduler spinlock _sched_spinlock on symmetric multiprocessing (SMP) systems. The timer expiration handler z_timer_expiration_handler() in kernel/timer.c and halt_thread() in kernel/sched.c manipulate wait queue state under different locks, allowing concurrent access from multiple CPUs.

Critical Impact

An unprivileged user-mode thread on a multi-CPU Zephyr build can trigger out-of-bounds writes, use-after-free writes in supervisor context, and scheduler state corruption by winning a narrow timing race.

Affected Products

  • Zephyr Project RTOS kernel (wait queue helpers in kernel/include/wait_q.h)
  • Builds with CONFIG_MP_MAX_NUM_CPUS greater than 1 (SMP targets)
  • Builds with CONFIG_USERSPACE enabled are reachable from unprivileged threads

Discovery Timeline

  • 2026-10-21 - CVE-2026-78118 published to NVD
  • 2026-10-22 - Last updated in NVD database

Technical Details for CVE-2026-78118

Vulnerability Analysis

The vulnerability is a time-of-check / time-of-use (TOCTOU) class race between the timer subsystem and the scheduler. z_timer_expiration_handler() reads timer->wait_q while holding only timer_lock, then calls unpend_thread_no_timeout() and arch_thread_return_value_set() on the obtained thread pointer. In parallel, halt_thread() can remove an aborted thread from the same wait queue while holding only _sched_spinlock. Because the two code paths serialize on different locks, they are not mutually exclusive on SMP builds.

When the last waiter is removed on another CPU inside the race window, sys_dlist_peek_head() can return the list sentinel, which is a pointer into the enclosing k_timer object typed as a struct k_thread *. With CONFIG_WAITQ_SCALABLE, rb_get_min() can return an arbitrary node of a red-black tree mid-restructure. The handler then performs a sys_dlist_remove() through attacker-influenced pointers and writes a return value through the same pointer.

Root Cause

The z_waitq_head() helper lacked a precondition that callers hold _sched_spinlock, the lock that serializes wait queue mutation. Timer-driven callers acquired only timer_lock, violating the implicit locking contract and permitting concurrent mutation during the read.

Attack Vector

Exploitation requires local code execution on an SMP Zephyr target. The primitives k_timer_start(), k_timer_status_sync(), k_thread_create() and k_thread_abort() are all exposed as system calls. With CONFIG_USERSPACE enabled, an unprivileged user-mode thread can orchestrate the race against kernel-owned data. The practical outcome is most often a kernel crash rather than controlled corruption, given the narrow timing window.

c
// Security patch excerpt from kernel/msg_q.c
// Splits callers based on whether the scheduler spinlock is already held
int z_msgq_cleanup(struct k_msgq *msgq, __maybe_unused bool locked)
{
    SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, cleanup, msgq);

    int ret = 0;
    k_spinlock_key_t key = k_spin_lock(&msgq->lock);

    CHECKIF(locked && (z_waitq_head_locked(&msgq->wait_q) != NULL)) {
        ret = -EBUSY;
        goto out;
    }

    CHECKIF(!locked && (z_waitq_head(&msgq->wait_q) != NULL)) {
        ret = -EBUSY;
        goto out;
    }
}
// Source: https://github.com/zephyrproject-rtos/zephyr/commit/a9b21fb354e8468dd15db307c3e599dc68b7ef33

Detection Methods for CVE-2026-78118

Indicators of Compromise

  • Unexpected kernel panics or faults originating from z_timer_expiration_handler(), unpend_thread_no_timeout(), or arch_thread_return_value_set().
  • Scheduler state corruption observable as threads waking from unrelated blocking calls with a spurious success return value.
  • Repeated, rapid invocations of k_timer_start(), k_timer_status_sync(), k_thread_create(), and k_thread_abort() from the same user-mode thread.

Detection Strategies

  • Audit Zephyr builds for CONFIG_MP_MAX_NUM_CPUS > 1 combined with CONFIG_USERSPACE=y to identify exposed targets.
  • Enable kernel assertions (CONFIG_ASSERT) and stack sentinel checks to surface the race's effects earlier in testing.
  • Review crash dumps for faulting addresses that fall within k_timer object bounds, which indicates the sentinel-pointer dereference path.

Monitoring Recommendations

  • Instrument devices with telemetry that captures kernel oops and reboot causes, correlating them with user-mode workloads using timer and thread syscalls.
  • Track firmware versions across fleets to confirm patched kernel builds are deployed.

How to Mitigate CVE-2026-78118

Immediate Actions Required

  • Apply the upstream Zephyr patch that introduces z_waitq_head_locked() and brings the timer expiration handler's head read, unpend, and ready operations under a single LOCK_SCHED_SPINLOCK region.
  • Rebuild and redeploy firmware for any SMP target that enables CONFIG_USERSPACE.
  • Prioritize patching for devices that execute untrusted user-mode code.

Patch Information

The fix is published in Zephyr commit a9b21fb354e8468dd15db307c3e599dc68b7ef33 and detailed in GitHub Security Advisory GHSA-gm6w-pv43-m3vf. The patch splits the helper into z_waitq_head_locked() for callers already holding _sched_spinlock and z_waitq_head() which acquires the spinlock itself.

Workarounds

  • Where feasible, build the affected image as uniprocessor (CONFIG_MP_MAX_NUM_CPUS=1), which renders the vulnerable region a no-op.
  • Disable CONFIG_USERSPACE on devices that do not require user-mode isolation to remove the syscall-reachable attack surface.
  • Restrict which application threads can call k_timer_* and k_thread_* syscalls until the patch is applied.
bash
# Verify Zephyr source includes the fix before building
cd zephyr
git log --oneline a9b21fb354e8468dd15db307c3e599dc68b7ef33 -1
grep -n "z_waitq_head_locked" kernel/include/wait_q.h

# Uniprocessor fallback configuration
# prj.conf
# CONFIG_MP_MAX_NUM_CPUS=1

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.