CVE-2026-130477: Kernel user mode: dynamic thread and stack objects can be freed while their thread is still running or exiting (use-after-free)
In the kernel's user-mode object management, unrefcheck() 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. kthreadcreate() keeps pointers to a dynamic struct kthread (from kobjectalloc(KOBJTHREAD)) and a dynamic stack (from kobjectallocsize(KOBJTHREADSTACKELEMENT, ...) or kthreadstackalloc() with KUSER) for the whole life of the thread, but nothing in the bitmap records this. zthreaduserinit() gives the new thread permission on its own thread object only, not on its stack. When the thread terminates, haltthread() calls zthreadrelease(), and its zthreaduserexit() drops all of the thread's permissions. If that leaves the bitmap empty, the thread's own struct kthread (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 kobjectrelease() on the stack, or exits, the stack block is freed while the child still runs on it. With CONFIGGENPRIVSTACKS that block also holds the privileged stack and zstackdata, and the child keeps user-mode access to it. Once the creator has released a dynamic thread object, the thread itself can call kobjectrelease() on its own thread object and free its struct kthread while it is running. zvrfykobjectrelease() 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 haltthread(). The kernel then still reads and writes the freed memory: thread->stackobj, the thread state, swapretval and switchhandle, 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 CONFIGUSERSPACE and CONFIGDYNAMICOBJECTS.
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 kthread that the scheduler still uses. This breaks kernel integrity (P1) and user-mode isolation (P2) from an unprivileged user thread. The supervisor-only kobjectfree() states that it is not exposed to user mode because the kernel cannot tell whether an object is still in use, and kthreadstackfree() refuses to free a stack in use. Dropping permissions gets around both.
Affected Software
Event History
Frequently Asked Questions
Who can trigger the issue?
Any user thread with a resource pool can trigger it through syscalls it is permitted to make. Exploitation requires local access, low privileges, and no user interaction.
What thread and stack configurations are exposed?
The issue affects dynamically allocated k_thread objects and dynamic user-mode stacks. Relevant stack allocation paths include k_object_alloc_size(K_OBJ_THREAD_STACK_ELEMENT, ...) and k_thread_stack_alloc() when used with K_USER.
What actions can lead to premature freeing?
A thread can create a thread on a dynamic stack and release that stack with k_object_release(), or terminate and drop its permissions. If the resulting permission bitmap is empty, the thread object or stack can be freed while the abort or context-switch path still uses it.