KCSAN: data-race in 0x0 / stop_this_handle

Status: moderation: reported on 2026/11/18 05:52
Subsystems: ext4
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+280596b5193673ac3a39@syzkaller.appspotmail.com
First crash: 1d04h, last: 10h05m
✨ AI-generated root cause summary:

This bug report is a false-positive self-race within KCSAN. When kcsan_setup_watchpoint() sets up a watchpoint on current->flags (during memalloc_flags_restore() in stop_this_handle()), it fails to increment current->kcsan_ctx.disable_count around delay_access(). On architectures like x86, delay_access() -> udelay() -> delay_tsc() enables preemption via preempt_enable(), allowing task 7736 to run instrumented code while still in_task() and consume its own watchpoint. Furthermore, in kernel/kcsan/report.c, when sanitize_stack_entries() finds zero usable stack entries for other_info (other_skipnr == num_stack_entries), print_report() reads past the valid entries into zeroed memory, formatting (void *)0 as '0x0' in the report title.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Root Cause Analysis

The reported BUG: KCSAN: data-race in 0x0 / stop_this_handle is an internal false-positive self-race within KCSAN, caused by an omission in kernel/kcsan/core.c combined with an out-of-bounds array access in kernel/kcsan/report.c. There is no genuine race condition or memory bug in the ext4/jbd2 filesystem code (stop_this_handle() / memalloc_flags_restore()).


Technical Breakdown

1. Functions, Structs, and Fields Involved

  • fs/jbd2/transaction.c:stop_this_handle() & include/linux/sched/mm.h:memalloc_flags_restore(): Calls memalloc_nofs_restore() / memalloc_flags_restore(), executing:

    current->flags &= ~flags;
    

    This is a 4-byte compound read-modify-write on current->flags (struct task_struct::flags, address 0xffff888101c967ac for task 7736).

  • kernel/kcsan/core.c:kcsan_setup_watchpoint(): KCSAN intercepts the compound access to current->flags. It calls insert_watchpoint(), increments ctx->disable_scoped++, and enters delay_access(type) -> udelay(). Crucially, when kcsan_interrupt_watcher is true (the default), kcsan_setup_watchpoint() leaves local IRQs and preemption enabled, but fails to increment ctx->disable_count (current->kcsan_ctx.disable_count).

  • arch/x86/lib/delay.c:delay_tsc(): udelay() on x86 calls delay_tsc(), which contains a busy loop:

    for (;;) {
        now = rdtsc_ordered();
        if ((now - bclock) >= cycles)
            break;
        preempt_enable();
        native_pause();
        preempt_disable();
        ...
    }
    

    delay_tsc() explicitly invokes preempt_enable() while waiting.

  • kernel/kcsan/report.c:print_report() & sanitize_stack_entries(): Handles the formatting and printing of the race report between the thread that set up the watchpoint (ai) and the thread/context that consumed it (other_info).


2. Triggering Mechanism and Invariant Violation

  1. Watchpoint Setup on current->flags: Task 7736 calls stop_this_handle(), which calls memalloc_flags_restore(). KCSAN's compiler instrumentation emits a call to check_access(&current->flags, 4, KCSAN_ACCESS_COMPOUND | KCSAN_ACCESS_WRITE, ip), which randomly decides to watch this access via kcsan_setup_watchpoint(). A watchpoint is placed on &current->flags (0xffff888101c967ac).

  2. Self-Consumption during delay_access(): kcsan_setup_watchpoint() calls delay_access(), which calls udelay(). In delay_tsc(), preempt_enable() is invoked. Because current->kcsan_ctx.disable_count was never incremented by kcsan_setup_watchpoint(), kcsan_is_enabled(&current->kcsan_ctx) remains true. While current is still task 7736 and in_task() remains true, code executed during the delay (e.g. preemption checks, scheduling transitions, or instrumented callbacks) reads current->flags. When this read occurs, KCSAN's check_access() sees the active watchpoint for &current->flags, matching the slot. try_consume_watchpoint() succeeds, and kcsan_found_watchpoint() -> kcsan_report_set_info() records other_info:

    • ptr: 0xffff888101c967ac (&current->flags)
    • task_pid: task_pid_nr(current) == 7736 (because in_task() is true)
    • cpu_id: 0 Task 7736 has consumed its own watchpoint on its own private task state.
  3. Generation of 0x0 in the Bug Title and Empty Stack Trace:

    • In prepare_report_producer(), other_info->num_stack_entries is recorded via stack_trace_save(other_info->stack_entries, NUM_STACK_ENTRIES, 2).
    • When kcsan_setup_watchpoint() finishes delay_access(), consume_watchpoint() returns false because the watchpoint was consumed. It calls kcsan_report_known_origin(), which invokes print_report().
    • In print_report():
      other_skipnr = sanitize_stack_entries(other_info->stack_entries,
                                            other_info->num_stack_entries,
                                            other_info->ai.ip, &other_reordered_to);
      other_frame = other_info->stack_entries[other_skipnr];
      
      Because the access was a plain read (!KCSAN_ACCESS_SCOPED), other_info->ai.ip is 0, so sanitize_stack_entries() calls get_stack_skipnr(). If num_stack_entries is 0 (or if all captured frames were KCSAN runtime functions kcsan_* / tsan_*), other_skipnr == other_info->num_stack_entries. print_report() then reads other_info->stack_entries[other_skipnr], reading uninitialized or zeroed memory (other_frame = 0x0).
    • print_stack_trace() prints other_info->num_stack_entries - other_skipnr frames, which evaluates to 0 frames, resulting in an empty stack for the reader.
    • When sorting symbol names to generate the report header:
      cmp = sym_strcmp((void *)other_frame, (void *)this_frame);
      pr_err("BUG: KCSAN: %s in %ps / %ps\n", ..., (void *)(cmp < 0 ? other_frame : this_frame), ...);
      
      sym_strcmp formats (void *)0x0 as string "0x0". Since "0x0" sorts lexicographically before "stop_this_handle", KCSAN prints: BUG: KCSAN: data-race in 0x0 / stop_this_handle.

