Technical Analysis of Bug Report
1. Crash Site and Exact Operation
The crash occurs in rb_erase_linked() at lib/rbtree.c:457:
bool rb_erase_linked(struct rb_node_linked *node, struct rb_root_linked *root)
{
if (node->prev)
node->prev->next = node->next;
else
root->rb_leftmost = node->next;
if (node->next)
node->next->prev = node->prev; /* Line 457: Write of size 8 */
rb_erase(&node->node, &root->rb_root);
RB_CLEAR_LINKED_NODE(node);
return !root->rb_leftmost;
}
The call path is:
sysvec_apic_timer_interrupt -> hrtimer_interrupt -> __hrtimer_run_queues -> __run_hrtimer -> __remove_hrtimer -> timerqueue_linked_del -> rb_erase_linked.
In __run_hrtimer(), the expiring timer (node) is dequeued from base->active. In rb_erase_linked(), because node->next is non-NULL, the kernel attempts to update node->next->prev = node->prev.
2. Struct Memory Layout and Buggy Address
struct hrtimer embeds struct timerqueue_linked_node node at offset 0, which embeds struct rb_node_linked node at offset 0.
The layout of struct rb_node_linked is:
struct rb_node node (24 bytes, offsets 0x00..0x17)
struct rb_node_linked *prev (8 bytes, offset 0x18)
struct rb_node_linked *next (8 bytes, offset 0x20)
The target address written to is 0xffffc90004457d68. This corresponds to:
$$\text{Base address of } \texttt{node->next} = 0xffffc90004457d68 - 0x18 = 0xffffc90004457d50$$
Thus, node->next pointed to a struct hrtimer whose start address is 0xffffc90004457d50.
3. Object Lifecycle and Invariant Violation
The memory range 0xffffc90004450000..0xffffc90004458000 was an 8-page (32KB) vmalloc region allocated via kernel_clone -> copy_process -> dup_task_struct -> alloc_thread_stack_node as a thread stack under CONFIG_VMAP_STACK.
The address 0xffffc90004457d50 is situated at offset 0x7d50, which is 0x2b0 (688) bytes below the top of the 32KB stack (0xffffc90004458000). This matches a local struct hrtimer (or struct hrtimer_sleeper) allocated on the stack of a top-level syscall handler.
When that task returned from its syscall and exited, free_thread_stack() cached/released the stack and poisoned the vmalloc address range in KASAN shadow with 0xff (KASAN_VMALLOC_INVALID).
However, the timer on that stack was still queued in base->active on the CPU:
- It was never unlinked via
timerqueue_linked_del(), or its links in the doubly-linked list (timerqueue_linked / rb_node_linked) were not properly severed prior to stack deallocation.
- As a result, when the timer preceding it (
node) expired during a subsequent hrtimer_interrupt, rb_erase_linked() attempted to write node->prev into node->next->prev at 0xffffc90004457d68, resulting in a KASAN use-after-free write to the freed vmalloc thread stack.
4. Scope and Unverified Details
- Verified:
- The crash mechanism in
rb_erase_linked(): unlinking the expiring node writes to node->next->prev.
node->next points to a struct hrtimer located at 0xffffc90004457d50 on a 32KB vmalloc thread stack.
- The thread exited and its stack was poisoned/cached in
free_thread_stack(), but its stack timer remained linked in base->active.
- Inconclusive / Unverified:
- The exact syscall or caller that armed this specific on-stack
hrtimer without cancelling it before exit could not be definitively isolated among the candidates (nanosleep, futex, io_uring, or alarmtimer), as syzkaller was executing compat 32-bit syscalls (__do_compat_sys_ia32_clone) and the thread had already exited by the time of the crash.
- An alternative possibility is a race or state desynchronization in
kernel/time/hrtimer.c (e.g. involving hrtimer_try_to_cancel() returning early if timer->is_queued was observed as 0 while still linked, or an edge case in remove_and_enqueue_same_base() / hrtimer_can_update_in_place()).