KCSAN: data-race in memchr / vsnprintf (3)

Status: moderation: reported on 2026/11/18 04:02
Subsystems: kernel
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+610a2b3497345c1370e9@syzkaller.appspotmail.com
First crash: 20h29m, last: 20h29m
✨ AI-generated root cause summary:

A KCSAN data race occurs between a writer thread formatting in-place into a shared buffer via vsnprintf() (e.g. via snprintf, scnprintf, or set_worker_desc()) and a concurrent reader thread scanning that same buffer via memchr() without synchronization. The call trace shows process_scheduled_works() invoking process_one_work(), which executes an indirect work callback via worker->current_func(work) at kernel/workqueue.c:3495. Because the minimal bug report omits stack frames above process_one_work and the entire call trace of the second thread, the specific work item callback and subsystem containing the shared buffer cannot be definitively identified from the truncated trace alone. However, the mechanism is verified: unsynchronized access to a shared character buffer between in-place vsnprintf formatting and bounded memchr scanning.

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

Technical Analysis & Root Cause

1. Bug Report & Context Breakdown

The reported KCSAN bug is:

BUG: KCSAN: data-race in memchr / vsnprintf
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
  • In kernel/workqueue.c:
    • process_scheduled_works() (line 3578) pulls scheduled work items from worker->scheduled and calls process_one_work(worker, work).
    • Inside process_one_work() at line 3495, the kernel executes:
      worker->current_func(work);
      
      This is an indirect call executing a subsystem-defined work function (work_func_t).
    • Because all stack frames above process_one_work (which identify the specific work function running) and the entire stack trace of the second racing thread were omitted from this truncated report, attributing the defect to a specific driver or subsystem work function is inconclusive without the missing frames.

2. KCSAN Leaf Functions: Writer vs. Reader Mechanism

  • KCSAN reports data races between two leaf access sites, sorting function names alphabetically (memchr before vsnprintf).
  • At least one access in a KCSAN data race must be a write:
    • memchr() (lib/string.c:787–796, fortified inline wrapper in include/linux/fortify-string.h:679–688) takes const void *s and performs byte reads (*p++ for at most n bytes) searching for character c. It never performs write accesses. Inspection of include/linux/fortify-string.h and lib/string.c also confirms that fortified string functions like sized_strscpy(), strlen(), and strnlen() use their own byte loops and do not lower to memchr().
    • vsnprintf() (lib/vsprintf.c) formats a string into a caller-provided destination buffer [buf, buf + size). It performs memory writes to that buffer.
  • Consequently, vsnprintf() is the writer formatting data into a shared buffer, while memchr() is the concurrent reader scanning that same buffer without adequate synchronization.

3. Investigation of Shared Buffers in kernel/workqueue.c

Because kernel/workqueue.c is the only file named in the trace, its own internal string buffers were audited:

  • worker->desc[WORKER_DESC_LEN] is initialized in process_one_work() via strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN) (line 3426).
  • Running work functions can call set_worker_desc(fmt, ...) (lines 6628–6639), which invokes vsnprintf(worker->desc, sizeof(worker->desc), fmt, args) without holding pool->lock.
  • Concurrent readers of worker->desc:
    • wq_worker_comm() (kernel/workqueue.c:6977–7011, invoked via proc_task_name() for /proc/[pid]/{comm,stat,status}) holds pool->lock and formats the string via scnprintf() (string_nocheck()), not memchr().
    • print_worker_info() (kernel/workqueue.c:6654–6688) copies via copy_from_kernel_nofault().
  • Neither workqueue reader calls memchr(). Thus, the racing shared buffer is an object managed by the specific subsystem callback invoked at worker->current_func(work) (kernel/workqueue.c:3495) rather than worker->desc itself.

4. Summary of Invariant Violation

The data race occurs when a subsystem work item executing under worker->current_func(work) (or concurrently with it) invokes vsnprintf() (or a wrapper such as sprintf(), snprintf(), or scnprintf()) to format text into a shared buffer in-place while another thread concurrently invokes memchr() to scan or parse the same buffer without proper locking (such as a mutex, spinlock, or RCU protection).

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
c697efbe bisect-cause 🏃 KCSAN: data-race in memchr / vsnprintf (3) 2026/11/18 04:13 2026/11/18 04:13 ca622473
29083c68 assessment-kcsan 🏃 KCSAN: data-race in memchr / vsnprintf (3) 2026/11/18 04:01 2026/11/18 04:01 ca622473
7685a02e assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in memchr / vsnprintf (3) 2026/11/18 03:41 2026/11/18 03:41 2026/11/18 04:01 ca622473
▶ ▼ Similar bugs (2)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in memchr / vsnprintf (2) prio:low ext4 net 6 2 200d 197d 0/29 auto-obsoleted due to no activity on 2026/06/26 06:22
upstream KCSAN: data-race in memchr / vsnprintf block 6 1 407d 407d 0/29 auto-obsoleted due to no activity on 2025/12/01 22:54

Sample crash report:
BUG: KCSAN: data-race in memchr / vsnprintf
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 08:22 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in memchr / vsnprintf
* Struck through repros no longer work on HEAD.