Conclusion

The defect resides in:

  1. kernel/kcsan/core.c: kcsan_setup_watchpoint() fails to temporarily disable KCSAN on current->kcsan_ctx during delay_access(), allowing the current task to consume its own watchpoints when re-entering task-context code during the delay.
  2. kernel/kcsan/report.c: print_report() incorrectly indexes other_info->stack_entries[other_skipnr] when other_skipnr == other_info->num_stack_entries, reading past valid entries and printing "0x0".
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
f42d1bc9 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in 0x0 / stop_this_handle 2026/11/18 05:12 2026/11/18 05:12 2026/11/18 05:58 ca622473
7cbe8044 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in 0x0 / stop_this_handle 2026/11/18 05:03 2026/11/18 05:03 2026/11/18 05:45 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in 0x0 / stop_this_handle

read to 0xffff888101c967ac of 4 bytes by task 7736 on cpu 0:

read-write to 0xffff888101c967ac of 4 bytes by task 7736 on cpu 0:
 memalloc_flags_restore include/linux/sched/mm.h:341 [inline]
 memalloc_nofs_restore include/linux/sched/mm.h:401 [inline]
 stop_this_handle+0x252/0x290 fs/jbd2/transaction.c:740
 jbd2_journal_stop+0x51b/0x6a0 fs/jbd2/transaction.c:2014
 __ext4_journal_stop+0x8f/0x1d0 fs/ext4/ext4_jbd2.c:148
 ext4_dirty_inode+0xa6/0xc0 fs/ext4/inode.c:7654
 __mark_inode_dirty+0x164/0x770 fs/fs-writeback.c:2751
 generic_update_time fs/inode.c:2274 [inline]
 file_update_time_flags+0x2ae/0x2e0 fs/inode.c:2504
 file_update_time+0x17/0x20 fs/inode.c:2525
 ext4_page_mkwrite+0x16b/0xd30 fs/ext4/inode.c:7838
 do_page_mkwrite mm/memory.c:3889 [inline]
 do_shared_fault mm/memory.c:6188 [inline]
 do_fault mm/memory.c:6250 [inline]
 do_pte_missing mm/memory.c:4778 [inline]
 handle_pte_fault mm/memory.c:6665 [inline]
 __handle_mm_fault mm/memory.c:6817 [inline]
 handle_mm_fault+0x269c/0x3880 mm/memory.c:6984
 do_user_addr_fault+0x3ce/0xde0 arch/x86/mm/fault.c:1343
 handle_page_fault arch/x86/mm/fault.c:1483 [inline]
 exc_page_fault+0x62/0xa0 arch/x86/mm/fault.c:1536
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 7736 Comm: syz.2.1162 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (78):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 20:20 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 19:11 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 16:05 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 14:58 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 13:55 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 12:27 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 12:13 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 12:13 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 12:04 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 11:58 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 11:54 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 11:40 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 10:34 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 10:28 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 08:36 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 08:30 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 08:07 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 07:54 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 07:42 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 07:35 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 07:26 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 07:25 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:47 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:39 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:34 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:26 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:11 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:05 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:02 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 06:00 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 05:52 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 05:52 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 05:20 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 04:58 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 04:19 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 04:03 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:54 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:52 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:52 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:50 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:49 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:47 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:37 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:37 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 03:34 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
2026/11/17 02:28 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / stop_this_handle
* Struck through repros no longer work on HEAD.