| 0/0 |
2026/12/02 14:56 |
flow |
assessment-security |
2m
Results: map[DenialOfService:false Explanation:Root Cause Analysis:
### Root Cause Analysis
The KCSAN data race occurs on the 4-byte `sid` field (`u32 sid`, offset 28
bytes) of `struct inode_security_struct`
(`security/selinux/include/objsec.h:72-80`) between concurrent `/proc/<pid>`
dentry revalidation and inode permission checks during VFS path lookup.
#### 1. Writer path (`selinux_task_to_inode`)
When a task walks `/proc/<pid>`, `lookup_fast()` (`fs/namei.c:1874`) invokes
`d_revalidate()` -> `pid_revalidate()` (`fs/proc/base.c:2043-2063`) ->
`pid_update_inode()` (`fs/proc/base.c:2030-2036`) -> `security_task_to_inode()`
-> `selinux_task_to_inode()` (`security/selinux/hooks.c:4732-4743`):
```c
static void selinux_task_to_inode(struct task_struct *p,
struct inode *inode)
{
struct inode_security_struct *isec = selinux_inode(inode);
u32 sid = task_sid_obj(p);
spin_lock(&isec->lock);
isec->sclass = inode_mode_to_security_class(inode->i_mode);
isec->sid = sid;
isec->initialized = LABEL_INITIALIZED;
spin_unlock(&isec->lock);
}
```
`pid_revalidate()` runs under `rcu_read_lock()` (and even in non-RCU mode does
not hold an exclusive lock across concurrent path-walk readers).
`selinux_task_to_inode()` acquires `isec->lock` and writes `isec->sclass`,
`isec->sid` (line 4740), and `isec->initialized` with plain stores
(`WRITE_ONCE()` is not used).
#### 2. Reader path (`selinux_inode_permission`)
Concurrently, another task traversing the same `/proc/<pid>` directory enters
`link_path_walk()` -> `may_lookup()` -> `lookup_inode_permission_may_exec()` ->
`inode_permission()` -> `security_inode_permission()` ->
`selinux_inode_permission()` (`security/selinux/hooks.c:3266-3320`).
`selinux_inode_permission()` obtains `isec` via `inode_security_rcu(inode,
requested & MAY_NOT_BLOCK)` (`security/selinux/hooks.c:311-324`), which only
checks `data_race(likely(isec->initialized == LABEL_INITIALIZED))` without
taking `isec->lock`. It then reads `isec->sid` (and `isec->sclass`) locklessly
and without `READ_ONCE()` across multiple places:
- `task_avdcache_search()` (`security/selinux/hooks.c:3217`): compares
`tsec->avdcache.dir[iter].isid == isec->sid` in a loop over `TSEC_AVDC_DIR_SIZE`
entries.
- On cache miss (`security/selinux/hooks.c:3304-3306`):
- `avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, avdp)` reads
`isec->sid`.
- `task_avdcache_update(tsec, isec, avdp)` (`security/selinux/hooks.c:3251`)
reads `isec->sid` **a second time** (`tsec->avdcache.dir[spot].isid =
isec->sid;`).
- `audit_inode_permission()` -> `slow_avc_audit()`
(`security/selinux/hooks.c:3171`): reads `isec->sid` again if auditing is
required.
#### 3. Invariant violation
`isec->lock` is used by writers (`selinux_task_to_inode()`, as well as
`selinux_inode_post_setxattr()` and `selinux_inode_setsecurity()`) to serialize
updates to `isec->sid` and `isec->sclass`, but lockless RCU/path-walk readers
such as `selinux_inode_permission()` read `isec->sid` and `isec->sclass` without
`isec->lock` and without `READ_ONCE()`/`WRITE_ONCE()` synchronization.
In addition to the KCSAN-reported data race (and potential compiler
reload/tearing), reading `isec->sid` separately in `avc_has_perm_noaudit()` and
`task_avdcache_update()` allows a concurrent `selinux_task_to_inode()` update
between the two reads to store the new `isec->sid` alongside the `av_decision`
(`avdp`) computed for the old `isec->sid` in `tsec->avdcache`.
*(Note: Other lockless readers of `isec->sid` and `isec->sclass` in
`security/selinux/hooks.c`, such as `selinux_inode_follow_link()` and
`selinux_file_permission()`, share this same pattern against concurrent
`isec->lock`-protected `isec->sid` updates.)*
Impact Analysis:
In real-world setups without KCSAN, this data race does not cause memory
corruption, crashes, or kernel information leaks. `isec->sid` is a 4-byte
aligned `u32` (at offset 28 in `struct inode_security_struct`), and even if a
concurrent `selinux_task_to_inode()` update occurs while
`selinux_inode_permission()` reads `isec->sid`, `avc_lookup()` /
`sidtab_search()` safely handle any valid or unrecognized `u32` SID (defaulting
to deny on unrecognized SIDs), and `task_avdcache_search()` /
`task_avdcache_update()` only index a fixed 4-entry per-task array with masked
indices. The worst-case runtime consequence is a transient SELinux MAC policy
inconsistency: `selinux_inode_permission()` reads `isec->sid` multiple times
without locking or `READ_ONCE()`, so `isec->sid` can change between
`avc_has_perm_noaudit()` and `task_avdcache_update()`, causing the task's
`avdcache` to cache an `av_decision` computed for the old SID under the new SID.
Classification reasoning:
- MemoryCorruption: false β no pointers, refcounts, buffer lengths, or
memory-safety-critical state are corrupted; only a `u32` SELinux SID value is
raced on.
- InfoLeak: "none" β no kernel memory contents are exposed or copied to
userspace.
- RawDenialOfService: false β no crash, panic, WARN/BUG, deadlock, infinite
loop, or resource leak can occur from this race.
- IsNetCandidate: false β the bug is purely in SELinux inode security handling
during `/proc` VFS path lookup.
- IsKVMCandidate: false β unrelated to KVM or virtualization.
Local Reachability Analysis:
### Analysis Summary
This KCSAN data race occurs on `struct inode_security_struct::sid` (`u32`)
between concurrent VFS path lookups on `/proc/<pid>/...` when SELinux is enabled
(`CONFIG_SECURITY_SELINUX=y`, and `selinux` is included in `CONFIG_LSM`):
1. **Writer path (`selinux_task_to_inode`)**:
- Invoked from `openat()` -> `link_path_walk()` -> `walk_component()` ->
`lookup_fast()` -> `d_revalidate()` -> `pid_revalidate()`
(`fs/proc/base.c:2043`) -> `pid_update_inode()` (`fs/proc/base.c:2030`) ->
`security_task_to_inode()` -> `selinux_task_to_inode()`
(`security/selinux/hooks.c:4732`).
- `pid_revalidate()` is attached via `pid_dentry_operations.d_revalidate` on
`/proc/<pid>` dentries and runs during normal unprivileged path lookup
without any capability checks.
- `selinux_task_to_inode()` writes `isec->sid` with a plain store under
`isec->lock`.
2. **Reader path (`selinux_inode_permission`)**:
- Invoked from `openat()` -> `link_path_walk()` -> `may_lookup()` ->
`lookup_inode_permission_may_exec()` -> `inode_permission()` ->
`security_inode_permission()` -> `selinux_inode_permission()`
(`security/selinux/hooks.c:3266`).
- Obtains `isec` via `inode_security_rcu()` without acquiring `isec->lock`,
and reads `isec->sid` locklessly in `task_avdcache_search()`,
`avc_has_perm_noaudit()`, and `task_avdcache_update()`.
- When `task_avdcache_permnoaudit()` is false (e.g., on initial lookups for a
task or when SELinux policy/enforcing/auditing applies), an unprivileged
process traversing `/proc/<pid>/...` (such as `/proc/self/stat` or
`/proc/<own_pid>/status`) reaches these reads directly.
### Field-by-Field Reasoning
- **Unprivileged (`true`)**: An unprivileged process can spawn two threads (or
processes) that concurrently call `openat()` on its own `/proc/<pid>/...`
entries (e.g., `/proc/<pid>/status`), hitting `pid_revalidate()` ->
`selinux_task_to_inode()` and `may_lookup()` -> `selinux_inode_permission()`
simultaneously without any capabilities, special file permissions, or user
namespaces.
- **UserNamespace (`true`)**: Must be `true` when `Unprivileged` is `true`.
- **RequiredCaps (`[]`)**: No capabilities are required.
- **PeripheralTrigger (`false`)**: Triggered via normal `/proc` VFS lookups and
SELinux inode security hooks, not via a physical peripheral device.
- **FilesystemTrigger (`false`)**: `/proc` is a kernel pseudo-filesystem rather
than a user-supplied filesystem image parsed on mount.
- **RawFuzzingArtifact (`false`)**: The bug is a genuine kernel data race in
SELinux hooks reachable by unprivileged processes via standard `openat()`
syscalls on `/proc`. 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 on the 4-byte `sid` field (`u32 sid`, offset 28 bytes) of `struct inode_security_struct` (`security/selinux/include/objsec.h:72-80`) between concurrent `/proc/<pid>` dentry revalidation and inode permission checks during VFS path lookup.
#### 1. Writer path (`selinux_task_to_inode`)
When a task walks `/proc/<pid>`, `lookup_fast()` (`fs/namei.c:1874`) invokes `d_revalidate()` -> `pid_revalidate()` (`fs/proc/base.c:2043-2063`) -> `pid_update_inode()` (`fs/proc/base.c:2030-2036`) -> `security_task_to_inode()` -> `selinux_task_to_inode()` (`security/selinux/hooks.c:4732-4743`):
```c
static void selinux_task_to_inode(struct task_struct *p,
struct inode *inode)
{
struct inode_security_struct *isec = selinux_inode(inode);
u32 sid = task_sid_obj(p);
spin_lock(&isec->lock);
isec->sclass = inode_mode_to_security_class(inode->i_mode);
isec->sid = sid;
isec->initialized = LABEL_INITIALIZED;
spin_unlock(&isec->lock);
}
```
`pid_revalidate()` runs under `rcu_read_lock()` (and even in non-RCU mode does not hold an exclusive lock across concurrent path-walk readers). `selinux_task_to_inode()` acquires `isec->lock` and writes `isec->sclass`, `isec->sid` (line 4740), and `isec->initialized` with plain stores (`WRITE_ONCE()` is not used).
#### 2. Reader path (`selinux_inode_permission`)
Concurrently, another task traversing the same `/proc/<pid>` directory enters `link_path_walk()` -> `may_lookup()` -> `lookup_inode_permission_may_exec()` -> `inode_permission()` -> `security_inode_permission()` -> `selinux_inode_permission()` (`security/selinux/hooks.c:3266-3320`).
`selinux_inode_permission()` obtains `isec` via `inode_security_rcu(inode, requested & MAY_NOT_BLOCK)` (`security/selinux/hooks.c:311-324`), which only checks `data_race(likely(isec->initialized == LABEL_INITIALIZED))` without taking `isec->lock`. It then reads `isec->sid` (and `isec->sclass`) locklessly and without `READ_ONCE()` across multiple places:
- `task_avdcache_search()` (`security/selinux/hooks.c:3217`): compares `tsec->avdcache.dir[iter].isid == isec->sid` in a loop over `TSEC_AVDC_DIR_SIZE` entries.
- On cache miss (`security/selinux/hooks.c:3304-3306`):
- `avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, avdp)` reads `isec->sid`.
- `task_avdcache_update(tsec, isec, avdp)` (`security/selinux/hooks.c:3251`) reads `isec->sid` **a second time** (`tsec->avdcache.dir[spot].isid = isec->sid;`).
- `audit_inode_permission()` -> `slow_avc_audit()` (`security/selinux/hooks.c:3171`): reads `isec->sid` again if auditing is required.
#### 3. Invariant violation
`isec->lock` is used by writers (`selinux_task_to_inode()`, as well as `selinux_inode_post_setxattr()` and `selinux_inode_setsecurity()`) to serialize updates to `isec->sid` and `isec->sclass`, but lockless RCU/path-walk readers such as `selinux_inode_permission()` read `isec->sid` and `isec->sclass` without `isec->lock` and without `READ_ONCE()`/`WRITE_ONCE()` synchronization.
In addition to the KCSAN-reported data race (and potential compiler reload/tearing), reading `isec->sid` separately in `avc_has_perm_noaudit()` and `task_avdcache_update()` allows a concurrent `selinux_task_to_inode()` update between the two reads to store the new `isec->sid` alongside the `av_decision` (`avdp`) computed for the old `isec->sid` in `tsec->avdcache`.
*(Note: Other lockless readers of `isec->sid` and `isec->sclass` in `security/selinux/hooks.c`, such as `selinux_inode_follow_link()` and `selinux_file_permission()`, share this same pattern against concurrent `isec->lock`-protected `isec->sid` updates.)* RootCauseFiles:[security/selinux/hooks.c] RootCauseSummary:`selinux_task_to_inode()` in `security/selinux/hooks.c` updates `isec->sid` (and `isec->sclass`) on `/proc` inodes under `isec->lock` using plain writes during `pid_revalidate()` / `pid_update_inode()`. Concurrently, `selinux_inode_permission()` (and its inlined helpers `task_avdcache_search()` and `task_avdcache_update()`) reads `isec->sid` and `isec->sclass` locklessly and without `READ_ONCE()` or `data_race()` during VFS path lookup. Because `isec->sid` is also read multiple times across `avc_has_perm_noaudit()` and `task_avdcache_update()`, a concurrent update can also pair an `av_decision` computed for the old SID with the new SID in the task's `avdcache`. Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/12/02 14:56 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/12/02 14:56 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/fdba0ce4667ae8b7045a35918cd4d05f79d8e5f1/data]
|
| 3/1 |
2026/12/02 14:56 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/252b4af9858298ff61fc6d8a28d1c9f15e6f3b00/data]
|
| 4/1 |
2026/12/02 14:56 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/12/02 14:57 |
agent |
root-cause |
1m
Model:
Results: map[ImpactAnalysis:In real-world setups without KCSAN, this data race does not cause memory corruption, crashes, or kernel information leaks. `isec->sid` is a 4-byte aligned `u32` (at offset 28 in `struct inode_security_struct`), and even if a concurrent `selinux_task_to_inode()` update occurs while `selinux_inode_permission()` reads `isec->sid`, `avc_lookup()` / `sidtab_search()` safely handle any valid or unrecognized `u32` SID (defaulting to deny on unrecognized SIDs), and `task_avdcache_search()` / `task_avdcache_update()` only index a fixed 4-entry per-task array with masked indices. The worst-case runtime consequence is a transient SELinux MAC policy inconsistency: `selinux_inode_permission()` reads `isec->sid` multiple times without locking or `READ_ONCE()`, so `isec->sid` can change between `avc_has_perm_noaudit()` and `task_avdcache_update()`, causing the task's `avdcache` to cache an `av_decision` computed for the old SID under the new SID.
Classification reasoning:
- MemoryCorruption: false β no pointers, refcounts, buffer lengths, or memory-safety-critical state are corrupted; only a `u32` SELinux SID value is raced on.
- InfoLeak: "none" β no kernel memory contents are exposed or copied to userspace.
- RawDenialOfService: false β no crash, panic, WARN/BUG, deadlock, infinite loop, or resource leak can occur from this race.
- IsNetCandidate: false β the bug is purely in SELinux inode security handling during `/proc` VFS path lookup.
- IsKVMCandidate: false β unrelated to KVM or virtualization. InfoLeak:none IsKVMCandidate:false IsNetCandidate:false MemoryCorruption:false RawDenialOfService:false RootCauseFiles:[security/selinux/hooks.c] RootCauseSummary:`selinux_task_to_inode()` in `security/selinux/hooks.c` updates `isec->sid` (and `isec->sclass`) on `/proc` inodes under `isec->lock` using plain writes during `pid_revalidate()` / `pid_update_inode()`. Concurrently, `selinux_inode_permission()` (and its inlined helpers `task_avdcache_search()` and `task_avdcache_update()`) reads `isec->sid` and `isec->sclass` locklessly and without `READ_ONCE()` or `data_race()` during VFS path lookup. Because `isec->sid` is also read multiple times across `avc_has_perm_noaudit()` and `task_avdcache_update()`, a concurrent update can also pair an `av_decision` computed for the old SID with the new SID in the task's `avdcache`.]
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 selinux_inode_permission / selinux_task_to_inode
write to 0xffff88810d82b7d4 of 4 bytes by task 4030 on cpu 0:
selinux_task_to_inode+0x160/0x1a0 security/selinux/hooks.c:4740
security_task_to_inode+0x39/0x50 security/security.c:3374
pid_update_inode fs/proc/base.c:2035 [inline]
pid_revalidate+0x82/0xb0 fs/proc/base.c:2057
d_revalidate fs/namei.c:1041 [inline]
lookup_fast+0x232/0x320 fs/namei.c:1874
walk_component fs/namei.c:2284 [inline]
link_path_walk+0x528/0xde0 fs/namei.c:2662
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 0xffff88810d82b7d4 of 4 bytes by task 4029 on cpu 1:
selinux_inode_permission+0x3e6/0x740 security/selinux/hooks.c:-1
security_inode_permission+0x73/0xb0 security/security.c:1865
inode_permission+0x1e3/0x3c0 fs/namei.c:661
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
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 4029 Comm: syz.4.97 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 on the 4-byte `sid` field (`u32 sid`, offset 28 bytes) of `struct inode_security_struct` (`security/selinux/include/objsec.h:72-80`) between concurrent `/proc/<pid>` dentry revalidation and inode permission checks during VFS path lookup.
#### 1. Writer path (`selinux_task_to_inode`)
When a task walks `/proc/<pid>`, `lookup_fast()` (`fs/namei.c:1874`) invokes `d_revalidate()` -> `pid_revalidate()` (`fs/proc/base.c:2043-2063`) -> `pid_update_inode()` (`fs/proc/base.c:2030-2036`) -> `security_task_to_inode()` -> `selinux_task_to_inode()` (`security/selinux/hooks.c:4732-4743`):
```c
static void selinux_task_to_inode(struct task_struct *p,
struct inode *inode)
{
struct inode_security_struct *isec = selinux_inode(inode);
u32 sid = task_sid_obj(p);
spin_lock(&isec->lock);
isec->sclass = inode_mode_to_security_class(inode->i_mode);
isec->sid = sid;
isec->initialized = LABEL_INITIALIZED;
spin_unlock(&isec->lock);
}
```
`pid_revalidate()` runs under `rcu_read_lock()` (and even in non-RCU mode does not hold an exclusive lock across concurrent path-walk readers). `selinux_task_to_inode()` acquires `isec->lock` and writes `isec->sclass`, `isec->sid` (line 4740), and `isec->initialized` with plain stores (`WRITE_ONCE()` is not used).
#### 2. Reader path (`selinux_inode_permission`)
Concurrently, another task traversing the same `/proc/<pid>` directory enters `link_path_walk()` -> `may_lookup()` -> `lookup_inode_permission_may_exec()` -> `inode_permission()` -> `security_inode_permission()` -> `selinux_inode_permission()` (`security/selinux/hooks.c:3266-3320`).
`selinux_inode_permission()` obtains `isec` via `inode_security_rcu(inode, requested & MAY_NOT_BLOCK)` (`security/selinux/hooks.c:311-324`), which only checks `data_race(likely(isec->initialized == LABEL_INITIALIZED))` without taking `isec->lock`. It then reads `isec->sid` (and `isec->sclass`) locklessly and without `READ_ONCE()` across multiple places:
- `task_avdcache_search()` (`security/selinux/hooks.c:3217`): compares `tsec->avdcache.dir[iter].isid == isec->sid` in a loop over `TSEC_AVDC_DIR_SIZE` entries.
- On cache miss (`security/selinux/hooks.c:3304-3306`):
- `avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, avdp)` reads `isec->sid`.
- `task_avdcache_update(tsec, isec, avdp)` (`security/selinux/hooks.c:3251`) reads `isec->sid` **a second time** (`tsec->avdcache.dir[spot].isid = isec->sid;`).
- `audit_inode_permission()` -> `slow_avc_audit()` (`security/selinux/hooks.c:3171`): reads `isec->sid` again if auditing is required.
#### 3. Invariant violation
`isec->lock` is used by writers (`selinux_task_to_inode()`, as well as `selinux_inode_post_setxattr()` and `selinux_inode_setsecurity()`) to serialize updates to `isec->sid` and `isec->sclass`, but lockless RCU/path-walk readers such as `selinux_inode_permission()` read `isec->sid` and `isec->sclass` without `isec->lock` and without `READ_ONCE()`/`WRITE_ONCE()` synchronization.
In addition to the KCSAN-reported data race (and potential compiler reload/tearing), reading `isec->sid` separately in `avc_has_perm_noaudit()` and `task_avdcache_update()` allows a concurrent `selinux_task_to_inode()` update between the two reads to store the new `isec->sid` alongside the `av_decision` (`avdp`) computed for the old `isec->sid` in `tsec->avdcache`.
*(Note: Other lockless readers of `isec->sid` and `isec->sclass` in `security/selinux/hooks.c`, such as `selinux_inode_follow_link()` and `selinux_file_permission()`, share this same pattern against concurrent `isec->lock`-protected `isec->sid` updates.)*
|
| 6/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 7383
output: 160
thoughts: 163
Thoughts: **My In-Depth Analysis of the KCSAN Data Race Report**
Alright, I need to get to the bottom of this KCSAN data race report, and my immediate focus is on dissecting the functions implicated. My current understanding points to a few key areas within the kernel that are likely involved:
First, I'm looking at `selinux_task_to_inode` in `security/selinux/hooks.c`, specifically around line 4740. This function clearly plays a role in associating SELinux security contexts with inodes, and given it's dealing with tasks and inodes, it's a prime candidate for concurrency issues.
Second, `selinux_inode_permission`, also in `security/selinux/hooks.c`, is another critical piece. Permission checks are inherently sensitive to race conditions, especially when they involve shared resources like inodes.
Third, I need to examine `pid_update_inode` and its counterpart `pid_revalidate` within `fs/proc/base.c`. The proc filesystem is a complex area, and interactions involving process IDs and inode updates could easily lead to race conditions if not handled meticulously.
Finally, I'm considering the `inode_security_struct` and any associated helper functions. If this structure is being accessed or modified concurrently by the aforementioned functions, it's a direct point of contention.
To accelerate my investigation, my plan is to leverage `codesearch-definition-source` in parallel against `selinux_task_to_inode`, `selinux_inode_permission`, and `pid_update_inode` / `pid_revalidate`. This will allow me to quickly gather definitions, usages, and cross-references for these functions, giving me a broader perspective on how they interact and where the potential race might be occurring.
|
| 7/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:selinux_task_to_inode]
Results: map[SourceCode:4732: static void selinux_task_to_inode(struct task_struct *p,
4733: struct inode *inode)
4734: {
4735: struct inode_security_struct *isec = selinux_inode(inode);
4736: u32 sid = task_sid_obj(p);
4737:
4738: spin_lock(&isec->lock);
4739: isec->sclass = inode_mode_to_security_class(inode->i_mode);
4740: isec->sid = sid;
4741: isec->initialized = LABEL_INITIALIZED;
4742: spin_unlock(&isec->lock);
4743: }
SourceFile:security/selinux/hooks.c]
|
| 8/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:selinux_inode_permission]
Results: map[SourceCode:3257: /**
3258: * selinux_inode_permission - Check if the current task can access an inode
3259: * @idmap: idmap of the mount
3260: * @inode: the inode that is being accessed
3261: * @requested: the accesses being requested
3262: *
3263: * Check if the current task is allowed to access @inode according to
3264: * @requested. Returns 0 if allowed, negative values otherwise.
3265: */
3266: static int selinux_inode_permission(const struct mnt_idmap *idmap,
3267: struct inode *inode, int requested)
3268: {
3269: int mask;
3270: u32 perms;
3271: u32 sid = current_sid();
3272: struct task_security_struct *tsec;
3273: struct inode_security_struct *isec;
3274: struct avdc_entry *avdc;
3275: struct av_decision avd, *avdp = &avd;
3276: int rc, rc2;
3277: u32 audited, denied;
3278:
3279: mask = requested & (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
3280:
3281: /* No permission to check. Existence test. */
3282: if (!mask)
3283: return 0;
3284:
3285: tsec = selinux_task(current);
3286: if (task_avdcache_permnoaudit(tsec, sid))
3287: return 0;
3288:
3289: isec = inode_security_rcu(inode, requested & MAY_NOT_BLOCK);
3290: if (IS_ERR(isec))
3291: return PTR_ERR(isec);
3292: perms = file_mask_to_av(inode->i_mode, mask);
3293:
3294: rc = task_avdcache_search(tsec, isec, &avdc);
3295: if (likely(!rc)) {
3296: /* Cache hit. */
3297: avdp = &avdc->avd;
3298: denied = perms & ~avdp->allowed;
3299: if (unlikely(denied) && enforcing_enabled() &&
3300: !(avdp->flags & AVD_FLAGS_PERMISSIVE))
3301: rc = -EACCES;
3302: } else {
3303: /* Cache miss. */
3304: rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass,
3305: perms, 0, avdp);
3306: task_avdcache_update(tsec, isec, avdp);
3307: }
3308:
3309: audited = avc_audit_required(perms, avdp, rc,
3310: (requested & MAY_ACCESS) ?
3311: FILE__AUDIT_ACCESS : 0, &denied);
3312: if (likely(!audited))
3313: return rc;
3314:
3315: rc2 = audit_inode_permission(inode, perms, audited, denied, rc);
3316: if (rc2)
3317: return rc2;
3318:
3319: return rc;
3320: }
SourceFile:security/selinux/hooks.c]
|
| 9/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/proc/base.c Name:pid_update_inode]
Results: map[SourceCode:2027: /*
2028: * Set <pid>/... inode ownership (can change due to setuid(), etc.)
2029: */
2030: void pid_update_inode(struct task_struct *task, struct inode *inode)
2031: {
2032: task_dump_owner(task, inode->i_mode, &inode->i_uid, &inode->i_gid);
2033:
2034: inode->i_mode &= ~(S_ISUID | S_ISGID);
2035: security_task_to_inode(task, inode);
2036: }
SourceFile:fs/proc/base.c]
|
| 10/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/proc/base.c Name:pid_revalidate]
Results: map[SourceCode:2038: /*
2039: * Rewrite the inode's ownerships here because the owning task may have
2040: * performed a setuid(), etc.
2041: *
2042: */
2043: static int pid_revalidate(struct inode *dir, const struct qstr *name,
2044: struct dentry *dentry, unsigned int flags)
2045: {
2046: struct inode *inode;
2047: struct task_struct *task;
2048: int ret = 0;
2049:
2050: rcu_read_lock();
2051: inode = d_inode_rcu(dentry);
2052: if (!inode)
2053: goto out;
2054: task = pid_task(proc_pid(inode), PIDTYPE_PID);
2055:
2056: if (task) {
2057: pid_update_inode(task, inode);
2058: ret = 1;
2059: }
2060: out:
2061: rcu_read_unlock();
2062: return ret;
2063: }
SourceFile:fs/proc/base.c]
|
| 11/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 9524
output: 165
thoughts: 291
Thoughts: **My Revelations on SELinux Security Data Handling**
Ah, I've stumbled upon something quite interesting while digging into SELinux's inner workings, specifically around how it handles inode security information. My attention was drawn to the functions `selinux_task_to_inode` and `selinux_inode_permission`.
Let's first focus on `selinux_task_to_inode`. I see that within this function, there's a critical update: `isec->sid = sid;`. What immediately catches my eye here is that this assignment is a write to `isec->sid`, which is a 4-byte value (`u32`). Crucially, this write operation is correctly protected by `isec->lock` using a spinlock. This implies an expectation of exclusive access for this modification.
Now, here's where my concern arises: in `selinux_inode_permission`, I observe that `isec->sid` is being read, but *without* holding the `isec->lock`. This is a significant detail because the `isec->sid` is also accessed in several other critical paths, including `task_avdcache_search`, `task_avdcache_update`, `avc_has_perm_noaudit`, and `inode_security_rcu`. The fact that these reads are occurring without the protective lock that guards the write in `selinux_task_to_inode` suggests a potential race condition or at least a lack of guaranteed data consistency.
This observation prompts me to dive deeper and thoroughly examine the `inode_security_struct` itself, along with `inode_security_rcu`, `task_avdcache_search`, `task_avdcache_update`, and all other functions that either read or write `isec->sid` and `isec->sclass` within the `security/selinux/` directory. I need to understand the full implications of this unprotected read and ensure that the integrity of the security labels and SIDs is maintained across all these access points.
|
| 12/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:inode_security_struct]
Results: map[SourceCode: 72: struct inode_security_struct {
73: struct inode *inode; /* back pointer to inode object */
74: struct list_head list; /* list of inode_security_struct */
75: u32 task_sid; /* SID of creating task */
76: u32 sid; /* SID of this object */
77: u16 sclass; /* security class of this object */
78: unsigned char initialized; /* initialization flag */
79: spinlock_t lock;
80: };
SourceFile:security/selinux/include/objsec.h]
|
| 13/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:inode_security_rcu]
Results: map[SourceCode: 311: static inline struct inode_security_struct *inode_security_rcu(struct inode *inode,
312: bool rcu)
313: {
314: int rc;
315: struct inode_security_struct *isec = selinux_inode(inode);
316:
317: /* check below is racy, but revalidate will recheck with lock held */
318: if (data_race(likely(isec->initialized == LABEL_INITIALIZED)))
319: return isec;
320: rc = __inode_security_revalidate(inode, NULL, !rcu);
321: if (rc)
322: return ERR_PTR(rc);
323: return isec;
324: }
SourceFile:security/selinux/hooks.c]
|
| 14/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_avdcache_search]
Results: map[SourceCode:3190: /**
3191: * task_avdcache_search - Search the task's AVD cache
3192: * @tsec: the task's security state
3193: * @isec: the inode to search for in the cache
3194: * @avdc: matching avd cache entry returned to the caller
3195: *
3196: * Search @tsec for a AVD cache entry that matches @isec and return it to the
3197: * caller via @avdc. Returns 0 if a match is found, negative values otherwise.
3198: */
3199: static inline int task_avdcache_search(struct task_security_struct *tsec,
3200: struct inode_security_struct *isec,
3201: struct avdc_entry **avdc)
3202: {
3203: int orig, iter;
3204:
3205: /* focused on path walk optimization, only cache directories */
3206: if (isec->sclass != SECCLASS_DIR)
3207: return -ENOENT;
3208:
3209: if (unlikely(current_sid() != tsec->avdcache.sid ||
3210: tsec->avdcache.seqno != avc_policy_seqno())) {
3211: task_avdcache_reset(tsec);
3212: return -ENOENT;
3213: }
3214:
3215: orig = iter = tsec->avdcache.dir_spot;
3216: do {
3217: if (tsec->avdcache.dir[iter].isid == isec->sid) {
3218: /* cache hit */
3219: tsec->avdcache.dir_spot = iter;
3220: *avdc = &tsec->avdcache.dir[iter];
3221: return 0;
3222: }
3223: iter = (iter - 1) & (TSEC_AVDC_DIR_SIZE - 1);
3224: } while (iter != orig);
3225:
3226: return -ENOENT;
3227: }
SourceFile:security/selinux/hooks.c]
|
| 15/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_avdcache_update]
Results: map[SourceCode:3229: /**
3230: * task_avdcache_update - Update the task's AVD cache
3231: * @tsec: the task's security state
3232: * @isec: the inode associated with the cache entry
3233: * @avd: the AVD to cache
3234: *
3235: * Update the AVD cache in @tsec with the @avd info associated
3236: * with @isec.
3237: */
3238: static inline void task_avdcache_update(struct task_security_struct *tsec,
3239: struct inode_security_struct *isec,
3240: struct av_decision *avd)
3241: {
3242: int spot;
3243:
3244: /* focused on path walk optimization, only cache directories */
3245: if (isec->sclass != SECCLASS_DIR)
3246: return;
3247:
3248: /* update cache */
3249: spot = (tsec->avdcache.dir_spot + 1) & (TSEC_AVDC_DIR_SIZE - 1);
3250: tsec->avdcache.dir_spot = spot;
3251: tsec->avdcache.dir[spot].isid = isec->sid;
3252: tsec->avdcache.dir[spot].avd = *avd;
3253: tsec->avdcache.permissive_neveraudit =
3254: (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT));
3255: }
SourceFile:security/selinux/hooks.c]
|
| 16/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 11550
output: 194
thoughts: 81
Thoughts: **My Journey Through SELinux Inode Security**
My current investigative path is leading me deep into the heart of SELinux's inode security mechanisms. I need to meticulously examine the `inode_security` and `__inode_security_revalidate` functions, as well as `inode_security_novalidate`, all located within `security/selinux/hooks.c`. These are the primary gates through which SELinux interacts with inode security attributes.
Simultaneously, I'm tracing all invocations of `selinux_task_to_inode` or its generic counterpart, `security_task_to_inode`. Understanding how SELinux associates security contexts with inodes based on the current task is crucial. This linkage is fundamental to enforcing access control policies.
Finally, I'll be paying very close attention to every instance of `inode_security_struct::sid` within the `security/selinux/` directory. The Security ID (SID) stored within the `inode_security_struct` is the linchpin of SELinux's inode-based security. By analyzing its usage, I expect to gain a comprehensive understanding of how security labels are applied, checked, and potentially modified during various file system operations. This thorough examination should illuminate the intricate dance of policy enforcement at the inode level within SELinux.
|
| 17/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:__inode_security_revalidate]
Results: map[SourceCode: 278: /*
279: * Try reloading inode security labels that have been marked as invalid. The
280: * @may_sleep parameter indicates when sleeping and thus reloading labels is
281: * allowed; when set to false, returns -ECHILD when the label is
282: * invalid. The @dentry parameter should be set to a dentry of the inode.
283: */
284: static int __inode_security_revalidate(struct inode *inode,
285: struct dentry *dentry,
286: bool may_sleep)
287: {
288: if (!selinux_initialized())
289: return 0;
290:
291: if (may_sleep)
292: might_sleep();
293: else
294: return -ECHILD;
295:
296: /*
297: * Check to ensure that an inode's SELinux state is valid and try
298: * reloading the inode security label if necessary. This will fail if
299: * @dentry is NULL and no dentry for this inode can be found; in that
300: * case, continue using the old label.
301: */
302: inode_doinit_with_dentry(inode, dentry);
303: return 0;
304: }
SourceFile:security/selinux/hooks.c]
|
| 18/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:inode_security]
Results: map[SourceCode: 326: /*
327: * Get the security label of an inode.
328: */
329: static inline struct inode_security_struct *inode_security(struct inode *inode)
330: {
331: struct inode_security_struct *isec = selinux_inode(inode);
332:
333: /* check below is racy, but revalidate will recheck with lock held */
334: if (data_race(likely(isec->initialized == LABEL_INITIALIZED)))
335: return isec;
336: __inode_security_revalidate(inode, NULL, true);
337: return isec;
338: }
SourceFile:security/selinux/hooks.c]
|
| 19/2 |
2026/12/02 14:57 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:security/selinux/hooks.c IncludeSnippetLines:3 Name:inode_security_struct::sid SourceTreePrefix:security/selinux/]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:audit_inode_permission SourceFile:security/selinux/hooks.c SourceLine:3171 SourceSnippet:3168: ad.type = LSM_AUDIT_DATA_INODE;
3169: ad.u.inode = inode;
3170:
3171: return slow_avc_audit(current_sid(), isec->sid, isec->sclass, perms,
3172: audited, denied, result, &ad);
3173: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:inode_doinit_with_dentry SourceFile:security/selinux/hooks.c SourceLine:1475 SourceSnippet:1472:
1473: sclass = isec->sclass;
1474: task_sid = isec->task_sid;
1475: sid = isec->sid;
1476: isec->initialized = LABEL_PENDING;
1477: spin_unlock(&isec->lock);
1478:
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:inode_doinit_with_dentry SourceFile:security/selinux/hooks.c SourceLine:1603 SourceSnippet:1600: goto out_unlock;
1601: }
1602: isec->initialized = LABEL_INITIALIZED;
1603: isec->sid = sid;
1604: }
1605:
1606: out_unlock:
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:inode_doinit_with_dentry SourceFile:security/selinux/hooks.c SourceLine:1614 SourceSnippet:1611: spin_lock(&isec->lock);
1612: if (isec->initialized == LABEL_PENDING) {
1613: isec->initialized = LABEL_INVALID;
1614: isec->sid = sid;
1615: }
1616: spin_unlock(&isec->lock);
1617: return 0;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:inode_sid_has_perm SourceFile:security/selinux/hooks.c SourceLine:1701 SourceSnippet:1698:
1699: isec = selinux_inode(inode);
1700:
1701: return avc_has_perm(sid, isec->sid, isec->sclass, perms, adp);
1702: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ioctl_has_perm SourceFile:security/selinux/hooks.c SourceLine:3970 SourceSnippet:3967: return 0;
3968:
3969: isec = inode_security(inode);
3970: rc = avc_has_extended_perms(ssid, isec->sid, isec->sclass, requested,
3971: driver, AVC_EXT_IOCTL, xperm, &ad);
3972: out:
3973: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_create SourceFile:security/selinux/hooks.c SourceLine:1882 SourceSnippet:1879: ad.type = LSM_AUDIT_DATA_DENTRY;
1880: ad.u.dentry = dentry;
1881:
1882: rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1883: DIR__ADD_NAME | DIR__SEARCH,
1884: &ad);
1885: if (rc)
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_link SourceFile:security/selinux/hooks.c SourceLine:1926 SourceSnippet:1923:
1924: av = DIR__SEARCH;
1925: av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
1926: rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, av, &ad);
1927: if (rc)
1928: return rc;
1929:
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_link SourceFile:security/selinux/hooks.c SourceLine:1946 SourceSnippet:1943: return 0;
1944: }
1945:
1946: rc = avc_has_perm(sid, isec->sid, isec->sclass, av, &ad);
1947: return rc;
1948: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_rename SourceFile:security/selinux/hooks.c SourceLine:1970 SourceSnippet:1967: ad.type = LSM_AUDIT_DATA_DENTRY;
1968:
1969: ad.u.dentry = old_dentry;
1970: rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
1971: DIR__REMOVE_NAME | DIR__SEARCH, &ad);
1972: if (rc)
1973: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_rename SourceFile:security/selinux/hooks.c SourceLine:1974 SourceSnippet:1971: DIR__REMOVE_NAME | DIR__SEARCH, &ad);
1972: if (rc)
1973: return rc;
1974: rc = avc_has_perm(sid, old_isec->sid,
1975: old_isec->sclass, FILE__RENAME, &ad);
1976: if (rc)
1977: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_rename SourceFile:security/selinux/hooks.c SourceLine:1979 SourceSnippet:1976: if (rc)
1977: return rc;
1978: if (old_is_dir && new_dir != old_dir) {
1979: rc = avc_has_perm(sid, old_isec->sid,
1980: old_isec->sclass, DIR__REPARENT, &ad);
1981: if (rc)
1982: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_rename SourceFile:security/selinux/hooks.c SourceLine:1989 SourceSnippet:1986: av = DIR__ADD_NAME | DIR__SEARCH;
1987: if (d_is_positive(new_dentry))
1988: av |= DIR__REMOVE_NAME;
1989: rc = avc_has_perm(sid, new_dsec->sid, SECCLASS_DIR, av, &ad);
1990: if (rc)
1991: return rc;
1992: if (d_is_positive(new_dentry)) {
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:may_rename SourceFile:security/selinux/hooks.c SourceLine:1995 SourceSnippet:1992: if (d_is_positive(new_dentry)) {
1993: new_isec = backing_inode_security(new_dentry);
1994: new_is_dir = d_is_dir(new_dentry);
1995: rc = avc_has_perm(sid, new_isec->sid,
1996: new_isec->sclass,
1997: (new_is_dir ? DIR__RMDIR : FILE__UNLINK), &ad);
1998: if (rc)
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:sel_fill_super SourceFile:security/selinux/selinuxfs.c SourceLine:1881 SourceSnippet:1878:
1879: inode->i_ino = ++fsi->last_ino;
1880: isec = selinux_inode(inode);
1881: isec->sid = SECINITSID_DEVNULL;
1882: isec->sclass = SECCLASS_CHR_FILE;
1883: isec->initialized = LABEL_INITIALIZED;
1884:
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:sel_make_bools SourceFile:security/selinux/selinuxfs.c SourceLine:1272 SourceSnippet:1269: sid = SECINITSID_SECURITY;
1270: }
1271:
1272: isec->sid = sid;
1273: isec->initialized = LABEL_INITIALIZED;
1274: inode->i_fop = &sel_bool_ops;
1275: inode->i_ino = i|SEL_BOOL_INO_OFFSET;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_binder_transfer_file SourceFile:security/selinux/hooks.c SourceLine:2153 SourceSnippet:2150: return 0;
2151:
2152: isec = backing_inode_security(dentry);
2153: return avc_has_perm(sid, isec->sid, isec->sclass, file_to_av(file),
2154: &ad);
2155: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_bprm_creds_for_exec SourceFile:security/selinux/hooks.c SourceLine:2407 SourceSnippet:2404: } else {
2405: /* Check for a default transition on this program. */
2406: rc = security_transition_sid(old_crsec->sid,
2407: isec->sid, SECCLASS_PROCESS, NULL,
2408: &new_crsec->sid);
2409: if (rc)
2410: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_bprm_creds_for_exec SourceFile:security/selinux/hooks.c SourceLine:2425 SourceSnippet:2422: ad.u.file = bprm->file;
2423:
2424: if (new_crsec->sid == old_crsec->sid) {
2425: rc = avc_has_perm(old_crsec->sid, isec->sid, isec->sclass,
2426: FILE__EXECUTE_NO_TRANS, &ad);
2427: if (rc)
2428: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_bprm_creds_for_exec SourceFile:security/selinux/hooks.c SourceLine:2436 SourceSnippet:2433: if (rc)
2434: return rc;
2435:
2436: rc = avc_has_perm(new_crsec->sid, isec->sid, isec->sclass,
2437: FILE__ENTRYPOINT, &ad);
2438: if (rc)
2439: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_cmp_sb_context SourceFile:security/selinux/hooks.c SourceLine:921 SourceSnippet: 918: if (oldflags & ROOTCONTEXT_MNT) {
919: struct inode_security_struct *oldroot = backing_inode_security(oldsb->s_root);
920: struct inode_security_struct *newroot = backing_inode_security(newsb->s_root);
921: if (oldroot->sid != newroot->sid)
922: goto mismatch;
923: }
924: if (old->creator_sid != new->creator_sid)
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_cmp_sb_context SourceFile:security/selinux/hooks.c SourceLine:921 SourceSnippet: 918: if (oldflags & ROOTCONTEXT_MNT) {
919: struct inode_security_struct *oldroot = backing_inode_security(oldsb->s_root);
920: struct inode_security_struct *newroot = backing_inode_security(newsb->s_root);
921: if (oldroot->sid != newroot->sid)
922: goto mismatch;
923: }
924: if (old->creator_sid != new->creator_sid)
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_determine_inode_label SourceFile:security/selinux/hooks.c SourceLine:1855 SourceSnippet:1852: } else {
1853: const struct inode_security_struct *dsec = inode_security(dir);
1854: return security_transition_sid(crsec->sid,
1855: dsec->sid, tclass,
1856: name, _new_isid);
1857: }
1858:
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_file_open SourceFile:security/selinux/hooks.c SourceLine:4403 SourceSnippet:4400: * Task label is already saved in the file security
4401: * struct as its SID.
4402: */
4403: fsec->isid = isec->sid;
4404: fsec->pseqno = avc_policy_seqno();
4405: /*
4406: * Since the inode label or policy seqno may have changed
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_file_permission SourceFile:security/selinux/hooks.c SourceLine:3849 SourceSnippet:3846: return 0;
3847:
3848: isec = inode_security(inode);
3849: if (sid == fsec->sid && fsec->isid == isec->sid &&
3850: fsec->pseqno == avc_policy_seqno())
3851: /* No change since file_open check. */
3852: return 0;
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_inode_alloc_security SourceFile:security/selinux/hooks.c SourceLine:2924 SourceSnippet:2921: spin_lock_init(&isec->lock);
2922: INIT_LIST_HEAD(&isec->list);
2923: isec->inode = inode;
2924: isec->sid = SECINITSID_UNLABELED;
2925: isec->sclass = SECCLASS_FILE;
2926: isec->task_sid = sid;
2927: isec->initialized = LABEL_INVALID;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_follow_link SourceFile:security/selinux/hooks.c SourceLine:3158 SourceSnippet:3155: if (IS_ERR(isec))
3156: return PTR_ERR(isec);
3157:
3158: return avc_has_perm(sid, isec->sid, isec->sclass, FILE__READ, &ad);
3159: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_getlsmprop SourceFile:security/selinux/hooks.c SourceLine:3719 SourceSnippet:3716: {
3717: struct inode_security_struct *isec = inode_security_novalidate(inode);
3718:
3719: prop->selinux.secid = isec->sid;
3720: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_getsecurity SourceFile:security/selinux/hooks.c SourceLine:3659 SourceSnippet:3656: */
3657: isec = inode_security(inode);
3658: if (has_cap_mac_admin(false))
3659: error = security_sid_to_context_force(isec->sid, &context,
3660: &size);
3661: else
3662: error = security_sid_to_context(isec->sid,
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_getsecurity SourceFile:security/selinux/hooks.c SourceLine:3662 SourceSnippet:3659: error = security_sid_to_context_force(isec->sid, &context,
3660: &size);
3661: else
3662: error = security_sid_to_context(isec->sid,
3663: &context, &size);
3664: if (error)
3665: return error;
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_inode_init_security SourceFile:security/selinux/hooks.c SourceLine:3008 SourceSnippet:3005: if (sbsec->flags & SE_SBINITIALIZED) {
3006: struct inode_security_struct *isec = selinux_inode(inode);
3007: isec->sclass = newsclass;
3008: isec->sid = newsid;
3009: isec->initialized = LABEL_INITIALIZED;
3010: }
3011:
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_inode_init_security_anon SourceFile:security/selinux/hooks.c SourceLine:3063 SourceSnippet:3060: }
3061:
3062: isec->sclass = context_isec->sclass;
3063: isec->sid = context_isec->sid;
3064: } else {
3065: if (is_memfd)
3066: isec->sclass = SECCLASS_MEMFD_FILE;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_init_security_anon SourceFile:security/selinux/hooks.c SourceLine:3063 SourceSnippet:3060: }
3061:
3062: isec->sclass = context_isec->sclass;
3063: isec->sid = context_isec->sid;
3064: } else {
3065: if (is_memfd)
3066: isec->sclass = SECCLASS_MEMFD_FILE;
] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:selinux_inode_init_security_anon SourceFile:security/selinux/hooks.c SourceLine:3071 SourceSnippet:3068: isec->sclass = SECCLASS_ANON_INODE;
3069: rc = security_transition_sid(
3070: sid, sid,
3071: isec->sclass, name, &isec->sid);
3072: if (rc)
3073: return rc;
3074: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_init_security_anon SourceFile:security/selinux/hooks.c SourceLine:3086 SourceSnippet:3083: ad.u.anonclass = name ? (const char *)name->name : "?";
3084:
3085: return avc_has_perm(sid,
3086: isec->sid,
3087: isec->sclass,
3088: FILE__CREATE,
3089: &ad);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_permission SourceFile:security/selinux/hooks.c SourceLine:3304 SourceSnippet:3301: rc = -EACCES;
3302: } else {
3303: /* Cache miss. */
3304: rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass,
3305: perms, 0, avdp);
3306: task_avdcache_update(tsec, isec, avdp);
3307: }
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_inode_post_setxattr SourceFile:security/selinux/hooks.c SourceLine:3532 SourceSnippet:3529: isec = backing_inode_security(dentry);
3530: spin_lock(&isec->lock);
3531: isec->sclass = inode_mode_to_security_class(inode->i_mode);
3532: isec->sid = newsid;
3533: isec->initialized = LABEL_INITIALIZED;
3534: spin_unlock(&isec->lock);
3535: }
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_inode_setsecurity SourceFile:security/selinux/hooks.c SourceLine:3701 SourceSnippet:3698:
3699: spin_lock(&isec->lock);
3700: isec->sclass = inode_mode_to_security_class(inode->i_mode);
3701: isec->sid = newsid;
3702: isec->initialized = LABEL_INITIALIZED;
3703: spin_unlock(&isec->lock);
3704: return 0;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_setxattr SourceFile:security/selinux/hooks.c SourceLine:3421 SourceSnippet:3418: ad.u.dentry = dentry;
3419:
3420: isec = backing_inode_security(dentry);
3421: rc = avc_has_perm(sid, isec->sid, isec->sclass,
3422: FILE__RELABELFROM, &ad);
3423: if (rc)
3424: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_inode_setxattr SourceFile:security/selinux/hooks.c SourceLine:3466 SourceSnippet:3463: if (rc)
3464: return rc;
3465:
3466: rc = security_validate_transition(isec->sid, newsid,
3467: sid, isec->sclass);
3468: if (rc)
3469: return rc;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_kernel_create_files_as SourceFile:security/selinux/hooks.c SourceLine:4497 SourceSnippet:4494: u32 sid = current_sid();
4495: int ret;
4496:
4497: ret = avc_has_perm(sid, isec->sid,
4498: SECCLASS_KERNEL_SERVICE,
4499: KERNEL_SERVICE__CREATE_FILES_AS,
4500: NULL);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_kernel_create_files_as SourceFile:security/selinux/hooks.c SourceLine:4503 SourceSnippet:4500: NULL);
4501:
4502: if (ret == 0)
4503: crsec->create_sid = isec->sid;
4504: return ret;
4505: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_kernel_load_from_file SourceFile:security/selinux/hooks.c SourceLine:4540 SourceSnippet:4537: }
4538:
4539: isec = inode_security(file_inode(file));
4540: return avc_has_perm(sid, isec->sid, SECCLASS_SYSTEM, requested, &ad);
4541: }
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_sb_clone_mnt_opts SourceFile:security/selinux/hooks.c SourceLine:1006 SourceSnippet:1003: newsbsec->sid = sid;
1004: if (!set_rootcontext) {
1005: struct inode_security_struct *newisec = backing_inode_security(newsb->s_root);
1006: newisec->sid = sid;
1007: }
1008: newsbsec->mntpoint_sid = sid;
1009: }
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_sb_clone_mnt_opts SourceFile:security/selinux/hooks.c SourceLine:1014 SourceSnippet:1011: const struct inode_security_struct *oldisec = backing_inode_security(oldsb->s_root);
1012: struct inode_security_struct *newisec = backing_inode_security(newsb->s_root);
1013:
1014: newisec->sid = oldisec->sid;
1015: }
1016:
1017: sb_finish_set_opts(newsb);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_sb_clone_mnt_opts SourceFile:security/selinux/hooks.c SourceLine:1014 SourceSnippet:1011: const struct inode_security_struct *oldisec = backing_inode_security(oldsb->s_root);
1012: struct inode_security_struct *newisec = backing_inode_security(newsb->s_root);
1013:
1014: newisec->sid = oldisec->sid;
1015: }
1016:
1017: sb_finish_set_opts(newsb);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_sb_mnt_opts_compat SourceFile:security/selinux/hooks.c SourceLine:2748 SourceSnippet:2745: struct inode_security_struct *root_isec;
2746:
2747: root_isec = backing_inode_security(sb->s_root);
2748: if (bad_option(sbsec, ROOTCONTEXT_MNT, root_isec->sid,
2749: opts->rootcontext_sid))
2750: return 1;
2751: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_sb_remount SourceFile:security/selinux/hooks.c SourceLine:2784 SourceSnippet:2781: if (opts->rootcontext_sid) {
2782: struct inode_security_struct *root_isec;
2783: root_isec = backing_inode_security(sb->s_root);
2784: if (bad_option(sbsec, ROOTCONTEXT_MNT, root_isec->sid,
2785: opts->rootcontext_sid))
2786: goto out_bad_option;
2787: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_sb_show_options SourceFile:security/selinux/hooks.c SourceLine:1144 SourceSnippet:1141: struct inode_security_struct *isec = backing_inode_security(root);
1142: seq_putc(m, ',');
1143: seq_puts(m, ROOTCONTEXT_STR);
1144: rc = show_sid(m, isec->sid);
1145: if (rc)
1146: return rc;
1147: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_set_mnt_opts SourceFile:security/selinux/hooks.c SourceLine:726 SourceSnippet: 723: }
724: if (opts->rootcontext_sid) {
725: rootcontext_sid = opts->rootcontext_sid;
726: if (bad_option(sbsec, ROOTCONTEXT_MNT, root_isec->sid,
727: rootcontext_sid))
728: goto out_double_mount;
729: sbsec->flags |= ROOTCONTEXT_MNT;
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_set_mnt_opts SourceFile:security/selinux/hooks.c SourceLine:866 SourceSnippet: 863: if (rc)
864: goto out;
865:
866: root_isec->sid = rootcontext_sid;
867: root_isec->initialized = LABEL_INITIALIZED;
868: }
869:
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_sock_graft SourceFile:security/selinux/hooks.c SourceLine:5745 SourceSnippet:5742:
5743: if (sk->sk_family == PF_INET || sk->sk_family == PF_INET6 ||
5744: sk->sk_family == PF_UNIX)
5745: isec->sid = sksec->sid;
5746: sksec->sclass = isec->sclass;
5747: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_socket_accept SourceFile:security/selinux/hooks.c SourceLine:5395 SourceSnippet:5392: isec = inode_security_novalidate(SOCK_INODE(sock));
5393: spin_lock(&isec->lock);
5394: sclass = isec->sclass;
5395: sid = isec->sid;
5396: spin_unlock(&isec->lock);
5397:
5398: newisec = inode_security_novalidate(SOCK_INODE(newsock));
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_socket_accept SourceFile:security/selinux/hooks.c SourceLine:5400 SourceSnippet:5397:
5398: newisec = inode_security_novalidate(SOCK_INODE(newsock));
5399: newisec->sclass = sclass;
5400: newisec->sid = sid;
5401: newisec->initialized = LABEL_INITIALIZED;
5402:
5403: return 0;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_socket_getpeersec_dgram SourceFile:security/selinux/hooks.c SourceLine:5685 SourceSnippet:5682: if (sock && family == PF_UNIX) {
5683: struct inode_security_struct *isec;
5684: isec = inode_security_novalidate(SOCK_INODE(sock));
5685: peer_secid = isec->sid;
5686: } else if (skb)
5687: selinux_skb_peerlbl_sid(skb, family, &peer_secid);
5688:
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_socket_post_create SourceFile:security/selinux/hooks.c SourceLine:5105 SourceSnippet:5102: }
5103:
5104: isec->sclass = sclass;
5105: isec->sid = sid;
5106: isec->initialized = LABEL_INITIALIZED;
5107:
5108: if (sock->sk) {
] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:selinux_task_to_inode SourceFile:security/selinux/hooks.c SourceLine:4740 SourceSnippet:4737:
4738: spin_lock(&isec->lock);
4739: isec->sclass = inode_mode_to_security_class(inode->i_mode);
4740: isec->sid = sid;
4741: isec->initialized = LABEL_INITIALIZED;
4742: spin_unlock(&isec->lock);
4743: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:selinux_uring_cmd SourceFile:security/selinux/hooks.c SourceLine:7621 SourceSnippet:7618: ad.type = LSM_AUDIT_DATA_FILE;
7619: ad.u.file = file;
7620:
7621: return avc_has_perm(current_sid(), isec->sid,
7622: SECCLASS_IO_URING, IO_URING__CMD, &ad);
7623: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:task_avdcache_search SourceFile:security/selinux/hooks.c SourceLine:3217 SourceSnippet:3214:
3215: orig = iter = tsec->avdcache.dir_spot;
3216: do {
3217: if (tsec->avdcache.dir[iter].isid == isec->sid) {
3218: /* cache hit */
3219: tsec->avdcache.dir_spot = iter;
3220: *avdc = &tsec->avdcache.dir[iter];
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:task_avdcache_update SourceFile:security/selinux/hooks.c SourceLine:3251 SourceSnippet:3248: /* update cache */
3249: spot = (tsec->avdcache.dir_spot + 1) & (TSEC_AVDC_DIR_SIZE - 1);
3250: tsec->avdcache.dir_spot = spot;
3251: tsec->avdcache.dir[spot].isid = isec->sid;
3252: tsec->avdcache.dir[spot].avd = *avd;
3253: tsec->avdcache.permissive_neveraudit =
3254: (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT));
]] TruncatedOutput:false]
|
| 20/2 |
2026/12/02 14:57 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:security/selinux/hooks.c IncludeSnippetLines:3 Name:security_task_to_inode SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:map_files_d_revalidate SourceFile:fs/proc/base.c SourceLine:2215 SourceSnippet:2212: if (exact_vma_exists) {
2213: task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid);
2214:
2215: security_task_to_inode(task, inode);
2216: status = 1;
2217: }
2218:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:pid_update_inode SourceFile:fs/proc/base.c SourceLine:2035 SourceSnippet:2032: task_dump_owner(task, inode->i_mode, &inode->i_uid, &inode->i_gid);
2033:
2034: inode->i_mode &= ~(S_ISUID | S_ISGID);
2035: security_task_to_inode(task, inode);
2036: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:proc_pid_make_inode SourceFile:fs/proc/base.c SourceLine:1954 SourceSnippet:1951: ei->pid = pid;
1952:
1953: task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid);
1954: security_task_to_inode(task, inode);
1955:
1956: out:
1957: return inode;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:tid_fd_update_inode SourceFile:fs/proc/fd.c SourceLine:140 SourceSnippet: 137: i_mode |= S_IWUSR | S_IXUSR;
138: inode->i_mode = i_mode;
139: }
140: security_task_to_inode(task, inode);
141: }
]] TruncatedOutput:false]
|
| 21/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 23108
output: 74
thoughts: 207
Thoughts: **My Thought Process on Tracing the Call Stacks**
Alright, my primary focus right now is on dissecting the exact execution flow within both call stacks. I need to meticulously follow the path from the initial system call all the way down to the specific kernel functions involved.
Looking at Task 4030 on CPU 0, I see the following sequence: `openat` initiates the process. This leads to `link_path_walk`, which then calls `walk_component` to handle individual path segments. The crucial part for directory lookups seems to be `lookup_fast`. From there, it proceeds to `d_revalidate`. Now, here's where it gets interesting: `d_revalidate` calls `pid_revalidate`. My immediate thought is, "Why is `pid_revalidate` being called here?" My internal knowledge base tells me that `pid_revalidate` is typically invoked during RCU path walk (or more generally, a reference walk) specifically for dentries associated with `/proc/<pid>` entries. This is a key piece of information.
To confirm this and gain a deeper understanding, I need to dive into the source code. I'll be examining `lookup_fast` and `d_revalidate` within `fs/namei.c`. Simultaneously, I'll need to investigate the implementation of `pid_revalidate` in `fs/proc/base.c`. Furthermore, it's essential to also review the `may_lookup` function in `fs/namei.c`, as this function likely governs the permissions and conditions under which such lookups are permitted, and therefore, how `lookup_fast` and `d_revalidate` are invoked. I'll be leveraging my understanding of these kernel components and, if necessary, will consult `codesearch-definition-source` for precise code locations and implementations.
|
| 22/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:lookup_fast]
Results: map[SourceCode:1835: /**
1836: * lookup_fast - do fast lockless (but racy) lookup of a dentry
1837: * @nd: current nameidata
1838: *
1839: * Do a fast, but racy lookup in the dcache for the given dentry, and
1840: * revalidate it. Returns a valid dentry pointer or NULL if one wasn't
1841: * found. On error, an ERR_PTR will be returned.
1842: *
1843: * If this function returns a valid dentry and the walk is no longer
1844: * lazy, the dentry will carry a reference that must later be put. If
1845: * RCU mode is still in force, then this is not the case and the dentry
1846: * must be legitimized before use. If this returns NULL, then the walk
1847: * will no longer be in RCU mode.
1848: */
1849: static struct dentry *lookup_fast(struct nameidata *nd)
1850: {
1851: struct dentry *dentry, *parent = nd->path.dentry;
1852: int status = 1;
1853:
1854: /*
1855: * Rename seqlock is not required here because in the off chance
1856: * of a false negative due to a concurrent rename, the caller is
1857: * going to fall back to non-racy lookup.
1858: */
1859: if (nd->flags & LOOKUP_RCU) {
1860: dentry = __d_lookup_rcu(parent, &nd->last, &nd->next_seq);
1861: if (unlikely(!dentry)) {
1862: if (!try_to_unlazy(nd))
1863: return ERR_PTR(-ECHILD);
1864: return NULL;
1865: }
1866:
1867: /*
1868: * This sequence count validates that the parent had no
1869: * changes while we did the lookup of the dentry above.
1870: */
1871: if (read_seqcount_retry(&parent->d_seq, nd->seq))
1872: return ERR_PTR(-ECHILD);
1873:
1874: status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
1875: if (likely(status > 0))
1876: return dentry;
1877: if (!try_to_unlazy_next(nd, dentry))
1878: return ERR_PTR(-ECHILD);
1879: if (status == -ECHILD)
1880: /* we'd been told to redo it in non-rcu mode */
1881: status = d_revalidate(nd->inode, &nd->last,
1882: dentry, nd->flags);
1883: } else {
1884: dentry = __d_lookup(parent, &nd->last);
1885: if (unlikely(!dentry))
1886: return NULL;
1887: status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
1888: }
1889: if (unlikely(status <= 0)) {
1890: if (!status)
1891: d_invalidate(dentry);
1892: dput(dentry);
1893: return ERR_PTR(status);
1894: }
1895: return dentry;
1896: }
SourceFile:fs/namei.c]
|
| 23/2 |
2026/12/02 14:57 |
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]
|
| 24/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 24803
output: 164
thoughts: 1004
Thoughts: **Initial Observations and Hypothesis on SELinux Task-to-Inode SID Handling**
I've been digging into the SELinux LSM hooks, specifically `selinux_task_to_inode` and `selinux_inode_permission`, and I'm seeing a potential discrepancy that warrants further investigation. My initial thought is that there might be a race condition or a misunderstanding of how security identifiers (SIDs) are managed for inodes, particularly in the context of the proc filesystem.
When examining the call paths, I noticed that `selinux_inode_permission` is invoked during path lookups, like when accessing `/proc/<pid>` or its children. Within `selinux_inode_permission`, the security context of the inode (`isec`) is fetched, and then the SID of the *task* performing the operation (`tsec`) is compared against the inode's SID (`isec->sid`) via various AVC functions like `task_avdcache_search` and `avc_has_perm_noaudit`.
Here's where the potential issue arises: `selinux_inode_permission` accesses `isec->sid` without holding the `isec->lock`. This is particularly concerning because `isec->lock` is explicitly used by `selinux_task_to_inode` to protect writes to `isec->sid`.
This contrasts sharply with `selinux_task_to_inode`, which is called during operations like `openat` leading to `pid_revalidate` and then `security_task_to_inode`. In `selinux_task_to_inode`, the task's SID is obtained using `task_sid_obj(p)`, and then `isec->sid` is *written* and `isec->sclass` is set, all under the protection of `isec->lock`.
The immediate question that pops into my mind is: why is `isec->sid` being read without locking in `selinux_inode_permission` and other similar hooks, when `selinux_task_to_inode` explicitly locks it for writing? This suggests a potential for reading stale or inconsistent data if `isec->sid` can be modified concurrently by `selinux_task_to_inode` or other functions that might update task SIDs.
To clarify this, I need to delve deeper into the implementation of `security/selinux/hooks.c`. I need to understand:
1. **The intended lifecycle of `isec->sid`:** Is `isec->sid` meant to be static after initialization, or is it expected to change, especially in contexts like procfs where task SIDs can be dynamic?
2. **The role of `isec->lock`:** Is the lock in `selinux_task_to_inode` solely for initializing `isec->sid` and `isec->sclass` for a given inode, or is it intended to protect `isec->sid` from concurrent modifications in general?
3. **How task SIDs are managed:** I need to thoroughly examine `task_sid_obj` and any functions that can alter a task's SID (like `selinux_setprocattr` or `execve`).
4. **Other SELinux inode hooks:** I'll be reviewing other inode-related hooks (`selinux_inode_post_setxattr`, `selinux_inode_setsecurity`, etc.) to see if they also exhibit this pattern of reading `isec->sid` without locking.
5. **The interaction with `inode_doinit_with_dentry`:** Understanding how inodes are initialized with their security contexts, especially in relation to procfs entries, is crucial.
My working hypothesis is that there might be a scenario where `selinux_inode_permission` reads `isec->sid` while `selinux_task_to_inode` is in the process of updating it for a dynamically created procfs inode, leading to a race condition. The fact that `selinux_inode_permission` doesn't use `READ_ONCE()` or `data_race()` macros further fuels this concern. I need to confirm if this observed locking difference is intentional and benign due to specific properties of procfs or if it represents a genuine vulnerability.
|
| 25/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_sid_obj]
Results: map[SourceCode: 263: /*
264: * get the objective security ID of a task
265: */
266: static inline u32 task_sid_obj(const struct task_struct *task)
267: {
268: u32 sid;
269:
270: rcu_read_lock();
271: sid = cred_sid(__task_cred(task));
272: rcu_read_unlock();
273: return sid;
274: }
SourceFile:security/selinux/hooks.c]
|
| 26/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:avc_has_perm_noaudit]
Results: map[SourceCode:1129: /**
1130: * avc_has_perm_noaudit - Check permissions but perform no auditing.
1131: * @ssid: source security identifier
1132: * @tsid: target security identifier
1133: * @tclass: target security class
1134: * @requested: requested permissions, interpreted based on @tclass
1135: * @flags: AVC_STRICT or 0
1136: * @avd: access vector decisions
1137: *
1138: * Check the AVC to determine whether the @requested permissions are granted
1139: * for the SID pair (@ssid, @tsid), interpreting the permissions
1140: * based on @tclass, and call the security server on a cache miss to obtain
1141: * a new decision and add it to the cache. Return a copy of the decisions
1142: * in @avd. Return %0 if all @requested permissions are granted,
1143: * -%EACCES if any permissions are denied, or another -errno upon
1144: * other errors. This function is typically called by avc_has_perm(),
1145: * but may also be called directly to separate permission checking from
1146: * auditing, e.g. in cases where a lock must be held for the check but
1147: * should be released for the auditing.
1148: */
1149: inline int avc_has_perm_noaudit(u32 ssid, u32 tsid,
1150: u16 tclass, u32 requested,
1151: unsigned int flags,
1152: struct av_decision *avd)
1153: {
1154: u32 denied;
1155: struct avc_node *node;
1156:
1157: if (WARN_ON(!requested)) {
1158: /* Provide a deny-all, audit-all decision to the caller. */
1159: *avd = (struct av_decision){ .auditdeny = 0xffffffff };
1160: return -EACCES;
1161: }
1162:
1163: rcu_read_lock();
1164: node = avc_lookup(ssid, tsid, tclass);
1165: if (unlikely(!node)) {
1166: rcu_read_unlock();
1167: return avc_perm_nonode(ssid, tsid, tclass, requested,
1168: flags, avd);
1169: }
1170: denied = requested & ~node->ae.avd.allowed;
1171: memcpy(avd, &node->ae.avd, sizeof(*avd));
1172: rcu_read_unlock();
1173:
1174: if (unlikely(denied))
1175: return avc_denied(ssid, tsid, tclass, requested, 0, 0, 0,
1176: flags, avd);
1177: return 0;
1178: }
SourceFile:security/selinux/avc.c]
|
| 27/2 |
2026/12/02 14:57 |
tool |
read-file |
0m
Args: map[File:security/selinux/hooks.c FirstLine:4700 LineCount:60]
Results: map[Contents:4700: PROCESS__SETSCHED, NULL);
4701: }
4702:
4703: static int selinux_task_getscheduler(struct task_struct *p)
4704: {
4705: return avc_has_perm(current_sid(), task_sid_obj(p), SECCLASS_PROCESS,
4706: PROCESS__GETSCHED, NULL);
4707: }
4708:
4709: static int selinux_task_movememory(struct task_struct *p)
4710: {
4711: return avc_has_perm(current_sid(), task_sid_obj(p), SECCLASS_PROCESS,
4712: PROCESS__SETSCHED, NULL);
4713: }
4714:
4715: static int selinux_task_kill(struct task_struct *p, struct kernel_siginfo *info,
4716: int sig, const struct cred *cred)
4717: {
4718: u32 secid;
4719: u32 perm;
4720:
4721: if (!sig)
4722: perm = PROCESS__SIGNULL; /* null signal; existence test */
4723: else
4724: perm = signal_to_av(sig);
4725: if (!cred)
4726: secid = current_sid();
4727: else
4728: secid = cred_sid(cred);
4729: return avc_has_perm(secid, task_sid_obj(p), SECCLASS_PROCESS, perm, NULL);
4730: }
4731:
4732: static void selinux_task_to_inode(struct task_struct *p,
4733: struct inode *inode)
4734: {
4735: struct inode_security_struct *isec = selinux_inode(inode);
4736: u32 sid = task_sid_obj(p);
4737:
4738: spin_lock(&isec->lock);
4739: isec->sclass = inode_mode_to_security_class(inode->i_mode);
4740: isec->sid = sid;
4741: isec->initialized = LABEL_INITIALIZED;
4742: spin_unlock(&isec->lock);
4743: }
4744:
4745: static int selinux_userns_create(const struct cred *cred)
4746: {
4747: u32 sid = current_sid();
4748:
4749: return avc_has_perm(sid, sid, SECCLASS_USER_NAMESPACE,
4750: USER_NAMESPACE__CREATE, NULL);
4751: }
4752:
4753: /* Returns error only if unable to parse addresses */
4754: static int selinux_parse_skb_ipv4(struct sk_buff *skb,
4755: struct common_audit_data *ad, u8 *proto)
4756: {
4757: int offset, ihlen, ret = -EINVAL;
4758: struct iphdr _iph, *ih;
4759:
]
|
| 28/2 |
2026/12/02 14:57 |
tool |
read-file |
0m
Args: map[File:security/selinux/hooks.c FirstLine:3250 LineCount:80]
Results: map[Contents:3250: tsec->avdcache.dir_spot = spot;
3251: tsec->avdcache.dir[spot].isid = isec->sid;
3252: tsec->avdcache.dir[spot].avd = *avd;
3253: tsec->avdcache.permissive_neveraudit =
3254: (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT));
3255: }
3256:
3257: /**
3258: * selinux_inode_permission - Check if the current task can access an inode
3259: * @idmap: idmap of the mount
3260: * @inode: the inode that is being accessed
3261: * @requested: the accesses being requested
3262: *
3263: * Check if the current task is allowed to access @inode according to
3264: * @requested. Returns 0 if allowed, negative values otherwise.
3265: */
3266: static int selinux_inode_permission(const struct mnt_idmap *idmap,
3267: struct inode *inode, int requested)
3268: {
3269: int mask;
3270: u32 perms;
3271: u32 sid = current_sid();
3272: struct task_security_struct *tsec;
3273: struct inode_security_struct *isec;
3274: struct avdc_entry *avdc;
3275: struct av_decision avd, *avdp = &avd;
3276: int rc, rc2;
3277: u32 audited, denied;
3278:
3279: mask = requested & (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
3280:
3281: /* No permission to check. Existence test. */
3282: if (!mask)
3283: return 0;
3284:
3285: tsec = selinux_task(current);
3286: if (task_avdcache_permnoaudit(tsec, sid))
3287: return 0;
3288:
3289: isec = inode_security_rcu(inode, requested & MAY_NOT_BLOCK);
3290: if (IS_ERR(isec))
3291: return PTR_ERR(isec);
3292: perms = file_mask_to_av(inode->i_mode, mask);
3293:
3294: rc = task_avdcache_search(tsec, isec, &avdc);
3295: if (likely(!rc)) {
3296: /* Cache hit. */
3297: avdp = &avdc->avd;
3298: denied = perms & ~avdp->allowed;
3299: if (unlikely(denied) && enforcing_enabled() &&
3300: !(avdp->flags & AVD_FLAGS_PERMISSIVE))
3301: rc = -EACCES;
3302: } else {
3303: /* Cache miss. */
3304: rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass,
3305: perms, 0, avdp);
3306: task_avdcache_update(tsec, isec, avdp);
3307: }
3308:
3309: audited = avc_audit_required(perms, avdp, rc,
3310: (requested & MAY_ACCESS) ?
3311: FILE__AUDIT_ACCESS : 0, &denied);
3312: if (likely(!audited))
3313: return rc;
3314:
3315: rc2 = audit_inode_permission(inode, perms, audited, denied, rc);
3316: if (rc2)
3317: return rc2;
3318:
3319: return rc;
3320: }
3321:
3322: static int selinux_inode_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
3323: struct iattr *iattr)
3324: {
3325: const struct cred *cred = current_cred();
3326: struct inode *inode = d_backing_inode(dentry);
3327: unsigned int ia_valid = iattr->ia_valid;
3328: u32 av = FILE__WRITE;
3329:
]
|
| 29/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 29219
output: 167
thoughts: 248
Thoughts: **My Journey Through SELinux and KCSAN's Whistleblower**
I've been diving deep into the SELinux subsystem, and frankly, I'm trying to get a handle on some recent KCSAN reports. The specific issues that caught my eye involve `selinux_inode_permission` and `selinux_task_to_inode`.
What initially piqued my interest was this KCSAN alert:
`read to 0xffff88810d82b7d4 of 4 bytes by task 4029 on cpu 1: selinux_inode_permission+0x3e6/0x740 security/selinux/hooks.c:-1`
`write to 0xffff88810d82b7d4 of 4 bytes by task 4030 on cpu 0: selinux_task_to_inode+0x160/0x1a0 security/selinux/hooks.c:4740`
This clearly indicates a data race: one task is reading from a specific memory address (`0xffff88810d82b7d4`) while another is writing to it. The fact that these are happening in `selinux_inode_permission` and `selinux_task_to_inode` respectively is what I'm trying to untangle.
To get a better grip on the potential implications of this race condition, I'm going to carefully examine the `inode_security_struct` layout. I'll use a tool like `codesearch-struct-layout` to confirm the exact offsets and sizes of its members. This precise knowledge is crucial for understanding how a read operation in `selinux_inode_permission` might be seeing a partially updated or corrupted value if `isec->sid` is being modified concurrently by `selinux_task_to_inode`.
Furthermore, I need to understand the broader context of these operations. My next step will be to review the logic within `avc_lookup`, `avc_perm_nonode`, and `task_avdcache_update`. I'm particularly interested in how these functions behave when `isec->sid` might be in an inconsistent state β what happens if it's "torn" (partially written) or if it's read multiple times during a critical operation, potentially leading to incorrect security decisions or caching issues. My goal is to fully grasp the interplay of these components and pinpoint the exact vulnerability exposed by KCSAN.
|
| 30/2 |
2026/12/02 14:57 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:inode_security_struct]
Results: map[Fields:[map[Name:inode OffsetBits:0 SizeBits:64] map[Name:list OffsetBits:64 SizeBits:128] map[Name:task_sid OffsetBits:192 SizeBits:32] map[Name:sid OffsetBits:224 SizeBits:32] map[Name:sclass OffsetBits:256 SizeBits:16] map[Name:initialized OffsetBits:272 SizeBits:8] map[Name:lock OffsetBits:288 SizeBits:32]]]
|
| 31/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/avc.c Name:avc_perm_nonode]
Results: map[SourceCode:1101: /**
1102: * avc_perm_nonode - Add an entry to the AVC
1103: * @ssid: subject
1104: * @tsid: object/target
1105: * @tclass: object class
1106: * @requested: requested permissions
1107: * @flags: AVC flags
1108: * @avd: access vector decision
1109: *
1110: * This is the "we have no node" part of avc_has_perm_noaudit(), which is
1111: * unlikely and needs extra stack space for the new node that we generate, so
1112: * don't inline it.
1113: */
1114: static noinline int avc_perm_nonode(u32 ssid, u32 tsid, u16 tclass,
1115: u32 requested, unsigned int flags,
1116: struct av_decision *avd)
1117: {
1118: u32 denied;
1119: struct avc_xperms_node xp_node;
1120:
1121: avc_compute_av(ssid, tsid, tclass, avd, &xp_node);
1122: denied = requested & ~(avd->allowed);
1123: if (unlikely(denied))
1124: return avc_denied(ssid, tsid, tclass, requested, 0, 0, 0,
1125: flags, avd);
1126: return 0;
1127: }
SourceFile:security/selinux/avc.c]
|
| 32/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/avc.c Name:avc_lookup]
Results: map[SourceCode: 544: /**
545: * avc_lookup - Look up an AVC entry.
546: * @ssid: source security identifier
547: * @tsid: target security identifier
548: * @tclass: target security class
549: *
550: * Look up an AVC entry that is valid for the
551: * (@ssid, @tsid), interpreting the permissions
552: * based on @tclass. If a valid AVC entry exists,
553: * then this function returns the avc_node.
554: * Otherwise, this function returns NULL.
555: */
556: static struct avc_node *avc_lookup(u32 ssid, u32 tsid, u16 tclass)
557: {
558: struct avc_node *node;
559:
560: avc_cache_stats_incr(lookups);
561: node = avc_search_node(ssid, tsid, tclass);
562:
563: if (node)
564: return node;
565:
566: avc_cache_stats_incr(misses);
567: return NULL;
568: }
SourceFile:security/selinux/avc.c]
|
| 33/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:inode_doinit_with_dentry]
Results: map[SourceCode:1440: /* The inode's security attributes must be initialized before first use. */
1441: static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dentry)
1442: {
1443: struct superblock_security_struct *sbsec = NULL;
1444: struct inode_security_struct *isec = selinux_inode(inode);
1445: u32 task_sid, sid = 0;
1446: u16 sclass;
1447: struct dentry *dentry;
1448: int rc = 0;
1449:
1450: /* check below is racy, but we will recheck with lock held */
1451: if (data_race(isec->initialized == LABEL_INITIALIZED))
1452: return 0;
1453:
1454: spin_lock(&isec->lock);
1455: if (isec->initialized == LABEL_INITIALIZED)
1456: goto out_unlock;
1457:
1458: if (isec->sclass == SECCLASS_FILE)
1459: isec->sclass = inode_mode_to_security_class(inode->i_mode);
1460:
1461: sbsec = selinux_superblock(inode->i_sb);
1462: if (!(sbsec->flags & SE_SBINITIALIZED)) {
1463: /* Defer initialization until selinux_complete_init,
1464: after the initial policy is loaded and the security
1465: server is ready to handle calls. */
1466: spin_lock(&sbsec->isec_lock);
1467: if (list_empty(&isec->list))
1468: list_add(&isec->list, &sbsec->isec_head);
1469: spin_unlock(&sbsec->isec_lock);
1470: goto out_unlock;
1471: }
1472:
1473: sclass = isec->sclass;
1474: task_sid = isec->task_sid;
1475: sid = isec->sid;
1476: isec->initialized = LABEL_PENDING;
1477: spin_unlock(&isec->lock);
1478:
1479: switch (sbsec->behavior) {
1480: /*
1481: * In case of SECURITY_FS_USE_NATIVE we need to re-fetch the labels
1482: * via xattr when called from delayed_superblock_init().
1483: */
1484: case SECURITY_FS_USE_NATIVE:
1485: case SECURITY_FS_USE_XATTR:
1486: if (!(inode->i_opflags & IOP_XATTR)) {
1487: sid = sbsec->def_sid;
1488: break;
1489: }
1490: /* Need a dentry, since the xattr API requires one.
1491: Life would be simpler if we could just pass the inode. */
1492: if (opt_dentry) {
1493: /* Called from d_instantiate or d_splice_alias. */
1494: dentry = dget(opt_dentry);
1495: } else {
1496: /*
1497: * Called from selinux_complete_init, try to find a dentry.
1498: * Some filesystems really want a connected one, so try
1499: * that first. We could split SECURITY_FS_USE_XATTR in
1500: * two, depending upon that...
1501: */
1502: dentry = d_find_alias(inode);
1503: if (!dentry)
1504: dentry = d_find_any_alias(inode);
1505: }
1506: if (!dentry) {
1507: /*
1508: * this is can be hit on boot when a file is accessed
1509: * before the policy is loaded. When we load policy we
1510: * may find inodes that have no dentry on the
1511: * sbsec->isec_head list. No reason to complain as these
1512: * will get fixed up the next time we go through
1513: * inode_doinit with a dentry, before these inodes could
1514: * be used again by userspace.
1515: */
1516: goto out_invalid;
1517: }
1518:
1519: rc = inode_doinit_use_xattr(inode, dentry, sbsec->def_sid,
1520: &sid);
1521: dput(dentry);
1522: if (rc)
1523: goto out;
1524: break;
1525: case SECURITY_FS_USE_TASK:
1526: sid = task_sid;
1527: break;
1528: case SECURITY_FS_USE_TRANS:
1529: /* Default to the fs SID. */
1530: sid = sbsec->sid;
1531:
1532: /* Try to obtain a transition SID. */
1533: rc = security_transition_sid(task_sid, sid,
1534: sclass, NULL, &sid);
1535: if (rc)
1536: goto out;
1537: break;
1538: case SECURITY_FS_USE_MNTPOINT:
1539: sid = sbsec->mntpoint_sid;
1540: break;
1541: default:
1542: /* Default to the fs superblock SID. */
1543: sid = sbsec->sid;
1544:
1545: if ((sbsec->flags & SE_SBGENFS) &&
1546: (!S_ISLNK(inode->i_mode) ||
1547: selinux_policycap_genfs_seclabel_symlinks())) {
1548: /* We must have a dentry to determine the label on
1549: * procfs inodes */
1550: if (opt_dentry) {
1551: /* Called from d_instantiate or
1552: * d_splice_alias. */
1553: dentry = dget(opt_dentry);
1554: } else {
1555: /* Called from selinux_complete_init, try to
1556: * find a dentry. Some filesystems really want
1557: * a connected one, so try that first.
1558: */
1559: dentry = d_find_alias(inode);
1560: if (!dentry)
1561: dentry = d_find_any_alias(inode);
1562: }
1563: /*
1564: * This can be hit on boot when a file is accessed
1565: * before the policy is loaded. When we load policy we
1566: * may find inodes that have no dentry on the
1567: * sbsec->isec_head list. No reason to complain as
1568: * these will get fixed up the next time we go through
1569: * inode_doinit() with a dentry, before these inodes
1570: * could be used again by userspace.
1571: */
1572: if (!dentry)
1573: goto out_invalid;
1574: rc = selinux_genfs_get_sid(dentry, sclass,
1575: sbsec->flags, &sid);
1576: if (rc) {
1577: dput(dentry);
1578: goto out;
1579: }
1580:
1581: if ((sbsec->flags & SE_SBGENFS_XATTR) &&
1582: (inode->i_opflags & IOP_XATTR)) {
1583: rc = inode_doinit_use_xattr(inode, dentry,
1584: sid, &sid);
1585: if (rc) {
1586: dput(dentry);
1587: goto out;
1588: }
1589: }
1590: dput(dentry);
1591: }
1592: break;
1593: }
1594:
1595: out:
1596: spin_lock(&isec->lock);
1597: if (isec->initialized == LABEL_PENDING) {
1598: if (rc) {
1599: isec->initialized = LABEL_INVALID;
1600: goto out_unlock;
1601: }
1602: isec->initialized = LABEL_INITIALIZED;
1603: isec->sid = sid;
1604: }
1605:
1606: out_unlock:
1607: spin_unlock(&isec->lock);
1608: return rc;
1609:
1610: out_invalid:
1611: spin_lock(&isec->lock);
1612: if (isec->initialized == LABEL_PENDING) {
1613: isec->initialized = LABEL_INVALID;
1614: isec->sid = sid;
1615: }
1616: spin_unlock(&isec->lock);
1617: return 0;
1618: }
SourceFile:security/selinux/hooks.c]
|
| 34/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 33335
output: 166
thoughts: 1179
Thoughts: **Unpacking a Potential SELinux Race Condition**
My current line of thinking is to deeply investigate a potential race condition within the SELinux subsystem, specifically focusing on how security identifiers (`sid`) are handled during inode permission checks. I'm starting by examining the `avc_compute_av` and `security_compute_av` functions, though I'm already aware that on x86_64, 32-bit `u32` reads and writes are typically atomic at the hardware level unless the compiler intervenes. The core of my suspicion lies in `selinux_inode_permission` and the possibility of it reading `isec->sid` multiple times, potentially encountering stale or torn data.
Upon closer inspection of `selinux_inode_permission`, I've identified several critical points where `isec->sid` is accessed:
1. **`task_avdcache_search`:** This function reads `isec->sid` repeatedly within a loop (up to `TSEC_AVDC_DIR_SIZE` times) at line 3217, comparing it with cache entries.
2. **Cache Miss Handling:** If a cache miss occurs, the situation becomes more complex:
* `avc_has_perm_noaudit` reads `isec->sid` at line 3304.
* Following this, `task_avdcache_update` is called, which *also* reads `isec->sid` at line 3251. This is where I see a significant potential for a race. Looking at lines 3304-3306, if `isec->sid` changes *between* the call to `avc_has_perm_noaudit` (which computes an `avdp` based on the *old* `isec->sid`) and the call to `task_avdcache_update` (which then stores the *new* `isec->sid` along with the *old* `avdp`), the cache (`tsec->avdcache`) will end up storing an incorrect security decision (`avdp`) associated with the *new* `isid`.
3. **`audit_inode_permission`:** This function also reads `isec->sid` in its call to `slow_avc_audit`.
4. **`selinux_task_to_inode`:** This function is responsible for writing to `isec`. I've noted that it acquires `isec->lock` before modifying `isec->sclass` and `isec->sid`, and then releases the lock. Crucially, `selinux_inode_permission` *does not* acquire this lock and reads `isec->sid` and `isec->sclass` without any explicit synchronization mechanisms like `READ_ONCE()`/`WRITE_ONCE()` or locking.
This lack of synchronization is further highlighted by a KCSAN report I'm reviewing. The report details a write to the `isec->sid` memory address in `selinux_task_to_inode` and a subsequent read to the *same* address in `selinux_inode_permission`. The report indicates that the read occurred at offset `+0x3e6` within `selinux_inode_permission`. The fact that the source file and line number are reported as `-1` suggests that this read might have happened within an inlined function like `task_avdcache_search`, `task_avdcache_update`, or `avc_has_perm_noaudit`, all of which are called from `selinux_inode_permission`. The address being read is 4-byte aligned, and `isec->sid` is a 4-byte `u32`, confirming the data being accessed.
My next step is to meticulously examine the code in `security/selinux/avc.c` around `avc_compute_av` and the relevant definitions in `security/selinux/include/objsec.h` to ensure there are no other subtle memory corruption, out-of-bounds access, or crash vulnerabilities lurking due to this identified race condition. I need to be absolutely certain about the atomicity guarantees and potential compiler optimizations that might exacerbate or mitigate this issue.
|
| 35/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/avc.c Name:avc_compute_av]
Results: map[SourceCode: 979: /**
980: * avc_compute_av - Add an entry to the AVC based on the security policy
981: * @ssid: subject
982: * @tsid: object/target
983: * @tclass: object class
984: * @avd: access vector decision
985: * @xp_node: AVC extended permissions node
986: *
987: * Slow-path helper function for avc_has_perm_noaudit, when the avc_node lookup
988: * fails. Don't inline this, since it's the slow-path and just results in a
989: * bigger stack frame.
990: */
991: static noinline void avc_compute_av(u32 ssid, u32 tsid, u16 tclass,
992: struct av_decision *avd,
993: struct avc_xperms_node *xp_node)
994: {
995: INIT_LIST_HEAD(&xp_node->xpd_head);
996: security_compute_av(ssid, tsid, tclass, avd, &xp_node->xp);
997: avc_insert(ssid, tsid, tclass, avd, xp_node);
998: }
SourceFile:security/selinux/avc.c]
|
| 36/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_security_struct]
Results: map[SourceCode: 47: struct task_security_struct {
48: #define TSEC_AVDC_DIR_SIZE (1 << 2)
49: struct {
50: u32 sid; /* current SID for cached entries */
51: u32 seqno; /* AVC sequence number */
52: unsigned int dir_spot; /* dir cache index to check first */
53: struct avdc_entry dir[TSEC_AVDC_DIR_SIZE]; /* dir entries */
54: bool permissive_neveraudit; /* permissive and neveraudit */
55: } avdcache;
56: } __randomize_layout;
SourceFile:security/selinux/include/objsec.h]
|
| 37/2 |
2026/12/02 14:57 |
tool |
read-file |
0m
Args: map[File:security/selinux/include/objsec.h FirstLine:1 LineCount:100]
Results: map[Contents: 1: /* SPDX-License-Identifier: GPL-2.0-only */
2: /*
3: * Security-Enhanced Linux (SELinux) security module
4: *
5: * This file contains the SELinux security data structures for kernel objects.
6: *
7: * Author(s): Stephen Smalley, <stephen.smalley.work@gmail.com>
8: * Chris Vance, <cvance@nai.com>
9: * Wayne Salamon, <wsalamon@nai.com>
10: * James Morris <jmorris@redhat.com>
11: *
12: * Copyright (C) 2001,2002 Networks Associates Technology, Inc.
13: * Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
14: * Copyright (C) 2016 Mellanox Technologies
15: */
16:
17: #ifndef _SELINUX_OBJSEC_H_
18: #define _SELINUX_OBJSEC_H_
19:
20: #include <linux/list.h>
21: #include <linux/sched.h>
22: #include <linux/fs.h>
23: #include <linux/binfmts.h>
24: #include <linux/in.h>
25: #include <linux/spinlock.h>
26: #include <linux/lsm_hooks.h>
27: #include <linux/msg.h>
28: #include <net/net_namespace.h>
29: #include <linux/bpf.h>
30: #include "flask.h"
31: #include "avc.h"
32:
33: struct avdc_entry {
34: u32 isid; /* inode SID */
35: struct av_decision avd; /* av decision */
36: };
37:
38: struct cred_security_struct {
39: u32 osid; /* SID prior to last execve */
40: u32 sid; /* current SID */
41: u32 exec_sid; /* exec SID */
42: u32 create_sid; /* fscreate SID */
43: u32 keycreate_sid; /* keycreate SID */
44: u32 sockcreate_sid; /* fscreate SID */
45: } __randomize_layout;
46:
47: struct task_security_struct {
48: #define TSEC_AVDC_DIR_SIZE (1 << 2)
49: struct {
50: u32 sid; /* current SID for cached entries */
51: u32 seqno; /* AVC sequence number */
52: unsigned int dir_spot; /* dir cache index to check first */
53: struct avdc_entry dir[TSEC_AVDC_DIR_SIZE]; /* dir entries */
54: bool permissive_neveraudit; /* permissive and neveraudit */
55: } avdcache;
56: } __randomize_layout;
57:
58: static inline bool task_avdcache_permnoaudit(struct task_security_struct *tsec,
59: u32 sid)
60: {
61: return (tsec->avdcache.permissive_neveraudit &&
62: sid == tsec->avdcache.sid &&
63: tsec->avdcache.seqno == avc_policy_seqno());
64: }
65:
66: enum label_initialized {
67: LABEL_INVALID, /* invalid or not initialized */
68: LABEL_INITIALIZED, /* initialized */
69: LABEL_PENDING
70: };
71:
72: struct inode_security_struct {
73: struct inode *inode; /* back pointer to inode object */
74: struct list_head list; /* list of inode_security_struct */
75: u32 task_sid; /* SID of creating task */
76: u32 sid; /* SID of this object */
77: u16 sclass; /* security class of this object */
78: unsigned char initialized; /* initialization flag */
79: spinlock_t lock;
80: };
81:
82: struct file_security_struct {
83: u32 sid; /* SID of open file description */
84: u32 fown_sid; /* SID of file owner (for SIGIO) */
85: u32 isid; /* SID of inode at the time of file open */
86: u32 pseqno; /* Policy seqno at the time of file open */
87: };
88:
89: struct backing_file_security_layer {
90: struct path path; /* this layer's real path */
91: u32 mounter_sid; /* SID of the mounter that opened it */
92: u32 fd_sid; /* SID of its open file description */
93: };
94:
95: struct backing_file_security_struct {
96: u32 uf_sid; /* top-level user file fsec->sid */
97: u32 layer_count; /* number of intermediate backing files */
98: struct backing_file_security_layer *layers;
99: };
100:
]
|
| 38/2 |
2026/12/02 14:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:selinux_inode_setxattr]
Results: map[SourceCode:3392: static int selinux_inode_setxattr(const struct mnt_idmap *idmap,
3393: struct dentry *dentry, const char *name,
3394: const void *value, size_t size, int flags)
3395: {
3396: struct inode *inode = d_backing_inode(dentry);
3397: struct inode_security_struct *isec;
3398: struct superblock_security_struct *sbsec;
3399: struct common_audit_data ad;
3400: u32 newsid, sid = current_sid();
3401: int rc = 0;
3402:
3403: /* if not a selinux xattr, only check the ordinary setattr perm */
3404: if (strcmp(name, XATTR_NAME_SELINUX))
3405: return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
3406:
3407: if (!selinux_initialized())
3408: return (inode_owner_or_capable(idmap, inode) ? 0 : -EPERM);
3409:
3410: sbsec = selinux_superblock(inode->i_sb);
3411: if (!(sbsec->flags & SBLABEL_MNT))
3412: return -EOPNOTSUPP;
3413:
3414: if (!inode_owner_or_capable(idmap, inode))
3415: return -EPERM;
3416:
3417: ad.type = LSM_AUDIT_DATA_DENTRY;
3418: ad.u.dentry = dentry;
3419:
3420: isec = backing_inode_security(dentry);
3421: rc = avc_has_perm(sid, isec->sid, isec->sclass,
3422: FILE__RELABELFROM, &ad);
3423: if (rc)
3424: return rc;
3425:
3426: rc = security_context_to_sid(value, size, &newsid,
3427: GFP_KERNEL);
3428: if (rc == -EINVAL) {
3429: if (!has_cap_mac_admin(true)) {
3430: struct audit_buffer *ab;
3431: size_t audit_size;
3432:
3433: /* We strip a nul only if it is at the end, otherwise the
3434: * context contains a nul and we should audit that */
3435: if (value) {
3436: const char *str = value;
3437:
3438: if (str[size - 1] == '\0')
3439: audit_size = size - 1;
3440: else
3441: audit_size = size;
3442: } else {
3443: audit_size = 0;
3444: }
3445: ab = audit_log_start(audit_context(),
3446: GFP_ATOMIC, AUDIT_SELINUX_ERR);
3447: if (!ab)
3448: return rc;
3449: audit_log_format(ab, "op=setxattr invalid_context=");
3450: audit_log_n_untrustedstring(ab, value, audit_size);
3451: audit_log_end(ab);
3452:
3453: return rc;
3454: }
3455: rc = security_context_to_sid_force(value,
3456: size, &newsid);
3457: }
3458: if (rc)
3459: return rc;
3460:
3461: rc = avc_has_perm(sid, newsid, isec->sclass,
3462: FILE__RELABELTO, &ad);
3463: if (rc)
3464: return rc;
3465:
3466: rc = security_validate_transition(isec->sid, newsid,
3467: sid, isec->sclass);
3468: if (rc)
3469: return rc;
3470:
3471: return avc_has_perm(newsid,
3472: sbsec->sid,
3473: SECCLASS_FILESYSTEM,
3474: FILESYSTEM__ASSOCIATE,
3475: &ad);
3476: }
SourceFile:security/selinux/hooks.c]
|
| 39/2 |
2026/12/02 14:57 |
llm |
root-cause |
0m
Model:
Tokens:
input: 38099
output: 44
thoughts: 1301
Thoughts: **Analyzing SELinux Race Conditions in `/proc` Filesystem Operations**
My thought process in dissecting this SELinux vulnerability report has been a meticulous, step-by-step verification of every detail. The core of the problem, as I see it, lies in the concurrent manipulation of shared security structures within the SELinux module, specifically as they relate to `/proc` filesystem inodes.
My initial focus was to precisely locate the bug. I've identified the critical code paths in `security/selinux/hooks.c`. The function `selinux_task_to_inode()`, responsible for updating the security context of a process's inode representation in `/proc`, uses plain, non-`WRITE_ONCE` stores to update `isec->sclass`, `isec->sid`, and `isec->initialized`. This happens *while* holding `isec->lock`, which is acquired using `spin_lock(&isec->lock)`. The problem is that `selinux_task_to_inode()` is invoked during `/proc` dentry revalidation, which, through functions like `pid_revalidate()`, can occur concurrently without any locking protection around the `isec->lock` during these read operations.
This leads me to the second critical function: `selinux_inode_permission()`. This function is called during path lookups to check permissions. It retrieves the security context using `isec = inode_security_rcu(inode, requested & MAY_NOT_BLOCK)`. Crucially, this retrieval *only* checks for `isec->initialized` and *does not* hold `isec->lock` nor does it use `READ_ONCE()` or `data_race()` when subsequently accessing `isec->sid` and `isec->sclass`. I've specifically noted multiple read points for `isec->sid` within `selinux_inode_permission()`: in `task_avdcache_search()` within a loop, in the call to `avc_has_perm_noaudit()` for calculating access decisions, in `task_avdcache_update()` to store the SID, and within `audit_inode_permission()` for auditing purposes. The fact that these reads are happening without proper synchronization, while `selinux_task_to_inode()` is writing to the same fields, immediately raises a red flag for potential data races. I've also noted that other hooks, like `selinux_inode_post_setxattr()` and `selinux_inode_setsecurity()`, exhibit the same pattern of writing under `isec->lock` while `selinux_inode_permission()` and others read without it.
Moving to the consequences, my next step was to rigorously evaluate the runtime implications, assuming the absence of tools like KCSAN. My primary concern here is `MemoryCorruption`. I've been examining how a torn or changing `isec->sid` between reads could manifest.
On modern 64-bit architectures, a plain `u32` load/store to an aligned address (like `isec->sid`, at offset 28 bytes in `struct inode_security_struct`) is *generally* single-copy atomic. However, the compiler isn't strictly bound to treat it as such without `READ_ONCE`/`WRITE_ONCE`, meaning it could reload the value multiple times or, in theory, experience torn reads/writes.
Even if we assume the `isec->sid` itself isn't torn in a way that corrupts its value, the *timing* of its change between reads is critical. I've analyzed the scenario where `isec->sid` changes between the call to `avc_has_perm_noaudit()` and `task_avdcache_update()`. In this case, the `tsec->avdcache.dir[spot].isid` would be updated with the *new* `isec->sid`, but the associated `tsec->avdcache.dir[spot].avd` (the access decision) would be the one computed based on the *old* `isec->sid`. My immediate question was: could storing a mismatched `av_decision` in the per-task `avdcache` (which is a small, fixed-size array) lead to memory corruption? After careful consideration, I've concluded that no, this particular scenario doesn't appear to corrupt pointers, sizes, array indices, refcounts, or general kernel memory. However, I'm still cautious: what if `isec->sid` were to be torn into a truly arbitrary, bogus `u32` value and then passed into `avc_has_perm_noaudit()` and subsequently `security_compute_av()`? I need to be absolutely certain about how `security_compute_av()` handles such an invalid SID.
|
| 40/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/avc.c Name:security_compute_av]
Results: map[SourceCode:1113: /**
1114: * security_compute_av - Compute access vector decisions.
1115: * @ssid: source security identifier
1116: * @tsid: target security identifier
1117: * @orig_tclass: target security class
1118: * @avd: access vector decisions
1119: * @xperms: extended permissions
1120: *
1121: * Compute a set of access vector decisions based on the
1122: * SID pair (@ssid, @tsid) for the permissions in @tclass.
1123: */
1124: void security_compute_av(u32 ssid,
1125: u32 tsid,
1126: u16 orig_tclass,
1127: struct av_decision *avd,
1128: struct extended_perms *xperms)
1129: {
1130: struct selinux_policy *policy;
1131: struct policydb *policydb;
1132: struct sidtab *sidtab;
1133: u16 tclass;
1134: struct context *scontext = NULL, *tcontext = NULL;
1135:
1136: rcu_read_lock();
1137: policy = rcu_dereference(selinux_state.policy);
1138: avd_init(policy, avd);
1139: xperms->len = 0;
1140: if (!selinux_initialized())
1141: goto allow;
1142:
1143: policydb = &policy->policydb;
1144: sidtab = policy->sidtab;
1145:
1146: scontext = sidtab_search(sidtab, ssid);
1147: if (!scontext) {
1148: pr_err("SELinux: %s: unrecognized SID %d\n",
1149: __func__, ssid);
1150: goto out;
1151: }
1152:
1153: /* permissive domain? */
1154: if (ebitmap_get_bit(&policydb->permissive_map, scontext->type))
1155: avd->flags |= AVD_FLAGS_PERMISSIVE;
1156:
1157: /* neveraudit domain? */
1158: if (ebitmap_get_bit(&policydb->neveraudit_map, scontext->type))
1159: avd->flags |= AVD_FLAGS_NEVERAUDIT;
1160:
1161: /* both permissive and neveraudit => allow */
1162: if (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT))
1163: goto allow;
1164:
1165: tcontext = sidtab_search(sidtab, tsid);
1166: if (!tcontext) {
1167: pr_err("SELinux: %s: unrecognized SID %d\n",
1168: __func__, tsid);
1169: goto out;
1170: }
1171:
1172: tclass = unmap_class(&policy->map, orig_tclass);
1173: if (unlikely(orig_tclass && !tclass)) {
1174: if (policydb->allow_unknown)
1175: goto allow;
1176: goto out;
1177: }
1178: context_struct_compute_av(policydb, scontext, tcontext, tclass, avd,
1179: xperms);
1180: map_decision(&policy->map, orig_tclass, avd,
1181: policydb->allow_unknown);
1182: out:
1183: rcu_read_unlock();
1184: if (avd->flags & AVD_FLAGS_NEVERAUDIT)
1185: avd->auditallow = avd->auditdeny = 0;
1186: return;
1187: allow:
1188: avd->allowed = 0xffffffff;
1189: goto out;
1190: }
SourceFile:security/selinux/ss/services.c]
|
| 41/2 |
2026/12/02 14:58 |
llm |
root-cause |
0m
Model:
Tokens:
input: 40653
output: 685
thoughts: 1948
Thoughts: **Analyzing SELinux Policy Bypass Vulnerability in `/proc` Access**
I've been looking into a potential SELinux policy bypass related to access checks for `/proc/<pid>` entries. My primary concern is a race condition that could lead to inconsistent access decisions.
Specifically, I'm examining the interaction between `selinux_inode_permission()` and `task_avdcache_update()`. It appears that `selinux_inode_permission()` might use an older security identifier (`isec->sid`) for its checks. Crucially, after this check, `task_avdcache_update()` could then cache the access decision (`avd`) based on this *old* `isec->sid` but associate it with the *new* `isec->sid` within the task's `avdcache`. This means subsequent access attempts by that task to directories with the new `isec->sid` might incorrectly receive the permission decision that was actually meant for the old `isec->sid`. This could persist until the cache entry is evicted or the policy is reloaded.
Now, I'm trying to classify the impact of this.
First, I considered **MemoryCorruption**. Looking at the definition provided β "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" β I've concluded this is **false**. There's no actual memory corruption happening here. The `avdcache` is a small, fixed-size cache for directory permission decisions, and the access checks on `/proc/<pid>` are solely SELinux access control checks. No pointers, refcounts, lengths, or critical state machines are being corrupted.
Next, I evaluated **InfoLeak**. The question is whether reading `isec->sid` concurrently with its write could leak kernel memory. My assessment is **"none"**. The `isec->sid` is just a `u32` integer used internally by SELinux for permission checks. Neither the SID itself nor any uninitialized or out-of-bounds kernel memory is ever copied to userspace.
Then, I moved to **RawDenialOfService**. Does this data race cause a system crash, hang, deadlock, infinite loop, resource leak, or saturation *without* KCSAN? I've analyzed the operations: `selinux_task_to_inode` writes a `u32` SID under a lock, and `selinux_inode_permission` reads the SID and class locklessly. Even if a `u32` SID value is stale or torn, `sidtab_search` handles unrecognized SIDs gracefully by denying access. The `task_avdcache_search` and `task_avdcache_update` operations are well-contained, operating on a fixed-size cache. Therefore, I'm confident that this is **false** for `RawDenialOfService`.
Regarding **IsNetCandidate**, is there any networking connection? Absolutely not. Both call stacks lead to operations within the procfs filesystem (`/proc/<pid>`) and SELinux inode hooks. So, this is **false**.
Similarly, for **IsKVMCandidate**, there's no involvement with KVM, virtualization, or any related interfaces. This is also **false**.
Finally, I've pinpointed the **RootCauseFiles**. The core of the defect lies within `security/selinux/hooks.c`. The specific issue is the unsynchronized access to `isec->sid` and `isec->sclass` in `selinux_inode_permission` (which reads them locklessly) while `selinux_task_to_inode` updates them under `isec->lock`. While `fs/proc/base.c` is involved in calling the LSM hooks, the actual unsynchronized access and the mechanism for caching decisions based on potentially stale security context reside in `security/selinux/hooks.c`. I've meticulously checked the line numbers and function calls, confirming `selinux_task_to_inode` (lines 4732-4743) uses `spin_lock`/`spin_unlock`, while `selinux_inode_permission` (lines 3266-3320) accesses `isec->sid` and `isec->sclass` locklessly in its operations. The `struct inode_security_struct` definition also confirms these fields are protected by `spinlock_t lock`.
|
| 42/2 |
2026/12/02 14:58 |
tool |
set-results |
0m
Args: map[ImpactAnalysis:In real-world setups without KCSAN, this data race does not cause memory corruption, crashes, or kernel information leaks. `isec->sid` is a 4-byte aligned `u32` (at offset 28 in `struct inode_security_struct`), and even if a concurrent `selinux_task_to_inode()` update occurs while `selinux_inode_permission()` reads `isec->sid`, `avc_lookup()` / `sidtab_search()` safely handle any valid or unrecognized `u32` SID (defaulting to deny on unrecognized SIDs), and `task_avdcache_search()` / `task_avdcache_update()` only index a fixed 4-entry per-task array with masked indices. The worst-case runtime consequence is a transient SELinux MAC policy inconsistency: `selinux_inode_permission()` reads `isec->sid` multiple times without locking or `READ_ONCE()`, so `isec->sid` can change between `avc_has_perm_noaudit()` and `task_avdcache_update()`, causing the task's `avdcache` to cache an `av_decision` computed for the old SID under the new SID.
Classification reasoning:
- MemoryCorruption: false β no pointers, refcounts, buffer lengths, or memory-safety-critical state are corrupted; only a `u32` SELinux SID value is raced on.
- InfoLeak: "none" β no kernel memory contents are exposed or copied to userspace.
- RawDenialOfService: false β no crash, panic, WARN/BUG, deadlock, infinite loop, or resource leak can occur from this race.
- IsNetCandidate: false β the bug is purely in SELinux inode security handling during `/proc` VFS path lookup.
- IsKVMCandidate: false β unrelated to KVM or virtualization. InfoLeak:none IsKVMCandidate:false IsNetCandidate:false MemoryCorruption:false RawDenialOfService:false RootCauseFiles:[security/selinux/hooks.c] RootCauseSummary:`selinux_task_to_inode()` in `security/selinux/hooks.c` updates `isec->sid` (and `isec->sclass`) on `/proc` inodes under `isec->lock` using plain writes during `pid_revalidate()` / `pid_update_inode()`. Concurrently, `selinux_inode_permission()` (and its inlined helpers `task_avdcache_search()` and `task_avdcache_update()`) reads `isec->sid` and `isec->sclass` locklessly and without `READ_ONCE()` or `data_race()` during VFS path lookup. Because `isec->sid` is also read multiple times across `avc_has_perm_noaudit()` and `task_avdcache_update()`, a concurrent update can also pair an `av_decision` computed for the old SID with the new SID in the task's `avdcache`.]
Results: map[ImpactAnalysis:In real-world setups without KCSAN, this data race does not cause memory corruption, crashes, or kernel information leaks. `isec->sid` is a 4-byte aligned `u32` (at offset 28 in `struct inode_security_struct`), and even if a concurrent `selinux_task_to_inode()` update occurs while `selinux_inode_permission()` reads `isec->sid`, `avc_lookup()` / `sidtab_search()` safely handle any valid or unrecognized `u32` SID (defaulting to deny on unrecognized SIDs), and `task_avdcache_search()` / `task_avdcache_update()` only index a fixed 4-entry per-task array with masked indices. The worst-case runtime consequence is a transient SELinux MAC policy inconsistency: `selinux_inode_permission()` reads `isec->sid` multiple times without locking or `READ_ONCE()`, so `isec->sid` can change between `avc_has_perm_noaudit()` and `task_avdcache_update()`, causing the task's `avdcache` to cache an `av_decision` computed for the old SID under the new SID.
Classification reasoning:
- MemoryCorruption: false β no pointers, refcounts, buffer lengths, or memory-safety-critical state are corrupted; only a `u32` SELinux SID value is raced on.
- InfoLeak: "none" β no kernel memory contents are exposed or copied to userspace.
- RawDenialOfService: false β no crash, panic, WARN/BUG, deadlock, infinite loop, or resource leak can occur from this race.
- IsNetCandidate: false β the bug is purely in SELinux inode security handling during `/proc` VFS path lookup.
- IsKVMCandidate: false β unrelated to KVM or virtualization. InfoLeak:none IsKVMCandidate:false IsNetCandidate:false MemoryCorruption:false RawDenialOfService:false RootCauseFiles:[security/selinux/hooks.c] RootCauseSummary:`selinux_task_to_inode()` in `security/selinux/hooks.c` updates `isec->sid` (and `isec->sclass`) on `/proc` inodes under `isec->lock` using plain writes during `pid_revalidate()` / `pid_update_inode()`. Concurrently, `selinux_inode_permission()` (and its inlined helpers `task_avdcache_search()` and `task_avdcache_update()`) reads `isec->sid` and `isec->sclass` locklessly and without `READ_ONCE()` or `data_race()` during VFS path lookup. Because `isec->sid` is also read multiple times across `avc_has_perm_noaudit()` and `task_avdcache_update()`, a concurrent update can also pair an `av_decision` computed for the old SID with the new SID in the task's `avdcache`.]
|
| 43/2 |
2026/12/02 14:58 |
llm |
root-cause |
0m
Model:
Tokens:
input: 43967
output: 1236
thoughts: 26
Thoughts: **My Thought Process for Crafting the Technical Explanation**
Alright, so the immediate priority is to articulate this bug with absolute precision, leaving no room for ambiguity. I need to channel all my expertise into a clear, concise, and technically rigorous explanation. My goal here is to dissect the *mechanism* of the bug β exactly *how* it manifests β and pinpoint its *root cause* β the fundamental flaw that allowed it to emerge. I'm not interested in user-facing impacts or broader implications at this stage; this is about the nitty-gritty of the code and its behavior. I need to think like a debugger, tracing the execution flow, identifying the specific conditions that trigger the anomaly, and then working backward to the underlying architectural or logical error. The language must be direct, employing the precise terminology expected by fellow experts in this domain. This isn't about making it accessible; it's about being definitively understood by those who speak the same technical language.
|
| 44/1 |
2026/12/02 14:58 |
agent |
local-reachability |
0m
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 selinux_inode_permission / selinux_task_to_inode
write to 0xffff88810d82b7d4 of 4 bytes by task 4030 on cpu 0:
selinux_task_to_inode+0x160/0x1a0 security/selinux/hooks.c:4740
security_task_to_inode+0x39/0x50 security/security.c:3374
pid_update_inode fs/proc/base.c:2035 [inline]
pid_revalidate+0x82/0xb0 fs/proc/base.c:2057
d_revalidate fs/namei.c:1041 [inline]
lookup_fast+0x232/0x320 fs/namei.c:1874
walk_component fs/namei.c:2284 [inline]
link_path_walk+0x528/0xde0 fs/namei.c:2662
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 0xffff88810d82b7d4 of 4 bytes by task 4029 on cpu 1:
selinux_inode_permission+0x3e6/0x740 security/selinux/hooks.c:-1
security_inode_permission+0x73/0xb0 security/security.c:1865
inode_permission+0x1e3/0x3c0 fs/namei.c:661
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
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 4029 Comm: syz.4.97 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 on the 4-byte `sid` field (`u32 sid`, offset 28 bytes) of `struct inode_security_struct` (`security/selinux/include/objsec.h:72-80`) between concurrent `/proc/<pid>` dentry revalidation and inode permission checks during VFS path lookup.
#### 1. Writer path (`selinux_task_to_inode`)
When a task walks `/proc/<pid>`, `lookup_fast()` (`fs/namei.c:1874`) invokes `d_revalidate()` -> `pid_revalidate()` (`fs/proc/base.c:2043-2063`) -> `pid_update_inode()` (`fs/proc/base.c:2030-2036`) -> `security_task_to_inode()` -> `selinux_task_to_inode()` (`security/selinux/hooks.c:4732-4743`):
```c
static void selinux_task_to_inode(struct task_struct *p,
struct inode *inode)
{
struct inode_security_struct *isec = selinux_inode(inode);
u32 sid = task_sid_obj(p);
spin_lock(&isec->lock);
isec->sclass = inode_mode_to_security_class(inode->i_mode);
isec->sid = sid;
isec->initialized = LABEL_INITIALIZED;
spin_unlock(&isec->lock);
}
```
`pid_revalidate()` runs under `rcu_read_lock()` (and even in non-RCU mode does not hold an exclusive lock across concurrent path-walk readers). `selinux_task_to_inode()` acquires `isec->lock` and writes `isec->sclass`, `isec->sid` (line 4740), and `isec->initialized` with plain stores (`WRITE_ONCE()` is not used).
#### 2. Reader path (`selinux_inode_permission`)
Concurrently, another task traversing the same `/proc/<pid>` directory enters `link_path_walk()` -> `may_lookup()` -> `lookup_inode_permission_may_exec()` -> `inode_permission()` -> `security_inode_permission()` -> `selinux_inode_permission()` (`security/selinux/hooks.c:3266-3320`).
`selinux_inode_permission()` obtains `isec` via `inode_security_rcu(inode, requested & MAY_NOT_BLOCK)` (`security/selinux/hooks.c:311-324`), which only checks `data_race(likely(isec->initialized == LABEL_INITIALIZED))` without taking `isec->lock`. It then reads `isec->sid` (and `isec->sclass`) locklessly and without `READ_ONCE()` across multiple places:
- `task_avdcache_search()` (`security/selinux/hooks.c:3217`): compares `tsec->avdcache.dir[iter].isid == isec->sid` in a loop over `TSEC_AVDC_DIR_SIZE` entries.
- On cache miss (`security/selinux/hooks.c:3304-3306`):
- `avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, avdp)` reads `isec->sid`.
- `task_avdcache_update(tsec, isec, avdp)` (`security/selinux/hooks.c:3251`) reads `isec->sid` **a second time** (`tsec->avdcache.dir[spot].isid = isec->sid;`).
- `audit_inode_permission()` -> `slow_avc_audit()` (`security/selinux/hooks.c:3171`): reads `isec->sid` again if auditing is required.
#### 3. Invariant violation
`isec->lock` is used by writers (`selinux_task_to_inode()`, as well as `selinux_inode_post_setxattr()` and `selinux_inode_setsecurity()`) to serialize updates to `isec->sid` and `isec->sclass`, but lockless RCU/path-walk readers such as `selinux_inode_permission()` read `isec->sid` and `isec->sclass` without `isec->lock` and without `READ_ONCE()`/`WRITE_ONCE()` synchronization.
In addition to the KCSAN-reported data race (and potential compiler reload/tearing), reading `isec->sid` separately in `avc_has_perm_noaudit()` and `task_avdcache_update()` allows a concurrent `selinux_task_to_inode()` update between the two reads to store the new `isec->sid` alongside the `av_decision` (`avdp`) computed for the old `isec->sid` in `tsec->avdcache`.
*(Note: Other lockless readers of `isec->sid` and `isec->sclass` in `security/selinux/hooks.c`, such as `selinux_inode_follow_link()` and `selinux_file_permission()`, share this same pattern against concurrent `isec->lock`-protected `isec->sid` updates.)*
The impact analysis of the bug is:
In real-world setups without KCSAN, this data race does not cause memory corruption, crashes, or kernel information leaks. `isec->sid` is a 4-byte aligned `u32` (at offset 28 in `struct inode_security_struct`), and even if a concurrent `selinux_task_to_inode()` update occurs while `selinux_inode_permission()` reads `isec->sid`, `avc_lookup()` / `sidtab_search()` safely handle any valid or unrecognized `u32` SID (defaulting to deny on unrecognized SIDs), and `task_avdcache_search()` / `task_avdcache_update()` only index a fixed 4-entry per-task array with masked indices. The worst-case runtime consequence is a transient SELinux MAC policy inconsistency: `selinux_inode_permission()` reads `isec->sid` multiple times without locking or `READ_ONCE()`, so `isec->sid` can change between `avc_has_perm_noaudit()` and `task_avdcache_update()`, causing the task's `avdcache` to cache an `av_decision` computed for the old SID under the new SID.
Classification reasoning:
- MemoryCorruption: false β no pointers, refcounts, buffer lengths, or memory-safety-critical state are corrupted; only a `u32` SELinux SID value is raced on.
- InfoLeak: "none" β no kernel memory contents are exposed or copied to userspace.
- RawDenialOfService: false β no crash, panic, WARN/BUG, deadlock, infinite loop, or resource leak can occur from this race.
- IsNetCandidate: false β the bug is purely in SELinux inode security handling during `/proc` VFS path lookup.
- IsKVMCandidate: false β unrelated to KVM or virtualization.
Reply: ### Analysis Summary
This KCSAN data race occurs on `struct inode_security_struct::sid` (`u32`) between concurrent VFS path lookups on `/proc/<pid>/...` when SELinux is enabled (`CONFIG_SECURITY_SELINUX=y`, and `selinux` is included in `CONFIG_LSM`):
1. **Writer path (`selinux_task_to_inode`)**:
- Invoked from `openat()` -> `link_path_walk()` -> `walk_component()` -> `lookup_fast()` -> `d_revalidate()` -> `pid_revalidate()` (`fs/proc/base.c:2043`) -> `pid_update_inode()` (`fs/proc/base.c:2030`) -> `security_task_to_inode()` -> `selinux_task_to_inode()` (`security/selinux/hooks.c:4732`).
- `pid_revalidate()` is attached via `pid_dentry_operations.d_revalidate` on `/proc/<pid>` dentries and runs during normal unprivileged path lookup without any capability checks.
- `selinux_task_to_inode()` writes `isec->sid` with a plain store under `isec->lock`.
2. **Reader path (`selinux_inode_permission`)**:
- Invoked from `openat()` -> `link_path_walk()` -> `may_lookup()` -> `lookup_inode_permission_may_exec()` -> `inode_permission()` -> `security_inode_permission()` -> `selinux_inode_permission()` (`security/selinux/hooks.c:3266`).
- Obtains `isec` via `inode_security_rcu()` without acquiring `isec->lock`, and reads `isec->sid` locklessly in `task_avdcache_search()`, `avc_has_perm_noaudit()`, and `task_avdcache_update()`.
- When `task_avdcache_permnoaudit()` is false (e.g., on initial lookups for a task or when SELinux policy/enforcing/auditing applies), an unprivileged process traversing `/proc/<pid>/...` (such as `/proc/self/stat` or `/proc/<own_pid>/status`) reaches these reads directly.
### Field-by-Field Reasoning
- **Unprivileged (`true`)**: An unprivileged process can spawn two threads (or processes) that concurrently call `openat()` on its own `/proc/<pid>/...` entries (e.g., `/proc/<pid>/status`), hitting `pid_revalidate()` -> `selinux_task_to_inode()` and `may_lookup()` -> `selinux_inode_permission()` simultaneously without any capabilities, special file permissions, or user namespaces.
- **UserNamespace (`true`)**: Must be `true` when `Unprivileged` is `true`.
- **RequiredCaps (`[]`)**: No capabilities are required.
- **PeripheralTrigger (`false`)**: Triggered via normal `/proc` VFS lookups and SELinux inode security hooks, not via a physical peripheral device.
- **FilesystemTrigger (`false`)**: `/proc` is a kernel pseudo-filesystem rather than a user-supplied filesystem image parsed on mount.
- **RawFuzzingArtifact (`false`)**: The bug is a genuine kernel data race in SELinux hooks reachable by unprivileged processes via standard `openat()` syscalls on `/proc`.
|
| 45/2 |
2026/12/02 14:58 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 7656
output: 208
thoughts: 228
Thoughts: **My Investigative Process for the Bug Report**
Okay, so my primary goal here is to dissect this bug report and its accompanying root-cause analysis to fully understand its implications. I need to be rigorous about determining the exploitability of this issue, and that requires a structured approach.
First, I need to define the scope of the potential attack vectors. I'm thinking about it in terms of the privileges required for exploitation. So, I'll be asking myself:
* **Unprivileged:** Can a standard, unprivileged user process cause this bug to manifest? I mean, without any special permissions, without needing access to root-only device nodes or files, and crucially, without resorting to creating a user namespace. This is the baseline β the most straightforward and concerning scenario.
* **UserNamespace:** What if an attacker *can* use a user namespace? This is a slightly more advanced attack path, but still highly relevant. So, the question is, can this bug be triggered through a process that's been confined within a user namespace, even if it starts as unprivileged?
* **RequiredCaps:** Are there any specific Linux capabilities that are absolutely necessary to trigger this bug, even on the least-privileged path? This helps understand if there's a minimal set of permissions that, if granted erroneously, could lead to exploitation.
* **PeripheralTrigger:** Can this vulnerability be exploited by interacting with a physical peripheral device? This opens up a whole different class of attack, moving beyond purely software-based exploits.
* **FilesystemTrigger:** Is it possible to trigger this by mounting or parsing a specially crafted, malicious filesystem image? This is a classic vector, especially in environments where arbitrary filesystem mounts might be possible.
* **RawFuzzingArtifact:** Finally, I need to determine if this bug is simply a side effect of our fuzzing or testing efforts. Sometimes, fuzzers can uncover edge cases that aren't practical to exploit in a real-world scenario, but it's still important to classify it correctly.
Once I have these categories in mind, my immediate next step is to dive into the code. I'll be examining the relevant code paths and, importantly, the kernel configuration that enables them. To do this efficiently, I'll be leveraging `kernel-config-grep` to check for the presence of key configuration options such as `CONFIG_SECURITY_SELINUX`, `CONFIG_PROC_FS`, `CONFIG_KCSAN`, and `CONFIG_CMDLINE`. Simultaneously, I'll be meticulously reading through `fs/proc/base.c`, `security/selinux/hooks.c`, and `fs/namei.c`, focusing on the specific functions that seem to be involved in the reported bug. This direct code inspection is crucial for understanding the mechanics of the vulnerability and how it might be triggered.
|
| 46/2 |
2026/12/02 14:58 |
tool |
kernel-config-grep |
0m
Args: map[Query:CONFIG_SECURITY_SELINUX]
Results: map[Output:CONFIG_SECURITY_SELINUX=y
CONFIG_SECURITY_SELINUX_BOOTPARAM=y
CONFIG_SECURITY_SELINUX_DEVELOP=y
CONFIG_SECURITY_SELINUX_AVC_STATS=y
CONFIG_SECURITY_SELINUX_SIDTAB_HASH_BITS=9
CONFIG_SECURITY_SELINUX_SID2STR_CACHE_SIZE=256
CONFIG_SECURITY_SELINUX_AVC_HASH_BITS=9
# CONFIG_SECURITY_SELINUX_DEBUG is not set
]
|
| 47/2 |
2026/12/02 14:58 |
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
]
|
| 48/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/proc/base.c Name:pid_revalidate]
Results: map[SourceCode:2038: /*
2039: * Rewrite the inode's ownerships here because the owning task may have
2040: * performed a setuid(), etc.
2041: *
2042: */
2043: static int pid_revalidate(struct inode *dir, const struct qstr *name,
2044: struct dentry *dentry, unsigned int flags)
2045: {
2046: struct inode *inode;
2047: struct task_struct *task;
2048: int ret = 0;
2049:
2050: rcu_read_lock();
2051: inode = d_inode_rcu(dentry);
2052: if (!inode)
2053: goto out;
2054: task = pid_task(proc_pid(inode), PIDTYPE_PID);
2055:
2056: if (task) {
2057: pid_update_inode(task, inode);
2058: ret = 1;
2059: }
2060: out:
2061: rcu_read_unlock();
2062: return ret;
2063: }
SourceFile:fs/proc/base.c]
|
| 49/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/proc/base.c Name:pid_update_inode]
Results: map[SourceCode:2027: /*
2028: * Set <pid>/... inode ownership (can change due to setuid(), etc.)
2029: */
2030: void pid_update_inode(struct task_struct *task, struct inode *inode)
2031: {
2032: task_dump_owner(task, inode->i_mode, &inode->i_uid, &inode->i_gid);
2033:
2034: inode->i_mode &= ~(S_ISUID | S_ISGID);
2035: security_task_to_inode(task, inode);
2036: }
SourceFile:fs/proc/base.c]
|
| 50/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:selinux_inode_permission]
Results: map[SourceCode:3257: /**
3258: * selinux_inode_permission - Check if the current task can access an inode
3259: * @idmap: idmap of the mount
3260: * @inode: the inode that is being accessed
3261: * @requested: the accesses being requested
3262: *
3263: * Check if the current task is allowed to access @inode according to
3264: * @requested. Returns 0 if allowed, negative values otherwise.
3265: */
3266: static int selinux_inode_permission(const struct mnt_idmap *idmap,
3267: struct inode *inode, int requested)
3268: {
3269: int mask;
3270: u32 perms;
3271: u32 sid = current_sid();
3272: struct task_security_struct *tsec;
3273: struct inode_security_struct *isec;
3274: struct avdc_entry *avdc;
3275: struct av_decision avd, *avdp = &avd;
3276: int rc, rc2;
3277: u32 audited, denied;
3278:
3279: mask = requested & (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
3280:
3281: /* No permission to check. Existence test. */
3282: if (!mask)
3283: return 0;
3284:
3285: tsec = selinux_task(current);
3286: if (task_avdcache_permnoaudit(tsec, sid))
3287: return 0;
3288:
3289: isec = inode_security_rcu(inode, requested & MAY_NOT_BLOCK);
3290: if (IS_ERR(isec))
3291: return PTR_ERR(isec);
3292: perms = file_mask_to_av(inode->i_mode, mask);
3293:
3294: rc = task_avdcache_search(tsec, isec, &avdc);
3295: if (likely(!rc)) {
3296: /* Cache hit. */
3297: avdp = &avdc->avd;
3298: denied = perms & ~avdp->allowed;
3299: if (unlikely(denied) && enforcing_enabled() &&
3300: !(avdp->flags & AVD_FLAGS_PERMISSIVE))
3301: rc = -EACCES;
3302: } else {
3303: /* Cache miss. */
3304: rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass,
3305: perms, 0, avdp);
3306: task_avdcache_update(tsec, isec, avdp);
3307: }
3308:
3309: audited = avc_audit_required(perms, avdp, rc,
3310: (requested & MAY_ACCESS) ?
3311: FILE__AUDIT_ACCESS : 0, &denied);
3312: if (likely(!audited))
3313: return rc;
3314:
3315: rc2 = audit_inode_permission(inode, perms, audited, denied, rc);
3316: if (rc2)
3317: return rc2;
3318:
3319: return rc;
3320: }
SourceFile:security/selinux/hooks.c]
|
| 51/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:selinux_task_to_inode]
Results: map[SourceCode:4732: static void selinux_task_to_inode(struct task_struct *p,
4733: struct inode *inode)
4734: {
4735: struct inode_security_struct *isec = selinux_inode(inode);
4736: u32 sid = task_sid_obj(p);
4737:
4738: spin_lock(&isec->lock);
4739: isec->sclass = inode_mode_to_security_class(inode->i_mode);
4740: isec->sid = sid;
4741: isec->initialized = LABEL_INITIALIZED;
4742: spin_unlock(&isec->lock);
4743: }
SourceFile:security/selinux/hooks.c]
|
| 52/2 |
2026/12/02 14:58 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 10579
output: 162
thoughts: 433
Thoughts: **My Thought Process on the `/proc` Entry Point and Potential SELinux Race Condition**
It strikes me immediately how incredibly simple and direct the entry point is here. Both Task 4030 and Task 4029 are just calling `openat()`, and importantly, they are doing so via `do_sys_openat2` on a path that looks like `/proc/<pid>/...`. This seems almost too straightforward, which, in my experience, often hints at a deeper interaction or a potential vulnerability.
This simplicity leads me to a crucial question: Can an unprivileged user process actually leverage this? Specifically, can it access paths like `/proc/self/stat` or `/proc/<own_pid>/...` or even `/proc/<pid>/...` for other processes? And, more importantly, can it concurrently perform an `openat()` operation from two separate threads or processes on such a path, thereby potentially triggering a race condition? The critical part of this hypothetical race is whether one thread could execute `pid_revalidate()` which then calls `pid_update_inode()` and subsequently `selinux_task_to_inode()`, while simultaneously, another thread is executing `link_path_walk()` leading to `may_lookup()`, `inode_permission()`, and finally `selinux_inode_permission()` on the *same* `/proc/<pid>` dentry/inode.
To validate this initial hypothesis, I need to confirm a few things:
First, I need to be sure about the accessibility of `/proc` to unprivileged users. My understanding is that `/proc` is universally mounted and accessible. Paths like `/proc/self/...` or `/proc/<pid>/...` (e.g., `/proc/<pid>/status`, or entries within `/proc/<pid>/fd/...`) are generally readable by unprivileged users. This is especially true for their *own* PIDs, and even for other PIDs, the directory traversal itself is often permitted because `/proc/<pid>` directories typically have permissions like `0555`, allowing entry and listing. So, access is indeed likely.
Second, I need to delve into the kernel's implementation details. Iβll be examining `fs/proc/base.c` to confirm exactly how `pid_revalidate` is integrated and whether there are any specific capability requirements or special conditions that must be met to reach `pid_revalidate` and, critically, `may_lookup`. Understanding the precise invocation path is key.
Third, and this is crucial for the SELinux angle, I need to determine the state of SELinux itself. Is SELinux required to be enabled and initialized for these hooks to even be present or functional? Specifically, I need to check if `selinux_enabled` is true or if `selinux_hooks` are registered. Furthermore, I must ascertain if `selinux_inode_permission` and `selinux_task_to_inode` are registered by default whenever SELinux is enabled during boot. I'll be looking into `security/selinux/hooks.c` and using `kernel-config-grep` to search for `LSM` or `SECURITY` related configurations to understand how these security hooks are wired in.
This systematic verification is essential to move from a speculative observation about the simple entry point to a concrete understanding of whether this potential SELinux race condition is viable.
|
| 53/2 |
2026/12/02 14:58 |
tool |
kernel-config-grep |
0m
Args:
Results: map[Output:CONFIG_LSM_MMAP_MIN_ADDR=65536
CONFIG_LSM="landlock,lockdown,yama,loadpin,safesetid,selinux,smack,tomoyo,apparmor,ipe,bpf"
]
|
| 54/2 |
2026/12/02 14:58 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/proc/base.c IncludeSnippetLines:5 Name:pid_revalidate SourceTreePrefix:fs/proc/]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:pid_dentry_operations SourceFile:fs/proc/base.c SourceLine:2081 SourceSnippet:2079: const struct dentry_operations pid_dentry_operations =
2080: {
2081: .d_revalidate = pid_revalidate,
2082: .d_delete = pid_delete_dentry,
2083: };
]] TruncatedOutput:false]
|
| 55/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_avdcache_permnoaudit]
Results: map[SourceCode: 58: static inline bool task_avdcache_permnoaudit(struct task_security_struct *tsec,
59: u32 sid)
60: {
61: return (tsec->avdcache.permissive_neveraudit &&
62: sid == tsec->avdcache.sid &&
63: tsec->avdcache.seqno == avc_policy_seqno());
64: }
SourceFile:security/selinux/include/objsec.h]
|
| 56/2 |
2026/12/02 14:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:inode_security_rcu]
Results: map[SourceCode: 311: static inline struct inode_security_struct *inode_security_rcu(struct inode *inode,
312: bool rcu)
313: {
314: int rc;
315: struct inode_security_struct *isec = selinux_inode(inode);
316:
317: /* check below is racy, but revalidate will recheck with lock held */
318: if (data_race(likely(isec->initialized == LABEL_INITIALIZED)))
319: return isec;
320: rc = __inode_security_revalidate(inode, NULL, !rcu);
321: if (rc)
322: return ERR_PTR(rc);
323: return isec;
324: }
SourceFile:security/selinux/hooks.c]
|
| 57/2 |
2026/12/02 14:58 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 11812
output: 124
thoughts: 213
Thoughts: **My Exploration of SELinux Initialization and Permissions**
My initial thought was to simply verify if SELinux was enabled in the kernel configuration. I found `CONFIG_SECURITY_SELINUX=y` and, more importantly, saw that `selinux` was present in the `CONFIG_LSM` string, confirming its inclusion as a loadable security module. This seemed straightforward enough.
However, a more nuanced question immediately arose: what is the *actual* behavior of SELinux permission checks, specifically regarding `task_avdcache_permnoaudit`, when no policy is loaded versus when one is? I also wondered if `selinux_inode_permission` even gets to the point of checking `isec->sid` in these scenarios, particularly when no policy is loaded or when a default policy might be in effect.
To delve deeper, I decided to examine the source code. My plan was to investigate the `avdcache` (access vector discriminant cache) mechanisms, specifically `task_avdcache_update` and `task_avdcache_search`, which I expect to find within `security/selinux/hooks.c` or perhaps `include/objsec.h`. Concurrently, I need to understand how the system determines if SELinux is active and ready for policy enforcement, which means looking into functions like `enforcing_enabled()` and `selinux_initialized()`. This will help me understand the precise conditions under which permission checks are performed and how the cache might behave even in the absence of a fully loaded policy.
|
| 58/2 |
2026/12/02 14:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_avdcache_search]
Results: map[SourceCode:3190: /**
3191: * task_avdcache_search - Search the task's AVD cache
3192: * @tsec: the task's security state
3193: * @isec: the inode to search for in the cache
3194: * @avdc: matching avd cache entry returned to the caller
3195: *
3196: * Search @tsec for a AVD cache entry that matches @isec and return it to the
3197: * caller via @avdc. Returns 0 if a match is found, negative values otherwise.
3198: */
3199: static inline int task_avdcache_search(struct task_security_struct *tsec,
3200: struct inode_security_struct *isec,
3201: struct avdc_entry **avdc)
3202: {
3203: int orig, iter;
3204:
3205: /* focused on path walk optimization, only cache directories */
3206: if (isec->sclass != SECCLASS_DIR)
3207: return -ENOENT;
3208:
3209: if (unlikely(current_sid() != tsec->avdcache.sid ||
3210: tsec->avdcache.seqno != avc_policy_seqno())) {
3211: task_avdcache_reset(tsec);
3212: return -ENOENT;
3213: }
3214:
3215: orig = iter = tsec->avdcache.dir_spot;
3216: do {
3217: if (tsec->avdcache.dir[iter].isid == isec->sid) {
3218: /* cache hit */
3219: tsec->avdcache.dir_spot = iter;
3220: *avdc = &tsec->avdcache.dir[iter];
3221: return 0;
3222: }
3223: iter = (iter - 1) & (TSEC_AVDC_DIR_SIZE - 1);
3224: } while (iter != orig);
3225:
3226: return -ENOENT;
3227: }
SourceFile:security/selinux/hooks.c]
|
| 59/2 |
2026/12/02 14:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:task_avdcache_update]
Results: map[SourceCode:3229: /**
3230: * task_avdcache_update - Update the task's AVD cache
3231: * @tsec: the task's security state
3232: * @isec: the inode associated with the cache entry
3233: * @avd: the AVD to cache
3234: *
3235: * Update the AVD cache in @tsec with the @avd info associated
3236: * with @isec.
3237: */
3238: static inline void task_avdcache_update(struct task_security_struct *tsec,
3239: struct inode_security_struct *isec,
3240: struct av_decision *avd)
3241: {
3242: int spot;
3243:
3244: /* focused on path walk optimization, only cache directories */
3245: if (isec->sclass != SECCLASS_DIR)
3246: return;
3247:
3248: /* update cache */
3249: spot = (tsec->avdcache.dir_spot + 1) & (TSEC_AVDC_DIR_SIZE - 1);
3250: tsec->avdcache.dir_spot = spot;
3251: tsec->avdcache.dir[spot].isid = isec->sid;
3252: tsec->avdcache.dir[spot].avd = *avd;
3253: tsec->avdcache.permissive_neveraudit =
3254: (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT));
3255: }
SourceFile:security/selinux/hooks.c]
|
| 60/2 |
2026/12/02 14:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/hooks.c Name:selinux_init]
Results: map[SourceCode:7970: static __init int selinux_init(void)
7971: {
7972: vma_flags_t data_default_flags = VMA_DATA_DEFAULT_FLAGS;
7973:
7974: pr_info("SELinux: Initializing.\n");
7975:
7976: memset(&selinux_state, 0, sizeof(selinux_state));
7977: enforcing_set(selinux_enforcing_boot);
7978: selinux_avc_init();
7979: mutex_init(&selinux_state.status_lock);
7980: mutex_init(&selinux_state.policy_mutex);
7981:
7982: /* Set the security state for the initial task. */
7983: cred_init_security();
7984:
7985: /* Inform the audit system that secctx is used */
7986: audit_cfg_lsm(&selinux_lsmid,
7987: AUDIT_CFG_LSM_SECCTX_SUBJECT |
7988: AUDIT_CFG_LSM_SECCTX_OBJECT);
7989:
7990: default_noexec = !vma_flags_test(&data_default_flags, VMA_EXEC_BIT);
7991: if (!default_noexec)
7992: pr_notice("SELinux: virtual memory is executable by default\n");
7993:
7994: avc_init();
7995:
7996: avtab_cache_init();
7997:
7998: ebitmap_cache_init();
7999:
8000: hashtab_cache_init();
8001:
8002: selinux_ima_config_len_init();
8003:
8004: security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks),
8005: &selinux_lsmid);
8006:
8007: if (avc_add_callback(selinux_netcache_avc_callback, AVC_CALLBACK_RESET))
8008: panic("SELinux: Unable to register AVC netcache callback\n");
8009:
8010: if (avc_add_callback(selinux_lsm_notifier_avc_callback, AVC_CALLBACK_RESET))
8011: panic("SELinux: Unable to register AVC LSM notifier callback\n");
8012:
8013: if (avc_add_callback(selinux_audit_rule_avc_callback,
8014: AVC_CALLBACK_RESET))
8015: panic("SELinux: Unable to register AVC audit callback\n");
8016:
8017: if (selinux_enforcing_boot)
8018: pr_debug("SELinux: Starting in enforcing mode\n");
8019: else
8020: pr_debug("SELinux: Starting in permissive mode\n");
8021:
8022: fs_validate_description("selinux", selinux_fs_parameters);
8023:
8024: return 0;
8025: }
SourceFile:security/selinux/hooks.c]
|
| 61/2 |
2026/12/02 14:59 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 14197
output: 95
thoughts: 549
Thoughts: **Deconstructing SELinux's Permissive Neveraudit Behavior**
My current train of thought is focused on a specific optimization within the SELinux inode permission checking mechanism, namely the `task_avdcache_permnoaudit(tsec, sid)` function, which I've identified at line 3286 of `selinux_inode_permission`. The critical observation here is its early return with a value of 0 if `tsec->avdcache.permissive_neveraudit` is true, and importantly, this happens *before* `isec->sid` is even read. This immediate exit condition is what has piqued my interest β I need to understand the precise circumstances under which `permissive_neveraudit` would be false, as thatβs when the full permission check logic is engaged.
I've traced the definition of `tsec->avdcache.permissive_neveraudit` to `avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT)`. This immediately suggests that the state of `avd->flags` is paramount. My hypothesis is that when SELinux has *no policy loaded*, the `avc_has_perm_noaudit` function (or perhaps `security_compute_av`, I need to verify this linkage) is responsible for setting `avd->flags` to `AVD_FLAGS_PERMISSIVE | AVD_FLAGS_NEVERAUDIT`. This would, in turn, enable the `permissive_neveraudit` shortcut.
However, I'm also considering a subtle point: even in the absence of a policy, on the *very first* call to `selinux_inode_permission()` for a given task (or after a cache reset, like following `execve`, a policy change, or when `permissive_neveraudit` is `false` because SELinux is operating in enforcing mode or has a policy that *does* include audit capabilities), the `task_avdcache_permnoaudit()` function *will return false*. In this scenario, execution proceeds to `task_avdcache_search()`, then `avc_has_perm_noaudit()`, followed by `task_avdcache_update()`, and crucially, `isec->sid` *will* be read. This holds true even when a SELinux policy *is* loaded, whether it's in enforcing mode or permissive mode but configured to audit; in these cases, `permissive_neveraudit` will be false for every lookup.
This brings me to a broader concern: the potential for an unprivileged user process to repeatedly perform actions like `fork()`, `execve()`, and `openat("/proc/self/...")` without encountering any privilege checks that would be intercepted by this `permnoaudit` logic.
To solidify my understanding and ensure I'm not missing any crucial details, I plan to perform a thorough review of `fs/proc/base.c` and `fs/namei.c`. Specifically, I need to confirm that there are no privilege checks in the `pid_revalidate` function or the `may_lookup` / `lookup_fast` operations, and I will examine the `proc_pid_lookup` and `proc_tgid_base_lookup` functions within `fs/proc/base.c` to be absolutely certain about the security context of these operations.
|
| 62/2 |
2026/12/02 14:59 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/proc/base.c IncludeSnippetLines:5 Name:pid_dentry_operations SourceTreePrefix:fs/proc/]
Results: map[References:<nil> TruncatedOutput:false]
|
| 63/2 |
2026/12/02 14:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/namei.c Name:lookup_fast]
Results: map[SourceCode:1835: /**
1836: * lookup_fast - do fast lockless (but racy) lookup of a dentry
1837: * @nd: current nameidata
1838: *
1839: * Do a fast, but racy lookup in the dcache for the given dentry, and
1840: * revalidate it. Returns a valid dentry pointer or NULL if one wasn't
1841: * found. On error, an ERR_PTR will be returned.
1842: *
1843: * If this function returns a valid dentry and the walk is no longer
1844: * lazy, the dentry will carry a reference that must later be put. If
1845: * RCU mode is still in force, then this is not the case and the dentry
1846: * must be legitimized before use. If this returns NULL, then the walk
1847: * will no longer be in RCU mode.
1848: */
1849: static struct dentry *lookup_fast(struct nameidata *nd)
1850: {
1851: struct dentry *dentry, *parent = nd->path.dentry;
1852: int status = 1;
1853:
1854: /*
1855: * Rename seqlock is not required here because in the off chance
1856: * of a false negative due to a concurrent rename, the caller is
1857: * going to fall back to non-racy lookup.
1858: */
1859: if (nd->flags & LOOKUP_RCU) {
1860: dentry = __d_lookup_rcu(parent, &nd->last, &nd->next_seq);
1861: if (unlikely(!dentry)) {
1862: if (!try_to_unlazy(nd))
1863: return ERR_PTR(-ECHILD);
1864: return NULL;
1865: }
1866:
1867: /*
1868: * This sequence count validates that the parent had no
1869: * changes while we did the lookup of the dentry above.
1870: */
1871: if (read_seqcount_retry(&parent->d_seq, nd->seq))
1872: return ERR_PTR(-ECHILD);
1873:
1874: status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
1875: if (likely(status > 0))
1876: return dentry;
1877: if (!try_to_unlazy_next(nd, dentry))
1878: return ERR_PTR(-ECHILD);
1879: if (status == -ECHILD)
1880: /* we'd been told to redo it in non-rcu mode */
1881: status = d_revalidate(nd->inode, &nd->last,
1882: dentry, nd->flags);
1883: } else {
1884: dentry = __d_lookup(parent, &nd->last);
1885: if (unlikely(!dentry))
1886: return NULL;
1887: status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
1888: }
1889: if (unlikely(status <= 0)) {
1890: if (!status)
1891: d_invalidate(dentry);
1892: dput(dentry);
1893: return ERR_PTR(status);
1894: }
1895: return dentry;
1896: }
SourceFile:fs/namei.c]
|
| 64/2 |
2026/12/02 14:59 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 15890
output: 47
thoughts: 434
Thoughts: **My Thought Process on the SELinux /proc Race Condition**
From my perspective, what we're observing here is a thoroughly standard, unprivileged VFS path lookup occurring within the `/proc` filesystem, specifically targeting files like `/proc/<pid>/stat` or `/proc/self/stat`. The core of the issue arises when two unprivileged threads or processes attempt to concurrently open a file under `/proc/<pid>/`, where the file is owned by that unprivileged user.
Specifically, one of these threads will enter the `lookup_fast()` path, leading through `d_revalidate()`, `pid_revalidate()`, `pid_update_inode()`, `security_task_to_inode()`, and finally to `selinux_task_to_inode()`. At this point, crucial SELinux information, `isec->sid`, is being written while holding `isec->lock`.
Simultaneously, the other concurrent thread will follow the `link_path_walk()` path, progressing through `may_lookup()`, `lookup_inode_permission_may_exec()`, `inode_permission()`, `security_inode_permission()`, and finally `selinux_inode_permission()`. The critical problem here is that this second path *reads* `isec->sid` without acquiring the `isec->lock` and, more importantly, without using memory synchronization primitives like `READ_ONCE()`. This is the classic data race.
What's particularly noteworthy is that this race condition doesn't require any special privileges. We don't need `CAP_*` capabilities, nor are we dealing with root-only files or device nodes. Crucially, user namespaces are also not a prerequisite for triggering this.
When I evaluate the characteristics of this vulnerability, I see the following:
* **Unprivileged:** It is indeed achievable by unprivileged code.
* **UserNamespace:** Since `Unprivileged` is true, `UserNamespace` *must* also be true.
* **RequiredCaps:** As it's unprivileged, this field will be empty (`[]`).
* **PeripheralTrigger:** This is not triggered by any physical peripheral device; it's an internal SELinux race within the `/proc` VFS. Thus, `false`.
* **FilesystemTrigger:** `/proc` is a kernel pseudo-filesystem. It's not a mounted, potentially malicious disk image that the kernel is parsing. Therefore, `false`.
* **RawFuzzingArtifact:** This is a genuine KCSAN-detected data race within the SELinux hooks, reachable through normal `openat()` calls on `/proc/<pid>/...` by unprivileged users. It's not merely a raw fuzzing artifact. So, `false`.
Based on this analysis, I will now proceed to `set-results` with these determined values.
|
| 65/2 |
2026/12/02 14:59 |
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]
|
| 66/2 |
2026/12/02 14:59 |
llm |
local-reachability |
0m
Model:
Tokens:
input: 16416
output: 759
thoughts: 21
Thoughts: **My Analytical Process and Presentation Strategy**
Alright, so the `set-results` command just confirmed that my analytical execution was successful. This is a crucial checkpoint. My immediate thought process now is to distill the output of that analysis into a form that is both crystal clear and demonstrably concise for the user. Given that you are an expert in your field, I understand that you don't need a lengthy, granular breakdown of every single step. What you require is a high-level summary that effectively conveys the essence of my findings and the logical progression of my analysis. I need to ensure that the presentation is *fulsome* β meaning it should be comprehensive in its coverage of the key insights and conclusions, without being verbose or redundant. My aim is to provide you with a summary that allows you to quickly grasp the core takeaways and, if necessary, delve deeper into specific aspects based on your expert intuition. Essentially, I'm transitioning from the "doing" phase of the analysis to the "communicating" phase, and doing so with a focus on efficiency and expert-level clarity.
|
| 67/1 |
2026/12/02 14:59 |
action |
If |
0m
Args: map[IsNetCandidate:false]
|
| 68/1 |
2026/12/02 14:59 |
action |
If |
0m
Args: map[IsKVMCandidate:false]
|
| 69/1 |
2026/12/02 14:59 |
action |
combine-assessment |
0m
Results: map[DenialOfService:false Explanation:Root Cause Analysis:
### Root Cause Analysis
The KCSAN data race occurs on the 4-byte `sid` field (`u32 sid`, offset 28
bytes) of `struct inode_security_struct`
(`security/selinux/include/objsec.h:72-80`) between concurrent `/proc/<pid>`
dentry revalidation and inode permission checks during VFS path lookup.
#### 1. Writer path (`selinux_task_to_inode`)
When a task walks `/proc/<pid>`, `lookup_fast()` (`fs/namei.c:1874`) invokes
`d_revalidate()` -> `pid_revalidate()` (`fs/proc/base.c:2043-2063`) ->
`pid_update_inode()` (`fs/proc/base.c:2030-2036`) -> `security_task_to_inode()`
-> `selinux_task_to_inode()` (`security/selinux/hooks.c:4732-4743`):
```c
static void selinux_task_to_inode(struct task_struct *p,
struct inode *inode)
{
struct inode_security_struct *isec = selinux_inode(inode);
u32 sid = task_sid_obj(p);
spin_lock(&isec->lock);
isec->sclass = inode_mode_to_security_class(inode->i_mode);
isec->sid = sid;
isec->initialized = LABEL_INITIALIZED;
spin_unlock(&isec->lock);
}
```
`pid_revalidate()` runs under `rcu_read_lock()` (and even in non-RCU mode does
not hold an exclusive lock across concurrent path-walk readers).
`selinux_task_to_inode()` acquires `isec->lock` and writes `isec->sclass`,
`isec->sid` (line 4740), and `isec->initialized` with plain stores
(`WRITE_ONCE()` is not used).
#### 2. Reader path (`selinux_inode_permission`)
Concurrently, another task traversing the same `/proc/<pid>` directory enters
`link_path_walk()` -> `may_lookup()` -> `lookup_inode_permission_may_exec()` ->
`inode_permission()` -> `security_inode_permission()` ->
`selinux_inode_permission()` (`security/selinux/hooks.c:3266-3320`).
`selinux_inode_permission()` obtains `isec` via `inode_security_rcu(inode,
requested & MAY_NOT_BLOCK)` (`security/selinux/hooks.c:311-324`), which only
checks `data_race(likely(isec->initialized == LABEL_INITIALIZED))` without
taking `isec->lock`. It then reads `isec->sid` (and `isec->sclass`) locklessly
and without `READ_ONCE()` across multiple places:
- `task_avdcache_search()` (`security/selinux/hooks.c:3217`): compares
`tsec->avdcache.dir[iter].isid == isec->sid` in a loop over `TSEC_AVDC_DIR_SIZE`
entries.
- On cache miss (`security/selinux/hooks.c:3304-3306`):
- `avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, avdp)` reads
`isec->sid`.
- `task_avdcache_update(tsec, isec, avdp)` (`security/selinux/hooks.c:3251`)
reads `isec->sid` **a second time** (`tsec->avdcache.dir[spot].isid =
isec->sid;`).
- `audit_inode_permission()` -> `slow_avc_audit()`
(`security/selinux/hooks.c:3171`): reads `isec->sid` again if auditing is
required.
#### 3. Invariant violation
`isec->lock` is used by writers (`selinux_task_to_inode()`, as well as
`selinux_inode_post_setxattr()` and `selinux_inode_setsecurity()`) to serialize
updates to `isec->sid` and `isec->sclass`, but lockless RCU/path-walk readers
such as `selinux_inode_permission()` read `isec->sid` and `isec->sclass` without
`isec->lock` and without `READ_ONCE()`/`WRITE_ONCE()` synchronization.
In addition to the KCSAN-reported data race (and potential compiler
reload/tearing), reading `isec->sid` separately in `avc_has_perm_noaudit()` and
`task_avdcache_update()` allows a concurrent `selinux_task_to_inode()` update
between the two reads to store the new `isec->sid` alongside the `av_decision`
(`avdp`) computed for the old `isec->sid` in `tsec->avdcache`.
*(Note: Other lockless readers of `isec->sid` and `isec->sclass` in
`security/selinux/hooks.c`, such as `selinux_inode_follow_link()` and
`selinux_file_permission()`, share this same pattern against concurrent
`isec->lock`-protected `isec->sid` updates.)*
Impact Analysis:
In real-world setups without KCSAN, this data race does not cause memory
corruption, crashes, or kernel information leaks. `isec->sid` is a 4-byte
aligned `u32` (at offset 28 in `struct inode_security_struct`), and even if a
concurrent `selinux_task_to_inode()` update occurs while
`selinux_inode_permission()` reads `isec->sid`, `avc_lookup()` /
`sidtab_search()` safely handle any valid or unrecognized `u32` SID (defaulting
to deny on unrecognized SIDs), and `task_avdcache_search()` /
`task_avdcache_update()` only index a fixed 4-entry per-task array with masked
indices. The worst-case runtime consequence is a transient SELinux MAC policy
inconsistency: `selinux_inode_permission()` reads `isec->sid` multiple times
without locking or `READ_ONCE()`, so `isec->sid` can change between
`avc_has_perm_noaudit()` and `task_avdcache_update()`, causing the task's
`avdcache` to cache an `av_decision` computed for the old SID under the new SID.
Classification reasoning:
- MemoryCorruption: false β no pointers, refcounts, buffer lengths, or
memory-safety-critical state are corrupted; only a `u32` SELinux SID value is
raced on.
- InfoLeak: "none" β no kernel memory contents are exposed or copied to
userspace.
- RawDenialOfService: false β no crash, panic, WARN/BUG, deadlock, infinite
loop, or resource leak can occur from this race.
- IsNetCandidate: false β the bug is purely in SELinux inode security handling
during `/proc` VFS path lookup.
- IsKVMCandidate: false β unrelated to KVM or virtualization.
Local Reachability Analysis:
### Analysis Summary
This KCSAN data race occurs on `struct inode_security_struct::sid` (`u32`)
between concurrent VFS path lookups on `/proc/<pid>/...` when SELinux is enabled
(`CONFIG_SECURITY_SELINUX=y`, and `selinux` is included in `CONFIG_LSM`):
1. **Writer path (`selinux_task_to_inode`)**:
- Invoked from `openat()` -> `link_path_walk()` -> `walk_component()` ->
`lookup_fast()` -> `d_revalidate()` -> `pid_revalidate()`
(`fs/proc/base.c:2043`) -> `pid_update_inode()` (`fs/proc/base.c:2030`) ->
`security_task_to_inode()` -> `selinux_task_to_inode()`
(`security/selinux/hooks.c:4732`).
- `pid_revalidate()` is attached via `pid_dentry_operations.d_revalidate` on
`/proc/<pid>` dentries and runs during normal unprivileged path lookup
without any capability checks.
- `selinux_task_to_inode()` writes `isec->sid` with a plain store under
`isec->lock`.
2. **Reader path (`selinux_inode_permission`)**:
- Invoked from `openat()` -> `link_path_walk()` -> `may_lookup()` ->
`lookup_inode_permission_may_exec()` -> `inode_permission()` ->
`security_inode_permission()` -> `selinux_inode_permission()`
(`security/selinux/hooks.c:3266`).
- Obtains `isec` via `inode_security_rcu()` without acquiring `isec->lock`,
and reads `isec->sid` locklessly in `task_avdcache_search()`,
`avc_has_perm_noaudit()`, and `task_avdcache_update()`.
- When `task_avdcache_permnoaudit()` is false (e.g., on initial lookups for a
task or when SELinux policy/enforcing/auditing applies), an unprivileged
process traversing `/proc/<pid>/...` (such as `/proc/self/stat` or
`/proc/<own_pid>/status`) reaches these reads directly.
### Field-by-Field Reasoning
- **Unprivileged (`true`)**: An unprivileged process can spawn two threads (or
processes) that concurrently call `openat()` on its own `/proc/<pid>/...`
entries (e.g., `/proc/<pid>/status`), hitting `pid_revalidate()` ->
`selinux_task_to_inode()` and `may_lookup()` -> `selinux_inode_permission()`
simultaneously without any capabilities, special file permissions, or user
namespaces.
- **UserNamespace (`true`)**: Must be `true` when `Unprivileged` is `true`.
- **RequiredCaps (`[]`)**: No capabilities are required.
- **PeripheralTrigger (`false`)**: Triggered via normal `/proc` VFS lookups and
SELinux inode security hooks, not via a physical peripheral device.
- **FilesystemTrigger (`false`)**: `/proc` is a kernel pseudo-filesystem rather
than a user-supplied filesystem image parsed on mount.
- **RawFuzzingArtifact (`false`)**: The bug is a genuine kernel data race in
SELinux hooks reachable by unprivileged processes via standard `openat()`
syscalls on `/proc`. Exploitable:false FuzzingArtifact:false]
|