| 0/0 |
2026/04/27 07:54 |
flow |
assessment-kcsan |
20m
Results: map[Benign:true Confident:true Explanation:The data race occurs on the global static variable `autofs_next_wait_queue` in
`fs/autofs/waitq.c`. This variable is used to assign a "token" (an identifier)
to each new wait request sent to the autofs daemon.
### Race Summary
The race happens in `autofs_wait()` when two different tasks are triggering
automounts on **different** autofs mount points simultaneously.
- **Task A** (Mount 1) holds `sbi1->wq_mutex`.
- **Task B** (Mount 2) holds `sbi2->wq_mutex`.
Since they hold different mutexes, they can concurrently execute the following
code:
```c
// fs/autofs/waitq.c:386
wq->wait_queue_token = autofs_next_wait_queue;
if (++autofs_next_wait_queue == 0)
autofs_next_wait_queue = 1;
```
This results in a non-atomic read-modify-write on the global
`autofs_next_wait_queue`.
### Synchronization Context
While each autofs superblock (`sbi`) has its own `wq_mutex` to serialize wait
queue operations for that specific mount, `autofs_next_wait_queue` is a shared
global variable. There is no global lock protecting it. Consequently, concurrent
updates from different mounts can race, potentially leading to lost increments
and duplicate tokens being assigned to different wait requests.
### Final Classification: **BENIGN**
#### Reasoning:
1. **Per-Mount Scoping:** The `wait_queue_token` is used to identify a specific
wait request when the daemon responds (via ioctl or write to the pipe). The
kernel performs this lookup using `autofs_wait_release()`, which searches for
the token only within the `sbi->queues` list of the **specific** superblock
associated with the response.
2. **Structural Tolerance:** Because the lookup is scoped to a single
superblock, duplicate tokens are only problematic if they exist within the
*same* superblock. However, within a single superblock, all access to the
counter is serialized by the per-superblock `sbi->wq_mutex`, ensuring tokens are
unique for that mount.
3. **Daemon Context:** The daemon receives requests from a specific pipe or
device associated with a mount. It tracks pending requests per mount. Even if it
receives the same token value from two different mounts, it can distinguish them
based on the communication channel.
4. **Intentional Design:** A comment in `fs/autofs/waitq.c` states: *"it is
better if we don't reassign numbers easily even across filesystems"*. This
indicates that global uniqueness is a preferred property for debugging or
diagnostic clarity, but not a requirement for correctness.
5. **No Memory Safety Issues:** The variable is a simple integer. A race here
does not involve pointers, array bounds, or complex state transitions that could
lead to a kernel crash or memory corruption.
#### Recommended Annotations:
To silence KCSAN and ensure the compiler does not perform unsafe optimizations,
the access should be wrapped in `data_race()` or the variable should be
converted to an `atomic_t`.
```c
/* Suggested fix using data_race() */
wq->wait_queue_token = data_race(autofs_next_wait_queue);
if (data_race(++autofs_next_wait_queue) == 0)
data_race(autofs_next_wait_queue = 1);
```]
|
| 1/1 |
2026/04/27 07:54 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/8e3239d6f9771a79cf22fa64d1b1561d7cb6cad8]
|
| 2/1 |
2026/04/27 07:56 |
action |
kernel-builder |
9m
Results: map[KernelObj:/app/workdir/cache/build/b92bc8a3aa671db6d823581a6fe0298366b0d815]
|
| 3/1 |
2026/04/27 08:05 |
action |
codesearch-prepare |
7m
Results: map[Index:codesearch-index]
|
| 4/1 |
2026/04/27 08:12 |
agent |
expert |
2m
Model:
Results: map[Benign:true Confident:true]
Instruction: # KCSAN Data Race Severity Analysis Protocol
You are an expert Linux kernel concurrency engineer analyzing a Kernel
Concurrency Sanitizer (KCSAN) data race report to determine if it is
**BENIGN** or **HARMFUL**.
## 1. CLASSIFICATIONS
### **BENIGN (Truly Benign)**
The logic is sound and structurally tolerant to compiler optimizations or
stale/torn reads.
- **Diagnostics/Stats:** Reads used only for '/proc', '/sys', counters, or
'pr_info'.
- **Heuristic Hints:** A "hint" flag where an old value only causes a
slightly delayed update or a sub-optimal but safe fast-path.
- **Single-Writer Flag Updates:** A single writer updating flags where the
concurrent read is a simple bitwise check (e.g., 'flags & MASK'). These are
historically tolerated, assuming neither "Fused Accesses" nor "Ordering
Violations" are relevant in this context.
- **Marked Reloads:** A load feeding into a 'cmpxchg()' loop or checked
against a later 'READ_ONCE()' reload.
- **Safe Overwrites:** Writing the same value already present.
### **HARMFUL (Logic Bug or Marking Required)**
The race causes incorrect behavior due to a synchronization failure or
because missing annotations allow the compiler to break the algorithm.
**Marking Required for Correctness:**
The algorithm is logically sound but requires annotations ('READ_ONCE()',
'WRITE_ONCE()', 'smp_load_acquire()', 'smp_store_release()', etc.) to be safe.
- **Fused Accesses:** The compiler might merge accesses or hoist a load out
of a loop, breaking polling/wait loops (livelocks).
- **Torn Accesses:** A large access (e.g., 64-bit on 32-bit arch) might be
split into multiple non-atomic accesses. Note that 'READ_ONCE()' does **not**
guarantee atomicity for 64-bit variables on 32-bit architectures.
- **Ordering Violations:** The race breaks a "happens-before" relationship
(requires primitives with implied or explicit memory barriers).
**Logic Bugs:**
A fundamental synchronization failure. Marking accesses will **not** fix it;
the logic itself must change.
- **Pointers/Lifecycle:** The racing variable is a pointer being dereferenced
or a refcount governing object lifecycle (Use-After-Free risk).
- **Control Flow:** The variable guards a critical section, memory allocation,
or hardware command.
- **Bitfields:** Concurrent writes to different bits in the same word.
Compilers often use non-atomic read-modify-write sequences, meaning a
write to 'bit_A' can "clobber" a concurrent write to 'bit_B'. However,
do not blindly assume all bitfield accesses are harmful; you must prove
that a concurrent write actually clobbers another in a way that breaks
logic.
- **Complex Structures:** Races on shared lists, trees, or hashmaps.
- **Lossy Updates:** Concurrent plain RMW operations (e.g., 'var++') on
non-diagnostic variables where every increment must be preserved.
- **State Machines:** Races allowing a state machine to bypass transitions
or enter an invalid state.
- **Adjacent Unsynchronized Operations:** Consider races happening at the
same time. For example, if both threads execute 'struct->has_elements = true;
list_add(node, &struct->list);', the race on 'has_elements' implies an
adjacent race on 'list_head', which is HARMFUL.
## 2. RESEARCH & ANALYSIS WORKFLOW
1. **Locate the Race:** Find the exact variables and functions in the stack
traces. **Use codesearch tools to read the actual source code and
confirm all assumptions.** Do not speculate about hypothetical compiler
behaviors or theoretical dangers (e.g., dismissing something as
"fundamentally unsafe") without tracing the actual data flow to a crash.
2. **Contextualize:** Identify held locks, RCU sections, or interrupt
contexts. Explain why the race is possible (e.g., "Thread A holds 'lock',
but Thread B is a lockless reader").
3. **Data Flow:** Follow the racing variable into its subsequent uses. If
the reader sees a stale or torn value, what branch is taken? Does it lead
to a pointer dereference or 'BUG_ON()'? **You must prove harm via this
data flow.**
4. **Failure Sequencing (if HARMFUL):** Construct a two-column execution trace
demonstrating the failure.
*Example format:*
CPU0 CPU1
function_a()
// lockless read
ptr = global_ptr
<PREEMPT>
function_b()
lock(&my_lock)
global_ptr = NULL
unlock(&my_lock)
kfree(ptr)
if (ptr)
*ptr = 1; // -> Use-After-Free!
## 3. OUTPUT FORMAT
- **Race Summary:** '[Function A]' vs '[Function B]' on '[Variable/Field]'.
- **Synchronization context:** List held locks and explain the lack of mutual
exclusion.
- **Final Classification:** **BENIGN** or **HARMFUL**.
**If BENIGN:**
- **Reasoning:** Briefly explain why the race is structurally tolerant to stale
or torn reads.
- **Recommended Annotations:** Suggest appropriate annotations (e.g.,
'READ_ONCE()', 'data_race()').
**If HARMFUL:**
- **Failure Reasoning:** Explain and provide a two-column interleaving showing
exactly how the race leads to a failure such as corruption or kernel crash.
- **Recommended Fix (ONLY if fix is trivial):** Suggest a structural fix (e.g.,
"Hold 'mapping->i_pages' lock", "Convert to 'atomic_t'") or required memory
ordering annotations (e.g., "Wrap in 'READ_ONCE()'", "Use
'smp_load_acquire()'").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The data race report is:
==================================================================
BUG: KCSAN: data-race in autofs_wait / autofs_wait
write to 0xffffffff86dffac0 of 4 bytes by task 6635 on cpu 0:
autofs_wait+0x8d5/0xbe0 fs/autofs/waitq.c:-1
autofs_mount_wait+0xc2/0x100 fs/autofs/root.c:256
autofs_d_automount+0x3f6/0x560 fs/autofs/root.c:410
follow_automount fs/namei.c:1560 [inline]
__traverse_mounts+0x256/0x420 fs/namei.c:1613
traverse_mounts fs/namei.c:1642 [inline]
handle_mounts fs/namei.c:1744 [inline]
step_into_slowpath+0x2d5/0x4c0 fs/namei.c:2100
step_into fs/namei.c:2148 [inline]
walk_component fs/namei.c:2284 [inline]
lookup_last fs/namei.c:2785 [inline]
path_lookupat+0x330/0x500 fs/namei.c:2809
filename_lookup+0x190/0x390 fs/namei.c:2838
vfs_statx+0x96/0x170 fs/stat.c:353
vfs_fstatat fs/stat.c:373 [inline]
vfs_lstat include/linux/fs.h:3212 [inline]
__do_sys_newlstat fs/stat.c:524 [inline]
__se_sys_newlstat+0x66/0x3f0 fs/stat.c:518
__x64_sys_newlstat+0x31/0x40 fs/stat.c:518
x64_sys_call+0x1b8c/0x3020 arch/x86/include/generated/asm/syscalls_64.h:7
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x12c/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
write to 0xffffffff86dffac0 of 4 bytes by task 6611 on cpu 1:
autofs_wait+0x8d5/0xbe0 fs/autofs/waitq.c:-1
autofs_mount_wait+0xc2/0x100 fs/autofs/root.c:256
autofs_d_automount+0x3f6/0x560 fs/autofs/root.c:410
follow_automount fs/namei.c:1560 [inline]
__traverse_mounts+0x256/0x420 fs/namei.c:1613
traverse_mounts fs/namei.c:1642 [inline]
handle_mounts fs/namei.c:1744 [inline]
step_into_slowpath+0x2d5/0x4c0 fs/namei.c:2100
step_into fs/namei.c:2148 [inline]
walk_component fs/namei.c:2284 [inline]
lookup_last fs/namei.c:2785 [inline]
path_lookupat+0x330/0x500 fs/namei.c:2809
filename_lookup+0x190/0x390 fs/namei.c:2838
vfs_statx+0x96/0x170 fs/stat.c:353
vfs_fstatat fs/stat.c:373 [inline]
vfs_lstat include/linux/fs.h:3212 [inline]
__do_sys_newlstat fs/stat.c:524 [inline]
__se_sys_newlstat+0x66/0x3f0 fs/stat.c:518
__x64_sys_newlstat+0x31/0x40 fs/stat.c:518
x64_sys_call+0x1b8c/0x3020 arch/x86/include/generated/asm/syscalls_64.h:7
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x12c/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x0000280d -> 0x0000280e
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 6611 Comm: syz.8.698 Tainted: G W syzkaller #0 PREEMPT(full)
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/18/2026
==================================================================
Reply: The data race occurs on the global static variable `autofs_next_wait_queue` in `fs/autofs/waitq.c`. This variable is used to assign a "token" (an identifier) to each new wait request sent to the autofs daemon.
### Race Summary
The race happens in `autofs_wait()` when two different tasks are triggering automounts on **different** autofs mount points simultaneously.
- **Task A** (Mount 1) holds `sbi1->wq_mutex`.
- **Task B** (Mount 2) holds `sbi2->wq_mutex`.
Since they hold different mutexes, they can concurrently execute the following code:
```c
// fs/autofs/waitq.c:386
wq->wait_queue_token = autofs_next_wait_queue;
if (++autofs_next_wait_queue == 0)
autofs_next_wait_queue = 1;
```
This results in a non-atomic read-modify-write on the global `autofs_next_wait_queue`.
### Synchronization Context
While each autofs superblock (`sbi`) has its own `wq_mutex` to serialize wait queue operations for that specific mount, `autofs_next_wait_queue` is a shared global variable. There is no global lock protecting it. Consequently, concurrent updates from different mounts can race, potentially leading to lost increments and duplicate tokens being assigned to different wait requests.
### Final Classification: **BENIGN**
#### Reasoning:
1. **Per-Mount Scoping:** The `wait_queue_token` is used to identify a specific wait request when the daemon responds (via ioctl or write to the pipe). The kernel performs this lookup using `autofs_wait_release()`, which searches for the token only within the `sbi->queues` list of the **specific** superblock associated with the response.
2. **Structural Tolerance:** Because the lookup is scoped to a single superblock, duplicate tokens are only problematic if they exist within the *same* superblock. However, within a single superblock, all access to the counter is serialized by the per-superblock `sbi->wq_mutex`, ensuring tokens are unique for that mount.
3. **Daemon Context:** The daemon receives requests from a specific pipe or device associated with a mount. It tracks pending requests per mount. Even if it receives the same token value from two different mounts, it can distinguish them based on the communication channel.
4. **Intentional Design:** A comment in `fs/autofs/waitq.c` states: *"it is better if we don't reassign numbers easily even across filesystems"*. This indicates that global uniqueness is a preferred property for debugging or diagnostic clarity, but not a requirement for correctness.
5. **No Memory Safety Issues:** The variable is a simple integer. A race here does not involve pointers, array bounds, or complex state transitions that could lead to a kernel crash or memory corruption.
#### Recommended Annotations:
To silence KCSAN and ensure the compiler does not perform unsafe optimizations, the access should be wrapped in `data_race()` or the variable should be converted to an `atomic_t`.
```c
/* Suggested fix using data_race() */
wq->wait_queue_token = data_race(autofs_next_wait_queue);
if (data_race(++autofs_next_wait_queue) == 0)
data_race(autofs_next_wait_queue = 1);
```
|
| 5/2 |
2026/04/27 08:12 |
llm |
expert |
0m
Model:
Tokens:
input: 5378
output: 51
thoughts: 172
Thoughts: **Analyzing a Data Race in autofs_wait**
Okay, so the report flags a nasty data race within `autofs_wait` in `fs/autofs/waitq.c`. It's pretty clear: two tasks are stepping on each other's toes while both running that function. The smoking gun is the shared memory address, `0xffffffff86dffac0`. Seeing that `0xffffffff8` prefix, I immediately think global or static variable β definitely residing in the kernel's data segment. The fact that the value transitions, in the report, from `0x0000280d` to `0x0000280e` strongly suggests a simple increment operation β a classic concurrency pitfall.
My next move is to crack open `fs/autofs/waitq.c` and zero in on the vicinity of `autofs_wait+0x8d5/0xbe0`. That offset gives me a precise location within the function to examine. I need to understand what's being written to that address and, critically, *how* multiple tasks could be accessing it concurrently without proper synchronization. Is it a counter, a flag, or something more complex? Finding the exact code at that offset is the key to understanding the root cause and devising a fix.
|
| 6/2 |
2026/04/27 08:12 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[autofs_i.h dev-ioctl.c expire.c init.c inode.c root.c symlink.c waitq.c] Subdirs:<nil>]
|
| 7/2 |
2026/04/27 08:12 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:fs/autofs/waitq.c]
Results: map[Entities:[map[Kind:function Name:autofs_catatonic_mode] map[Kind:function Name:autofs_find_wait] map[Kind:function Name:autofs_notify_daemon] map[Kind:function Name:autofs_wait] map[Kind:function Name:autofs_wait_release] map[Kind:function Name:autofs_write] map[Kind:function Name:validate_request] map[Kind:global_variable Name:autofs_next_wait_queue]]]
|
| 8/2 |
2026/04/27 08:12 |
llm |
expert |
0m
Model:
Tokens:
input: 6096
output: 46
thoughts: 96
Thoughts: **Analyzing a Memory Write in the Context of AutoFS**
Okay, so the report points out a write to a memory address, and that value change, `0x280d -> 0x280e`, it's practically screaming "incrementing counter" to me. That's a classic pattern. Now, where could this counter live within an autofs context? Let's see... my initial thought is to check out the entities in `fs/autofs/waitq.c`. It's a prime location for something like this. And bingo, there it is: a global variable named `autofs_next_wait_queue` jumps out. That name is pretty suggestive; it definitely fits the bill.
My next step is clear: let's dive into the definition and usage of `autofs_next_wait_queue`. I need to confirm whether this is indeed the target, and understand *how* it's being used to fully grasp the significance of that memory write. I'll need to look at the surrounding code to determine if the increment is intended or if the counter is being mishandled.
|
| 9/2 |
2026/04/27 08:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/waitq.c IncludeLines:true Name:autofs_next_wait_queue]
Results: map[SourceCode: 10: /* We make this a static variable rather than a part of the superblock; it
11: * is better if we don't reassign numbers easily even across filesystems
12: */
13: static autofs_wqt_t autofs_next_wait_queue = 1;
SourceFile:fs/autofs/waitq.c]
|
| 10/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 6586
output: 42
thoughts: 35
Thoughts: Here's my analysis of the provided snippet, as if it were my thought process:
**Diving into `autofs_next_wait_queue` and `autofs_wait`**
Alright, so `autofs_next_wait_queue` is declared as a static variable. That immediately flags it as being local to a specific source file, and likely plays a crucial role in some internal state management. My next step is obvious: I need to understand its relationship to `autofs_wait`. Given the naming convention, I'd bet these are interconnected, probably dealing with some form of wait queue functionality within the autofs system. Let's see how `autofs_next_wait_queue` is actually *used* inside `autofs_wait`. That's where the real insights lie. Time to trace those calls and data dependencies. Understanding this interaction will likely unlock the purpose of the wait functionality.
|
| 11/2 |
2026/04/27 08:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/waitq.c IncludeLines:true Name:autofs_wait]
Results: map[SourceCode: 303: int autofs_wait(struct autofs_sb_info *sbi,
304: const struct path *path, enum autofs_notify notify)
305: {
306: struct dentry *dentry = path->dentry;
307: struct autofs_wait_queue *wq;
308: struct qstr qstr;
309: char *name;
310: int status, ret, type;
311: unsigned int offset = 0;
312: pid_t pid;
313: pid_t tgid;
314:
315: /* In catatonic mode, we don't wait for nobody */
316: if (sbi->flags & AUTOFS_SBI_CATATONIC)
317: return -ENOENT;
318:
319: /*
320: * Try translating pids to the namespace of the daemon.
321: *
322: * Zero means failure: we are in an unrelated pid namespace.
323: */
324: pid = task_pid_nr_ns(current, ns_of_pid(sbi->oz_pgrp));
325: tgid = task_tgid_nr_ns(current, ns_of_pid(sbi->oz_pgrp));
326: if (pid == 0 || tgid == 0)
327: return -ENOENT;
328:
329: if (d_really_is_negative(dentry)) {
330: /*
331: * A wait for a negative dentry is invalid for certain
332: * cases. A direct or offset mount "always" has its mount
333: * point directory created and so the request dentry must
334: * be positive or the map key doesn't exist. The situation
335: * is very similar for indirect mounts except only dentrys
336: * in the root of the autofs file system may be negative.
337: */
338: if (autofs_type_trigger(sbi->type))
339: return -ENOENT;
340: else if (!IS_ROOT(dentry->d_parent))
341: return -ENOENT;
342: }
343:
344: name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
345: if (!name)
346: return -ENOMEM;
347:
348: /* If this is a direct mount request create a dummy name */
349: if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type)) {
350: qstr.name = name;
351: qstr.len = sprintf(name, "%p", dentry);
352: } else {
353: char *p = dentry_path_raw(dentry, name, NAME_MAX);
354: if (IS_ERR(p)) {
355: kfree(name);
356: return -ENOENT;
357: }
358: qstr.name = ++p; // skip the leading slash
359: qstr.len = strlen(p);
360: offset = p - name;
361: }
362: qstr.hash = full_name_hash(dentry, qstr.name, qstr.len);
363:
364: if (mutex_lock_interruptible(&sbi->wq_mutex)) {
365: kfree(name);
366: return -EINTR;
367: }
368:
369: ret = validate_request(&wq, sbi, &qstr, path, notify);
370: if (ret <= 0) {
371: if (ret != -EINTR)
372: mutex_unlock(&sbi->wq_mutex);
373: kfree(name);
374: return ret;
375: }
376:
377: if (!wq) {
378: /* Create a new wait queue */
379: wq = kmalloc_obj(struct autofs_wait_queue);
380: if (!wq) {
381: kfree(name);
382: mutex_unlock(&sbi->wq_mutex);
383: return -ENOMEM;
384: }
385:
386: wq->wait_queue_token = autofs_next_wait_queue;
387: if (++autofs_next_wait_queue == 0)
388: autofs_next_wait_queue = 1;
389: wq->next = sbi->queues;
390: sbi->queues = wq;
391: init_waitqueue_head(&wq->queue);
392: memcpy(&wq->name, &qstr, sizeof(struct qstr));
393: wq->offset = offset;
394: wq->dev = autofs_get_dev(sbi);
395: wq->ino = autofs_get_ino(sbi);
396: wq->uid = current_uid();
397: wq->gid = current_gid();
398: wq->pid = pid;
399: wq->tgid = tgid;
400: wq->status = -EINTR; /* Status return if interrupted */
401: wq->wait_ctr = 2;
402:
403: if (sbi->version < 5) {
404: if (notify == NFY_MOUNT)
405: type = autofs_ptype_missing;
406: else
407: type = autofs_ptype_expire_multi;
408: } else {
409: if (notify == NFY_MOUNT)
410: type = autofs_type_trigger(sbi->type) ?
411: autofs_ptype_missing_direct :
412: autofs_ptype_missing_indirect;
413: else
414: type = autofs_type_trigger(sbi->type) ?
415: autofs_ptype_expire_direct :
416: autofs_ptype_expire_indirect;
417: }
418:
419: pr_debug("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
420: (unsigned long) wq->wait_queue_token, wq->name.len,
421: wq->name.name, notify);
422:
423: /*
424: * autofs_notify_daemon() may block; it will unlock ->wq_mutex
425: */
426: autofs_notify_daemon(sbi, wq, type);
427: } else {
428: wq->wait_ctr++;
429: pr_debug("existing wait id = 0x%08lx, name = %.*s, nfy=%d\n",
430: (unsigned long) wq->wait_queue_token, wq->name.len,
431: wq->name.name, notify);
432: mutex_unlock(&sbi->wq_mutex);
433: kfree(name);
434: }
435:
436: /*
437: * wq->name.name is NULL iff the lock is already released
438: * or the mount has been made catatonic.
439: */
440: wait_event_killable(wq->queue, wq->name.name == NULL);
441: status = wq->status;
442:
443: /*
444: * For direct and offset mounts we need to track the requester's
445: * uid and gid in the dentry info struct. This is so it can be
446: * supplied, on request, by the misc device ioctl interface.
447: * This is needed during daemon resatart when reconnecting
448: * to existing, active, autofs mounts. The uid and gid (and
449: * related string values) may be used for macro substitution
450: * in autofs mount maps.
451: */
452: if (!status) {
453: struct autofs_info *ino;
454: struct dentry *de = NULL;
455:
456: /* direct mount or browsable map */
457: ino = autofs_dentry_ino(dentry);
458: if (!ino) {
459: /* If not lookup actual dentry used */
460: de = d_lookup(dentry->d_parent, &dentry->d_name);
461: if (de)
462: ino = autofs_dentry_ino(de);
463: }
464:
465: /* Set mount requester */
466: if (ino) {
467: spin_lock(&sbi->fs_lock);
468: ino->uid = wq->uid;
469: ino->gid = wq->gid;
470: spin_unlock(&sbi->fs_lock);
471: }
472:
473: if (de)
474: dput(de);
475: }
476:
477: /* Are we the last process to need status? */
478: mutex_lock(&sbi->wq_mutex);
479: if (!--wq->wait_ctr)
480: kfree(wq);
481: mutex_unlock(&sbi->wq_mutex);
482:
483: return status;
484: }
SourceFile:fs/autofs/waitq.c]
|
| 12/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 9671
output: 44
thoughts: 480
Thoughts: **Race Condition Discovered in autofs Wait Queue Token Assignment**
Okay, so I've been digging into this autofs code, and I think I've found a race condition. The race is on the `autofs_next_wait_queue` variable. Looking at the code in `autofs_wait`, specifically lines 386-388, I see that this global variable is incremented and assigned as the wait queue token, `wq->wait_queue_token`. The crucial point is that this increment happens *inside* an `if (!wq)` block, but *after* acquiring a `sbi->wq_mutex`. Ah-ha, a per-superblock mutex!
My brain is screaming "race condition!" because `autofs_next_wait_queue` is a **static global**. So, if two different autofs mounts (each with its own `sbi` and `wq_mutex`) are being accessed at the same time, each will try to increment that global counter. Since the mutexes are *different* per mount, they can both enter the `if` and increment the global counter concurrently, essentially racing on `autofs_next_wait_queue`.
The report clearly shows this. Two tasks, running on different CPUs, are writing to the same memory location, the address of `autofs_next_wait_queue`, and one write can be lost. I saw the value change from `0x280d` to `0x280e` but if one thread increments it, and another does right after, we could skip a value. This is a classic lost increment problem.
The implications are that two wait queues could end up with the same `wait_queue_token`. That is bad. So, what is `wait_queue_token` actually used for? I remember that token is used to identify the wait request when the autofs daemon responds, which I know it does via `autofs_wait_release`. I need to go over that function and see what it will do if it has the wrong token.
|
| 13/2 |
2026/04/27 08:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/waitq.c IncludeLines:true Name:autofs_wait_release]
Results: map[SourceCode: 487: int autofs_wait_release(struct autofs_sb_info *sbi,
488: autofs_wqt_t wait_queue_token, int status)
489: {
490: struct autofs_wait_queue *wq, **wql;
491:
492: mutex_lock(&sbi->wq_mutex);
493: for (wql = &sbi->queues; (wq = *wql) != NULL; wql = &wq->next) {
494: if (wq->wait_queue_token == wait_queue_token)
495: break;
496: }
497:
498: if (!wq) {
499: mutex_unlock(&sbi->wq_mutex);
500: return -EINVAL;
501: }
502:
503: *wql = wq->next; /* Unlink from chain */
504: kfree(wq->name.name - wq->offset);
505: wq->name.name = NULL; /* Do not wait on this queue */
506: wq->status = status;
507: wake_up(&wq->queue);
508: if (!--wq->wait_ctr)
509: kfree(wq);
510: mutex_unlock(&sbi->wq_mutex);
511:
512: return 0;
513: }
SourceFile:fs/autofs/waitq.c]
|
| 14/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 11080
output: 44
thoughts: 894
Thoughts: **Analyzing the Autofs Token Allocation**
Okay, so I'm diving into this `autofs` token allocation process. My initial thought was that since `autofs_wait_release` searches for tokens within `sbi->queues`, and `sbi->queues` is specific to each superblock, and further, that `sbi->wq_mutex` guards it, having the same token in different superblocks should be fine. It is. But I need to be sure.
The daemon receives the token, but does it know the originating superblock? The daemon interacts with the kernel through a pipe or device, and each `autofs` mount has its unique communication channel. This means if two mounts use the same token, they're likely communicating with different daemons or, if it's the same daemon, different communication channels. The crucial point is the token's uniqueness *per mount* (per `sbi`).
But then I saw `autofs_next_wait_queue` is global. This threw me a bit. So, if two mounts race and get the same token, that's okay, right, as long as they are distinct mounts. But what if it's the same mount, trying to get a token?
Let's think. If it's the same mount, they are protected by `sbi->wq_mutex`. That means that the same mount cannot race on `autofs_next_wait_queue`.
Okay, let me reread `autofs_wait`. Ah, here's the key. Two threads in `autofs_wait` for the *same* `sbi` are serialized by `sbi->wq_mutex`. That's good. But, if they're for *different* `sbi`s, they can run concurrently, and that's where I get a potential problem. If they run concurrently, both could read the *same* `autofs_next_wait_queue` value and then increment it. This is bad. One increment could be lost!
Let's say `autofs_next_wait_queue` is 10. CPU 0 (Mount A) reads 10. CPU 1 (Mount B) reads 10. CPU 0 sets its `wq_A->wait_queue_token = 10`. CPU 1 sets `wq_B->wait_queue_token = 10`. Then CPU 0 increments `autofs_next_wait_queue` to 11, and CPU 1 increments it to 11. The result? Both get token 10. `autofs_next_wait_queue` is now 11.
Is this a problem in practice?
`autofs_wait_release` looks up the token in `sbi->queues`. If both Mount A and Mount B get the token 10, they are in separate `sbi->queues`. The daemon for Mount A will send a release for token 10 to Mount A's control channel. The kernel will look up token 10 in `sbi_A->queues` and find it. Similarly, the daemon for Mount B will release token 10 for Mount B, and the kernel will correctly look up token 10 in `sbi_B->queues`. So, from the kernel's point of view it is okay.
But, hang on, what if a single daemon manages multiple mounts? Even in that case, the daemon receives the request from a specific pipe and is supposed to know which pipe the request originated from. The `autofs_dev_ioctl` interface *also* uses `sbi`.
To be certain, I should really check how the daemon receives the request - `autofs_notify_daemon`. But at least I can see there is no conflict.
|
| 15/2 |
2026/04/27 08:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/waitq.c IncludeLines:true Name:autofs_notify_daemon]
Results: map[SourceCode: 79: static void autofs_notify_daemon(struct autofs_sb_info *sbi,
80: struct autofs_wait_queue *wq,
81: int type)
82: {
83: union {
84: struct autofs_packet_hdr hdr;
85: union autofs_packet_union v4_pkt;
86: union autofs_v5_packet_union v5_pkt;
87: } pkt;
88: struct file *pipe = NULL;
89: size_t pktsz;
90: int ret;
91:
92: pr_debug("wait id = 0x%08lx, name = %.*s, type=%d\n",
93: (unsigned long) wq->wait_queue_token,
94: wq->name.len, wq->name.name, type);
95:
96: memset(&pkt, 0, sizeof(pkt)); /* For security reasons */
97:
98: pkt.hdr.proto_version = sbi->version;
99: pkt.hdr.type = type;
100:
101: switch (type) {
102: /* Kernel protocol v4 missing and expire packets */
103: case autofs_ptype_missing:
104: {
105: struct autofs_packet_missing *mp = &pkt.v4_pkt.missing;
106:
107: pktsz = sizeof(*mp);
108:
109: mp->wait_queue_token = wq->wait_queue_token;
110: mp->len = wq->name.len;
111: memcpy(mp->name, wq->name.name, wq->name.len);
112: mp->name[wq->name.len] = '\0';
113: break;
114: }
115: case autofs_ptype_expire_multi:
116: {
117: struct autofs_packet_expire_multi *ep =
118: &pkt.v4_pkt.expire_multi;
119:
120: pktsz = sizeof(*ep);
121:
122: ep->wait_queue_token = wq->wait_queue_token;
123: ep->len = wq->name.len;
124: memcpy(ep->name, wq->name.name, wq->name.len);
125: ep->name[wq->name.len] = '\0';
126: break;
127: }
128: /*
129: * Kernel protocol v5 packet for handling indirect and direct
130: * mount missing and expire requests
131: */
132: case autofs_ptype_missing_indirect:
133: case autofs_ptype_expire_indirect:
134: case autofs_ptype_missing_direct:
135: case autofs_ptype_expire_direct:
136: {
137: struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
138: struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
139:
140: pktsz = sizeof(*packet);
141:
142: packet->wait_queue_token = wq->wait_queue_token;
143: packet->len = wq->name.len;
144: memcpy(packet->name, wq->name.name, wq->name.len);
145: packet->name[wq->name.len] = '\0';
146: packet->dev = wq->dev;
147: packet->ino = wq->ino;
148: packet->uid = from_kuid_munged(user_ns, wq->uid);
149: packet->gid = from_kgid_munged(user_ns, wq->gid);
150: packet->pid = wq->pid;
151: packet->tgid = wq->tgid;
152: break;
153: }
154: default:
155: pr_warn("bad type %d!\n", type);
156: mutex_unlock(&sbi->wq_mutex);
157: return;
158: }
159:
160: pipe = get_file(sbi->pipe);
161:
162: mutex_unlock(&sbi->wq_mutex);
163:
164: switch (ret = autofs_write(sbi, pipe, &pkt, pktsz)) {
165: case 0:
166: break;
167: case -ENOMEM:
168: case -ERESTARTSYS:
169: /* Just fail this one */
170: autofs_wait_release(sbi, wq->wait_queue_token, ret);
171: break;
172: default:
173: autofs_catatonic_mode(sbi);
174: break;
175: }
176: fput(pipe);
177: }
SourceFile:fs/autofs/waitq.c]
|
| 16/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 14353
output: 26
thoughts: 340
Thoughts: **Analyzing the Autofs Daemon Communication**
Okay, so the packet is clearly written to `sbi->pipe`. That means the daemon gets it from a very specific pipe, which is good. Then the daemon replies, either directly to the autofs device or by using an ioctl on the mount. The crucial thing is that the kernel *knows* which `sbi` the response is for in either case.
Therefore, duplicate tokens across different `sbi` instances shouldn't be a problem at all. My focus shifts to that `autofs_next_wait_queue`. The only possible issue I see would be if that variable is used in some other context that demands global uniqueness.
The comment in the code snippet is interesting: "it is better if we don't reassign numbers easily even across filesystems". That language suggests it's a *desirable* property rather than an absolute requirement for the system to function correctly. If it were truly essential, it would be a bug right out of the gate, and I would be seeing something much more emphatic. Since it's phrased as "better," I suspect it's more of a "nice-to-have" optimization.
However, even if it's "better," a race condition that results in a lost increment is still *technically* a bug, although its consequences may be minimal. I have to think through that angle more.
Wait, what if `autofs_next_wait_queue` is a 64-bit value, but we're dealing with a 32-bit architecture? I should check the definition of `autofs_wqt_t` in `include/uapi/linux/autofs.h`. That's where the definition would be.
|
| 17/2 |
2026/04/27 08:13 |
tool |
read-file |
0m
Error:
Args: map[File:include/uapi/linux/autofs.h]
Results:
|
| 18/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 15109
output: 23
thoughts: 24
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Autofs Internals Deep Dive**
Okay, so I'm thinking about how this autofs interaction is defined, and I need to get into the details. I immediately jump to checking `fs/autofs/autofs_i.h`. That's where the core internal structures and declarations for autofs live. If I don't find what I'm looking for immediately in that header, my next step is a targeted search. I'd be looking for a specific definition, function prototype, or macro that relates to the behavior I'm investigating. I need to get down to the brass tacks and understand the underlying data structures or API calls that govern this particular autofs function or feature. It's time to dig into the guts of the kernel module.
|
| 19/2 |
2026/04/27 08:13 |
tool |
grepper |
0m
Args: map[Expression:typedef.*autofs_wqt_t]
Results: map[Output:include/uapi/linux/auto_fs.h-35-#if defined(__ia64__) || defined(__alpha__) /* pure 64bit architectures */
include/uapi/linux/auto_fs.h:36:typedef unsigned long autofs_wqt_t;
include/uapi/linux/auto_fs.h-37-#else
include/uapi/linux/auto_fs.h:38:typedef unsigned int autofs_wqt_t;
include/uapi/linux/auto_fs.h-39-#endif
]
|
| 20/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 15476
output: 29
thoughts: 690
Thoughts: **Analyzing the Autofs Wait Queue Token Race Condition**
Okay, so I'm looking at this KCSAN report related to `autofs_wqt_t` and trying to dissect the potential race condition. First, I'm noting that this `autofs_wqt_t` is defined as an `unsigned int` on most architectures, and an `unsigned long` on pure 64-bit ones. The report shows a 4-byte write, confirming it's an `unsigned int` in this specific case. Good, that makes things slightly easier as writes to `unsigned int` are usually atomic on x86, but the increment operation is more complex.
The race itself is clearly centered around this code snippet:
```c
386: wq->wait_queue_token = autofs_next_wait_queue;
387: if (++autofs_next_wait_queue == 0)
388: autofs_next_wait_queue = 1;
```
This is not a straightforward atomic increment. It's a read-modify-write operation (`++autofs_next_wait_queue`), which KCSAN has flagged as a race. I can see the issue if two threads simultaneously read the same value of `autofs_next_wait_queue`, increment it independently, and then both write the same incremented value back. This leads to a lost increment, and potentially duplicate tokens.
Now, as I understand it, if these threads are operating on different `sbi` (superblock information) structures, this is fine because they are independent. But if they're in the same `sbi`, then `sbi->wq_mutex` is supposed to protect this section of code.
So, I need to confirm the locking around this operation. Is there any way this `autofs_wait` function is called without holding the `sbi->wq_mutex`? I look at the code and confirm that indeed, `sbi->wq_mutex` is acquired within `autofs_wait` before accessing `autofs_next_wait_queue`, so the locking is correct for operations in the same `sbi`.
This confirms the race is limited to threads operating on *different* `sbi` structures. Next, I am thinking is there any global state that uses `wait_queue_token` without reference to the `sbi`? I look at other call sites like `autofs_wait_release` and the `autofs_dev_ioctl` functions in `fs/autofs/dev-ioctl.c`. Since they take `sbi` as an argument or have `sbi` indirectly (via `file->private_data`) I confirm this looks to be the case. I need to be sure there are no other consumers, but I am fairly confident in this assessment. I think I have a good handle on where this race is happening, and that it's correctly handled in the cases with the same `sbi`.
|
| 21/2 |
2026/04/27 08:13 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:fs/autofs/dev-ioctl.c]
Results: map[Entities:[map[Kind:function Name:_autofs_dev_ioctl] map[Kind:function Name:autofs_dev_ioctl] map[Kind:function Name:autofs_dev_ioctl_askumount] map[Kind:function Name:autofs_dev_ioctl_catatonic] map[Kind:function Name:autofs_dev_ioctl_closemount] map[Kind:function Name:autofs_dev_ioctl_compat] map[Kind:function Name:autofs_dev_ioctl_exit] map[Kind:function Name:autofs_dev_ioctl_expire] map[Kind:function Name:autofs_dev_ioctl_fail] map[Kind:function Name:autofs_dev_ioctl_init] map[Kind:function Name:autofs_dev_ioctl_ismountpoint] map[Kind:function Name:autofs_dev_ioctl_open_mountpoint] map[Kind:function Name:autofs_dev_ioctl_openmount] map[Kind:function Name:autofs_dev_ioctl_protosubver] map[Kind:function Name:autofs_dev_ioctl_protover] map[Kind:function Name:autofs_dev_ioctl_ready] map[Kind:function Name:autofs_dev_ioctl_requester] map[Kind:function Name:autofs_dev_ioctl_setpipefd] map[Kind:function Name:autofs_dev_ioctl_timeout] map[Kind:function Name:autofs_dev_ioctl_version] map[Kind:function Name:check_dev_ioctl_version] map[Kind:function Name:check_name] map[Kind:function Name:copy_dev_ioctl] map[Kind:function Name:find_autofs_mount] map[Kind:function Name:free_dev_ioctl] map[Kind:function Name:invalid_str] map[Kind:function Name:lookup_dev_ioctl] map[Kind:function Name:test_by_dev] map[Kind:function Name:test_by_type] map[Kind:function Name:validate_dev_ioctl] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_676] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_677] map[Kind:global_variable Name:_autofs_dev_ioctl_misc] map[Kind:global_variable Name:_dev_ioctl_fops] map[Kind:typedef Name:ioctl_fn]]]
|
| 22/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 17509
output: 47
thoughts: 35
Thoughts: Okay, let's dive into this. Here's my thought process on this, as I understand the situation:
**Reviewing Relevant Autofs IOCTL Functions**
Alright, so the focus is clearly on `autofs_dev_ioctl_ready` and `autofs_dev_ioctl_fail`. My immediate hunch is correct; these are the likely candidates for token utilization. The text is very clear on that. I want to confirm that these two IOCTL calls are, in fact, the places where the token, whatever its role is in this context, would be actively used and potentially manipulated within the autofs kernel module. We are going to make a judgement based on this text. Now to make our assesment of our situation and next step.
|
| 23/2 |
2026/04/27 08:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/dev-ioctl.c IncludeLines:true Name:autofs_dev_ioctl_ready]
Results: map[SourceCode: 283: /*
284: * Send "ready" status for an existing wait (either a mount or an expire
285: * request).
286: */
287: static int autofs_dev_ioctl_ready(struct file *fp,
288: struct autofs_sb_info *sbi,
289: struct autofs_dev_ioctl *param)
290: {
291: autofs_wqt_t token;
292:
293: token = (autofs_wqt_t) param->ready.token;
294: return autofs_wait_release(sbi, token, 0);
295: }
SourceFile:fs/autofs/dev-ioctl.c]
|
| 24/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 17977
output: 47
thoughts: 11
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing the `autofs_dev_ioctl_fail` Scenario**
Right, so I'm looking at `autofs_dev_ioctl_fail`, and immediately I'm thinking about the implications. This isn't just a minor blip; it signals a pretty fundamental problem in how autofs is interacting with the underlying device or file system. The `ioctl` system call is the low-level mechanism here, and a failure there suggests a communication breakdown at a critical point.
My mind immediately starts ticking through the usual suspects: is there a permissions issue? A resource limit being hit? Perhaps a driver bug or incompatibility between the autofs version and the kernel? Am I seeing this due to a device going offline unexpectedly? A stale file handle or directory entry that it's trying to interact with? If so, this has a number of potential security implications too.
Given that this is an `ioctl` failure, I'd need to trace the specific call being made. What `ioctl` command is autofs attempting? That information is key. I'll need to know the specific arguments passed, and ideally, have access to kernel logs that show the return value and any error codes associated with the `ioctl` call. I am going to have to dive into a tracing tool like `strace` or even `perf` if it's performance-related.
Furthermore, I have to consider the context of the autofs mount. Is it a direct mount, or is it cascaded through other layers? Does the device support the specific `ioctl` requests being made by autofs? This is an important question. I would need to check the device support to verify that the autofs expects it to be supported. A misconfigured mount point could lead to this, and this is the first thing I'd check.
The next step would be isolating the problem: can I reproduce the issue reliably? What are the conditions that trigger the failure? What's the impact β does it just lead to a temporary stall, or does it cause a more serious system instability? Is this a one-off, or is it a persistent issue? Getting reproducible steps and capturing the execution path would be my priority. Then the error message tells me nothing without the supporting information!
Ultimately, this is going to involve digging deep into kernel internals, checking dependencies and likely stepping through source code. It's time to put my expertise to work.
|
| 25/2 |
2026/04/27 08:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/dev-ioctl.c IncludeLines:true Name:autofs_dev_ioctl_fail]
Results: map[SourceCode: 297: /*
298: * Send "fail" status for an existing wait (either a mount or an expire
299: * request).
300: */
301: static int autofs_dev_ioctl_fail(struct file *fp,
302: struct autofs_sb_info *sbi,
303: struct autofs_dev_ioctl *param)
304: {
305: autofs_wqt_t token;
306: int status;
307:
308: token = (autofs_wqt_t) param->fail.token;
309: status = param->fail.status < 0 ? param->fail.status : -ENOENT;
310: return autofs_wait_release(sbi, token, status);
311: }
SourceFile:fs/autofs/dev-ioctl.c]
|
| 26/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 18826
output: 26
thoughts: 709
Thoughts: **Analyzing the `autofs_next_wait_queue` Data Race**
Okay, so I've been digging into this `autofs_next_wait_queue` issue flagged by KCSAN. Both code paths in question call `autofs_wait_release` with the `sbi` passed in. In the `_autofs_dev_ioctl` function, `sbi` is retrieved from the file pointer of the autofs device. The critical point is that when the daemon initially opens `/dev/autofs`, it *doesn't* have an `sbi` yet; it gets one through `AUTOFS_DEV_IOCTL_OPENMOUNT` or a similar ioctl.
Now, the daemon needs to know which `sbi` to use. The common approach is for the daemon to open the autofs mount point first, and then use `AUTOFS_DEV_IOCTL_OPENMOUNT` to get a file descriptor for the associated device. Alternatively, it might use a pipe passed during the mount process. In both cases (pipe or device ioctl), the `sbi` association is per-mount.
Given this, the conclusion that duplicate tokens across different `sbi` instances are harmless still holds. The potential race condition on `autofs_next_wait_queue` is benign because:
1. It *only* occurs between different superblocks (different `sbi` instances).
2. Duplicate tokens across superblocks won't cause any confusion in the kernel or the daemon's operation.
3. The only implication is a loss of strict global token uniqueness, which is acceptable because it's only a "nice-to-have" and not a requirement.
However, KCSAN is correct; there is a data race. To keep KCSAN happy and potentially avoid compiler weirdness, using `READ_ONCE`/`WRITE_ONCE` or an `atomic_t` would be the proper fix. But, is it actually **HARMFUL**? If it's *just* about "nice to have" uniqueness, it's **BENIGN**.
Let's dive deeper into the "Torn Accesses" aspect. The `autofs_wqt_t` is a 4-byte unsigned integer. The race is on a 4-byte variable. On x86, 4-byte aligned writes are atomic. And the given memory address, `0xffffffff86dffac0`, is 8-byte aligned. Therefore, it's atomic.
Now, concerning "Fused Accesses". The code is:
```c
386: wq->wait_queue_token = autofs_next_wait_queue;
387: if (++autofs_next_wait_queue == 0)
388: autofs_next_wait_queue = 1;
```
The compiler could, in theory, optimize this. However, since it's a global variable with function calls around it, like `kmalloc_obj`, the likelihood of aggressive hoisting is slim. Even if it *does* happen, the worst-case outcome is a duplicate token, which, we've established, is fine.
To be thorough, I should look for other places where `autofs_next_wait_queue` is being used to make sure there are no other points of concern.
|
| 27/2 |
2026/04/27 08:13 |
tool |
codesearch-find-references |
0m
Args: map[Name:autofs_next_wait_queue]
Results: map[References:<nil> TruncatedOutput:false]
|
| 28/2 |
2026/04/27 08:13 |
llm |
expert |
0m
Model:
Tokens:
input: 20308
output: 22
thoughts: 93
Thoughts: **Debugging a Kernel Function**
Okay, hold on a second. I ran that search and came up empty on the references β that's strange. Let me broaden the scope of my search or maybe I just missed something in the file, I'll go back and double-check.
Ah, right, I see it now. `autofs_next_wait_queue` is defined and used *only* in `fs/autofs/waitq.c`. I already noted its definition and its use within `autofs_wait`, of course. Let's make sure I didn't miss something subtler, a secondary use or indirect call within the same file. I'll take another look at `fs/autofs/waitq.c` to be sure.
|
| 29/2 |
2026/04/27 08:14 |
tool |
grepper |
0m
Args: map[Expression:autofs_next_wait_queue]
Results: map[Output:fs/autofs/waitq.c-12- */
fs/autofs/waitq.c:13:static autofs_wqt_t autofs_next_wait_queue = 1;
fs/autofs/waitq.c-14-
--
fs/autofs/waitq.c=303=int autofs_wait(struct autofs_sb_info *sbi,
--
fs/autofs/waitq.c-385-
fs/autofs/waitq.c:386: wq->wait_queue_token = autofs_next_wait_queue;
fs/autofs/waitq.c:387: if (++autofs_next_wait_queue == 0)
fs/autofs/waitq.c:388: autofs_next_wait_queue = 1;
fs/autofs/waitq.c-389- wq->next = sbi->queues;
]
|
| 30/2 |
2026/04/27 08:14 |
llm |
expert |
0m
Model:
Tokens:
input: 20830
output: 22
thoughts: 1592
Thoughts: **My Analysis of the `autofs_next_wait_queue` Race Condition**
Okay, let's break this down. First, it looks like this `autofs_next_wait_queue` variable is only used in two places, and that's a good starting point for understanding its role and potential issues.
My immediate thought was about data tearing, so I needed to check if `autofs_wqt_t` can be 64-bit on some architectures. If that happened, could it lead to problems? A quick `grep` confirms it's an `unsigned long` on Alpha and IA64, making it 64-bit there. Now, if it's 64-bit on a 64-bit architecture, atomicity is guaranteed, so no problem there. However, if it's 64-bit on a 32-bit arch, that *could* be torn. But, the `typedef` resolves this: 32-bit architectures get an `unsigned int` (32-bit), so that's atomic and 64-bit get an `unsigned long` or `unsigned int`, so that's also atomic. Data tearing is not an issue.
Now, could there be "Ordering Violations"? The token is assigned to `wq->wait_queue_token`, then `wq` is added to `sbi->queues`, and `autofs_notify_daemon` is called. Everything is serialized by `sbi->wq_mutex` (except for the `autofs_write` in `autofs_notify_daemon`, but the token is already in the packet). The daemon returns the token, and `autofs_wait_release` uses the mutex to find the right entry. So the race on `autofs_next_wait_queue` is *only* affecting the *value* of `wq->wait_queue_token`. It's stable once assigned. The only downside is for duplicate tokens across different `sbi` structs. Weβve already established this is fine because we're not using any global registry of the tokens β `sbi->queues` is the only place it's stored.
What if the daemon is confused? The daemon is specific to a mount, and tracks pending requests per mount. Different mounts will know what request is what because they came from different pipes, so the fact that there might be duplicates isn't an issue. If the daemon uses `/dev/autofs`, each mount has its own file descriptor, so confusion is impossible.
**Conclusion: The race is BENIGN.** It's a "Structural Tolerance" race condition. The global counter generates identifiers which only need to be unique per-mount. Per-mount uniqueness is guaranteed by the per-mount mutex. The global counter makes them "more unique" across mounts, but isn't strictly required.
Okay, let's think about this a bit more. What if `autofs_next_wait_queue` wraps around? The code specifically avoids zero: if `++autofs_next_wait_queue` becomes zero, it's set to 1. This is fine.
Is there a "Logic Bug"? The only problem could be a *lost* increment leading to a duplicate token *within the same `sbi`*. But `sbi->wq_mutex` serializes increments for the same `sbi`. So, impossible.
Let's verify that the mutex is held, and, yep, it is. `autofs_wait` is called from `autofs_mount_wait` which is called from `autofs_d_automount`. These are standard autofs paths.
Is there any other place where `autofs_next_wait_queue` is modified? No, `grep` confirms this.
So the race is between two threads: A (Mount 1) `wq1->token = autofs_next_wait_queue++` and B (Mount 2): `wq2->token = autofs_next_wait_queue++`. If they race, they *might* get the same token. As we said, this is fine.
Any *other* potential issues? What if the compiler does something crazy? Itβs a simple increment, but could the compiler use a non-atomic RMW instruction? On x86, `inc` or `add` to memory is *not* atomic unless it's prefixed with `lock`. This is what KCSAN is likely flagging.
But even if an increment is "lost" (e.g., `10 -> 11` and `10 -> 11`), the outcome is just a duplicate or skipped token. *Neither* are harmful.
Could it be "corrupted" to something else? A 4
|
| 31/2 |
2026/04/27 08:14 |
tool |
grepper |
0m
Args: map[Expression:autofs_next_wait_queue]
Results: map[Output:fs/autofs/waitq.c-12- */
fs/autofs/waitq.c:13:static autofs_wqt_t autofs_next_wait_queue = 1;
fs/autofs/waitq.c-14-
--
fs/autofs/waitq.c=303=int autofs_wait(struct autofs_sb_info *sbi,
--
fs/autofs/waitq.c-385-
fs/autofs/waitq.c:386: wq->wait_queue_token = autofs_next_wait_queue;
fs/autofs/waitq.c:387: if (++autofs_next_wait_queue == 0)
fs/autofs/waitq.c:388: autofs_next_wait_queue = 1;
fs/autofs/waitq.c-389- wq->next = sbi->queues;
]
|
| 32/2 |
2026/04/27 08:14 |
llm |
expert |
0m
Model:
Tokens:
input: 23712
output: 44
thoughts: 2323
Thoughts: **My Analysis of the `fs/autofs/waitq.c` Race Condition**
Okay, let's dive into this. I'm looking at the history of `fs/autofs/waitq.c` and specifically focusing on the use of `autofs_next_wait_queue`. I quickly notice the comment explaining it's a static variable, and the reason for that, which doesn't touch on synchronization.
I'm zeroing in on this snippet in `autofs_wait`:
```c
386: wq->wait_queue_token = autofs_next_wait_queue;
387: if (++autofs_next_wait_queue == 0)
388: autofs_next_wait_queue = 1;
```
My initial thought is to slap an atomic variable on it, but the critical question is: is this *HARMFUL*? I'm going through the protocol. Given the information I'm given, I'm thinking this more closely fits the "Structural Tolerance" category. The algorithm is tolerant to duplicate tokens across different superblocks, and the per-superblock mutex guarantees uniqueness within a superblock. The global counter is really just a way to reduce, but not eliminate, the chance of duplicates.
But, hold on. Does the daemon even *care* about global uniqueness? If the daemon manages multiple autofs mounts, would it care? If the daemon is using a global hash table keyed by the token, yes. But, the daemon *must* know which mount a request belongs to. When it receives a packet from a pipe, it knows the mount. A well-written daemon would track tokens per mount, not globally. And it turns out that the standard `automount` daemon does indeed track requests per mount, with its own state machine and lists.
So, even if the daemon gets "confused," it's a daemon bug, not a kernel bug, unless the kernel is guaranteeing global uniqueness. The kernel *comment* says "it is better if we don't reassign numbers easily" β that is not a *guarantee*!
Even with a lost increment, duplicates are very unlikely unless many mounts are being triggered *simultaneously* and happen to read the same value.
I also have to consider the UAPI: `autofs_wqt_t` is used in the UAPI. If the kernel starts giving out duplicate tokens, and some user-space tool *depends* on global uniqueness, it could break. But what tool would that be? Again, the daemon is the primary user.
Let's revisit "HARMFUL". "Control Flow"? No, this token doesn't guard anything, it's just an ID. "State Machines"? Nope, it's part of the wait queue *state*, not the state itself. "Lossy Updates"? Is every increment required to be preserved? If we don't care about duplicates (across different `sbi`), then we don't care.
Given the context, I'm leaning heavily towards this being **BENIGN**. These tokens are used for a request-response protocol, and the channel (the pipe) handles disambiguation.
I want to be thorough, so let's check where else `wait_queue_token` is used. `autofs_notify_daemon` uses it to fill packets. It's used to find the `wq` in `autofs_wait_release`. Also in `autofs_dev_ioctl_ready` and `autofs_dev_ioctl_fail` to call `autofs_wait_release`. And it's printed in `pr_debug`. It's consistently used as an identifier.
One tiny detail: `autofs_next_wait_queue` is initialized to 1 and explicitly avoids 0. The reason is likely because 0 might be used as a special value (though I don't see that use in the kernel code). A lost increment and `autofs_next_wait_queue` becoming 0 might be bad, but the `++` should prevent it from staying at zero and it will eventually move past it. I should note that the check `if (++autofs_next_wait_queue == 0)` is also part of the race. But, worst case is a 0 or duplicate token.
I think, ultimately, it's benign, but I'm thinking I should use `data_race()` or convert to `atomic_t` to be safe and silence KCSAN and prevent theoretical compiler weirdness.
Okay, reviewing the code again:
```c
386: wq->wait_queue_token = autofs_next_wait_queue;
38
|
| 33/2 |
2026/04/27 08:14 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/waitq.c IncludeLines:true Name:autofs_find_wait]
Results: map[SourceCode: 179: static struct autofs_wait_queue *
180: autofs_find_wait(struct autofs_sb_info *sbi, const struct qstr *qstr)
181: {
182: struct autofs_wait_queue *wq;
183:
184: for (wq = sbi->queues; wq; wq = wq->next) {
185: if (wq->name.hash == qstr->hash &&
186: wq->name.len == qstr->len &&
187: wq->name.name &&
188: !memcmp(wq->name.name, qstr->name, qstr->len))
189: break;
190: }
191: return wq;
192: }
SourceFile:fs/autofs/waitq.c]
|
| 34/2 |
2026/04/27 08:14 |
llm |
expert |
0m
Model:
Tokens:
input: 27363
output: 41
thoughts: 23
Thoughts: Okay, here's my summary, tailored as if I'm an expert in the field thinking through this:
**Analyzing the Authentication Approach**
Right, hold on. That initial assumption was wrong. It's *not* using a more robust mechanism; it's still relying on a combination of the name and the hash. That's a key observation. We're back to square one, essentially evaluating the security of a name-hash combination.
Now, a crucial follow-up question. What about the `validate_request` function? Is that where the security checks actually *happen*? What's the implementation of that function doing? That's going to be the lynchpin, the place where any vulnerabilities would likely reside. The name and hash combination itself is just the *input*; the validation function is the crucial *process*. I need to drill down into that code immediately.
|
| 35/2 |
2026/04/27 08:14 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/autofs/waitq.c IncludeLines:true Name:validate_request]
Results: map[SourceCode: 194: /*
195: * Check if we have a valid request.
196: * Returns
197: * 1 if the request should continue.
198: * In this case we can return an autofs_wait_queue entry if one is
199: * found or NULL to idicate a new wait needs to be created.
200: * 0 or a negative errno if the request shouldn't continue.
201: */
202: static int validate_request(struct autofs_wait_queue **wait,
203: struct autofs_sb_info *sbi,
204: const struct qstr *qstr,
205: const struct path *path, enum autofs_notify notify)
206: {
207: struct dentry *dentry = path->dentry;
208: struct autofs_wait_queue *wq;
209: struct autofs_info *ino;
210:
211: if (sbi->flags & AUTOFS_SBI_CATATONIC)
212: return -ENOENT;
213:
214: /* Wait in progress, continue; */
215: wq = autofs_find_wait(sbi, qstr);
216: if (wq) {
217: *wait = wq;
218: return 1;
219: }
220:
221: *wait = NULL;
222:
223: /* If we don't yet have any info this is a new request */
224: ino = autofs_dentry_ino(dentry);
225: if (!ino)
226: return 1;
227:
228: /*
229: * If we've been asked to wait on an existing expire (NFY_NONE)
230: * but there is no wait in the queue ...
231: */
232: if (notify == NFY_NONE) {
233: /*
234: * Either we've betean the pending expire to post it's
235: * wait or it finished while we waited on the mutex.
236: * So we need to wait till either, the wait appears
237: * or the expire finishes.
238: */
239:
240: while (ino->flags & AUTOFS_INF_EXPIRING) {
241: mutex_unlock(&sbi->wq_mutex);
242: schedule_timeout_interruptible(HZ/10);
243: if (mutex_lock_interruptible(&sbi->wq_mutex))
244: return -EINTR;
245:
246: if (sbi->flags & AUTOFS_SBI_CATATONIC)
247: return -ENOENT;
248:
249: wq = autofs_find_wait(sbi, qstr);
250: if (wq) {
251: *wait = wq;
252: return 1;
253: }
254: }
255:
256: /*
257: * Not ideal but the status has already gone. Of the two
258: * cases where we wait on NFY_NONE neither depend on the
259: * return status of the wait.
260: */
261: return 0;
262: }
263:
264: /*
265: * If we've been asked to trigger a mount and the request
266: * completed while we waited on the mutex ...
267: */
268: if (notify == NFY_MOUNT) {
269: struct dentry *new = NULL;
270: struct path this;
271: int valid = 1;
272:
273: /*
274: * If the dentry was successfully mounted while we slept
275: * on the wait queue mutex we can return success. If it
276: * isn't mounted (doesn't have submounts for the case of
277: * a multi-mount with no mount at it's base) we can
278: * continue on and create a new request.
279: */
280: if (!IS_ROOT(dentry)) {
281: if (d_unhashed(dentry) &&
282: d_really_is_positive(dentry)) {
283: struct dentry *parent = dentry->d_parent;
284:
285: new = d_lookup(parent, &dentry->d_name);
286: if (new)
287: dentry = new;
288: }
289: }
290: this.mnt = path->mnt;
291: this.dentry = dentry;
292: if (path_has_submounts(&this))
293: valid = 0;
294:
295: if (new)
296: dput(new);
297: return valid;
298: }
299:
300: return 1;
301: }
SourceFile:fs/autofs/waitq.c]
|
| 36/2 |
2026/04/27 08:14 |
llm |
expert |
0m
Model:
Tokens:
input: 29151
output: 19
thoughts: 608
Thoughts: **My Assessment of the Autofs Wait Queue Token Race**
Okay, let's break this down. No, I don't see any use of `autofs_next_wait_queue` other than for assigning a token to a new wait queue entry. And that token, as far as I can tell, is only used to match responses to requests *within* the same superblock.
I had to double check, but it's clear the race is in `fs/autofs/waitq.c` on the global static `autofs_next_wait_queue`. Multiple autofs mounts β different superblocks β can race on this counter because there isn't protection between them, though each mount has its own mutex. We might get duplicate tokens assigned, but that's okay.
I was being overly cautious there. Think about it. The autofs protocol and its kernel implementation are mount-specific. The kernel and user space communicate via pipes or devices specific to the mount. The daemon gets a token in a packet, reads from a pipe, and knows which pipe it came from, therefore knows which mount it belongs to. When the daemon replies, it either writes to the same pipe (which is typically one-way, from the kernel to the daemon) or uses an ioctl on the autofs device. If it's an ioctl, the kernel uses the superblock information from the file descriptor to look up the token. So the lookup is per-mount.
Thus, tokens only need to be unique *per-mount*. So, despite the race, it's benign. No data corruption, no incorrect behavior.
The race is harmless, and a simple solution is to use `atomic_t` for `autofs_next_wait_queue` or, to satisfy the checkers, wrap the access in `data_race()`. No two-column trace needed.
|
| 37/2 |
2026/04/27 08:14 |
tool |
set-results |
0m
Args: map[Benign:true Confident:true]
Results: map[Benign:true Confident:true]
|
| 38/2 |
2026/04/27 08:14 |
llm |
expert |
0m
Model:
Tokens:
input: 30188
output: 771
thoughts: 370
Thoughts: **My Analysis of the `autofs_wait` Race Condition**
Okay, so I've been asked to summarize this race condition analysis involving `autofs_wait`. Let me break it down. Essentially, we have a potential race between two `autofs_wait` calls, both vying for access to `autofs_next_wait_queue`. This global counter generates tokens, which are crucial for matching daemon responses with kernel wait requests, so the question is, could there be a problem with overlapping token generation?
The key here is understanding the context, as always. The race is between two instances of `autofs_wait` on separate mounts. Crucially, I see that both tasks *do* hold their respective `sbi->wq_mutex`. That's a vital piece. Because these `sbi` are different (referring to different autofs mounts), we are dealing with distinct mutexes. The critical point is that there isn't a *global* lock protecting the `autofs_next_wait_queue` variable itself.
But here's why it's ultimately benign. The tokens aren't globally unique, and that's okay. They're unique *per mount*. Each autofs mount has its own queue of pending requests (`sbi->queues`). When the kernel receives a response, it only searches within the token queue of the originating mount. So, duplicate tokens *within* a single mount *would* be a problem, but that access to `autofs_next_wait_queue` within that single mount is protected by the `sbi->wq_mutex`, ensuring unique tokens *per mount*.
While a race might result in duplicate tokens *across* separate mounts, the kernel and the daemon are designed to handle this. The analysis points out that global uniqueness is a desirable feature, but not a necessity.
So, my final classification is that this is **BENIGN**. My recommendation, although the condition doesn't present an issue, would be to either use `data_race()` to document the potential data race, or to convert `autofs_next_wait_queue` to an `atomic_t`, to make the token generation explicit.
|
| 39/1 |
2026/04/27 08:15 |
action |
format-explanation |
0m
Results: map[Explanation:The data race occurs on the global static variable `autofs_next_wait_queue` in
`fs/autofs/waitq.c`. This variable is used to assign a "token" (an identifier)
to each new wait request sent to the autofs daemon.
### Race Summary
The race happens in `autofs_wait()` when two different tasks are triggering
automounts on **different** autofs mount points simultaneously.
- **Task A** (Mount 1) holds `sbi1->wq_mutex`.
- **Task B** (Mount 2) holds `sbi2->wq_mutex`.
Since they hold different mutexes, they can concurrently execute the following
code:
```c
// fs/autofs/waitq.c:386
wq->wait_queue_token = autofs_next_wait_queue;
if (++autofs_next_wait_queue == 0)
autofs_next_wait_queue = 1;
```
This results in a non-atomic read-modify-write on the global
`autofs_next_wait_queue`.
### Synchronization Context
While each autofs superblock (`sbi`) has its own `wq_mutex` to serialize wait
queue operations for that specific mount, `autofs_next_wait_queue` is a shared
global variable. There is no global lock protecting it. Consequently, concurrent
updates from different mounts can race, potentially leading to lost increments
and duplicate tokens being assigned to different wait requests.
### Final Classification: **BENIGN**
#### Reasoning:
1. **Per-Mount Scoping:** The `wait_queue_token` is used to identify a specific
wait request when the daemon responds (via ioctl or write to the pipe). The
kernel performs this lookup using `autofs_wait_release()`, which searches for
the token only within the `sbi->queues` list of the **specific** superblock
associated with the response.
2. **Structural Tolerance:** Because the lookup is scoped to a single
superblock, duplicate tokens are only problematic if they exist within the
*same* superblock. However, within a single superblock, all access to the
counter is serialized by the per-superblock `sbi->wq_mutex`, ensuring tokens are
unique for that mount.
3. **Daemon Context:** The daemon receives requests from a specific pipe or
device associated with a mount. It tracks pending requests per mount. Even if it
receives the same token value from two different mounts, it can distinguish them
based on the communication channel.
4. **Intentional Design:** A comment in `fs/autofs/waitq.c` states: *"it is
better if we don't reassign numbers easily even across filesystems"*. This
indicates that global uniqueness is a preferred property for debugging or
diagnostic clarity, but not a requirement for correctness.
5. **No Memory Safety Issues:** The variable is a simple integer. A race here
does not involve pointers, array bounds, or complex state transitions that could
lead to a kernel crash or memory corruption.
#### Recommended Annotations:
To silence KCSAN and ensure the compiler does not perform unsafe optimizations,
the access should be wrapped in `data_race()` or the variable should be
converted to an `atomic_t`.
```c
/* Suggested fix using data_race() */
wq->wait_queue_token = data_race(autofs_next_wait_queue);
if (data_race(++autofs_next_wait_queue) == 0)
data_race(autofs_next_wait_queue = 1);
```]
|