| 0/0 |
2026/11/19 20:48 |
flow |
assessment-security |
2m
Results: map[DenialOfService:false Explanation:Root Cause Analysis:
### Root Cause Analysis
The KCSAN data race occurs because `kernfs_iop_permission()` in
`fs/kernfs/inode.c` mutates fields of the shared VFS `struct inode` while
holding only a shared reader lock (`down_read(&root->kernfs_iattr_rwsem)`),
allowing concurrent VFS lookups on the same kernfs node to read and write
`inode->i_mode` without synchronization.
#### Technical Mechanism
1. **Shared locking in `kernfs_iop_permission()`
(`fs/kernfs/inode.c:273-292`)**:
- When VFS path traversal (`link_path_walk()` -> `may_lookup()` ->
`inode_permission()` -> `do_inode_permission()`) checks permissions on a
kernfs inode (in non-RCU mode, i.e., without `MAY_NOT_BLOCK`), it invokes
`inode->i_op->permission`, which points to `kernfs_iop_permission()`
(registered in `kernfs_iops`, `kernfs_dir_iops`, and `kernfs_symlink_iops`).
- `kernfs_iop_permission()` acquires `root->kernfs_iattr_rwsem` for reading:
```c
down_read(&root->kernfs_iattr_rwsem);
kernfs_refresh_inode(kn, inode);
ret = generic_permission(&nop_mnt_idmap, inode, mask);
up_read(&root->kernfs_iattr_rwsem);
```
- `kernfs_iop_getattr()` (`fs/kernfs/inode.c:182-196`) follows the same
pattern, calling `kernfs_refresh_inode()` and `generic_fillattr()` under
`down_read(&root->kernfs_iattr_rwsem)`.
2. **Unprotected writes in `kernfs_refresh_inode()`
(`fs/kernfs/inode.c:165-180`)**:
- Because `root->kernfs_iattr_rwsem` is only acquired for reading, multiple
tasks can enter `kernfs_iop_permission()` (and `kernfs_iop_getattr()`)
simultaneously for the same `struct kernfs_node` (`kn`) and `struct inode`
(`inode`).
- `kernfs_refresh_inode()` unconditionally performs plain (non-atomic) writes
to `inode` fields:
- `inode->i_mode = kn->mode;` (`fs/kernfs/inode.c:169`), a 2-byte `umode_t`
write at offset 0 of `struct inode`.
- `set_inode_attr(inode, attrs);` (`fs/kernfs/inode.c:176`), which writes
`inode->i_uid`, `inode->i_gid`, and timestamps.
- `set_nlink(inode, kn->dir.subdirs + 2);` (`fs/kernfs/inode.c:179`), which
writes `inode->__i_nlink` for active directories.
3. **Concurrent read in `generic_permission()` / `acl_permission_check()`
(`fs/namei.c:438-531`)**:
- After `kernfs_refresh_inode()`, `kernfs_iop_permission()` calls
`generic_permission(&nop_mnt_idmap, inode, mask)` (`fs/kernfs/inode.c:288`),
which calls `acl_permission_check()` (`fs/namei.c:529`).
- `acl_permission_check()` performs a plain 2-byte read of `inode->i_mode`
(`unsigned int mode = inode->i_mode;` at `fs/namei.c:441`) and may also read
`inode->i_uid` and `inode->i_gid`.
- In the reported trace, Task 3731 (`openat` -> `kernfs_iop_permission()` ->
`kernfs_refresh_inode()` at `fs/kernfs/inode.c:169`) writes 2 bytes to
`inode->i_mode` (`0xffff888107516f88`) concurrently with Task 3010
(`readlink` -> `kernfs_iop_permission()` -> `generic_permission()` ->
`acl_permission_check()` at `fs/namei.c:441`) reading those 2 bytes.
#### Lifecycle and Invariants
- Modifications to `kn->mode` (via `__kernfs_setattr()` in `kernfs_setattr()` /
`kernfs_iop_setattr()`) and `kn->iattr` attributes are serialized under
`down_write(&root->kernfs_iattr_rwsem)`.
- `kernfs_iattr_rwsem` protects the `kernfs_node` attributes against concurrent
`setattr`, but it does **not** serialize the copy/refresh of those attributes
from `kn` into the VFS `struct inode`, nor does `kernfs_iop_permission()` hold
`inode->i_lock` or `inode->i_rwsem` exclusively. Consequently, any two
concurrent readers executing `kernfs_iop_permission()` or `kernfs_iop_getattr()`
on the same kernfs inode violate the C memory model invariant against
unsynchronized concurrent read/write (and write/write) accesses to
`inode->i_mode` (as well as `i_uid`, `i_gid`, and `__i_nlink`).
Impact Analysis:
In real-world setups without KCSAN, this data race is benign. While multiple
threads execute kernfs_iop_permission() (and kernfs_iop_getattr()) concurrently
under down_read(&root->kernfs_iattr_rwsem), any modifications to kn->mode or
kernfs_iattrs take down_write(&root->kernfs_iattr_rwsem). As a result, kn->mode
(and uid/gid/nlink/timestamps) remain constant across all concurrent readers, so
kernfs_refresh_inode() repeatedly writes the exact same 2-byte kn->mode value to
inode->i_mode. Even if kn->mode was updated in an earlier kernfs_setattr() and
two readers race to refresh inode->i_mode, both write the identical new value to
a naturally aligned 16-bit field (inode->i_mode at offset 0 of struct inode),
and acl_permission_check() observes either the old or new valid mode bits
without crashing, hanging, or corrupting adjacent fields or pointers.
Classification reasoning:
- MemoryCorruption = false: The race involves plain accesses to inode->i_mode (a
2-byte umode_t permission/type mask) writing identical values; it does not
corrupt pointers, refcounts, buffer lengths, or control flow.
- InfoLeak = "none": No kernel memory contents are leaked to userspace or
external observers.
- RawDenialOfService = false: Without KCSAN, concurrent 2-byte accesses to
inode->i_mode do not trigger a kernel panic, hang, deadlock, or resource leak.
- IsNetCandidate = false: The bug is in kernfs/VFS path lookup (openat and
readlink by udevd) with no relation to networking.
- IsKVMCandidate = false: The bug and call traces have no relation to KVM,
virtualization, or vhost/virtio.
Local Reachability Analysis:
### Analysis Summary
* **Unprivileged (`true`)**:
The data race occurs in `kernfs_iop_permission()`
(`fs/kernfs/inode.c:273-292`), which is assigned as the `.permission` inode
operation for all kernfs inodes (`kernfs_iops`, `kernfs_dir_iops`, and
`kernfs_symlink_iops` in `fs/kernfs/inode.c`, `fs/kernfs/dir.c`, and
`fs/kernfs/symlink.c`).
- Kernel configuration has both `CONFIG_SYSFS=y` and `CONFIG_CGROUPS=y`, so
`/sys` (sysfs) and `/sys/fs/cgroup` (cgroupfs) are mounted and expose
world-traversable/readable directories, files, and symlinks to unprivileged
users.
- During VFS path lookup (`link_path_walk()` -> `may_lookup()` ->
`do_inode_permission()`), `kernfs_iop_permission()` returns `-ECHILD` when
`MAY_NOT_BLOCK` is set (`LOOKUP_RCU`), causing `may_lookup()`
(`fs/namei.c:1961-1983`) to drop out of RCU mode (`try_to_unlazy()`) and
invoke `kernfs_iop_permission()` without `MAY_NOT_BLOCK`.
- No capabilities, root-only device nodes, or user namespaces are required:
any unprivileged user running two concurrent threads or processes calling
standard VFS syscalls (e.g., `openat()`, `readlink()`, `stat()`, or
`access()`) on the same world-readable path in `/sys` or `/sys/fs/cgroup` will
enter `kernfs_iop_permission()` concurrently under
`down_read(&root->kernfs_iattr_rwsem)`, racing between
`kernfs_refresh_inode()` writing `inode->i_mode` (`fs/kernfs/inode.c:169`) and
`generic_permission()` -> `acl_permission_check()` reading `inode->i_mode`
(`fs/namei.c:441`).
* **UserNamespace (`true`)**:
Since the bug is reachable directly by an unprivileged process without any
namespace, `UserNamespace` is also `true`.
* **RequiredCaps (`[]`)**:
No capabilities are required along the unprivileged `/sys` lookup path.
* **PeripheralTrigger (`false`)**:
The race is triggered purely by concurrent VFS path lookups on kernfs/sysfs
inodes and does not depend on parsing input from an untrusted physical
peripheral device.
* **FilesystemTrigger (`false`)**:
Kernfs is an in-memory virtual filesystem infrastructure (used by
sysfs/cgroupfs), not a disk/image-backed filesystem parser.
* **RawFuzzingArtifact (`false`)**:
This is a genuine KCSAN data race in `fs/kernfs/inode.c` reachable via normal
unprivileged VFS syscalls on sysfs. Exploitable:false FilesystemTrigger:false FuzzingArtifact:false InfoLeak:none MemoryCorruption:false NetworkNeedsSetup:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false RequiredCaps:<nil> RootCauseAnalysis:### Root Cause Analysis
The KCSAN data race occurs because `kernfs_iop_permission()` in `fs/kernfs/inode.c` mutates fields of the shared VFS `struct inode` while holding only a shared reader lock (`down_read(&root->kernfs_iattr_rwsem)`), allowing concurrent VFS lookups on the same kernfs node to read and write `inode->i_mode` without synchronization.
#### Technical Mechanism
1. **Shared locking in `kernfs_iop_permission()` (`fs/kernfs/inode.c:273-292`)**:
- When VFS path traversal (`link_path_walk()` -> `may_lookup()` -> `inode_permission()` -> `do_inode_permission()`) checks permissions on a kernfs inode (in non-RCU mode, i.e., without `MAY_NOT_BLOCK`), it invokes `inode->i_op->permission`, which points to `kernfs_iop_permission()` (registered in `kernfs_iops`, `kernfs_dir_iops`, and `kernfs_symlink_iops`).
- `kernfs_iop_permission()` acquires `root->kernfs_iattr_rwsem` for reading:
```c
down_read(&root->kernfs_iattr_rwsem);
kernfs_refresh_inode(kn, inode);
ret = generic_permission(&nop_mnt_idmap, inode, mask);
up_read(&root->kernfs_iattr_rwsem);
```
- `kernfs_iop_getattr()` (`fs/kernfs/inode.c:182-196`) follows the same pattern, calling `kernfs_refresh_inode()` and `generic_fillattr()` under `down_read(&root->kernfs_iattr_rwsem)`.
2. **Unprotected writes in `kernfs_refresh_inode()` (`fs/kernfs/inode.c:165-180`)**:
- Because `root->kernfs_iattr_rwsem` is only acquired for reading, multiple tasks can enter `kernfs_iop_permission()` (and `kernfs_iop_getattr()`) simultaneously for the same `struct kernfs_node` (`kn`) and `struct inode` (`inode`).
- `kernfs_refresh_inode()` unconditionally performs plain (non-atomic) writes to `inode` fields:
- `inode->i_mode = kn->mode;` (`fs/kernfs/inode.c:169`), a 2-byte `umode_t` write at offset 0 of `struct inode`.
- `set_inode_attr(inode, attrs);` (`fs/kernfs/inode.c:176`), which writes `inode->i_uid`, `inode->i_gid`, and timestamps.
- `set_nlink(inode, kn->dir.subdirs + 2);` (`fs/kernfs/inode.c:179`), which writes `inode->__i_nlink` for active directories.
3. **Concurrent read in `generic_permission()` / `acl_permission_check()` (`fs/namei.c:438-531`)**:
- After `kernfs_refresh_inode()`, `kernfs_iop_permission()` calls `generic_permission(&nop_mnt_idmap, inode, mask)` (`fs/kernfs/inode.c:288`), which calls `acl_permission_check()` (`fs/namei.c:529`).
- `acl_permission_check()` performs a plain 2-byte read of `inode->i_mode` (`unsigned int mode = inode->i_mode;` at `fs/namei.c:441`) and may also read `inode->i_uid` and `inode->i_gid`.
- In the reported trace, Task 3731 (`openat` -> `kernfs_iop_permission()` -> `kernfs_refresh_inode()` at `fs/kernfs/inode.c:169`) writes 2 bytes to `inode->i_mode` (`0xffff888107516f88`) concurrently with Task 3010 (`readlink` -> `kernfs_iop_permission()` -> `generic_permission()` -> `acl_permission_check()` at `fs/namei.c:441`) reading those 2 bytes.
#### Lifecycle and Invariants
- Modifications to `kn->mode` (via `__kernfs_setattr()` in `kernfs_setattr()` / `kernfs_iop_setattr()`) and `kn->iattr` attributes are serialized under `down_write(&root->kernfs_iattr_rwsem)`.
- `kernfs_iattr_rwsem` protects the `kernfs_node` attributes against concurrent `setattr`, but it does **not** serialize the copy/refresh of those attributes from `kn` into the VFS `struct inode`, nor does `kernfs_iop_permission()` hold `inode->i_lock` or `inode->i_rwsem` exclusively. Consequently, any two concurrent readers executing `kernfs_iop_permission()` or `kernfs_iop_getattr()` on the same kernfs inode violate the C memory model invariant against unsynchronized concurrent read/write (and write/write) accesses to `inode->i_mode` (as well as `i_uid`, `i_gid`, and `__i_nlink`). RootCauseFiles:[fs/kernfs/inode.c] RootCauseSummary:kernfs_iop_permission() in fs/kernfs/inode.c acquires only a shared read lock (down_read(&root->kernfs_iattr_rwsem)) before calling kernfs_refresh_inode(kn, inode) and generic_permission(). Because down_read() permits concurrent execution on the same inode, one task's plain 2-byte write to inode->i_mode in kernfs_refresh_inode() races with another task's plain 2-byte read of inode->i_mode in acl_permission_check() (via generic_permission()), as well as with concurrent kernfs_refresh_inode() calls in kernfs_iop_permission() and kernfs_iop_getattr(). Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/11/19 20:48 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/11/19 20:48 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/53b838f3f44a740248a5e515f921a00eaeeeb0e1/data]
|
| 3/1 |
2026/11/19 20:48 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/d139c14113fd09ded7171630aecd977ce866e25f/data]
|
| 4/1 |
2026/11/19 20:48 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/11/19 20:48 |
agent |
root-cause |
1m
Model:
Results: map[ImpactAnalysis:In real-world setups without KCSAN, this data race is benign. While multiple threads execute kernfs_iop_permission() (and kernfs_iop_getattr()) concurrently under down_read(&root->kernfs_iattr_rwsem), any modifications to kn->mode or kernfs_iattrs take down_write(&root->kernfs_iattr_rwsem). As a result, kn->mode (and uid/gid/nlink/timestamps) remain constant across all concurrent readers, so kernfs_refresh_inode() repeatedly writes the exact same 2-byte kn->mode value to inode->i_mode. Even if kn->mode was updated in an earlier kernfs_setattr() and two readers race to refresh inode->i_mode, both write the identical new value to a naturally aligned 16-bit field (inode->i_mode at offset 0 of struct inode), and acl_permission_check() observes either the old or new valid mode bits without crashing, hanging, or corrupting adjacent fields or pointers.
Classification reasoning:
- MemoryCorruption = false: The race involves plain accesses to inode->i_mode (a 2-byte umode_t permission/type mask) writing identical values; it does not corrupt pointers, refcounts, buffer lengths, or control flow.
- InfoLeak = "none": No kernel memory contents are leaked to userspace or external observers.
- RawDenialOfService = false: Without KCSAN, concurrent 2-byte accesses to inode->i_mode do not trigger a kernel panic, hang, deadlock, or resource leak.
- IsNetCandidate = false: The bug is in kernfs/VFS path lookup (openat and readlink by udevd) with no relation to networking.
- IsKVMCandidate = false: The bug and call traces have no relation to KVM, virtualization, or vhost/virtio. InfoLeak:none IsKVMCandidate:false IsNetCandidate:false MemoryCorruption:false RawDenialOfService:false RootCauseFiles:[fs/kernfs/inode.c] RootCauseSummary:kernfs_iop_permission() in fs/kernfs/inode.c acquires only a shared read lock (down_read(&root->kernfs_iattr_rwsem)) before calling kernfs_refresh_inode(kn, inode) and generic_permission(). Because down_read() permits concurrent execution on the same inode, one task's plain 2-byte write to inode->i_mode in kernfs_refresh_inode() races with another task's plain 2-byte read of inode->i_mode in acl_permission_check() (via generic_permission()), as well as with concurrent kernfs_refresh_inode() calls in kernfs_iop_permission() and kernfs_iop_getattr().]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze the given kernel bug report,
determine its root cause in the kernel source tree, and classify the direct consequences of the defect.
Use the provided tools to examine the source code and understand the exact nature of the bug:
- Determine the root cause directly from the present state of the source code. Do NOT search git history or run
git-log/git-blame to find when code was introduced or modified; only use git tools as a last resort if the current
code itself is ambiguous and cannot be understood without a commit description.
- You can check the kernel build configuration and "CONFIG_CMDLINE=" using the kernel-config-grep tool (do not
try to read or grep ".config" as a file in the source tree). Assume sysctl parameters have default values.
- When classifying consequences, consider real-world setups WITHOUT debugging sanitizers enabled
(KASAN, KMSAN, KCSAN, UBSAN, lockdep) and without panic_on_warn enabled.
In your final reply, write a clear, detailed technical explanation of the root cause aimed at kernel developers
investigating and fixing the bug:
- The exact functions, structs, fields, and files involved.
- How the bug is triggered, what invariant or lifecycle rule is violated, and how that leads to the reported failure.
- Keep the final reply strictly focused on the bug's technical mechanism and root cause; put all impact evaluation and
classification reasoning into `ImpactAnalysis` when calling `set-results`.
- Pinpointing the exact root cause is best-effort: try your best, but if the problem turns out to be too complicated or
inconclusive after thoroughly inspecting the functions in the crash, allocation, and free stacks (for example, an
elusive race or external/deferred memory corruption where the offending caller is not recorded in the report), it is
okay to give up on finding the exact trigger rather than searching indefinitely. State your verified findings (the
crash site, object lifecycle, invariants checked, and hypotheses ruled out), note what remains inconclusive, and
provide best-effort output values so downstream steps have enough context to assess the impact and reachability of the
problem.
Another engineer will use your explanation and `ImpactAnalysis` to trace caller reachability and attack surfaces.
Analysis dimensions (in output schema order):
* RootCauseSummary:
Provide a concise (up to 4-5 sentences), self-contained technical summary of the root cause (or verified crash
mechanism if the exact trigger is inconclusive) and how it leads to the reported failure, suitable for displaying at the
top of a bug report or email above the full technical breakdown.
* RootCauseFiles:
Provide a short non-empty list (typically 1-3 files) of kernel source file paths (relative to the kernel tree root,
e.g., "net/ipv4/tcp_input.c") where the underlying defect resides.
Distinguish where the crash *manifests* from where the actual *bug* is:
- Do NOT list generic error-reporting, memory-allocator, refcount-tracking, or locking infrastructure files
(such as "mm/kasan/", "mm/slub.c", "lib/ref_tracker.c", "lib/dump_stack.c", "kernel/locking/lockdep.c",
or generic sk_buff helpers in "net/core/skbuff.c") unless the defect is genuinely in that core infrastructure itself.
- Instead, inspect the call trace, allocation/free stacks, and object lifecycle to identify the specific
subsystem, protocol, or driver file(s) containing the faulty logic.
* ImpactAnalysis:
Explain what happens at runtime in real-world setups (without debugging sanitizers or panic_on_warn) after the bug is
triggered, and why you chose each of the remaining output values (`MemoryCorruption`, `InfoLeak`,
`RawDenialOfService`, `IsNetCandidate`, `IsKVMCandidate`).
* MemoryCorruption:
Set to true if the bug can result in memory corruption, use-after-free, out-of-bounds write, invalid/double free,
control-flow hijack, or direct privilege escalation in real-world setups.
- Memory safety issues (KASAN or UBSAN reports for use-after-free, out-of-bounds write, invalid free; refcounting
imbalances, corrupted linked lists, etc.) are almost always true.
- When the kernel crashes on a wild pointer access (e.g., a user-space address or non-canonical address, including
both data accesses and control transfers, often reported as "unable to handle kernel paging request"), set to true.
- Pure NULL-pointer dereferences (including accesses to KASAN shadow memory for NULL around 0xdfff800000000000 or
0xdffffc0000000000) do NOT count as memory corruption on their own; set MemoryCorruption to false for those.
- Pure out-of-bounds reads or uninitialized memory reads (KMSAN) that only copy data to userspace without corrupting
memory or hijacking control flow should have MemoryCorruption = false (classify those under InfoLeak instead).
However, if an uninitialized value or out-of-bounds read is subsequently used as a pointer, array index, allocation
size, or branch condition that leads to memory corruption, set MemoryCorruption to true.
- For KCSAN data races, think whether concurrent access can corrupt pointers, refcounts, lengths, or state machines
in a way that leads to memory corruption; benign races (e.g., statistics counters or idempotent flags) are false.
* InfoLeak:
Determine whether the bug can leak kernel memory contents to userspace or an external observer. Must be one of:
- "none": The bug does not leak kernel memory contents.
- "pointers": The bug only leaks kernel, guest, or userspace pointer values (e.g., defeating KASLR by exposing an
uninitialized pointer field or printing/returning an unhashed kernel address, with no other data leaked).
- "arbitrary": The bug can leak non-pointer kernel memory contents (e.g., an out-of-bounds read or uninitialized
heap/stack buffer copied to userspace or to a network packet). If a leak is present and there is no obvious,
strict guarantee that only pointer values can be read, use "arbitrary".
* RawDenialOfService:
Set to true if the bug can result in denial-of-service in real-world setups (system crash/panic/BUG, NULL-pointer
dereference, hang, deadlock, infinite loop, CPU/network saturation, or memory/resource leak).
- Note that WARNING reports (WARN_ON / WARN_ON_ONCE) and sanitizer splats do NOT halt execution in real-world setups.
For WARNINGs, check what happens in the code after the macro: if the unexpected condition is gracefully handled
by normal error recovery (e.g., "if (WARN_ON(...)) return -EINVAL;") without leaking resources or leaving locks/state
inconsistent, set RawDenialOfService to false.
- Benign KCSAN data races that do not cause crashes, hangs, or resource leaks also have RawDenialOfService = false.
* IsNetCandidate:
Set to true if the bug, call trace, or reproducer has any relation to networking, sockets, network devices,
network protocols, or remote packet processing (so that a dedicated network-reachability pass should evaluate it).
* IsKVMCandidate:
Set to true if the bug, call trace, or reproducer has any relation to KVM, virtualization, hypervisors,
vhost/virtio, or guest/host interfaces (so that a dedicated virtualization-reachability pass should evaluate it).
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
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.
During execution, you may receive periodic guidance in <supervisor_advice> tags;
use it to refine your investigation or wrap up once you have sufficient evidence.
Prompt:
The kernel bug report is:
==================================================================
BUG: KCSAN: data-race in generic_permission / kernfs_iop_permission
write to 0xffff888107516f88 of 2 bytes by task 3731 on cpu 1:
kernfs_refresh_inode fs/kernfs/inode.c:169 [inline]
kernfs_iop_permission+0x9d/0x220 fs/kernfs/inode.c:287
do_inode_permission fs/namei.c:583 [inline]
inode_permission+0x2b4/0x3c0 fs/namei.c:653
lookup_inode_permission_may_exec fs/namei.c:-1 [inline]
may_lookup fs/namei.c:1967 [inline]
link_path_walk+0x881/0xde0 fs/namei.c:2610
path_openat+0x142/0x11e0 fs/namei.c:5012
do_file_open+0x16c/0x290 fs/namei.c:5045
do_sys_openat2+0xa1/0x140 fs/open.c:1443
do_sys_open fs/open.c:1449 [inline]
__do_sys_openat fs/open.c:1465 [inline]
__se_sys_openat fs/open.c:1460 [inline]
__x64_sys_openat+0xf2/0x120 fs/open.c:1460
x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
read to 0xffff888107516f88 of 2 bytes by task 3010 on cpu 0:
acl_permission_check fs/namei.c:441 [inline]
generic_permission+0x2a/0x470 fs/namei.c:529
kernfs_iop_permission+0x1fd/0x220 fs/kernfs/inode.c:288
do_inode_permission fs/namei.c:583 [inline]
inode_permission+0x2b4/0x3c0 fs/namei.c:653
lookup_inode_permission_may_exec fs/namei.c:-1 [inline]
may_lookup fs/namei.c:1967 [inline]
link_path_walk+0x881/0xde0 fs/namei.c:2610
path_lookupat+0x53/0x4c0 fs/namei.c:2818
filename_lookup+0x18f/0x390 fs/namei.c:2848
do_readlinkat+0x74/0x2f0 fs/stat.c:575
__do_sys_readlink fs/stat.c:609 [inline]
__se_sys_readlink fs/stat.c:606 [inline]
__x64_sys_readlink+0x47/0x60 fs/stat.c:606
x64_sys_call+0x1d41/0x2550 arch/x86/include/generated/asm/syscalls_64.h:90
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3010 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
Reply: ### Root Cause Analysis
The KCSAN data race occurs because `kernfs_iop_permission()` in `fs/kernfs/inode.c` mutates fields of the shared VFS `struct inode` while holding only a shared reader lock (`down_read(&root->kernfs_iattr_rwsem)`), allowing concurrent VFS lookups on the same kernfs node to read and write `inode->i_mode` without synchronization.
#### Technical Mechanism
1. **Shared locking in `kernfs_iop_permission()` (`fs/kernfs/inode.c:273-292`)**:
- When VFS path traversal (`link_path_walk()` -> `may_lookup()` -> `inode_permission()` -> `do_inode_permission()`) checks permissions on a kernfs inode (in non-RCU mode, i.e., without `MAY_NOT_BLOCK`), it invokes `inode->i_op->permission`, which points to `kernfs_iop_permission()` (registered in `kernfs_iops`, `kernfs_dir_iops`, and `kernfs_symlink_iops`).
- `kernfs_iop_permission()` acquires `root->kernfs_iattr_rwsem` for reading:
```c
down_read(&root->kernfs_iattr_rwsem);
kernfs_refresh_inode(kn, inode);
ret = generic_permission(&nop_mnt_idmap, inode, mask);
up_read(&root->kernfs_iattr_rwsem);
```
- `kernfs_iop_getattr()` (`fs/kernfs/inode.c:182-196`) follows the same pattern, calling `kernfs_refresh_inode()` and `generic_fillattr()` under `down_read(&root->kernfs_iattr_rwsem)`.
2. **Unprotected writes in `kernfs_refresh_inode()` (`fs/kernfs/inode.c:165-180`)**:
- Because `root->kernfs_iattr_rwsem` is only acquired for reading, multiple tasks can enter `kernfs_iop_permission()` (and `kernfs_iop_getattr()`) simultaneously for the same `struct kernfs_node` (`kn`) and `struct inode` (`inode`).
- `kernfs_refresh_inode()` unconditionally performs plain (non-atomic) writes to `inode` fields:
- `inode->i_mode = kn->mode;` (`fs/kernfs/inode.c:169`), a 2-byte `umode_t` write at offset 0 of `struct inode`.
- `set_inode_attr(inode, attrs);` (`fs/kernfs/inode.c:176`), which writes `inode->i_uid`, `inode->i_gid`, and timestamps.
- `set_nlink(inode, kn->dir.subdirs + 2);` (`fs/kernfs/inode.c:179`), which writes `inode->__i_nlink` for active directories.
3. **Concurrent read in `generic_permission()` / `acl_permission_check()` (`fs/namei.c:438-531`)**:
- After `kernfs_refresh_inode()`, `kernfs_iop_permission()` calls `generic_permission(&nop_mnt_idmap, inode, mask)` (`fs/kernfs/inode.c:288`), which calls `acl_permission_check()` (`fs/namei.c:529`).
- `acl_permission_check()` performs a plain 2-byte read of `inode->i_mode` (`unsigned int mode = inode->i_mode;` at `fs/namei.c:441`) and may also read `inode->i_uid` and `inode->i_gid`.
- In the reported trace, Task 3731 (`openat` -> `kernfs_iop_permission()` -> `kernfs_refresh_inode()` at `fs/kernfs/inode.c:169`) writes 2 bytes to `inode->i_mode` (`0xffff888107516f88`) concurrently with Task 3010 (`readlink` -> `kernfs_iop_permission()` -> `generic_permission()` -> `acl_permission_check()` at `fs/namei.c:441`) reading those 2 bytes.
#### Lifecycle and Invariants
- Modifications to `kn->mode` (via `__kernfs_setattr()` in `kernfs_setattr()` / `kernfs_iop_setattr()`) and `kn->iattr` attributes are serialized under `down_write(&root->kernfs_iattr_rwsem)`.
- `kernfs_iattr_rwsem` protects the `kernfs_node` attributes against concurrent `setattr`, but it does **not** serialize the copy/refresh of those attributes from `kn` into the VFS `struct inode`, nor does `kernfs_iop_permission()` hold `inode->i_lock` or `inode->i_rwsem` exclusively. Consequently, any two concurrent readers executing `kernfs_iop_permission()` or `kernfs_iop_getattr()` on the same kernfs inode violate the C memory model invariant against unsynchronized concurrent read/write (and write/write) accesses to `inode->i_mode` (as well as `i_uid`, `i_gid`, and `__i_nlink`).
|
| 6/2 |
2026/11/19 20:48 |
llm |
root-cause |
0m
Model:
Tokens:
input: 7349
output: 193
thoughts: 147
Thoughts: **Unpacking KCSAN's Data-Race Report: A Deep Dive into Inode Permissions**
Alright, my immediate task is to dissect this KCSAN data-race report. I need to understand *precisely* where the race condition is occurring. My focus, therefore, is on tracing the execution paths through the relevant kernel functions.
The report has pointed me towards two primary areas of interest:
First, I'm looking at `fs/kernfs/inode.c`. Specifically, the functions `kernfs_refresh_inode` and `kernfs_iop_permission` are flagged. I need to examine the code around line 169 for `kernfs_refresh_inode` and lines 287-288 for `kernfs_iop_permission`. These are likely points where an inode's state might be accessed or modified concurrently.
Second, the report directs me to `fs/namei.c`. Here, the functions `acl_permission_check` (around line 441), `generic_permission` (around line 529), `do_inode_permission` (around line 583), and `inode_permission` (around line 653) are implicated. This chain of functions clearly deals with the core permission checking logic, which is a prime candidate for concurrency issues if not handled meticulously.
To get a comprehensive view and to facilitate comparison, my strategy is to fetch the source code for all these functions simultaneously. This parallel fetching will allow me to quickly jump between them, correlate their operations, and identify the exact points of contention that KCSAN is signaling. My goal is to map out the data flow and identify shared mutable state that's being accessed without proper synchronization.
|
| 7/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/kernfs/inode.c Name:kernfs_refresh_inode]
Results: map[SourceCode: 165: static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
166: {
167: struct kernfs_iattrs *attrs;
168:
169: inode->i_mode = kn->mode;
170: attrs = kernfs_iattrs_noalloc(kn);
171: if (attrs)
172: /*
173: * kernfs_node has non-default attributes get them from
174: * persistent copy in kernfs_node.
175: */
176: set_inode_attr(inode, attrs);
177:
178: if (kernfs_type(kn) == KERNFS_DIR && !(kn->flags & KERNFS_REMOVING))
179: set_nlink(inode, kn->dir.subdirs + 2);
180: }
SourceFile:fs/kernfs/inode.c]
|
| 8/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/kernfs/inode.c Name:kernfs_iop_permission]
Results: map[SourceCode: 273: int kernfs_iop_permission(const struct mnt_idmap *idmap,
274: struct inode *inode, int mask)
275: {
276: struct kernfs_node *kn;
277: struct kernfs_root *root;
278: int ret;
279:
280: if (mask & MAY_NOT_BLOCK)
281: return -ECHILD;
282:
283: kn = inode->i_private;
284: root = kernfs_root(kn);
285:
286: down_read(&root->kernfs_iattr_rwsem);
287: kernfs_refresh_inode(kn, inode);
288: ret = generic_permission(&nop_mnt_idmap, inode, mask);
289: up_read(&root->kernfs_iattr_rwsem);
290:
291: return ret;
292: }
SourceFile:fs/kernfs/inode.c]
|
| 9/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:acl_permission_check]
Results: map[SourceCode: 422: /**
423: * acl_permission_check - perform basic UNIX permission checking
424: * @idmap: idmap of the mount the inode was found from
425: * @inode: inode to check permissions on
426: * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC ...)
427: *
428: * This function performs the basic UNIX permission checking. Since this
429: * function may retrieve POSIX acls it needs to know whether it is called from a
430: * blocking or non-blocking context and thus cares about the MAY_NOT_BLOCK bit.
431: *
432: * If the inode has been found through an idmapped mount the idmap of
433: * the vfsmount must be passed through @idmap. This function will then take
434: * care to map the inode according to @idmap before checking permissions.
435: * On non-idmapped mounts or if permission checking is to be performed on the
436: * raw inode simply pass @nop_mnt_idmap.
437: */
438: static int acl_permission_check(const struct mnt_idmap *idmap,
439: struct inode *inode, int mask)
440: {
441: unsigned int mode = inode->i_mode;
442: vfsuid_t vfsuid;
443:
444: /*
445: * Common cheap case: everybody has the requested
446: * rights, and there are no ACLs to check. No need
447: * to do any owner/group checks in that case.
448: *
449: * - 'mask&7' is the requested permission bit set
450: * - multiplying by 0111 spreads them out to all of ugo
451: * - '& ~mode' looks for missing inode permission bits
452: * - the '!' is for "no missing permissions"
453: *
454: * After that, we just need to check that there are no
455: * ACL's on the inode - do the 'IS_POSIXACL()' check last
456: * because it will dereference the ->i_sb pointer and we
457: * want to avoid that if at all possible.
458: */
459: if (!((mask & 7) * 0111 & ~mode)) {
460: if (no_acl_inode(inode))
461: return 0;
462: if (!IS_POSIXACL(inode))
463: return 0;
464: }
465:
466: /* Are we the owner? If so, ACL's don't matter */
467: vfsuid = i_uid_into_vfsuid(idmap, inode);
468: if (likely(vfsuid_eq_kuid(vfsuid, current_fsuid()))) {
469: mask &= 7;
470: mode >>= 6;
471: return (mask & ~mode) ? -EACCES : 0;
472: }
473:
474: /* Do we have ACL's? */
475: if (IS_POSIXACL(inode) && (mode & S_IRWXG)) {
476: int error = check_acl(idmap, inode, mask);
477: if (error != -EAGAIN)
478: return error;
479: }
480:
481: /* Only RWX matters for group/other mode bits */
482: mask &= 7;
483:
484: /*
485: * Are the group permissions different from
486: * the other permissions in the bits we care
487: * about? Need to check group ownership if so.
488: */
489: if (mask & (mode ^ (mode >> 3))) {
490: vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
491: if (vfsgid_in_group_p(vfsgid))
492: mode >>= 3;
493: }
494:
495: /* Bits in 'mode' clear that we require? */
496: return (mask & ~mode) ? -EACCES : 0;
497: }
SourceFile:fs/namei.c]
|
| 10/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:generic_permission]
Results: map[SourceCode: 499: /**
500: * generic_permission - check for access rights on a Posix-like filesystem
501: * @idmap: idmap of the mount the inode was found from
502: * @inode: inode to check access rights for
503: * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC,
504: * %MAY_NOT_BLOCK ...)
505: *
506: * Used to check for read/write/execute permissions on a file.
507: * We use "fsuid" for this, letting us set arbitrary permissions
508: * for filesystem access without changing the "normal" uids which
509: * are used for other things.
510: *
511: * generic_permission is rcu-walk aware. It returns -ECHILD in case an rcu-walk
512: * request cannot be satisfied (eg. requires blocking or too much complexity).
513: * It would then be called again in ref-walk mode.
514: *
515: * If the inode has been found through an idmapped mount the idmap of
516: * the vfsmount must be passed through @idmap. This function will then take
517: * care to map the inode according to @idmap before checking permissions.
518: * On non-idmapped mounts or if permission checking is to be performed on the
519: * raw inode simply pass @nop_mnt_idmap.
520: */
521: int generic_permission(const struct mnt_idmap *idmap, struct inode *inode,
522: int mask)
523: {
524: int ret;
525:
526: /*
527: * Do the basic permission checks.
528: */
529: ret = acl_permission_check(idmap, inode, mask);
530: if (ret != -EACCES)
531: return ret;
532:
533: if (S_ISDIR(inode->i_mode)) {
534: /* DACs are overridable for directories */
535: if (!(mask & MAY_WRITE))
536: if (capable_wrt_inode_uidgid(idmap, inode,
537: CAP_DAC_READ_SEARCH))
538: return 0;
539: if (capable_wrt_inode_uidgid(idmap, inode,
540: CAP_DAC_OVERRIDE))
541: return 0;
542: return -EACCES;
543: }
544:
545: /*
546: * Searching includes executable on directories, else just read.
547: */
548: mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
549: if (mask == MAY_READ)
550: if (capable_wrt_inode_uidgid(idmap, inode,
551: CAP_DAC_READ_SEARCH))
552: return 0;
553: /*
554: * Read/write DACs are always overridable.
555: * Executable DACs are overridable when there is
556: * at least one exec bit set.
557: */
558: if (!(mask & MAY_EXEC) || (inode->i_mode & S_IXUGO))
559: if (capable_wrt_inode_uidgid(idmap, inode,
560: CAP_DAC_OVERRIDE))
561: return 0;
562:
563: return -EACCES;
564: }
SourceFile:fs/namei.c]
|
| 11/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:do_inode_permission]
Results: map[SourceCode: 567: /**
568: * do_inode_permission - UNIX permission checking
569: * @idmap: idmap of the mount the inode was found from
570: * @inode: inode to check permissions on
571: * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC ...)
572: *
573: * We _really_ want to just do "generic_permission()" without
574: * even looking at the inode->i_op values. So we keep a cache
575: * flag in inode->i_opflags, that says "this has not special
576: * permission function, use the fast case".
577: */
578: static inline int do_inode_permission(const struct mnt_idmap *idmap,
579: struct inode *inode, int mask)
580: {
581: if (unlikely(!(inode->i_opflags & IOP_FASTPERM))) {
582: if (likely(inode->i_op->permission))
583: return inode->i_op->permission(idmap, inode, mask);
584:
585: /* This gets set once for the inode lifetime */
586: spin_lock(&inode->i_lock);
587: inode->i_opflags |= IOP_FASTPERM;
588: spin_unlock(&inode->i_lock);
589: }
590: return generic_permission(idmap, inode, mask);
591: }
SourceFile:fs/namei.c]
|
| 12/2 |
2026/11/19 20:48 |
llm |
root-cause |
0m
Model:
Tokens:
input: 11100
output: 214
thoughts: 485
Thoughts: **Analyzing a Potential Race Condition in `kernfs` Inode Permissions**
I've been poring over the `kernfs` implementation, specifically focusing on how inode permissions are handled. My attention was drawn to the `kernfs_iop_permission` function in `fs/kernfs/inode.c`.
What immediately struck me as unusual, and frankly, concerning, is the sequence of operations within this function. It begins by acquiring a read lock on `root->kernfs_iattr_rwsem` using `down_read()`. This, on its own, seems standard – read locks are designed to allow concurrent access. However, the *very next step* is a call to `kernfs_refresh_inode(kn, inode)`.
And here's the crux of my concern: `kernfs_refresh_inode` *writes* to the `inode` structure. It modifies `inode->i_mode` and, via `set_inode_attr`, potentially other inode attributes like owner, group, and permissions. It also calls `set_nlink` to update the link count for directories.
This creates a clear potential for a race condition. I'm holding a read lock (`down_read`), which implies that other threads are *allowed* to read the attributes associated with `root->kernfs_iattr_rwsem`. Yet, within this read-locked section, I'm *modifying* the very inode structure that might be concurrently accessed or relied upon by other processes operating under the assumption that the attributes are stable during a read operation.
If another thread were to attempt to access or modify the inode's attributes while `kernfs_refresh_inode` is executing, it could lead to inconsistent state, data corruption, or even kernel panics. The `kernfs_iattr_rwsem` is clearly intended to serialize modifications to the inode's attributes, but it appears to be misused here by allowing writes to the `inode` structure itself within a read-locked section.
My immediate next steps are to thoroughly examine `set_inode_attr`, `set_nlink`, and the entire `fs/kernfs/inode.c` file to understand the full impact of these writes. Crucially, I need to trace all callers of `kernfs_refresh_inode` and all users of `root->kernfs_iattr_rwsem` to ascertain the extent of this potential issue and identify any scenarios where this race could manifest. I suspect there might be an underlying assumption that `kernfs_refresh_inode` only reads, but the implementation clearly shows it modifies the `inode` struct.
|
| 13/2 |
2026/11/19 20:48 |
tool |
read-file |
0m
Args: map[File:fs/kernfs/inode.c FirstLine:1 LineCount:100]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0-only
2: /*
3: * fs/kernfs/inode.c - kernfs inode implementation
4: *
5: * Copyright (c) 2001-3 Patrick Mochel
6: * Copyright (c) 2007 SUSE Linux Products GmbH
7: * Copyright (c) 2007, 2013 Tejun Heo <tj@kernel.org>
8: */
9:
10: #include <linux/pagemap.h>
11: #include <linux/backing-dev.h>
12: #include <linux/capability.h>
13: #include <linux/errno.h>
14: #include <linux/slab.h>
15: #include <linux/xattr.h>
16: #include <linux/security.h>
17:
18: #include "kernfs-internal.h"
19:
20: static const struct inode_operations kernfs_iops = {
21: .permission = kernfs_iop_permission,
22: .setattr = kernfs_iop_setattr,
23: .getattr = kernfs_iop_getattr,
24: .listxattr = kernfs_iop_listxattr,
25: };
26:
27: static struct kernfs_iattrs *__kernfs_iattrs(struct kernfs_node *kn, bool alloc)
28: {
29: struct kernfs_iattrs *ret __free(kfree) = NULL;
30: struct kernfs_iattrs *attr;
31:
32: attr = READ_ONCE(kn->iattr);
33: if (attr || !alloc)
34: return attr;
35:
36: ret = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL);
37: if (!ret)
38: return NULL;
39:
40: INIT_LIST_HEAD_RCU(&ret->xattrs);
41: /* assign default attributes */
42: ret->ia_uid = GLOBAL_ROOT_UID;
43: ret->ia_gid = GLOBAL_ROOT_GID;
44:
45: ktime_get_real_ts64(&ret->ia_atime);
46: ret->ia_mtime = ret->ia_atime;
47: ret->ia_ctime = ret->ia_atime;
48:
49: simple_xattr_limits_init(&ret->xattr_limits);
50:
51: /* If someone raced us, recognize it. */
52: if (!try_cmpxchg(&kn->iattr, &attr, ret))
53: return READ_ONCE(kn->iattr);
54:
55: return no_free_ptr(ret);
56: }
57:
58: static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
59: {
60: return __kernfs_iattrs(kn, true);
61: }
62:
63: static struct kernfs_iattrs *kernfs_iattrs_noalloc(struct kernfs_node *kn)
64: {
65: return __kernfs_iattrs(kn, false);
66: }
67:
68: int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
69: {
70: struct kernfs_iattrs *attrs;
71: unsigned int ia_valid = iattr->ia_valid;
72:
73: attrs = kernfs_iattrs(kn);
74: if (!attrs)
75: return -ENOMEM;
76:
77: if (ia_valid & ATTR_UID)
78: attrs->ia_uid = iattr->ia_uid;
79: if (ia_valid & ATTR_GID)
80: attrs->ia_gid = iattr->ia_gid;
81: if (ia_valid & ATTR_ATIME)
82: attrs->ia_atime = iattr->ia_atime;
83: if (ia_valid & ATTR_MTIME)
84: attrs->ia_mtime = iattr->ia_mtime;
85: if (ia_valid & ATTR_CTIME)
86: attrs->ia_ctime = iattr->ia_ctime;
87: if (ia_valid & ATTR_MODE)
88: kn->mode = iattr->ia_mode;
89: return 0;
90: }
91:
92: /**
93: * kernfs_setattr - set iattr on a node
94: * @kn: target node
95: * @iattr: iattr to set
96: *
97: * Return: %0 on success, -errno on failure.
98: */
99: int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
100: {
]
|
| 14/2 |
2026/11/19 20:48 |
tool |
read-file |
0m
Args: map[File:fs/kernfs/inode.c FirstLine:101 LineCount:100]
Results: map[Contents: 101: int ret;
102: struct kernfs_root *root = kernfs_root(kn);
103:
104: down_write(&root->kernfs_iattr_rwsem);
105: ret = __kernfs_setattr(kn, iattr);
106: up_write(&root->kernfs_iattr_rwsem);
107: return ret;
108: }
109:
110: int kernfs_iop_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
111: struct iattr *iattr)
112: {
113: struct inode *inode = d_inode(dentry);
114: struct kernfs_node *kn = inode->i_private;
115: struct kernfs_root *root;
116: int error;
117:
118: if (!kn)
119: return -EINVAL;
120:
121: root = kernfs_root(kn);
122: down_write(&root->kernfs_iattr_rwsem);
123: error = setattr_prepare(&nop_mnt_idmap, dentry, iattr);
124: if (error)
125: goto out;
126:
127: error = __kernfs_setattr(kn, iattr);
128: if (error)
129: goto out;
130:
131: /* this ignores size changes */
132: setattr_copy(&nop_mnt_idmap, inode, iattr);
133:
134: out:
135: up_write(&root->kernfs_iattr_rwsem);
136: return error;
137: }
138:
139: ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
140: {
141: struct kernfs_node *kn = kernfs_dentry_node(dentry);
142: struct kernfs_iattrs *attrs;
143:
144: attrs = kernfs_iattrs_noalloc(kn);
145:
146: return simple_xattr_list(d_inode(dentry), attrs ? &attrs->xattrs : NULL, buf, size);
147: }
148:
149: static inline void set_default_inode_attr(struct inode *inode, umode_t mode)
150: {
151: inode->i_mode = mode;
152: simple_inode_init_ts(inode);
153: }
154:
155: static inline void set_inode_attr(struct inode *inode,
156: struct kernfs_iattrs *attrs)
157: {
158: inode->i_uid = attrs->ia_uid;
159: inode->i_gid = attrs->ia_gid;
160: inode_set_atime_to_ts(inode, attrs->ia_atime);
161: inode_set_mtime_to_ts(inode, attrs->ia_mtime);
162: inode_set_ctime_to_ts(inode, attrs->ia_ctime);
163: }
164:
165: static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
166: {
167: struct kernfs_iattrs *attrs;
168:
169: inode->i_mode = kn->mode;
170: attrs = kernfs_iattrs_noalloc(kn);
171: if (attrs)
172: /*
173: * kernfs_node has non-default attributes get them from
174: * persistent copy in kernfs_node.
175: */
176: set_inode_attr(inode, attrs);
177:
178: if (kernfs_type(kn) == KERNFS_DIR && !(kn->flags & KERNFS_REMOVING))
179: set_nlink(inode, kn->dir.subdirs + 2);
180: }
181:
182: int kernfs_iop_getattr(const struct mnt_idmap *idmap,
183: const struct path *path, struct kstat *stat,
184: u32 request_mask, unsigned int query_flags)
185: {
186: struct inode *inode = d_inode(path->dentry);
187: struct kernfs_node *kn = inode->i_private;
188: struct kernfs_root *root = kernfs_root(kn);
189:
190: down_read(&root->kernfs_iattr_rwsem);
191: kernfs_refresh_inode(kn, inode);
192: generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
193: up_read(&root->kernfs_iattr_rwsem);
194:
195: return 0;
196: }
197:
198: static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
199: {
200: kernfs_get(kn);
]
|
| 15/2 |
2026/11/19 20:48 |
tool |
read-file |
0m
Args: map[File:fs/kernfs/inode.c FirstLine:201 LineCount:120]
Results: map[Contents: 201: inode->i_private = kn;
202: inode->i_mapping->a_ops = &ram_aops;
203: inode->i_op = &kernfs_iops;
204: inode->i_generation = kernfs_gen(kn);
205:
206: set_default_inode_attr(inode, kn->mode);
207: kernfs_refresh_inode(kn, inode);
208:
209: /* initialize inode according to type */
210: switch (kernfs_type(kn)) {
211: case KERNFS_DIR:
212: inode->i_op = &kernfs_dir_iops;
213: inode->i_fop = &kernfs_dir_fops;
214: if (kn->flags & KERNFS_EMPTY_DIR)
215: make_empty_dir_inode(inode);
216: break;
217: case KERNFS_FILE:
218: inode->i_size = kn->attr.size;
219: inode->i_fop = &kernfs_file_fops;
220: break;
221: case KERNFS_LINK:
222: inode->i_op = &kernfs_symlink_iops;
223: break;
224: default:
225: BUG();
226: }
227:
228: unlock_new_inode(inode);
229: }
230:
231: /**
232: * kernfs_get_inode - get inode for kernfs_node
233: * @sb: super block
234: * @kn: kernfs_node to allocate inode for
235: *
236: * Get inode for @kn. If such inode doesn't exist, a new inode is
237: * allocated and basics are initialized. New inode is returned
238: * locked.
239: *
240: * Locking:
241: * Kernel thread context (may sleep).
242: *
243: * Return:
244: * Pointer to allocated inode on success, %NULL on failure.
245: */
246: struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
247: {
248: struct inode *inode;
249:
250: inode = iget_locked(sb, kernfs_ino(kn));
251: if (inode && (inode_state_read_once(inode) & I_NEW))
252: kernfs_init_inode(kn, inode);
253:
254: return inode;
255: }
256:
257: /*
258: * The kernfs_node serves as both an inode and a directory entry for
259: * kernfs. To prevent the kernfs inode numbers from being freed
260: * prematurely we take a reference to kernfs_node from the kernfs inode. A
261: * super_operations.evict_inode() implementation is needed to drop that
262: * reference upon inode destruction.
263: */
264: void kernfs_evict_inode(struct inode *inode)
265: {
266: struct kernfs_node *kn = inode->i_private;
267:
268: truncate_inode_pages_final(&inode->i_data);
269: clear_inode(inode);
270: kernfs_put(kn);
271: }
272:
273: int kernfs_iop_permission(const struct mnt_idmap *idmap,
274: struct inode *inode, int mask)
275: {
276: struct kernfs_node *kn;
277: struct kernfs_root *root;
278: int ret;
279:
280: if (mask & MAY_NOT_BLOCK)
281: return -ECHILD;
282:
283: kn = inode->i_private;
284: root = kernfs_root(kn);
285:
286: down_read(&root->kernfs_iattr_rwsem);
287: kernfs_refresh_inode(kn, inode);
288: ret = generic_permission(&nop_mnt_idmap, inode, mask);
289: up_read(&root->kernfs_iattr_rwsem);
290:
291: return ret;
292: }
293:
294: int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
295: void *value, size_t size)
296: {
297: struct kernfs_iattrs *attrs = kernfs_iattrs_noalloc(kn);
298: struct simple_xattr_cache *cache = &kernfs_root(kn)->xa_cache;
299:
300: if (!attrs)
]
|
| 16/2 |
2026/11/19 20:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:kernfs_refresh_inode SourceTreePrefix:fs/kernfs/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:kernfs_init_inode SourceFile:fs/kernfs/inode.c SourceLine:207 SourceSnippet: 202: inode->i_mapping->a_ops = &ram_aops;
203: inode->i_op = &kernfs_iops;
204: inode->i_generation = kernfs_gen(kn);
205:
206: set_default_inode_attr(inode, kn->mode);
207: kernfs_refresh_inode(kn, inode);
208:
209: /* initialize inode according to type */
210: switch (kernfs_type(kn)) {
211: case KERNFS_DIR:
212: inode->i_op = &kernfs_dir_iops;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_getattr SourceFile:fs/kernfs/inode.c SourceLine:191 SourceSnippet: 186: struct inode *inode = d_inode(path->dentry);
187: struct kernfs_node *kn = inode->i_private;
188: struct kernfs_root *root = kernfs_root(kn);
189:
190: down_read(&root->kernfs_iattr_rwsem);
191: kernfs_refresh_inode(kn, inode);
192: generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
193: up_read(&root->kernfs_iattr_rwsem);
194:
195: return 0;
196: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_permission SourceFile:fs/kernfs/inode.c SourceLine:287 SourceSnippet: 282:
283: kn = inode->i_private;
284: root = kernfs_root(kn);
285:
286: down_read(&root->kernfs_iattr_rwsem);
287: kernfs_refresh_inode(kn, inode);
288: ret = generic_permission(&nop_mnt_idmap, inode, mask);
289: up_read(&root->kernfs_iattr_rwsem);
290:
291: return ret;
292: }
]] TruncatedOutput:false]
|
| 17/2 |
2026/11/19 20:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:kernfs_root::kernfs_iattr_rwsem SourceTreePrefix:fs/kernfs/]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:__kernfs_remove SourceFile:fs/kernfs/dir.c SourceLine:1557 SourceSnippet:1552: return;
1553:
1554: pr_debug("kernfs %s: removing\n", kernfs_rcu_name(kn));
1555:
1556: /* prevent new usage by marking all nodes removing and deactivating */
1557: down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
1558: pos = NULL;
1559: while ((pos = kernfs_next_descendant_post(pos, kn))) {
1560: pos->flags |= KERNFS_REMOVING;
1561: if (kernfs_active(pos))
1562: atomic_add(KN_DEACTIVATED_BIAS, &pos->active);
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:__kernfs_remove SourceFile:fs/kernfs/dir.c SourceLine:1564 SourceSnippet:1559: while ((pos = kernfs_next_descendant_post(pos, kn))) {
1560: pos->flags |= KERNFS_REMOVING;
1561: if (kernfs_active(pos))
1562: atomic_add(KN_DEACTIVATED_BIAS, &pos->active);
1563: }
1564: up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
1565:
1566: /* deactivate and unlink the subtree node-by-node */
1567: do {
1568: pos = kernfs_leftmost_descendant(kn);
1569:
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:__kernfs_remove SourceFile:fs/kernfs/dir.c SourceLine:1588 SourceSnippet:1583: */
1584: if (!parent || kernfs_unlink_sibling(pos)) {
1585: struct kernfs_iattrs *ps_iattr =
1586: parent ? parent->iattr : NULL;
1587:
1588: down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
1589:
1590: kernfs_clear_inode_nlink(pos);
1591:
1592: /* update timestamps on the parent */
1593: if (ps_iattr) {
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:__kernfs_remove SourceFile:fs/kernfs/dir.c SourceLine:1598 SourceSnippet:1593: if (ps_iattr) {
1594: ktime_get_real_ts64(&ps_iattr->ia_ctime);
1595: ps_iattr->ia_mtime = ps_iattr->ia_ctime;
1596: }
1597:
1598: up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
1599: kernfs_put(pos);
1600: }
1601:
1602: kernfs_put(pos);
1603: } while (pos != kn);
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_add_one SourceFile:fs/kernfs/dir.c SourceLine:857 SourceSnippet: 852: ret = kernfs_link_sibling(kn);
853: if (ret)
854: goto out_unlock;
855:
856: /* Update timestamps on the parent */
857: down_write(&root->kernfs_iattr_rwsem);
858:
859: ps_iattr = parent->iattr;
860: if (ps_iattr) {
861: ktime_get_real_ts64(&ps_iattr->ia_ctime);
862: ps_iattr->ia_mtime = ps_iattr->ia_ctime;
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_add_one SourceFile:fs/kernfs/dir.c SourceLine:865 SourceSnippet: 860: if (ps_iattr) {
861: ktime_get_real_ts64(&ps_iattr->ia_ctime);
862: ps_iattr->ia_mtime = ps_iattr->ia_ctime;
863: }
864:
865: up_write(&root->kernfs_iattr_rwsem);
866:
867: /*
868: * Activate the new node unless CREATE_DEACTIVATED is requested.
869: * If not activated here, the kernfs user is responsible for
870: * activating the node with kernfs_activate(). A node which hasn't
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_create_link SourceFile:fs/kernfs/symlink.c SourceLine:41 SourceSnippet: 36: * come from the same moment: read them under kernfs_iattr_rwsem, or
37: * a chown of the target racing this could leave the link with the
38: * old uid and the new gid. The section ends before kernfs_add_one()
39: * takes kernfs_rwsem.
40: */
41: scoped_guard(rwsem_read, &kernfs_root(target)->kernfs_iattr_rwsem) {
42: struct kernfs_iattrs *attrs = READ_ONCE(target->iattr);
43:
44: if (attrs) {
45: uid = attrs->ia_uid;
46: gid = attrs->ia_gid;
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_create_link SourceFile:fs/kernfs/symlink.c SourceLine:41 SourceSnippet: 36: * come from the same moment: read them under kernfs_iattr_rwsem, or
37: * a chown of the target racing this could leave the link with the
38: * old uid and the new gid. The section ends before kernfs_add_one()
39: * takes kernfs_rwsem.
40: */
41: scoped_guard(rwsem_read, &kernfs_root(target)->kernfs_iattr_rwsem) {
42: struct kernfs_iattrs *attrs = READ_ONCE(target->iattr);
43:
44: if (attrs) {
45: uid = attrs->ia_uid;
46: gid = attrs->ia_gid;
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_create_root SourceFile:fs/kernfs/dir.c SourceLine:1043 SourceSnippet:1038: return ERR_PTR(-ENOMEM);
1039:
1040: idr_init(&root->ino_idr);
1041: spin_lock_init(&root->kernfs_idr_lock);
1042: init_rwsem(&root->kernfs_rwsem);
1043: init_rwsem(&root->kernfs_iattr_rwsem);
1044: init_rwsem(&root->kernfs_supers_rwsem);
1045: INIT_LIST_HEAD(&root->supers);
1046: rwlock_init(&root->kernfs_rename_lock);
1047:
1048: /*
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_getattr SourceFile:fs/kernfs/inode.c SourceLine:190 SourceSnippet: 185: {
186: struct inode *inode = d_inode(path->dentry);
187: struct kernfs_node *kn = inode->i_private;
188: struct kernfs_root *root = kernfs_root(kn);
189:
190: down_read(&root->kernfs_iattr_rwsem);
191: kernfs_refresh_inode(kn, inode);
192: generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
193: up_read(&root->kernfs_iattr_rwsem);
194:
195: return 0;
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_getattr SourceFile:fs/kernfs/inode.c SourceLine:193 SourceSnippet: 188: struct kernfs_root *root = kernfs_root(kn);
189:
190: down_read(&root->kernfs_iattr_rwsem);
191: kernfs_refresh_inode(kn, inode);
192: generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
193: up_read(&root->kernfs_iattr_rwsem);
194:
195: return 0;
196: }
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_permission SourceFile:fs/kernfs/inode.c SourceLine:286 SourceSnippet: 281: return -ECHILD;
282:
283: kn = inode->i_private;
284: root = kernfs_root(kn);
285:
286: down_read(&root->kernfs_iattr_rwsem);
287: kernfs_refresh_inode(kn, inode);
288: ret = generic_permission(&nop_mnt_idmap, inode, mask);
289: up_read(&root->kernfs_iattr_rwsem);
290:
291: return ret;
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_permission SourceFile:fs/kernfs/inode.c SourceLine:289 SourceSnippet: 284: root = kernfs_root(kn);
285:
286: down_read(&root->kernfs_iattr_rwsem);
287: kernfs_refresh_inode(kn, inode);
288: ret = generic_permission(&nop_mnt_idmap, inode, mask);
289: up_read(&root->kernfs_iattr_rwsem);
290:
291: return ret;
292: }
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_setattr SourceFile:fs/kernfs/inode.c SourceLine:122 SourceSnippet: 117:
118: if (!kn)
119: return -EINVAL;
120:
121: root = kernfs_root(kn);
122: down_write(&root->kernfs_iattr_rwsem);
123: error = setattr_prepare(&nop_mnt_idmap, dentry, iattr);
124: if (error)
125: goto out;
126:
127: error = __kernfs_setattr(kn, iattr);
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_iop_setattr SourceFile:fs/kernfs/inode.c SourceLine:135 SourceSnippet: 130:
131: /* this ignores size changes */
132: setattr_copy(&nop_mnt_idmap, inode, iattr);
133:
134: out:
135: up_write(&root->kernfs_iattr_rwsem);
136: return error;
137: }
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_link_sibling SourceFile:fs/kernfs/dir.c SourceLine:413 SourceSnippet: 408: /* add new node and rebalance the tree */
409: rb_link_node(&kn->rb, parent, node);
410: rb_insert_color(&kn->rb, &kn_parent->dir.children);
411:
412: /* successfully added, account subdir number */
413: down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
414: if (kernfs_type(kn) == KERNFS_DIR)
415: kn_parent->dir.subdirs++;
416: kernfs_inc_rev(kn_parent);
417: up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
418:
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_link_sibling SourceFile:fs/kernfs/dir.c SourceLine:417 SourceSnippet: 412: /* successfully added, account subdir number */
413: down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
414: if (kernfs_type(kn) == KERNFS_DIR)
415: kn_parent->dir.subdirs++;
416: kernfs_inc_rev(kn_parent);
417: up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
418:
419: return 0;
420: }
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_setattr SourceFile:fs/kernfs/inode.c SourceLine:104 SourceSnippet: 99: int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
100: {
101: int ret;
102: struct kernfs_root *root = kernfs_root(kn);
103:
104: down_write(&root->kernfs_iattr_rwsem);
105: ret = __kernfs_setattr(kn, iattr);
106: up_write(&root->kernfs_iattr_rwsem);
107: return ret;
108: }
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_setattr SourceFile:fs/kernfs/inode.c SourceLine:106 SourceSnippet: 101: int ret;
102: struct kernfs_root *root = kernfs_root(kn);
103:
104: down_write(&root->kernfs_iattr_rwsem);
105: ret = __kernfs_setattr(kn, iattr);
106: up_write(&root->kernfs_iattr_rwsem);
107: return ret;
108: }
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_unlink_sibling SourceFile:fs/kernfs/dir.c SourceLine:443 SourceSnippet: 438:
439: if (RB_EMPTY_NODE(&kn->rb))
440: return false;
441:
442: kn_parent = kernfs_parent(kn);
443: down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
444: if (kernfs_type(kn) == KERNFS_DIR)
445: kn_parent->dir.subdirs--;
446: kernfs_inc_rev(kn_parent);
447: up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
448:
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_unlink_sibling SourceFile:fs/kernfs/dir.c SourceLine:447 SourceSnippet: 442: kn_parent = kernfs_parent(kn);
443: down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
444: if (kernfs_type(kn) == KERNFS_DIR)
445: kn_parent->dir.subdirs--;
446: kernfs_inc_rev(kn_parent);
447: up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
448:
449: rb_erase(&kn->rb, &kn_parent->dir.children);
450: RB_CLEAR_NODE(&kn->rb);
451: return true;
452: }
]] TruncatedOutput:false]
|
| 18/2 |
2026/11/19 20:48 |
llm |
root-cause |
0m
Model:
Tokens:
input: 21786
output: 209
thoughts: 110
Thoughts: **My Line of Reasoning on Kernfs IOP Performance**
Okay, this initial observation is incredibly promising, it's crystal clear! Given this, I need to be absolutely thorough in my investigation. My next steps are to dive deeper into `kernfs_dir_iops` and `kernfs_symlink_iops` to ensure I'm not missing any nuances in directory and symlink operations within kernfs.
Simultaneously, I want to meticulously examine the `struct inode` layout, specifically focusing on the size and implications of `i_mode` which, as I know, is represented by `umode_t` and is typically 2 bytes. Understanding its exact position and size within the inode structure will be crucial for identifying potential optimizations or interactions.
To achieve this, my plan is to employ a multi-pronged approach. I'll be grepping for `kernfs_iop_permission` across the relevant source files. Additionally, I intend to directly inspect the source code in `fs/kernfs/dir.c` and `fs/kernfs/symlink.c`, as these are the most likely places to find the implementation details for these specific IOPs. Finally, I'll cross-reference with `include/linux/fs.h` to gain a definitive understanding of the `struct inode` definition, ensuring my analysis is grounded in the kernel's actual data structures. This comprehensive approach will allow me to build a robust understanding of kernfs IOP performance.
|
| 19/2 |
2026/11/19 20:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:kernfs_iop_permission SourceTreePrefix:fs/kernfs/]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_dir_iops SourceFile:fs/kernfs/dir.c SourceLine:1361 SourceSnippet:1359: const struct inode_operations kernfs_dir_iops = {
1360: .lookup = kernfs_iop_lookup,
1361: .permission = kernfs_iop_permission,
1362: .setattr = kernfs_iop_setattr,
1363: .getattr = kernfs_iop_getattr,
1364: .listxattr = kernfs_iop_listxattr,
1365:
1366: .mkdir = kernfs_iop_mkdir,
] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_iops SourceFile:fs/kernfs/inode.c SourceLine:21 SourceSnippet: 20: static const struct inode_operations kernfs_iops = {
21: .permission = kernfs_iop_permission,
22: .setattr = kernfs_iop_setattr,
23: .getattr = kernfs_iop_getattr,
24: .listxattr = kernfs_iop_listxattr,
25: };
] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_symlink_iops SourceFile:fs/kernfs/symlink.c SourceLine:165 SourceSnippet: 160: const struct inode_operations kernfs_symlink_iops = {
161: .listxattr = kernfs_iop_listxattr,
162: .get_link = kernfs_iop_get_link,
163: .setattr = kernfs_iop_setattr,
164: .getattr = kernfs_iop_getattr,
165: .permission = kernfs_iop_permission,
166: };
]] TruncatedOutput:false]
|
| 20/2 |
2026/11/19 20:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:kernfs_iop_getattr SourceTreePrefix:fs/kernfs/]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_dir_iops SourceFile:fs/kernfs/dir.c SourceLine:1363 SourceSnippet:1359: const struct inode_operations kernfs_dir_iops = {
1360: .lookup = kernfs_iop_lookup,
1361: .permission = kernfs_iop_permission,
1362: .setattr = kernfs_iop_setattr,
1363: .getattr = kernfs_iop_getattr,
1364: .listxattr = kernfs_iop_listxattr,
1365:
1366: .mkdir = kernfs_iop_mkdir,
1367: .rmdir = kernfs_iop_rmdir,
1368: .rename = kernfs_iop_rename,
] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_iops SourceFile:fs/kernfs/inode.c SourceLine:23 SourceSnippet: 20: static const struct inode_operations kernfs_iops = {
21: .permission = kernfs_iop_permission,
22: .setattr = kernfs_iop_setattr,
23: .getattr = kernfs_iop_getattr,
24: .listxattr = kernfs_iop_listxattr,
25: };
] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_symlink_iops SourceFile:fs/kernfs/symlink.c SourceLine:164 SourceSnippet: 160: const struct inode_operations kernfs_symlink_iops = {
161: .listxattr = kernfs_iop_listxattr,
162: .get_link = kernfs_iop_get_link,
163: .setattr = kernfs_iop_setattr,
164: .getattr = kernfs_iop_getattr,
165: .permission = kernfs_iop_permission,
166: };
]] TruncatedOutput:false]
|
| 21/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/kernfs/inode.c Name:set_nlink]
Results: map[SourceCode: 432: /**
433: * set_nlink - directly set an inode's link count
434: * @inode: inode
435: * @nlink: new nlink (should be non-zero)
436: *
437: * This is a low-level filesystem helper to replace any
438: * direct filesystem manipulation of i_nlink.
439: */
440: void set_nlink(struct inode *inode, unsigned int nlink)
441: {
442: if (!nlink) {
443: clear_nlink(inode);
444: } else {
445: /* Yes, some filesystems do change nlink from zero to one */
446: if (inode->i_nlink == 0)
447: atomic_long_dec(&inode->i_sb->s_remove_count);
448:
449: inode->__i_nlink = nlink;
450: }
451: }
SourceFile:fs/inode.c]
|
| 22/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/kernfs/inode.c Name:inode_set_atime_to_ts]
Results: map[SourceCode:1620: static inline struct timespec64 inode_set_atime_to_ts(struct inode *inode,
1621: struct timespec64 ts)
1622: {
1623: WRITE_ONCE(inode->i_atime_sec, ts.tv_sec);
1624: WRITE_ONCE(inode->i_atime_nsec, ts.tv_nsec);
1625: return ts;
1626: }
SourceFile:include/linux/fs.h]
|
| 23/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:generic_fillattr]
Results: map[SourceCode: 65: /**
66: * generic_fillattr - Fill in the basic attributes from the inode struct
67: * @idmap: idmap of the mount the inode was found from
68: * @request_mask: statx request_mask
69: * @inode: Inode to use as the source
70: * @stat: Where to fill in the attributes
71: *
72: * Fill in the basic attributes in the kstat structure from data that's to be
73: * found on the VFS inode structure. This is the default if no getattr inode
74: * operation is supplied.
75: *
76: * If the inode has been found through an idmapped mount the idmap of
77: * the vfsmount must be passed through @idmap. This function will then
78: * take care to map the inode according to @idmap before filling in the
79: * uid and gid filds. On non-idmapped mounts or if permission checking is to be
80: * performed on the raw inode simply pass @nop_mnt_idmap.
81: */
82: void generic_fillattr(const struct mnt_idmap *idmap, u32 request_mask,
83: struct inode *inode, struct kstat *stat)
84: {
85: vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
86: vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
87:
88: stat->dev = inode->i_sb->s_dev;
89: stat->ino = inode->i_ino;
90: stat->mode = inode->i_mode;
91: stat->nlink = inode->i_nlink;
92: stat->uid = vfsuid_into_kuid(vfsuid);
93: stat->gid = vfsgid_into_kgid(vfsgid);
94: stat->rdev = inode->i_rdev;
95: stat->size = i_size_read(inode);
96: stat->atime = inode_get_atime(inode);
97:
98: if (is_mgtime(inode)) {
99: fill_mg_cmtime(stat, request_mask, inode);
100: } else {
101: stat->ctime = inode_get_ctime(inode);
102: stat->mtime = inode_get_mtime(inode);
103: }
104:
105: stat->blksize = i_blocksize(inode);
106: stat->blocks = inode->i_blocks;
107:
108: if ((request_mask & STATX_CHANGE_COOKIE) && IS_I_VERSION(inode)) {
109: stat->result_mask |= STATX_CHANGE_COOKIE;
110: stat->change_cookie = inode_query_iversion(inode);
111: }
112:
113: }
SourceFile:fs/stat.c]
|
| 24/2 |
2026/11/19 20:48 |
llm |
root-cause |
0m
Model:
Tokens:
input: 24640
output: 122
thoughts: 774
Thoughts: **My Thorough Examination of `kernfs` Concurrency Issues**
I've been meticulously going through the `kernfs` code, specifically in `fs/kernfs/inode.c`, and I've uncovered what I believe to be a significant concurrency vulnerability. My thought process has been a systematic dissection of the `kernfs_iop_permission()` function and its interactions.
My initial concern is how `kernfs_iop_permission()` is invoked. It's called without the necessary locks, either `inode->i_lock` or an exclusive hold on `inode->i_rwsem`. This is critical because the VFS layer, particularly during path traversal operations like `openat` and `readlink` within `link_path_walk`, `may_lookup`, `inode_permission`, and `do_inode_permission`, can and does call `inode_permission()` concurrently across multiple tasks.
Now, within `kernfs_iop_permission()`, I observe that it acquires a *shared* read lock: `down_read(&root->kernfs_iattr_rwsem)`. This immediately raises a red flag for me. While holding only this shared lock, the function proceeds to call `kernfs_refresh_inode(kn, inode)`. I've noted that `kernfs_iop_getattr()` exhibits the exact same pattern.
The core of the problem, as I see it, lies within `kernfs_refresh_inode()`. This function makes modifications to `struct inode` fields using plain, unprotected writes. I'm talking about non-atomic operations and, crucially, the absence of `WRITE_ONCE`. Specifically, I'm looking at:
* `inode->i_mode = kn->mode;` at line 169. This is a small, 2-byte write.
* The `set_inode_attr(inode, attrs)` call, which modifies `inode->i_uid`, `inode->i_gid`, `i_atime`, `i_mtime`, and `i_ctime`.
* The `set_nlink(inode, kn->dir.subdirs + 2);` call at line 179. This writes to `inode->__i_nlink`. I'm also making a mental note to double-check `kernfs_clear_inode_nlink` and its potential impact on `s_remove_count`, especially if `inode->i_nlink` could somehow reach zero (though for a directory, `kn->dir.subdirs + 2` should generally be greater than or equal to 2).
The timing here is what worries me immensely. Immediately after these writes in `kernfs_refresh_inode()`, `kernfs_iop_permission()` continues its execution by calling `generic_permission(&nop_mnt_idmap, inode, mask)`. It's still holding that *shared* read lock (`down_read(&root->kernfs_iattr_rwsem)`). This `generic_permission()` function, in turn, invokes `acl_permission_check()`. And it's within `acl_permission_check()` (or even earlier in `generic_permission()` itself, or even another concurrent call to `kernfs_refresh_inode()`) that fields like `inode->i_mode` (at `fs/namei.c:441`, where it's read as `unsigned int mode = inode->i_mode;`) and others (`inode->i_uid`, `inode->i_gid`, etc.) are read.
The problem is that the shared read lock (`down_read(&root->kernfs_iattr_rwsem)`) explicitly permits multiple tasks to be inside `kernfs_iop_permission()` (and/or `kernfs_iop_getattr()`) concurrently, operating on the same `inode`. So, I have a scenario where Task 1 is performing the write to `inode->i_mode` (a 2-byte operation) in `kernfs_refresh_inode()` at line 169, and concurrently, Task 2 is reading `inode->i_mode` (also a 2-byte read) via `acl_permission_check()` at line 441, or `generic_permission()`, or even another `kernfs_refresh_inode()`. There's no synchronization whatsoever, and critically, no use of `READ_ONCE` or `WRITE_ONCE` to ensure atomic visibility of these writes and reads. This lack of protection on simple, unprotected writes while allowing concurrent reads creates a race condition.
My initial check on `kernfs_clear_inode_nlink` and related fields like `inode->i_nlink` and `s_remove_count` was to ensure I wasn't missing any subtle, cascading effects. While my primary focus is on the `i_mode` race, I believe that understanding the state of `i_nlink` and `s_remove_count` is crucial for a complete picture of potential interactions.
|
| 25/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/kernfs/dir.c Name:kernfs_clear_inode_nlink]
Results: map[SourceCode:1505: /*
1506: * This function enables VFS to send fsnotify events for deletions.
1507: * There is gap in this implementation for certain file removals due their
1508: * unique nature in kernfs. Directory removals that trigger file removals occur
1509: * through vfs_rmdir, which shrinks the dcache and emits fsnotify events after
1510: * the rmdir operation; there is no issue here. However kernfs writes to
1511: * particular files (e.g. cgroup.subtree_control) can also cause file removal,
1512: * but vfs_write does not attempt to emit fsnotify events after the write
1513: * operation, even if i_nlink counts are 0. As a usecase for monitoring this
1514: * category of file removals is not known, they are left without having
1515: * IN_DELETE or IN_DELETE_SELF events generated.
1516: * Fanotify recursive monitoring also does not work for kernfs nodes that do not
1517: * have inodes attached, as they are created on-demand in kernfs.
1518: */
1519: static void kernfs_clear_inode_nlink(struct kernfs_node *kn)
1520: {
1521: struct kernfs_root *root = kernfs_root(kn);
1522: struct kernfs_super_info *info;
1523:
1524: lockdep_assert_held_read(&root->kernfs_supers_rwsem);
1525:
1526: list_for_each_entry(info, &root->supers, node) {
1527: struct inode *inode = ilookup(info->sb, kernfs_ino(kn));
1528:
1529: if (inode) {
1530: clear_nlink(inode);
1531: iput(inode);
1532: }
1533: }
1534: }
SourceFile:fs/kernfs/dir.c]
|
| 26/2 |
2026/11/19 20:48 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:fs/kernfs/inode.c Name:inode]
Results: map[Fields:[map[Name:i_mode OffsetBits:0 SizeBits:16] map[Name:i_opflags OffsetBits:16 SizeBits:16] map[Name:i_flags OffsetBits:32 SizeBits:32] map[Name:i_acl OffsetBits:64 SizeBits:64] map[Name:i_default_acl OffsetBits:128 SizeBits:64] map[Name:i_uid OffsetBits:192 SizeBits:32] map[Name:i_gid OffsetBits:224 SizeBits:32] map[Name:i_op OffsetBits:256 SizeBits:64] map[Name:i_sb OffsetBits:320 SizeBits:64] map[Name:i_mapping OffsetBits:384 SizeBits:64] map[Name:i_security OffsetBits:448 SizeBits:64] map[Name:i_ino OffsetBits:512 SizeBits:64] map[Name: OffsetBits:576 SizeBits:32] map[Name:i_rdev OffsetBits:608 SizeBits:32] map[Name:i_size OffsetBits:640 SizeBits:64] map[Name:i_atime_sec OffsetBits:704 SizeBits:64] map[Name:i_mtime_sec OffsetBits:768 SizeBits:64] map[Name:i_ctime_sec OffsetBits:832 SizeBits:64] map[Name:i_atime_nsec OffsetBits:896 SizeBits:32] map[Name:i_mtime_nsec OffsetBits:928 SizeBits:32] map[Name:i_ctime_nsec OffsetBits:960 SizeBits:32] map[Name:i_generation OffsetBits:992 SizeBits:32] map[Name:i_lock OffsetBits:1024 SizeBits:32] map[Name:i_bytes OffsetBits:1056 SizeBits:16] map[Name:i_blkbits OffsetBits:1072 SizeBits:8] map[Name:i_write_hint OffsetBits:1080 SizeBits:8] map[Name:i_blocks OffsetBits:1088 SizeBits:64] map[Name:i_state OffsetBits:1152 SizeBits:32] map[Name:i_rwsem OffsetBits:1216 SizeBits:256] map[Name:dirtied_when OffsetBits:1472 SizeBits:64] map[Name:dirtied_time_when OffsetBits:1536 SizeBits:64] map[Name:i_hash OffsetBits:1600 SizeBits:128] map[Name:i_io_list OffsetBits:1728 SizeBits:128] map[Name:i_wb OffsetBits:1856 SizeBits:64] map[Name:i_wb_frn_winner OffsetBits:1920 SizeBits:32] map[Name:i_wb_frn_avg_time OffsetBits:1952 SizeBits:16] map[Name:i_wb_frn_history OffsetBits:1968 SizeBits:16] map[Name:i_lru OffsetBits:1984 SizeBits:128] map[Name:i_sb_list OffsetBits:2112 SizeBits:128] map[Name:i_wb_list OffsetBits:2240 SizeBits:128] map[Name: OffsetBits:2368 SizeBits:128] map[Name:i_version OffsetBits:2496 SizeBits:64] map[Name:i_sequence OffsetBits:2560 SizeBits:64] map[Name:i_count OffsetBits:2624 SizeBits:32] map[Name:i_dio_count OffsetBits:2656 SizeBits:32] map[Name:i_writecount OffsetBits:2688 SizeBits:32] map[Name:i_readcount OffsetBits:2720 SizeBits:32] map[Name: OffsetBits:2752 SizeBits:64] map[Name:i_flctx OffsetBits:2816 SizeBits:64] map[Name:i_data OffsetBits:2880 SizeBits:1216] map[Name: OffsetBits:4096 SizeBits:128] map[Name: OffsetBits:4224 SizeBits:64] map[Name:i_fsnotify_mask OffsetBits:4288 SizeBits:32] map[Name:i_fsnotify_marks OffsetBits:4352 SizeBits:64] map[Name:i_private OffsetBits:4416 SizeBits:64]]]
|
| 27/2 |
2026/11/19 20:48 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/kernfs/inode.c Name:kernfs_iop_getattr]
Results: map[SourceCode: 182: int kernfs_iop_getattr(const struct mnt_idmap *idmap,
183: const struct path *path, struct kstat *stat,
184: u32 request_mask, unsigned int query_flags)
185: {
186: struct inode *inode = d_inode(path->dentry);
187: struct kernfs_node *kn = inode->i_private;
188: struct kernfs_root *root = kernfs_root(kn);
189:
190: down_read(&root->kernfs_iattr_rwsem);
191: kernfs_refresh_inode(kn, inode);
192: generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
193: up_read(&root->kernfs_iattr_rwsem);
194:
195: return 0;
196: }
SourceFile:fs/kernfs/inode.c]
|
| 28/2 |
2026/11/19 20:48 |
llm |
root-cause |
0m
Model:
Tokens:
input: 27649
output: 48
thoughts: 755
Thoughts: **Analyzing a Potential Data Race in Kernfs**
I've been meticulously examining real-world scenarios without KCSAN to pinpoint the exact mechanics of this data race. My investigation has focused on the `kernfs_iop_permission()` and `kernfs_iop_getattr()` functions. I've realized that these functions, when acquiring the `root->kernfs_iattr_rwsem`, are using `down_read()`, not `down_write()`, and critically, they are *not* taking `inode->i_lock` or `inode->i_rwsem`. This is a key oversight.
Under this shared read lock, `kernfs_iop_permission()` proceeds to call `kernfs_refresh_inode()`. This function, in turn, writes to several fields within the `inode` structure. Specifically, I'm seeing writes to `inode->i_mode` (a straightforward 2-byte write), various timestamp fields and `i_uid`/`i_gid` via `set_inode_attr()` (where timestamps use `WRITE_ONCE` but uid/gid are plain 4-byte writes), and `inode->__i_nlink` (a 4-byte write for directories).
The problem escalates when `kernfs_iop_permission()` then calls `generic_permission()`, which leads into `acl_permission_check()`. This latter function reads `inode->i_mode`, `inode->i_uid`, and `inode->i_gid`.
The core of the race condition lies here: because `kernfs_iattr_rwsem` is only held for reading, two concurrent tasks performing path lookups (like `openat` and `readlink` as seen in the report) within the same kernfs directory or node will both enter `kernfs_iop_permission()` simultaneously. One task might be in the process of writing `inode->i_mode` via `kernfs_refresh_inode()`, while another task is attempting to read `inode->i_mode` in `acl_permission_check()`. This creates a classic read-write race. Furthermore, if both tasks execute `kernfs_refresh_inode()` concurrently, we’re looking at a write-write race on fields like `inode->i_mode`, `inode->i_uid`, `inode->i_gid`, and `inode->__i_nlink`.
Now, to understand the impact without KCSAN or other sanitizers, I'm delving into *what* values are actually being written to `inode->i_mode`. I see that both calls to `kernfs_refresh_inode()` read `kn->mode` under `down_read(&root->kernfs_iattr_rwsem)`. My immediate thought is that `kn->mode` should only be modifiable under `down_write(&root->kernfs_iattr_rwsem)`, for instance, in `kernfs_setattr()` or `kernfs_iop_setattr()`. However, I need to double-check if `kn->mode` can be modified elsewhere without this write lock. I'm currently cross-referencing all uses of `kernfs_node::mode` to ensure I haven't missed any potential entry points for modification.
|
| 29/2 |
2026/11/19 20:48 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:3 Name:kernfs_node::mode SourceTreePrefix:fs/kernfs/]
Results: map[References:[map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:__kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:690 SourceSnippet: 687: RB_CLEAR_NODE(&kn->rb);
688:
689: rcu_assign_pointer(kn->name, name);
690: kn->mode = mode;
691: kn->flags = flags;
692:
693: if (!uid_eq(uid, GLOBAL_ROOT_UID) || !gid_eq(gid, GLOBAL_ROOT_GID)) {
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:__kernfs_setattr SourceFile:fs/kernfs/inode.c SourceLine:88 SourceSnippet: 85: if (ia_valid & ATTR_CTIME)
86: attrs->ia_ctime = iattr->ia_ctime;
87: if (ia_valid & ATTR_MODE)
88: kn->mode = iattr->ia_mode;
89: return 0;
90: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_fop_readdir SourceFile:fs/kernfs/dir.c SourceLine:2029 SourceSnippet:2026: for (pos = kernfs_dir_pos(ns, parent, ctx->pos, pos, NULL, NULL);
2027: pos;
2028: pos = kernfs_dir_next_pos(ns, parent, ctx->pos, pos, name)) {
2029: unsigned int type = fs_umode_to_dtype(pos->mode);
2030: ino_t ino = kernfs_ino(pos);
2031: int len;
2032:
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_init_inode SourceFile:fs/kernfs/inode.c SourceLine:206 SourceSnippet: 203: inode->i_op = &kernfs_iops;
204: inode->i_generation = kernfs_gen(kn);
205:
206: set_default_inode_attr(inode, kn->mode);
207: kernfs_refresh_inode(kn, inode);
208:
209: /* initialize inode according to type */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:kernfs_new_node SourceFile:fs/kernfs/dir.c SourceLine:746 SourceSnippet: 743: * a node that does not exist yet, so nothing orders a racing chmod or
744: * chown against this creation.
745: */
746: if (READ_ONCE(parent->mode) & S_ISGID) {
747: /* this code block imitates inode_init_owner() for
748: * kernfs
749: */
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:kernfs_refresh_inode SourceFile:fs/kernfs/inode.c SourceLine:169 SourceSnippet: 166: {
167: struct kernfs_iattrs *attrs;
168:
169: inode->i_mode = kn->mode;
170: attrs = kernfs_iattrs_noalloc(kn);
171: if (attrs)
172: /*
]] TruncatedOutput:false]
|
| 30/2 |
2026/11/19 20:48 |
llm |
root-cause |
0m
Model:
Tokens:
input: 30435
output: 74
thoughts: 1538
Thoughts: **Analyzing Potential Data Races in Kernfs Inode Attribute Updates**
I've been scrutinizing how `kn->mode` and other inode attributes are handled within the kernfs filesystem, specifically focusing on potential data races. My initial understanding was that `kn->mode` is exclusively set during node creation or under the protection of `down_write(&root->kernfs_iattr_rwsem)` during attribute modification (`__kernfs_setattr`).
However, I stumbled upon a point of concern in `kernfs_refresh_inode()`, where `set_nlink(inode, kn->dir.subdirs + 2)` is called. I needed to verify the synchronization context around this operation. My investigation revealed that `kernfs_clear_inode_nlink()` is indeed called under `down_write(&kernfs_root(kn)->kernfs_iattr_rwsem)`, and importantly, only after the `KERNFS_REMOVING` flag has been set, also under the write lock.
The crucial observation is within `kernfs_refresh_inode()` itself:
if (kernfs_type(kn) == KERNFS_DIR && !(kn->flags & KERNFS_REMOVING))
set_nlink(inode, kn->dir.subdirs + 2);
This happens while `kernfs_iattr_rwsem` is held for *reading* in functions like `kernfs_iop_permission` and `kernfs_iop_getattr`. This means that during these read-locked periods:
* `kn->mode`, `attrs->ia_uid`, `attrs->ia_gid`, `attrs->ia_atime/mtime/ctime`, `kn->flags`, and `kn->dir.subdirs` are effectively constant. Any modifications to these fields require acquiring the `down_write(&root->kernfs_iattr_rwsem)` lock.
* Consequently, any concurrent readers executing `kernfs_refresh_inode(kn, inode)` will be writing *identical* values to `inode->i_mode`, `inode->i_uid`, `inode->i_gid`, `inode->__i_nlink`, and so on.
I then considered the potential issue of `set_nlink()`'s check: `if (inode->i_nlink == 0) atomic_long_dec(&inode->i_sb->s_remove_count);`. Could `inode->i_nlink` be zero at this point? My check of `inode_init_always_gfp()` and `kernfs_init_inode()` indicated that new inodes are initialized with `i_nlink = 1`. Furthermore, `kernfs_clear_inode_nlink()` is only called after `KERNFS_REMOVING` is set, ensuring that `inode->i_nlink` will not be zero when `!(kn->flags & KERNFS_REMOVING)`.
The primary concern I'm wrestling with relates to `inode->i_mode`. It's a `umode_t`, a 16-bit field at offset 0 of `struct inode`. Writing the same 16-bit value (`kn->mode`) to `inode->i_mode` while another thread reads it (e.g., in `acl_permission_check()`) is technically a data race according to the C memory model and KCSAN. While on modern architectures this might be an atomic 2-byte write, the question of compiler optimizations and potential tearing, especially if `READ_ONCE`/`WRITE_ONCE` aren't involved, is still nagging at me.
I've also looked at the adjacent field, `i_opflags`, at offset 16 bits. On architectures like x86-64 and arm64, compilers typically emit a 16-bit store for `movw`. The `i_opflags` field is modified under `inode->i_lock`, and for kernfs inodes, `IOP_FASTPERM` is not set because `inode->i_op->permission` is non-NULL. I've confirmed that `i_opflags` isn't modified at runtime on kernfs inodes in a way that would interact with this potential race.
Even if `inode->i_mode` already holds the correct value (`kn->mode`) when `kernfs_refresh_inode` writes it, or if multiple `kernfs_refresh_inode` calls race after an `kernfs_iop_setattr`, the core of the issue is the potential for a read to see a partially updated value or a value in transition. However, I've evaluated the practical implications:
1. **Memory Corruption:** Unlikely. No pointers, lengths, indices, or refcounts are being corrupted. All concurrent `kernfs_refresh_inode` operations write identical attribute values derived under the read lock.
2. **Information Leak:** Not possible. No kernel memory is exposed to userspace.
3. **Denial-of-Service:** No. On real hardware without KCSAN, the aligned 2-byte access to `inode->i_mode` doesn't cause crashes, hangs, or resource leaks. Even if a read sees a value being written, both the old and new values during concurrent `down_read` operations are identical (`kn->mode`). In the edge case where `kernfs_iop_setattr` changed `kn->mode` and then two readers raced to refresh `inode->i_mode`, they would both write the *same new* `kn->mode`. An aligned read would see either the old valid `i_mode` or the new valid `kn->mode`, neither of which should cause a crash or memory corruption.
4. **Networking/Virtualization:** I've checked the call traces and associated processes. Task 3010 (`udevd` doing `readlink`) and Task 3731 (`openat` on sysfs/kernfs) are involved. No networking or KVM/virtualization is present, so those specific areas of concern are ruled out.
Despite these reassurances, I want to be absolutely certain. I've decided to re-examine `inode_permission` and `may_lookup` in `fs/namei.c` to get a complete picture of the call path and the locks held during these operations, just to ensure I haven't missed any subtle synchronization details.
|
| 31/2 |
2026/11/19 20:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:inode_permission]
Results: map[SourceCode: 616: /**
617: * inode_permission - Check for access rights to a given inode
618: * @idmap: idmap of the mount the inode was found from
619: * @inode: Inode to check permission on
620: * @mask: Right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
621: *
622: * Check for read/write/execute permissions on an inode. We use fs[ug]id for
623: * this, letting us set arbitrary permissions for filesystem access without
624: * changing the "normal" UIDs which are used for other things.
625: *
626: * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask.
627: */
628: int inode_permission(const struct mnt_idmap *idmap,
629: struct inode *inode, int mask)
630: {
631: int retval;
632:
633: retval = sb_permission(inode->i_sb, inode, mask);
634: if (unlikely(retval))
635: return retval;
636:
637: if (mask & MAY_WRITE) {
638: /*
639: * Nobody gets write access to an immutable file.
640: */
641: if (unlikely(IS_IMMUTABLE(inode)))
642: return -EPERM;
643:
644: /*
645: * Updating mtime will likely cause i_uid and i_gid to be
646: * written back improperly if their true value is unknown
647: * to the vfs.
648: */
649: if (unlikely(HAS_UNMAPPED_ID(idmap, inode)))
650: return -EACCES;
651: }
652:
653: retval = do_inode_permission(idmap, inode, mask);
654: if (unlikely(retval))
655: return retval;
656:
657: retval = devcgroup_inode_permission(inode, mask);
658: if (unlikely(retval))
659: return retval;
660:
661: return security_inode_permission(idmap, inode, mask);
662: }
SourceFile:fs/namei.c]
|
| 32/2 |
2026/11/19 20:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:may_lookup]
Results: map[SourceCode:1961: static inline int may_lookup(const struct mnt_idmap *idmap,
1962: struct nameidata *restrict nd)
1963: {
1964: int err, mask;
1965:
1966: mask = nd->flags & LOOKUP_RCU ? MAY_NOT_BLOCK : 0;
1967: err = lookup_inode_permission_may_exec(idmap, nd->inode, mask);
1968: if (likely(!err))
1969: return 0;
1970:
1971: // If we failed, and we weren't in LOOKUP_RCU, it's final
1972: if (!(nd->flags & LOOKUP_RCU))
1973: return err;
1974:
1975: // Drop out of RCU mode to make sure it wasn't transient
1976: if (!try_to_unlazy(nd))
1977: return -ECHILD; // redo it all non-lazy
1978:
1979: if (err != -ECHILD) // hard error
1980: return err;
1981:
1982: return lookup_inode_permission_may_exec(idmap, nd->inode, 0);
1983: }
SourceFile:fs/namei.c]
|
| 33/2 |
2026/11/19 20:49 |
llm |
root-cause |
0m
Model:
Tokens:
input: 33145
output: 635
thoughts: 1171
Thoughts: **My Thought Process on the `kernfs` Race Condition**
Okay, let's break down what's happening here and how I'm thinking through this bug.
First, I'm confirming that the stack traces provided in the bug report are exactly what I'm seeing. This is crucial – it means I'm looking at the right path through the kernel. I can see how a CPU handling Task 3731, which seems to be performing an `openat` operation, is diving deep into the `kernfs` layer, specifically calling `kernfs_iop_permission`. This leads to `kernfs_refresh_inode`, where it's attempting to write 2 bytes to `inode->i_mode`. Simultaneously, I see Task 3010, a `udevd` process, doing a `readlink` operation. This path also hits `kernfs_iop_permission`, but then branches into `generic_permission` and `acl_permission_check`, where it's *reading* from that same `inode->i_mode`. The line numbers (`fs/kernfs/inode.c:287` vs. `fs/kernfs/inode.c:288`) and the specific functions involved (`kernfs_refresh_inode` vs. `generic_permission`) confirm this is a read-write race on the same piece of memory.
Now, I need to pinpoint the *root cause*. The bug report points to `fs/kernfs/inode.c`. My reasoning here is that `kernfs_iop_permission` (and its sibling `kernfs_iop_getattr`) is the critical function. It acquires a *shared read lock* (`down_read(&root->kernfs_iattr_rwsem)`) before proceeding. This is the key problem: a shared lock means multiple tasks can be in this section concurrently. `kernfs_refresh_inode` then modifies several fields of the `inode` – `i_mode`, `i_uid`, `i_gid`, `i_nlink` – but it does so with plain, unprotected writes. There's no exclusive locking on the `inode` itself, nor are there atomic or idempotent operations that would be safe even with concurrent access. So, while one task is writing to `inode->i_mode`, another task might be reading from it via `generic_permission` and `acl_permission_check`. The `fs/namei.c` functions are just standard VFS helpers; they *expect* the filesystem layer to handle synchronization of inode attributes. They aren't the source of the problem; `kernfs` is. Therefore, `fs/kernfs/inode.c` is the sole root cause file.
Next, I'm reviewing the parameters for `set-results`, which involves crafting the summary and analysis.
For `RootCauseSummary`, I need to articulate this race condition clearly. I'll explain that `kernfs_iop_permission` uses a shared read lock, which allows concurrent execution. During this concurrent execution, `kernfs_refresh_inode` performs unprotected writes to `inode->i_mode` (and other attributes like `i_uid`, `i_gid`, `i_nlink`), while `generic_permission` and `acl_permission_check` perform unprotected reads from `inode->i_mode`. This creates a classic race condition.
For `RootCauseFiles`, as established, it's just `["fs/kernfs/inode.c"]`.
Now, for `ImpactAnalysis`, this is where I assess the *actual* harm. In typical scenarios *without* KCSAN (the kernel sanitizer that detected this), the `down_read` lock in `kernfs_iop_permission` would prevent `kernfs_setattr` (which uses a `down_write` lock) from running concurrently. This means that while readers are active, the attributes like `kn->mode` can't be changed. Consequently, all concurrent `kernfs_refresh_inode` calls are likely writing the *same* value to `inode->i_mode` (and the other attributes). On most architectures, a simple 2-byte write of an already stored or refreshed value to `umode_t` is benign. It won't corrupt pointers, lengths, reference counts, state machines, cause memory leaks, crashes, or hangs. Therefore, `MemoryCorruption` is `false`, `InfoLeak` is `"none"`, and `RawDenialOfService` is `false`. The bug involves `openat` and `readlink` on `kernfs` nodes, which are purely filesystem operations and don't touch networking or virtualization. Hence, `IsNetCandidate` and `IsKVMCandidate` are `false`.
With all this analyzed, I'm ready to call `set-results`.
|
| 34/2 |
2026/11/19 20:49 |
tool |
set-results |
0m
Args: map[ImpactAnalysis:In real-world setups without KCSAN, this data race is benign. While multiple threads execute kernfs_iop_permission() (and kernfs_iop_getattr()) concurrently under down_read(&root->kernfs_iattr_rwsem), any modifications to kn->mode or kernfs_iattrs take down_write(&root->kernfs_iattr_rwsem). As a result, kn->mode (and uid/gid/nlink/timestamps) remain constant across all concurrent readers, so kernfs_refresh_inode() repeatedly writes the exact same 2-byte kn->mode value to inode->i_mode. Even if kn->mode was updated in an earlier kernfs_setattr() and two readers race to refresh inode->i_mode, both write the identical new value to a naturally aligned 16-bit field (inode->i_mode at offset 0 of struct inode), and acl_permission_check() observes either the old or new valid mode bits without crashing, hanging, or corrupting adjacent fields or pointers.
Classification reasoning:
- MemoryCorruption = false: The race involves plain accesses to inode->i_mode (a 2-byte umode_t permission/type mask) writing identical values; it does not corrupt pointers, refcounts, buffer lengths, or control flow.
- InfoLeak = "none": No kernel memory contents are leaked to userspace or external observers.
- RawDenialOfService = false: Without KCSAN, concurrent 2-byte accesses to inode->i_mode do not trigger a kernel panic, hang, deadlock, or resource leak.
- IsNetCandidate = false: The bug is in kernfs/VFS path lookup (openat and readlink by udevd) with no relation to networking.
- IsKVMCandidate = false: The bug and call traces have no relation to KVM, virtualization, or vhost/virtio. InfoLeak:none IsKVMCandidate:false IsNetCandidate:false MemoryCorruption:false RawDenialOfService:false RootCauseFiles:[fs/kernfs/inode.c] RootCauseSummary:kernfs_iop_permission() in fs/kernfs/inode.c acquires only a shared read lock (down_read(&root->kernfs_iattr_rwsem)) before calling kernfs_refresh_inode(kn, inode) and generic_permission(). Because down_read() permits concurrent execution on the same inode, one task's plain 2-byte write to inode->i_mode in kernfs_refresh_inode() races with another task's plain 2-byte read of inode->i_mode in acl_permission_check() (via generic_permission()), as well as with concurrent kernfs_refresh_inode() calls in kernfs_iop_permission() and kernfs_iop_getattr().]
Results: map[ImpactAnalysis:In real-world setups without KCSAN, this data race is benign. While multiple threads execute kernfs_iop_permission() (and kernfs_iop_getattr()) concurrently under down_read(&root->kernfs_iattr_rwsem), any modifications to kn->mode or kernfs_iattrs take down_write(&root->kernfs_iattr_rwsem). As a result, kn->mode (and uid/gid/nlink/timestamps) remain constant across all concurrent readers, so kernfs_refresh_inode() repeatedly writes the exact same 2-byte kn->mode value to inode->i_mode. Even if kn->mode was updated in an earlier kernfs_setattr() and two readers race to refresh inode->i_mode, both write the identical new value to a naturally aligned 16-bit field (inode->i_mode at offset 0 of struct inode), and acl_permission_check() observes either the old or new valid mode bits without crashing, hanging, or corrupting adjacent fields or pointers.
Classification reasoning:
- MemoryCorruption = false: The race involves plain accesses to inode->i_mode (a 2-byte umode_t permission/type mask) writing identical values; it does not corrupt pointers, refcounts, buffer lengths, or control flow.
- InfoLeak = "none": No kernel memory contents are leaked to userspace or external observers.
- RawDenialOfService = false: Without KCSAN, concurrent 2-byte accesses to inode->i_mode do not trigger a kernel panic, hang, deadlock, or resource leak.
- IsNetCandidate = false: The bug is in kernfs/VFS path lookup (openat and readlink by udevd) with no relation to networking.
- IsKVMCandidate = false: The bug and call traces have no relation to KVM, virtualization, or vhost/virtio. InfoLeak:none IsKVMCandidate:false IsNetCandidate:false MemoryCorruption:false RawDenialOfService:false RootCauseFiles:[fs/kernfs/inode.c] RootCauseSummary:kernfs_iop_permission() in fs/kernfs/inode.c acquires only a shared read lock (down_read(&root->kernfs_iattr_rwsem)) before calling kernfs_refresh_inode(kn, inode) and generic_permission(). Because down_read() permits concurrent execution on the same inode, one task's plain 2-byte write to inode->i_mode in kernfs_refresh_inode() races with another task's plain 2-byte read of inode->i_mode in acl_permission_check() (via generic_permission()), as well as with concurrent kernfs_refresh_inode() calls in kernfs_iop_permission() and kernfs_iop_getattr().]
|
| 35/2 |
2026/11/19 20:49 |
llm |
root-cause |
0m
Model:
Tokens:
input: 35582
output: 1229
thoughts: 44
Thoughts: **My Thought Process for Diagnosing the Bug**
Right, the next crucial step is to articulate the *exact* technical underpinnings of this bug. I need to be surgically precise here, focusing solely on the mechanism and the definitive root cause. This means drilling down into the code, pinpointing specific files, the exact line numbers where the issue manifests, the functions involved, and the particular structs and fields that are at play. The goal is to provide a crystal-clear, detailed technical explanation that leaves no room for ambiguity, a narrative built from the ground up with empirical observations from the codebase itself.
|
| 36/1 |
2026/11/19 20:49 |
agent |
local-reachability |
1m
Model:
Results: map[FilesystemTrigger:false PeripheralTrigger:false RawFuzzingArtifact:false RequiredCaps:<nil> Unprivileged:true UserNamespace:true]
Instruction: You are an experienced Linux kernel security engineer. You are given a kernel bug report, an optional draft reproducer,
and a root-cause analysis prepared by another engineer. Your task is to determine the minimum privileges required to
trigger the bug from a local userspace process, as well as whether it can be triggered via a physical peripheral or
a mounted filesystem image.
(Note: Remote network ingress and KVM/virtualization triggers are evaluated by separate specialized steps.)
Trust the provided root-cause analysis (which has already identified the vulnerable functions, files, and defect
mechanism). Do NOT spend tool calls re-investigating or re-verifying the root cause from scratch unless you encounter
serious evidence while tracing callers that the root-cause analysis might be wrong.
Use the provided tools to trace callers of the vulnerable functions in the kernel source code, inspect capability checks
(such as capable(), ns_capable(), file_ns_capable(), netlink/socket permission checks), and check the kernel build
configuration (and "CONFIG_CMDLINE=") using the kernel-config-grep tool. Assume sysctl parameters have default
values.
CRITICAL — Multiple Entry Points vs. Reproducer Path:
- A kernel bug can often be reached through multiple distinct code paths or entry points.
- A syzkaller reproducer only demonstrates the one path the fuzzer happened to find, and fuzzer programs frequently
run with full capabilities inside a user/network namespace, which overstates the privileges actually required.
- Do not stop at analyzing the reproducer's syscall sequence: search for other callers of the buggy function(s) across
the codebase (including unprivileged syscalls, socket operations, ioctls, procfs/sysfs files, etc.).
- Try both strategies:
1. Look for ways an unprivileged process can reach the vulnerable code.
2. Check whether every local path to the vulnerable code is gated by a capability check, root-only device node, or
disabled Kconfig/sysctl.
- If still unsure after inspecting the code, err on the side of the bug requiring higher privileges / not being
reachable from an external surface.
In your final reply, explain the local entry points you investigated, the capability or configuration checks along those
paths, and the reasoning behind each output field.
Analysis dimensions (in output schema order):
* Unprivileged:
Set to true if the bug can be triggered from a typical unprivileged user process that does NOT have any special
capabilities (such as CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON), does NOT have access to device nodes
or files restricted to root, and does NOT create a user namespace.
Assume unprivileged_bpf_disabled=1 (unprivileged eBPF is disabled, though classic cBPF remains available to
unprivileged processes).
* UserNamespace:
Set to true if the bug can be triggered from an unprivileged user process EITHER directly (when Unprivileged is true)
OR by creating a user namespace (and associated network/mount/etc. namespaces) where the process holds namespace-local
capabilities checked via ns_capable() (or sk_net_capable(), netlink_ns_capable(), etc.).
Note: when Unprivileged is true, UserNamespace must also be true.
* RequiredCaps:
Provide the list of Linux capability names (e.g., ["CAP_NET_ADMIN"], ["CAP_SYS_ADMIN"], ["CAP_NET_RAW"]) required by
the least-privileged local path that can trigger the bug:
- Must be empty ([]) when Unprivileged is true, or when the bug cannot be triggered from any local userspace process.
- Otherwise, list all CAP_* capabilities required along the least-privileged local path (whether in a user namespace
or in init_user_ns). If access is gated by root-only device node or file permissions without an explicit capable()
check, use ["CAP_DAC_OVERRIDE"].
* PeripheralTrigger:
Set to true if the bug can be triggered via an untrusted peripheral device physically plugged into a system (such as a
malicious USB device or external hardware input handled by a device driver).
* FilesystemTrigger:
Set to true if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
* RawFuzzingArtifact:
This field identifies artificial fuzzer-induced reports that upstream kernel developers would dismiss as "not a real
bug". Be very conservative: when in doubt, set RawFuzzingArtifact to false.
- Real bugs reached via virtual or testing interfaces (RawFuzzingArtifact = false):
Syzkaller reproducers frequently use virtual, emulation, or testing interfaces (such as tun, veth, netdevsim,
mac80211_hwsim, pktgen, raw-gadget/vhci_hcd, or fault injection). Using these interfaces in the reproducer — or
triggering a genuine bug (such as memory corruption, UAF, OOB, refcount bug, or crash) inside virtual drivers like
netdevsim, mac80211_hwsim, tun, or veth — is NOT a fuzzing artifact.
- True fuzzing artifacts (RawFuzzingArtifact = true):
Set to true ONLY when the report requires capabilities (even if obtainable in a user/network namespace, i.e.
Unprivileged = false), cannot be triggered via a peripheral, filesystem, network peer, or VM, AND falls into one of
these specific categories:
1. Degenerate administrative configurations that self-inflict hangs, RCU/CPU stalls, or resource exhaustion without
violating memory safety (e.g., using CAP_NET_ADMIN to wire bridge/veth/tunnel interfaces into a packet loop that
starves the CPU or RTNL lock, or configuring extreme sub-microsecond sch_taprio / timer intervals that flood the
CPU).
2. Artificial fault-injection or debug/test-knob interactions that violate internal kernel invariants in ways that
real hardware or normal operation cannot (e.g., spurious lockdep chains caused by fault-injected probe/firmware
paths, or writing directly to internal debugfs/sysfs test knobs that intentionally corrupt or bypass kernel state).
For all genuine kernel bugs, or anything reachable without capabilities (Unprivileged = true) or from an external
surface, set RawFuzzingArtifact to false.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
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.
During execution, you may receive periodic guidance in <supervisor_advice> tags;
use it to refine your investigation or wrap up once you have sufficient evidence.
Prompt:
The kernel bug report is:
==================================================================
BUG: KCSAN: data-race in generic_permission / kernfs_iop_permission
write to 0xffff888107516f88 of 2 bytes by task 3731 on cpu 1:
kernfs_refresh_inode fs/kernfs/inode.c:169 [inline]
kernfs_iop_permission+0x9d/0x220 fs/kernfs/inode.c:287
do_inode_permission fs/namei.c:583 [inline]
inode_permission+0x2b4/0x3c0 fs/namei.c:653
lookup_inode_permission_may_exec fs/namei.c:-1 [inline]
may_lookup fs/namei.c:1967 [inline]
link_path_walk+0x881/0xde0 fs/namei.c:2610
path_openat+0x142/0x11e0 fs/namei.c:5012
do_file_open+0x16c/0x290 fs/namei.c:5045
do_sys_openat2+0xa1/0x140 fs/open.c:1443
do_sys_open fs/open.c:1449 [inline]
__do_sys_openat fs/open.c:1465 [inline]
__se_sys_openat fs/open.c:1460 [inline]
__x64_sys_openat+0xf2/0x120 fs/open.c:1460
x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
read to 0xffff888107516f88 of 2 bytes by task 3010 on cpu 0:
acl_permission_check fs/namei.c:441 [inline]
generic_permission+0x2a/0x470 fs/namei.c:529
kernfs_iop_permission+0x1fd/0x220 fs/kernfs/inode.c:288
do_inode_permission fs/namei.c:583 [inline]
inode_permission+0x2b4/0x3c0 fs/namei.c:653
lookup_inode_permission_may_exec fs/namei.c:-1 [inline]
may_lookup fs/namei.c:1967 [inline]
link_path_walk+0x881/0xde0 fs/namei.c:2610
path_lookupat+0x53/0x4c0 fs/namei.c:2818
filename_lookup+0x18f/0x390 fs/namei.c:2848
do_readlinkat+0x74/0x2f0 fs/stat.c:575
__do_sys_readlink fs/stat.c:609 [inline]
__se_sys_readlink fs/stat.c:606 [inline]
__x64_sys_readlink+0x47/0x60 fs/stat.c:606
x64_sys_call+0x1d41/0x2550 arch/x86/include/generated/asm/syscalls_64.h:90
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3010 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
The root-cause analysis of the bug is:
### Root Cause Analysis
The KCSAN data race occurs because `kernfs_iop_permission()` in `fs/kernfs/inode.c` mutates fields of the shared VFS `struct inode` while holding only a shared reader lock (`down_read(&root->kernfs_iattr_rwsem)`), allowing concurrent VFS lookups on the same kernfs node to read and write `inode->i_mode` without synchronization.
#### Technical Mechanism
1. **Shared locking in `kernfs_iop_permission()` (`fs/kernfs/inode.c:273-292`)**:
- When VFS path traversal (`link_path_walk()` -> `may_lookup()` -> `inode_permission()` -> `do_inode_permission()`) checks permissions on a kernfs inode (in non-RCU mode, i.e., without `MAY_NOT_BLOCK`), it invokes `inode->i_op->permission`, which points to `kernfs_iop_permission()` (registered in `kernfs_iops`, `kernfs_dir_iops`, and `kernfs_symlink_iops`).
- `kernfs_iop_permission()` acquires `root->kernfs_iattr_rwsem` for reading:
```c
down_read(&root->kernfs_iattr_rwsem);
kernfs_refresh_inode(kn, inode);
ret = generic_permission(&nop_mnt_idmap, inode, mask);
up_read(&root->kernfs_iattr_rwsem);
```
- `kernfs_iop_getattr()` (`fs/kernfs/inode.c:182-196`) follows the same pattern, calling `kernfs_refresh_inode()` and `generic_fillattr()` under `down_read(&root->kernfs_iattr_rwsem)`.
2. **Unprotected writes in `kernfs_refresh_inode()` (`fs/kernfs/inode.c:165-180`)**:
- Because `root->kernfs_iattr_rwsem` is only acquired for reading, multiple tasks can enter `kernfs_iop_permission()` (and `kernfs_iop_getattr()`) simultaneously for the same `struct kernfs_node` (`kn`) and `struct inode` (`inode`).
- `kernfs_refresh_inode()` unconditionally performs plain (non-atomic) writes to `inode` fields:
- `inode->i_mode = kn->mode;` (`fs/kernfs/inode.c:169`), a 2-byte `umode_t` write at offset 0 of `struct inode`.
- `set_inode_attr(inode, attrs);` (`fs/kernfs/inode.c:176`), which writes `inode->i_uid`, `inode->i_gid`, and timestamps.
- `set_nlink(inode, kn->dir.subdirs + 2);` (`fs/kernfs/inode.c:179`), which writes `inode->__i_nlink` for active directories.
3. **Concurrent read in `generic_permission()` / `acl_permission_check()` (`fs/namei.c:438-531`)**:
- After `kernfs_refresh_inode()`, `kernfs_iop_permission()` calls `generic_permission(&nop_mnt_idmap, inode, mask)` (`fs/kernfs/inode.c:288`), which calls `acl_permission_check()` (`fs/namei.c:529`).
- `acl_permission_check()` performs a plain 2-byte read of `inode->i_mode` (`unsigned int mode = inode->i_mode;` at `fs/namei.c:441`) and may also read `inode->i_uid` and `inode->i_gid`.
- In the reported trace, Task 3731 (`openat` -> `kernfs_iop_permission()` -> `kernfs_refresh_inode()` at `fs/kernfs/inode.c:169`) writes 2 bytes to `inode->i_mode` (`0xffff888107516f88`) concurrently with Task 3010 (`readlink` -> `kernfs_iop_permission()` -> `generic_permission()` -> `acl_permission_check()` at `fs/namei.c:441`) reading those 2 bytes.
#### Lifecycle and Invariants
- Modifications to `kn->mode` (via `__kernfs_setattr()` in `kernfs_setattr()` / `kernfs_iop_setattr()`) and `kn->iattr` attributes are serialized under `down_write(&root->kernfs_iattr_rwsem)`.
- `kernfs_iattr_rwsem` protects the `kernfs_node` attributes against concurrent `setattr`, but it does **not** serialize the copy/refresh of those attributes from `kn` into the VFS `struct inode`, nor does `kernfs_iop_permission()` hold `inode->i_lock` or `inode->i_rwsem` exclusively. Consequently, any two concurrent readers executing `kernfs_iop_permission()` or `kernfs_iop_getattr()` on the same kernfs inode violate the C memory model invariant against unsynchronized concurrent read/write (and write/write) accesses to `inode->i_mode` (as well as `i_uid`, `i_gid`, and `__i_nlink`).
The impact analysis of the bug is:
In real-world setups without KCSAN, this data race is benign. While multiple threads execute kernfs_iop_permission() (and kernfs_iop_getattr()) concurrently under down_read(&root->kernfs_iattr_rwsem), any modifications to kn->mode or kernfs_iattrs take down_write(&root->kernfs_iattr_rwsem). As a result, kn->mode (and uid/gid/nlink/timestamps) remain constant across all concurrent readers, so kernfs_refresh_inode() repeatedly writes the exact same 2-byte kn->mode value to inode->i_mode. Even if kn->mode was updated in an earlier kernfs_setattr() and two readers race to refresh inode->i_mode, both write the identical new value to a naturally aligned 16-bit field (inode->i_mode at offset 0 of struct inode), and acl_permission_check() observes either the old or new valid mode bits without crashing, hanging, or corrupting adjacent fields or pointers.
Classification reasoning:
- MemoryCorruption = false: The race involves plain accesses to inode->i_mode (a 2-byte umode_t permission/type mask) writing identical values; it does not corrupt pointers, refcounts, buffer lengths, or control flow.
- InfoLeak = "none": No kernel memory contents are leaked to userspace or external observers.
- RawDenialOfService = false: Without KCSAN, concurrent 2-byte accesses to inode->i_mode do not trigger a kernel panic, hang, deadlock, or resource leak.
- IsNetCandidate = false: The bug is in kernfs/VFS path lookup (openat and readlink by udevd) with no relation to networking.
- IsKVMCandidate = false: The bug and call traces have no relation to KVM, virtualization, or vhost/virtio.
Reply: ### Analysis Summary
* **Unprivileged (`true`)**:
The data race occurs in `kernfs_iop_permission()` (`fs/kernfs/inode.c:273-292`), which is assigned as the `.permission` inode operation for all kernfs inodes (`kernfs_iops`, `kernfs_dir_iops`, and `kernfs_symlink_iops` in `fs/kernfs/inode.c`, `fs/kernfs/dir.c`, and `fs/kernfs/symlink.c`).
- Kernel configuration has both `CONFIG_SYSFS=y` and `CONFIG_CGROUPS=y`, so `/sys` (sysfs) and `/sys/fs/cgroup` (cgroupfs) are mounted and expose world-traversable/readable directories, files, and symlinks to unprivileged users.
- During VFS path lookup (`link_path_walk()` -> `may_lookup()` -> `do_inode_permission()`), `kernfs_iop_permission()` returns `-ECHILD` when `MAY_NOT_BLOCK` is set (`LOOKUP_RCU`), causing `may_lookup()` (`fs/namei.c:1961-1983`) to drop out of RCU mode (`try_to_unlazy()`) and invoke `kernfs_iop_permission()` without `MAY_NOT_BLOCK`.
- No capabilities, root-only device nodes, or user namespaces are required: any unprivileged user running two concurrent threads or processes calling standard VFS syscalls (e.g., `openat()`, `readlink()`, `stat()`, or `access()`) on the same world-readable path in `/sys` or `/sys/fs/cgroup` will enter `kernfs_iop_permission()` concurrently under `down_read(&root->kernfs_iattr_rwsem)`, racing between `kernfs_refresh_inode()` writing `inode->i_mode` (`fs/kernfs/inode.c:169`) and `generic_permission()` -> `acl_permission_check()` reading `inode->i_mode` (`fs/namei.c:441`).
* **UserNamespace (`true`)**:
Since the bug is reachable directly by an unprivileged process without any namespace, `UserNamespace` is also `true`.
* **RequiredCaps (`[]`)**:
No capabilities are required along the unprivileged `/sys` lookup path.
* **PeripheralTrigger (`false`)**:
The race is triggered purely by concurrent VFS path lookups on kernfs/sysfs inodes and does not depend on parsing input from an untrusted physical peripheral device.
* **FilesystemTrigger (`false`)**:
Kernfs is an in-memory virtual filesystem infrastructure (used by sysfs/cgroupfs), not a disk/image-backed filesystem parser.
* **RawFuzzingArtifact (`false`)**:
This is a genuine KCSAN data race in `fs/kernfs/inode.c` reachable via normal unprivileged VFS syscalls on sysfs.
|
| 37/2 |
2026/11/19 20:49 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 7617
output: 154
thoughts: 167
Thoughts: **My Debugging Journey: Unraveling Concurrent Permission Checks in Kernfs**
My primary objective is to understand a specific bug related to concurrent permission checks within the `kernfs` subsystem. To achieve this, I'm initiating a systematic investigation, starting with the `kernfs_iop_permission` function itself, located in `fs/kernfs/inode.c`. My first step is to thoroughly examine its usage to ascertain which filesystems, such as `sysfs` and `cgroupfs`, rely on `kernfs`. Crucially, I need to determine if it's possible for an unprivileged user to trigger simultaneous calls to `kernfs_iop_permission` in a non-RCU (Read-Copy-Update) context, meaning without the `MAY_NOT_BLOCK` flag being set.
Following this, I'll dive deeper into the `fs/kernfs/inode.c` file, specifically focusing on the code section between lines 165 and 300. Simultaneously, I'll be cross-referencing this with `fs/namei.c`, paying close attention to functions like `do_inode_permission` and `may_lookup`. My goal here is to identify the precise circumstances under which `kernfs_iop_permission` is invoked without the `MAY_NOT_BLOCK` flag. This will illuminate the potential race conditions I'm trying to uncover.
|
| 38/2 |
2026/11/19 20:49 |
tool |
read-file |
0m
Args: map[File:fs/kernfs/inode.c FirstLine:160 LineCount:140]
Results: map[Contents: 160: inode_set_atime_to_ts(inode, attrs->ia_atime);
161: inode_set_mtime_to_ts(inode, attrs->ia_mtime);
162: inode_set_ctime_to_ts(inode, attrs->ia_ctime);
163: }
164:
165: static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
166: {
167: struct kernfs_iattrs *attrs;
168:
169: inode->i_mode = kn->mode;
170: attrs = kernfs_iattrs_noalloc(kn);
171: if (attrs)
172: /*
173: * kernfs_node has non-default attributes get them from
174: * persistent copy in kernfs_node.
175: */
176: set_inode_attr(inode, attrs);
177:
178: if (kernfs_type(kn) == KERNFS_DIR && !(kn->flags & KERNFS_REMOVING))
179: set_nlink(inode, kn->dir.subdirs + 2);
180: }
181:
182: int kernfs_iop_getattr(const struct mnt_idmap *idmap,
183: const struct path *path, struct kstat *stat,
184: u32 request_mask, unsigned int query_flags)
185: {
186: struct inode *inode = d_inode(path->dentry);
187: struct kernfs_node *kn = inode->i_private;
188: struct kernfs_root *root = kernfs_root(kn);
189:
190: down_read(&root->kernfs_iattr_rwsem);
191: kernfs_refresh_inode(kn, inode);
192: generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
193: up_read(&root->kernfs_iattr_rwsem);
194:
195: return 0;
196: }
197:
198: static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
199: {
200: kernfs_get(kn);
201: inode->i_private = kn;
202: inode->i_mapping->a_ops = &ram_aops;
203: inode->i_op = &kernfs_iops;
204: inode->i_generation = kernfs_gen(kn);
205:
206: set_default_inode_attr(inode, kn->mode);
207: kernfs_refresh_inode(kn, inode);
208:
209: /* initialize inode according to type */
210: switch (kernfs_type(kn)) {
211: case KERNFS_DIR:
212: inode->i_op = &kernfs_dir_iops;
213: inode->i_fop = &kernfs_dir_fops;
214: if (kn->flags & KERNFS_EMPTY_DIR)
215: make_empty_dir_inode(inode);
216: break;
217: case KERNFS_FILE:
218: inode->i_size = kn->attr.size;
219: inode->i_fop = &kernfs_file_fops;
220: break;
221: case KERNFS_LINK:
222: inode->i_op = &kernfs_symlink_iops;
223: break;
224: default:
225: BUG();
226: }
227:
228: unlock_new_inode(inode);
229: }
230:
231: /**
232: * kernfs_get_inode - get inode for kernfs_node
233: * @sb: super block
234: * @kn: kernfs_node to allocate inode for
235: *
236: * Get inode for @kn. If such inode doesn't exist, a new inode is
237: * allocated and basics are initialized. New inode is returned
238: * locked.
239: *
240: * Locking:
241: * Kernel thread context (may sleep).
242: *
243: * Return:
244: * Pointer to allocated inode on success, %NULL on failure.
245: */
246: struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
247: {
248: struct inode *inode;
249:
250: inode = iget_locked(sb, kernfs_ino(kn));
251: if (inode && (inode_state_read_once(inode) & I_NEW))
252: kernfs_init_inode(kn, inode);
253:
254: return inode;
255: }
256:
257: /*
258: * The kernfs_node serves as both an inode and a directory entry for
259: * kernfs. To prevent the kernfs inode numbers from being freed
]
|
| 39/2 |
2026/11/19 20:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:do_inode_permission]
Results: map[SourceCode: 567: /**
568: * do_inode_permission - UNIX permission checking
569: * @idmap: idmap of the mount the inode was found from
570: * @inode: inode to check permissions on
571: * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC ...)
572: *
573: * We _really_ want to just do "generic_permission()" without
574: * even looking at the inode->i_op values. So we keep a cache
575: * flag in inode->i_opflags, that says "this has not special
576: * permission function, use the fast case".
577: */
578: static inline int do_inode_permission(const struct mnt_idmap *idmap,
579: struct inode *inode, int mask)
580: {
581: if (unlikely(!(inode->i_opflags & IOP_FASTPERM))) {
582: if (likely(inode->i_op->permission))
583: return inode->i_op->permission(idmap, inode, mask);
584:
585: /* This gets set once for the inode lifetime */
586: spin_lock(&inode->i_lock);
587: inode->i_opflags |= IOP_FASTPERM;
588: spin_unlock(&inode->i_lock);
589: }
590: return generic_permission(idmap, inode, mask);
591: }
SourceFile:fs/namei.c]
|
| 40/2 |
2026/11/19 20:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:may_lookup]
Results: map[SourceCode:1961: static inline int may_lookup(const struct mnt_idmap *idmap,
1962: struct nameidata *restrict nd)
1963: {
1964: int err, mask;
1965:
1966: mask = nd->flags & LOOKUP_RCU ? MAY_NOT_BLOCK : 0;
1967: err = lookup_inode_permission_may_exec(idmap, nd->inode, mask);
1968: if (likely(!err))
1969: return 0;
1970:
1971: // If we failed, and we weren't in LOOKUP_RCU, it's final
1972: if (!(nd->flags & LOOKUP_RCU))
1973: return err;
1974:
1975: // Drop out of RCU mode to make sure it wasn't transient
1976: if (!try_to_unlazy(nd))
1977: return -ECHILD; // redo it all non-lazy
1978:
1979: if (err != -ECHILD) // hard error
1980: return err;
1981:
1982: return lookup_inode_permission_may_exec(idmap, nd->inode, 0);
1983: }
SourceFile:fs/namei.c]
|
| 41/2 |
2026/11/19 20:49 |
tool |
codesearch-find-references |
0m
Error:
Args: map[IncludeSnippetLines:0 Name:kernfs_mount_ns SourceTreePrefix:]
Results: map[References:<nil> TruncatedOutput:false]
|
| 42/2 |
2026/11/19 20:49 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 10358
output: 107
thoughts: 69
Thoughts: **Investigating Kernfs Inode Operations and Usage**
My current focus is on deepening my understanding of the `kernfs` subsystem, specifically by examining its inode operations. To that end, I'm intending to review lines 260-310 of `fs/kernfs/inode.c`. This section is likely to contain critical logic for how `kernfs` manages its inodes, and I want to ensure I have a firm grasp of those details.
Concurrently, I need to identify which filesystems are actually leveraging `kernfs`. My plan is to investigate the `kernfs_mount` and `kernfs_get_tree` functions for this purpose. By tracing their usage, I should be able to pinpoint the specific filesystems that integrate with `kernfs`.
Finally, to contextualize `kernfs`'s role within the broader kernel infrastructure, I intend to cross-reference its usage with configuration options for well-known users such as `sysfs` and `cgroup`. Understanding how these systems are configured to utilize `kernfs` will provide valuable insights into its operational scope and its importance in managing kernel-related information hierarchies.
|
| 43/2 |
2026/11/19 20:49 |
tool |
read-file |
0m
Args: map[File:fs/kernfs/inode.c FirstLine:260 LineCount:50]
Results: map[Contents: 260: * prematurely we take a reference to kernfs_node from the kernfs inode. A
261: * super_operations.evict_inode() implementation is needed to drop that
262: * reference upon inode destruction.
263: */
264: void kernfs_evict_inode(struct inode *inode)
265: {
266: struct kernfs_node *kn = inode->i_private;
267:
268: truncate_inode_pages_final(&inode->i_data);
269: clear_inode(inode);
270: kernfs_put(kn);
271: }
272:
273: int kernfs_iop_permission(const struct mnt_idmap *idmap,
274: struct inode *inode, int mask)
275: {
276: struct kernfs_node *kn;
277: struct kernfs_root *root;
278: int ret;
279:
280: if (mask & MAY_NOT_BLOCK)
281: return -ECHILD;
282:
283: kn = inode->i_private;
284: root = kernfs_root(kn);
285:
286: down_read(&root->kernfs_iattr_rwsem);
287: kernfs_refresh_inode(kn, inode);
288: ret = generic_permission(&nop_mnt_idmap, inode, mask);
289: up_read(&root->kernfs_iattr_rwsem);
290:
291: return ret;
292: }
293:
294: int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
295: void *value, size_t size)
296: {
297: struct kernfs_iattrs *attrs = kernfs_iattrs_noalloc(kn);
298: struct simple_xattr_cache *cache = &kernfs_root(kn)->xa_cache;
299:
300: if (!attrs)
301: return -ENODATA;
302:
303: return simple_xattr_get(cache, &attrs->xattrs, name, value, size);
304: }
305:
306: int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
307: const void *value, size_t size, int flags)
308: {
309: struct simple_xattr *old_xattr;
]
|
| 44/2 |
2026/11/19 20:49 |
tool |
kernel-config-grep |
0m
Args:
Results: map[Output:# CONFIG_SYSFS_SYSCALL is not set
# CONFIG_DMI_SYSFS is not set
# CONFIG_FW_CFG_SYSFS is not set
# CONFIG_ISCSI_BOOT_SYSFS is not set
# CONFIG_GPIO_SYSFS is not set
# CONFIG_WATCHDOG_SYSFS is not set
CONFIG_VIDEO_PVRUSB2_SYSFS=y
CONFIG_RTC_INTF_SYSFS=y
# CONFIG_CROS_EC_SYSFS is not set
# CONFIG_IIO_SYSFS_TRIGGER is not set
CONFIG_NVMEM_SYSFS=y
CONFIG_SYSFS=y
]
|
| 45/2 |
2026/11/19 20:49 |
tool |
kernel-config-grep |
0m
Args:
Results: map[Output:CONFIG_CGROUPS=y
# CONFIG_CGROUP_FAVOR_DYNMODS is not set
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_WRITEBACK=y
CONFIG_CGROUP_SCHED=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_RDMA=y
# CONFIG_CGROUP_DMEM is not set
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_HUGETLB=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_PERF=y
# CONFIG_CGROUP_BPF is not set
CONFIG_CGROUP_MISC=y
CONFIG_CGROUP_DEBUG=y
CONFIG_SOCK_CGROUP_DATA=y
CONFIG_BLK_CGROUP_IOLATENCY=y
CONFIG_BLK_CGROUP_IOCOST=y
CONFIG_BLK_CGROUP_IOPRIO=y
CONFIG_NETFILTER_XT_MATCH_CGROUP=y
CONFIG_NET_CLS_CGROUP=y
CONFIG_CGROUP_NET_PRIO=y
CONFIG_CGROUP_NET_CLASSID=y
]
|
| 46/2 |
2026/11/19 20:49 |
tool |
kernel-config-grep |
0m
Args: map[Query:CONFIG_CMDLINE]
Results: map[Output:CONFIG_CMDLINE_LOG_WRAP_IDEAL_LEN=1021
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="earlyprintk=serial net.ifnames=0 sysctl.kernel.hung_task_all_cpu_backtrace=1 ima_policy=tcb nf-conntrack-ftp.ports=20000 nf-conntrack-tftp.ports=20000 nf-conntrack-sip.ports=20000 nf-conntrack-irc.ports=20000 nf-conntrack-sane.ports=20000 binder.debug_mask=0 rcupdate.rcu_expedited=1 rcupdate.rcu_cpu_stall_cputime=1 no_hash_pointers page_owner=on sysctl.vm.nr_hugepages=4 sysctl.vm.nr_overcommit_hugepages=4 secretmem.enable=1 sysctl.max_rcu_stall_to_panic=1 msr.allow_writes=off coredump_filter=0xffff root=/dev/sda console=ttyS0 vsyscall=native numa=fake=2 kvm-intel.nested=1 spec_store_bypass_disable=prctl nopcid vivid.n_devs=64 vivid.multiplanar=1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2 netrom.nr_ndevs=32 rose.rose_ndevs=32 smp.csd_lock_timeout=100000 watchdog_thresh=55 workqueue.watchdog_thresh=140 sysctl.net.core.netdev_unregister_timeout_secs=140 dummy_hcd.num=32 max_loop=32 nbds_max=32"
# CONFIG_CMDLINE_OVERRIDE is not set
]
|
| 47/2 |
2026/11/19 20:49 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 12284
output: 106
thoughts: 631
Thoughts: **My Revelations on Kernfs Permission Handling**
It's truly remarkable how elegantly this kernfs permission mechanism unfolds. I've been looking at the various operations that trigger `kernfs_iop_permission` – things like `openat`, `stat`, `readlink`, and `access` – when dealing with any filesystem backed by kernfs, such as `/sys` (sysfs) or `/sys/fs/cgroup` (cgroupfs).
The initial observation is that `kernfs_iop_permission` will return `-ECHILD` if the operation is being performed under RCU (`mask & MAY_NOT_BLOCK`). This immediately makes me think about how lookups are handled.
Digging into `may_lookup` in `fs/namei.c`, the first thing it does is call `lookup_inode_permission_may_exec(idmap, nd->inode, MAY_NOT_BLOCK)`. As expected, `kernfs_iop_permission` returns that `-ECHILD` because of the RCU context. But here's the crucial part: `may_lookup` doesn't just stop there. It then calls `try_to_unlazy(nd)` to gracefully exit RCU mode. *After* that, it makes a second call to `lookup_inode_permission_may_exec(idmap, nd->inode, 0)`. This second call, which is no longer under RCU, eventually leads to `kernfs_iop_permission(idmap, inode, 0)` being invoked, and this time, it will actually proceed because `MAY_NOT_BLOCK` is not set.
This process is also relevant for any non-RCU lookup operation on paths within `/sys` (or `/sys/fs/cgroup`). Since many of these directories and files are world-readable, operations like `openat`, `stat`, `access`, and `readlinkat` on `/sys/kernel/...`, `/sys/class/...`, or `/sys/devices/...` will all eventually hit `kernfs_iop_permission()`.
Now, where things get particularly interesting is when two unprivileged processes, or even threads within the same unprivileged process, try to perform these operations concurrently on the same path in sysfs or cgroupfs. Both will enter `kernfs_iop_permission()` while holding `down_read(&root->kernfs_iattr_rwsem)`. In this scenario, one thread might execute `kernfs_refresh_inode(kn, inode)`, which updates `inode->i_mode` with `kn->mode`. Simultaneously, the other thread might be in `generic_permission()` which calls `acl_permission_check()`, and this function reads `inode->i_mode`. Alternatively, both threads could be attempting `kernfs_refresh_inode` themselves. This potential for concurrent modification and reading of `inode->i_mode` within a locked section is something I need to scrutinize further to ensure no race conditions exist.
To confirm my understanding of sysfs accessibility and its use of kernfs, I plan to verify that `/sys` is indeed accessible by unprivileged users and to double-check that `kernfs_iops`, `kernfs_dir_iops`, or `kernfs_symlink_iops` are indeed being employed by sysfs. I'll be looking at `fs/sysfs/mount.c` and performing a grep for `kernfs_` within `fs/sysfs/`.
|
| 48/2 |
2026/11/19 20:49 |
tool |
grepper |
0m
Args: map[Expression:kernfs_iop_permission|kernfs_dir_iops|kernfs_iops|kernfs_symlink_iops PathPrefixes:[fs/kernfs/ fs/sysfs/]]
Results: map[Output:fs/kernfs/dir.c=1328=static int kernfs_iop_rename(const struct mnt_idmap *idmap,
--
fs/kernfs/dir.c-1358-
fs/kernfs/dir.c:1359:const struct inode_operations kernfs_dir_iops = {
fs/kernfs/dir.c-1360- .lookup = kernfs_iop_lookup,
fs/kernfs/dir.c:1361: .permission = kernfs_iop_permission,
fs/kernfs/dir.c-1362- .setattr = kernfs_iop_setattr,
--
fs/kernfs/inode.c-19-
fs/kernfs/inode.c:20:static const struct inode_operations kernfs_iops = {
fs/kernfs/inode.c:21: .permission = kernfs_iop_permission,
fs/kernfs/inode.c-22- .setattr = kernfs_iop_setattr,
--
fs/kernfs/inode.c=198=static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
--
fs/kernfs/inode.c-202- inode->i_mapping->a_ops = &ram_aops;
fs/kernfs/inode.c:203: inode->i_op = &kernfs_iops;
fs/kernfs/inode.c-204- inode->i_generation = kernfs_gen(kn);
--
fs/kernfs/inode.c-211- case KERNFS_DIR:
fs/kernfs/inode.c:212: inode->i_op = &kernfs_dir_iops;
fs/kernfs/inode.c-213- inode->i_fop = &kernfs_dir_fops;
--
fs/kernfs/inode.c-221- case KERNFS_LINK:
fs/kernfs/inode.c:222: inode->i_op = &kernfs_symlink_iops;
fs/kernfs/inode.c-223- break;
--
fs/kernfs/inode.c=264=void kernfs_evict_inode(struct inode *inode)
--
fs/kernfs/inode.c-272-
fs/kernfs/inode.c:273:int kernfs_iop_permission(const struct mnt_idmap *idmap,
fs/kernfs/inode.c-274- struct inode *inode, int mask)
--
fs/kernfs/kernfs-internal.h=179=void kernfs_evict_inode(struct inode *inode);
fs/kernfs/kernfs-internal.h:180:int kernfs_iop_permission(const struct mnt_idmap *idmap,
fs/kernfs/kernfs-internal.h-181- struct inode *inode, int mask);
--
fs/kernfs/kernfs-internal.h=194=extern const struct file_operations kernfs_dir_fops;
fs/kernfs/kernfs-internal.h:195:extern const struct inode_operations kernfs_dir_iops;
fs/kernfs/kernfs-internal.h-196-
--
fs/kernfs/kernfs-internal.h=211=void kernfs_drain_open_files(struct kernfs_node *kn);
--
fs/kernfs/kernfs-internal.h-215- */
fs/kernfs/kernfs-internal.h:216:extern const struct inode_operations kernfs_symlink_iops;
fs/kernfs/kernfs-internal.h-217-
--
fs/kernfs/symlink.c=139=static const char *kernfs_iop_get_link(struct dentry *dentry,
--
fs/kernfs/symlink.c-159-
fs/kernfs/symlink.c:160:const struct inode_operations kernfs_symlink_iops = {
fs/kernfs/symlink.c-161- .listxattr = kernfs_iop_listxattr,
--
fs/kernfs/symlink.c-164- .getattr = kernfs_iop_getattr,
fs/kernfs/symlink.c:165: .permission = kernfs_iop_permission,
fs/kernfs/symlink.c-166-};
]
|
| 49/2 |
2026/11/19 20:49 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:0 Name:kernfs_iop_permission SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_dir_iops SourceFile:fs/kernfs/dir.c SourceLine:1361] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_iops SourceFile:fs/kernfs/inode.c SourceLine:21] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:kernfs_symlink_iops SourceFile:fs/kernfs/symlink.c SourceLine:165]] TruncatedOutput:false]
|
| 50/2 |
2026/11/19 20:49 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 14331
output: 78
thoughts: 51
Thoughts: **Verifying Sysfs Mount Permissions**
Okay, so my immediate thought is to go poke around in the kernel source code, specifically in `fs/sysfs/mount.c`. I'm doing this as a sanity check, just to confirm my understanding of how sysfs is mounted. My hypothesis is that the root directory of sysfs, which is mounted on `/sys`, will have fairly permissive access rights – I'm expecting something like `0755` or equivalent. This means it should be world-readable and traversable, so any user can `cd` into it and list its contents. Crucially, I also want to verify that there aren't any special security capabilities or elevated privileges required for a process to access `/sys` in the first place. This is a fundamental aspect of how `/sys` operates, and I want to be absolutely certain it's configured as expected.
|
| 51/2 |
2026/11/19 20:49 |
tool |
read-file |
0m
Args: map[File:fs/sysfs/mount.c FirstLine:1 LineCount:100]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0
2: /*
3: * fs/sysfs/symlink.c - operations for initializing and mounting sysfs
4: *
5: * Copyright (c) 2001-3 Patrick Mochel
6: * Copyright (c) 2007 SUSE Linux Products GmbH
7: * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
8: *
9: * Please see Documentation/filesystems/sysfs.rst for more information.
10: */
11:
12: #include <linux/fs.h>
13: #include <linux/magic.h>
14: #include <linux/mount.h>
15: #include <linux/init.h>
16: #include <linux/slab.h>
17: #include <linux/user_namespace.h>
18: #include <linux/fs_context.h>
19: #include <net/net_namespace.h>
20:
21: #include "sysfs.h"
22:
23: static struct kernfs_root *sysfs_root;
24: struct kernfs_node *sysfs_root_kn;
25:
26: static void sysfs_fs_context_free(struct fs_context *fc)
27: {
28: struct kernfs_fs_context *kfc = fc->fs_private;
29:
30: if (kfc->ns_tag)
31: kobj_ns_drop(KOBJ_NS_TYPE_NET, kfc->ns_tag);
32: kernfs_free_fs_context(fc);
33: kfree(kfc);
34: }
35:
36: static const struct fs_context_operations sysfs_fs_context_ops = {
37: .free = sysfs_fs_context_free,
38: .get_tree = kernfs_get_tree,
39: };
40:
41: static int sysfs_init_fs_context(struct fs_context *fc)
42: {
43: struct kernfs_fs_context *kfc;
44: struct ns_common *ns;
45:
46: if (!(fc->sb_flags & SB_KERNMOUNT)) {
47: if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
48: return -EPERM;
49: }
50:
51: kfc = kzalloc_obj(struct kernfs_fs_context);
52: if (!kfc)
53: return -ENOMEM;
54:
55: kfc->ns_tag = ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
56: kfc->root = sysfs_root;
57: kfc->magic = SYSFS_MAGIC;
58: fc->fs_private = kfc;
59: fc->ops = &sysfs_fs_context_ops;
60: if (ns) {
61: struct net *netns = to_net_ns(ns);
62:
63: put_user_ns(fc->user_ns);
64: fc->user_ns = get_user_ns(netns->user_ns);
65: }
66: fc->global = true;
67: return 0;
68: }
69:
70: static void sysfs_kill_sb(struct super_block *sb)
71: {
72: struct ns_common *ns = (struct ns_common *)kernfs_super_ns(sb);
73:
74: kernfs_kill_sb(sb);
75: kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
76: }
77:
78: static struct file_system_type sysfs_fs_type = {
79: .name = "sysfs",
80: .init_fs_context = sysfs_init_fs_context,
81: .kill_sb = sysfs_kill_sb,
82: .fs_flags = FS_USERNS_MOUNT | FS_USERNS_MOUNT_RESTRICTED,
83: };
84:
85: int __init sysfs_init(void)
86: {
87: int err;
88:
89: sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
90: NULL);
91: if (IS_ERR(sysfs_root))
92: return PTR_ERR(sysfs_root);
93:
94: sysfs_root_kn = kernfs_root_to_node(sysfs_root);
95:
96: err = register_filesystem(&sysfs_fs_type);
97: if (err) {
98: kernfs_destroy_root(sysfs_root);
99: return err;
100: }
]
|
| 52/2 |
2026/11/19 20:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:acl_permission_check]
Results: map[SourceCode: 422: /**
423: * acl_permission_check - perform basic UNIX permission checking
424: * @idmap: idmap of the mount the inode was found from
425: * @inode: inode to check permissions on
426: * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC ...)
427: *
428: * This function performs the basic UNIX permission checking. Since this
429: * function may retrieve POSIX acls it needs to know whether it is called from a
430: * blocking or non-blocking context and thus cares about the MAY_NOT_BLOCK bit.
431: *
432: * If the inode has been found through an idmapped mount the idmap of
433: * the vfsmount must be passed through @idmap. This function will then take
434: * care to map the inode according to @idmap before checking permissions.
435: * On non-idmapped mounts or if permission checking is to be performed on the
436: * raw inode simply pass @nop_mnt_idmap.
437: */
438: static int acl_permission_check(const struct mnt_idmap *idmap,
439: struct inode *inode, int mask)
440: {
441: unsigned int mode = inode->i_mode;
442: vfsuid_t vfsuid;
443:
444: /*
445: * Common cheap case: everybody has the requested
446: * rights, and there are no ACLs to check. No need
447: * to do any owner/group checks in that case.
448: *
449: * - 'mask&7' is the requested permission bit set
450: * - multiplying by 0111 spreads them out to all of ugo
451: * - '& ~mode' looks for missing inode permission bits
452: * - the '!' is for "no missing permissions"
453: *
454: * After that, we just need to check that there are no
455: * ACL's on the inode - do the 'IS_POSIXACL()' check last
456: * because it will dereference the ->i_sb pointer and we
457: * want to avoid that if at all possible.
458: */
459: if (!((mask & 7) * 0111 & ~mode)) {
460: if (no_acl_inode(inode))
461: return 0;
462: if (!IS_POSIXACL(inode))
463: return 0;
464: }
465:
466: /* Are we the owner? If so, ACL's don't matter */
467: vfsuid = i_uid_into_vfsuid(idmap, inode);
468: if (likely(vfsuid_eq_kuid(vfsuid, current_fsuid()))) {
469: mask &= 7;
470: mode >>= 6;
471: return (mask & ~mode) ? -EACCES : 0;
472: }
473:
474: /* Do we have ACL's? */
475: if (IS_POSIXACL(inode) && (mode & S_IRWXG)) {
476: int error = check_acl(idmap, inode, mask);
477: if (error != -EAGAIN)
478: return error;
479: }
480:
481: /* Only RWX matters for group/other mode bits */
482: mask &= 7;
483:
484: /*
485: * Are the group permissions different from
486: * the other permissions in the bits we care
487: * about? Need to check group ownership if so.
488: */
489: if (mask & (mode ^ (mode >> 3))) {
490: vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
491: if (vfsgid_in_group_p(vfsgid))
492: mode >>= 3;
493: }
494:
495: /* Bits in 'mode' clear that we require? */
496: return (mask & ~mode) ? -EACCES : 0;
497: }
SourceFile:fs/namei.c]
|
| 53/2 |
2026/11/19 20:49 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 17196
output: 47
thoughts: 753
Thoughts: **My Thought Process on Analyzing the Sysfs/Kernfs Vulnerability**
Okay, let's break down my analysis of this sysfs/kernfs issue step-by-step, focusing on the key attributes.
First, the most crucial question is: **`Unprivileged`**: Can a regular, unprivileged user trigger this without needing any special permissions, root access, or even user namespaces? My analysis says an emphatic **yes**. Here's why: standard Linux systems, with sysfs and cgroups enabled (which they almost always are), mount `/sys` at boot. This mount is world-readable and traversable. So, any user can spawn two threads or processes. If these concurrently try to `openat()` a read-only file in `/sys`, or use `readlink()` or `stat()` on a world-readable entry, they can hit this race condition. The path traversal mechanism (`link_path_walk()`) is key here. Initially, it tries a fast, non-blocking permission check (`kernfs_iop_permission()` with `LOOKUP_RCU`). If that fails (returning `-ECHILD`), it falls back to a blocking mode. Now, imagine two threads doing this simultaneously. Both grab a read lock (`down_read`) on the same inode. One thread might be busy refreshing the inode's attributes (`kernfs_refresh_inode`), writing its mode, while the other is simultaneously trying to check permissions (`generic_permission` -> `acl_permission_check`), reading that *same* mode. This is a classic race condition, hence, `Unprivileged = true`.
Second, following from the `Unprivileged` finding, it logically follows that **`UserNamespace`**: If an unprivileged user can trigger it, then user namespaces are definitely involved in the exploit chain. So, `UserNamespace = true`.
Third, **`RequiredCaps`**: Because an unprivileged user can trigger this, no special capabilities are needed. Therefore, `RequiredCaps = []`.
Fourth, **`PeripheralTrigger`**: Does this require a physical device to be plugged in? My thought is **no**. The trigger is purely within the virtual file system (VFS) layer and kernfs itself, through concurrent system calls on `/sys`. While `udevd` might react to a peripheral hotplug by reading `/sys`, that's just normal sysfs activity. The peripheral itself isn't injecting bad data into `kernfs_iop_permission`. The vulnerability is a locking issue in path lookups, not a device driver mishandling peripheral input. So, `PeripheralTrigger = false`.
Fifth, **`FilesystemTrigger`**: Is this about a kernel mounting and parsing a malicious filesystem image? Again, my answer is **no**. Kernfs is an in-memory pseudo-filesystem, like sysfs or cgroupfs. It doesn't parse on-disk filesystem images. So, `FilesystemTrigger = false`.
Sixth, **`RawFuzzingArtifact`**: This is a genuine data race detected by KCSAN, located in `fs/kernfs/inode.c`, specifically within `kernfs_iop_permission`. It's a real bug, not something generated by a fuzzy input artifact. Therefore, `RawFuzzingArtifact = false`.
With these attributes confirmed, I'm ready to finalize the results and articulate a clear explanation.
|
| 54/2 |
2026/11/19 20:50 |
tool |
set-results |
0m
Args: map[FilesystemTrigger:false PeripheralTrigger:false RawFuzzingArtifact:false RequiredCaps:[] Unprivileged:true UserNamespace:true]
Results: map[FilesystemTrigger:false PeripheralTrigger:false RawFuzzingArtifact:false RequiredCaps:<nil> Unprivileged:true UserNamespace:true]
|
| 55/2 |
2026/11/19 20:50 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 18041
output: 669
thoughts: 21
Thoughts: **My Thought Process: Finalizing and Presenting the Response**
Alright, everything's been thoroughly checked and cross-referenced. I've confirmed all the data points, validated the analytical steps, and I'm satisfied with the outcome. The `set-results` command has been executed, meaning the definitive findings are now locked in and ready for dissemination. My task now is to articulate these conclusions clearly and comprehensively, ensuring the depth and nuance befitting your expertise. I will proceed with presenting our final response.
|
| 56/1 |
2026/11/19 20:50 |
action |
If |
0m
Args: map[IsNetCandidate:false]
|
| 57/1 |
2026/11/19 20:50 |
action |
If |
0m
Args: map[IsKVMCandidate:false]
|
| 58/1 |
2026/11/19 20:50 |
action |
combine-assessment |
0m
Results: map[DenialOfService:false Explanation:Root Cause Analysis:
### Root Cause Analysis
The KCSAN data race occurs because `kernfs_iop_permission()` in
`fs/kernfs/inode.c` mutates fields of the shared VFS `struct inode` while
holding only a shared reader lock (`down_read(&root->kernfs_iattr_rwsem)`),
allowing concurrent VFS lookups on the same kernfs node to read and write
`inode->i_mode` without synchronization.
#### Technical Mechanism
1. **Shared locking in `kernfs_iop_permission()`
(`fs/kernfs/inode.c:273-292`)**:
- When VFS path traversal (`link_path_walk()` -> `may_lookup()` ->
`inode_permission()` -> `do_inode_permission()`) checks permissions on a
kernfs inode (in non-RCU mode, i.e., without `MAY_NOT_BLOCK`), it invokes
`inode->i_op->permission`, which points to `kernfs_iop_permission()`
(registered in `kernfs_iops`, `kernfs_dir_iops`, and `kernfs_symlink_iops`).
- `kernfs_iop_permission()` acquires `root->kernfs_iattr_rwsem` for reading:
```c
down_read(&root->kernfs_iattr_rwsem);
kernfs_refresh_inode(kn, inode);
ret = generic_permission(&nop_mnt_idmap, inode, mask);
up_read(&root->kernfs_iattr_rwsem);
```
- `kernfs_iop_getattr()` (`fs/kernfs/inode.c:182-196`) follows the same
pattern, calling `kernfs_refresh_inode()` and `generic_fillattr()` under
`down_read(&root->kernfs_iattr_rwsem)`.
2. **Unprotected writes in `kernfs_refresh_inode()`
(`fs/kernfs/inode.c:165-180`)**:
- Because `root->kernfs_iattr_rwsem` is only acquired for reading, multiple
tasks can enter `kernfs_iop_permission()` (and `kernfs_iop_getattr()`)
simultaneously for the same `struct kernfs_node` (`kn`) and `struct inode`
(`inode`).
- `kernfs_refresh_inode()` unconditionally performs plain (non-atomic) writes
to `inode` fields:
- `inode->i_mode = kn->mode;` (`fs/kernfs/inode.c:169`), a 2-byte `umode_t`
write at offset 0 of `struct inode`.
- `set_inode_attr(inode, attrs);` (`fs/kernfs/inode.c:176`), which writes
`inode->i_uid`, `inode->i_gid`, and timestamps.
- `set_nlink(inode, kn->dir.subdirs + 2);` (`fs/kernfs/inode.c:179`), which
writes `inode->__i_nlink` for active directories.
3. **Concurrent read in `generic_permission()` / `acl_permission_check()`
(`fs/namei.c:438-531`)**:
- After `kernfs_refresh_inode()`, `kernfs_iop_permission()` calls
`generic_permission(&nop_mnt_idmap, inode, mask)` (`fs/kernfs/inode.c:288`),
which calls `acl_permission_check()` (`fs/namei.c:529`).
- `acl_permission_check()` performs a plain 2-byte read of `inode->i_mode`
(`unsigned int mode = inode->i_mode;` at `fs/namei.c:441`) and may also read
`inode->i_uid` and `inode->i_gid`.
- In the reported trace, Task 3731 (`openat` -> `kernfs_iop_permission()` ->
`kernfs_refresh_inode()` at `fs/kernfs/inode.c:169`) writes 2 bytes to
`inode->i_mode` (`0xffff888107516f88`) concurrently with Task 3010
(`readlink` -> `kernfs_iop_permission()` -> `generic_permission()` ->
`acl_permission_check()` at `fs/namei.c:441`) reading those 2 bytes.
#### Lifecycle and Invariants
- Modifications to `kn->mode` (via `__kernfs_setattr()` in `kernfs_setattr()` /
`kernfs_iop_setattr()`) and `kn->iattr` attributes are serialized under
`down_write(&root->kernfs_iattr_rwsem)`.
- `kernfs_iattr_rwsem` protects the `kernfs_node` attributes against concurrent
`setattr`, but it does **not** serialize the copy/refresh of those attributes
from `kn` into the VFS `struct inode`, nor does `kernfs_iop_permission()` hold
`inode->i_lock` or `inode->i_rwsem` exclusively. Consequently, any two
concurrent readers executing `kernfs_iop_permission()` or `kernfs_iop_getattr()`
on the same kernfs inode violate the C memory model invariant against
unsynchronized concurrent read/write (and write/write) accesses to
`inode->i_mode` (as well as `i_uid`, `i_gid`, and `__i_nlink`).
Impact Analysis:
In real-world setups without KCSAN, this data race is benign. While multiple
threads execute kernfs_iop_permission() (and kernfs_iop_getattr()) concurrently
under down_read(&root->kernfs_iattr_rwsem), any modifications to kn->mode or
kernfs_iattrs take down_write(&root->kernfs_iattr_rwsem). As a result, kn->mode
(and uid/gid/nlink/timestamps) remain constant across all concurrent readers, so
kernfs_refresh_inode() repeatedly writes the exact same 2-byte kn->mode value to
inode->i_mode. Even if kn->mode was updated in an earlier kernfs_setattr() and
two readers race to refresh inode->i_mode, both write the identical new value to
a naturally aligned 16-bit field (inode->i_mode at offset 0 of struct inode),
and acl_permission_check() observes either the old or new valid mode bits
without crashing, hanging, or corrupting adjacent fields or pointers.
Classification reasoning:
- MemoryCorruption = false: The race involves plain accesses to inode->i_mode (a
2-byte umode_t permission/type mask) writing identical values; it does not
corrupt pointers, refcounts, buffer lengths, or control flow.
- InfoLeak = "none": No kernel memory contents are leaked to userspace or
external observers.
- RawDenialOfService = false: Without KCSAN, concurrent 2-byte accesses to
inode->i_mode do not trigger a kernel panic, hang, deadlock, or resource leak.
- IsNetCandidate = false: The bug is in kernfs/VFS path lookup (openat and
readlink by udevd) with no relation to networking.
- IsKVMCandidate = false: The bug and call traces have no relation to KVM,
virtualization, or vhost/virtio.
Local Reachability Analysis:
### Analysis Summary
* **Unprivileged (`true`)**:
The data race occurs in `kernfs_iop_permission()`
(`fs/kernfs/inode.c:273-292`), which is assigned as the `.permission` inode
operation for all kernfs inodes (`kernfs_iops`, `kernfs_dir_iops`, and
`kernfs_symlink_iops` in `fs/kernfs/inode.c`, `fs/kernfs/dir.c`, and
`fs/kernfs/symlink.c`).
- Kernel configuration has both `CONFIG_SYSFS=y` and `CONFIG_CGROUPS=y`, so
`/sys` (sysfs) and `/sys/fs/cgroup` (cgroupfs) are mounted and expose
world-traversable/readable directories, files, and symlinks to unprivileged
users.
- During VFS path lookup (`link_path_walk()` -> `may_lookup()` ->
`do_inode_permission()`), `kernfs_iop_permission()` returns `-ECHILD` when
`MAY_NOT_BLOCK` is set (`LOOKUP_RCU`), causing `may_lookup()`
(`fs/namei.c:1961-1983`) to drop out of RCU mode (`try_to_unlazy()`) and
invoke `kernfs_iop_permission()` without `MAY_NOT_BLOCK`.
- No capabilities, root-only device nodes, or user namespaces are required:
any unprivileged user running two concurrent threads or processes calling
standard VFS syscalls (e.g., `openat()`, `readlink()`, `stat()`, or
`access()`) on the same world-readable path in `/sys` or `/sys/fs/cgroup` will
enter `kernfs_iop_permission()` concurrently under
`down_read(&root->kernfs_iattr_rwsem)`, racing between
`kernfs_refresh_inode()` writing `inode->i_mode` (`fs/kernfs/inode.c:169`) and
`generic_permission()` -> `acl_permission_check()` reading `inode->i_mode`
(`fs/namei.c:441`).
* **UserNamespace (`true`)**:
Since the bug is reachable directly by an unprivileged process without any
namespace, `UserNamespace` is also `true`.
* **RequiredCaps (`[]`)**:
No capabilities are required along the unprivileged `/sys` lookup path.
* **PeripheralTrigger (`false`)**:
The race is triggered purely by concurrent VFS path lookups on kernfs/sysfs
inodes and does not depend on parsing input from an untrusted physical
peripheral device.
* **FilesystemTrigger (`false`)**:
Kernfs is an in-memory virtual filesystem infrastructure (used by
sysfs/cgroupfs), not a disk/image-backed filesystem parser.
* **RawFuzzingArtifact (`false`)**:
This is a genuine KCSAN data race in `fs/kernfs/inode.c` reachable via normal
unprivileged VFS syscalls on sysfs. Exploitable:false FuzzingArtifact:false]
|