| 0/0 |
2026/07/27 02:10 |
flow |
assessment-security |
5m
Results: map[DenialOfService:true Explanation:Based on the analysis of the bug report and the kernel source code, here is the
assessment of the issue:
**Bug Analysis:**
The bug report indicates an RCU stall (soft lockup) occurring in
`avtab_search_node()` within the SELinux subsystem. The call trace shows that an
unprivileged process is performing a standard file access (`openat2` -> `mmap`),
which triggers a SELinux permission check (`security_compute_av` ->
`context_struct_compute_av` -> `cond_compute_av` -> `avtab_search_node`).
In `context_struct_compute_av()`, the kernel iterates over all attributes of the
source context type and all attributes of the target context type using nested
`ebitmap_for_each_positive_bit` loops. For each combination, it searches the
SELinux Access Vector (AV) tables (`te_avtab` and `te_cond_avtab`) using
`avtab_search_node()` and `avtab_search_node_next()`.
If a loaded SELinux policy contains an abnormally large number of attributes for
specific types, or a massive number of conditional rules that hash to the same
bucket in `te_cond_avtab`, these nested loops and hash table traversals will
execute millions or billions of times. This results in the CPU spending an
excessive amount of time in this function without yielding, ultimately
triggering an RCU stall / soft lockup.
**Security Impact:**
While this is a Denial of Service (DoS) condition, it is entirely dependent on
the contents of the loaded SELinux policy.
- **Privilege Boundary:** Loading or modifying a SELinux policy requires highly
privileged capabilities, specifically the `SECURITY__LOAD_POLICY` SELinux
permission (typically reserved for processes with `CAP_MAC_ADMIN` or equivalent
root-level administrative roles).
- **Unprivileged Access:** An unprivileged user cannot load a malicious policy,
nor can they arbitrarily add attributes or rules to an existing policy. They can
only trigger the evaluation of the existing policy. Assuming a standard,
non-malicious policy, the number of attributes and rules is bounded and will not
cause a lockup.
- **User Namespaces:** SELinux policies are global and are not isolated per user
namespace. Entering a user namespace does not grant a process the ability to
load a SELinux policy.
Since the fuzzer (syzbot) runs with root privileges in the test environment, it
is able to load a mutated, malicious SELinux policy that intentionally triggers
this pathological performance edge-case. However, in a real-world scenario, an
attacker would already need full administrative control over the system to load
such a policy, at which point the system is already fully compromised.
Therefore, this is not considered a security vulnerability that crosses a
privilege boundary. It is not exploitable for memory corruption, privilege
escalation, or information leaks.
**Conclusion:**
- **Exploitable:** False
- **Denial of Service:** True (but requires administrative privileges to set up
the malicious policy)
- **Accessible From Unprivileged Processes:** False
- **Accessible From User Namespaces:** False Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/07/27 02:10 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/07/27 02:10 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/ea1ec46165a34622b3d5769ce1a7084d96856f42]
|
| 3/1 |
2026/07/27 02:10 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/1f800065309ae5a266e72bb56d30409321e3988a]
|
| 4/1 |
2026/07/27 02:10 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/07/27 02:10 |
agent |
expert |
5m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
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.
Prompt:
The kernel bug report is:
rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
rcu: Tasks blocked on level-0 rcu_node (CPUs 0-1): P24535/1:b..l
rcu: (detected by 1, t=10505 jiffies, g=166629, q=286 ncpus=2)
task:syz.5.4203 state:R running task stack:27048 pid:24535 tgid:24530 ppid:22082 task_flags:0x400140 flags:0x00080000
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5510 [inline]
__schedule+0x125c/0x6730 kernel/sched/core.c:7234
preempt_schedule_irq+0x50/0x90 kernel/sched/core.c:7556
irqentry_exit_to_kernel_mode_preempt include/linux/irq-entry-common.h:468 [inline]
irqentry_exit_to_kernel_mode include/linux/irq-entry-common.h:539 [inline]
irqentry_exit+0x205/0xa00 kernel/entry/common.c:167
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
RIP: 0010:avtab_search_node+0x0/0x490 security/selinux/ss/avtab.c:146
Code: e8 05 26 a3 fd 8b 04 24 e9 b5 fc ff ff e8 98 25 a3 fd e9 00 ff ff ff 0f 1f 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 <0f> 1f 40 d6 41 57 41 56 41 55 41 54 55 48 89 f5 53 48 89 fb 48 83
RSP: 0018:ffffc900056372d0 EFLAGS: 00000283
RAX: 000000000000c631 RBX: ffff8880353b8988 RCX: ffffc90010789000
RDX: 0000000000080000 RSI: ffffc90005637420 RDI: ffff8880353b8988
RBP: ffff88802a078de0 R08: 0000000000000002 R09: 00000000000004d5
R10: 00000000000000bf R11: 0000000000000000 R12: ffffc900056376e0
R13: 0000000000000600 R14: ffffc900056376e0 R15: ffffc90005637420
cond_compute_av+0x5f/0x350 security/selinux/ss/conditional.c:591
context_struct_compute_av+0x81f/0x1250 security/selinux/ss/services.c:677
security_compute_av+0x5ea/0x11e0 security/selinux/ss/services.c:1178
avc_compute_av+0x84/0x820 security/selinux/avc.c:992
avc_perm_nonode+0xb1/0x180 security/selinux/avc.c:1117
avc_has_perm_noaudit+0x2d4/0x3b0 security/selinux/avc.c:1160
cred_has_capability.isra.0+0x171/0x300 security/selinux/hooks.c:1666
security_capable+0x10d/0x260 security/security.c:660
ns_capable_common kernel/capability.c:342 [inline]
ns_capable kernel/capability.c:363 [inline]
capable_wrt_inode_uidgid+0xca/0x170 kernel/capability.c:478
generic_permission fs/namei.c:536 [inline]
generic_permission+0x496/0x800 fs/namei.c:521
do_inode_permission fs/namei.c:590 [inline]
inode_permission+0x2df/0x620 fs/namei.c:653
lookup_one_common fs/namei.c:3121 [inline]
lookup_one_common fs/namei.c:3114 [inline]
start_creating+0x84/0x120 fs/namei.c:3402
ovl_start_creating_upper fs/overlayfs/overlayfs.h:428 [inline]
ovl_create_upper+0x1f3/0x610 fs/overlayfs/dir.c:371
ovl_create_handle_whiteouts fs/overlayfs/dir.c:644 [inline]
ovl_create_or_link+0x321/0x390 fs/overlayfs/dir.c:686
ovl_create_object+0x2bf/0x3b0 fs/overlayfs/dir.c:723
lookup_open fs/namei.c:4508 [inline]
open_last_lookups fs/namei.c:4608 [inline]
path_openat+0x341f/0x4280 fs/namei.c:4860
do_file_open+0x20e/0x430 fs/namei.c:4892
do_sys_openat2+0x10f/0x1e0 fs/open.c:1368
do_sys_open fs/open.c:1374 [inline]
__do_sys_creat fs/open.c:1452 [inline]
__se_sys_creat fs/open.c:1446 [inline]
__x64_sys_creat+0xcc/0x120 fs/open.c:1446
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f932299de99
RSP: 002b:00007f932391c028 EFLAGS: 00000246 ORIG_RAX: 0000000000000055
RAX: ffffffffffffffda RBX: 00007f9322c26090 RCX: 00007f932299de99
RDX: 0000000000000000 RSI: 0000000000000062 RDI: 0000200000000000
RBP: 00007f9322a33eaf R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f9322c26128 R14: 00007f9322c26090 R15: 00007ffcf53cd5e8
</TASK>
rcu: rcu_preempt kthread timer wakeup didn't happen for 10500 jiffies! g166629 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402
rcu: Possible timer handling issue on cpu=0 timer-softirq=110479
rcu: rcu_preempt kthread starved for 10501 jiffies! g166629 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402 ->cpu=0
rcu: Unless rcu_preempt kthread gets sufficient CPU time, OOM is now expected behavior.
rcu: RCU grace-period kthread stack dump:
task:rcu_preempt state:I stack:27432 pid:16 tgid:16 ppid:2 task_flags:0x208040 flags:0x00080000
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5510 [inline]
__schedule+0x125c/0x6730 kernel/sched/core.c:7234
__schedule_loop kernel/sched/core.c:7311 [inline]
schedule+0xdd/0x2c0 kernel/sched/core.c:7326
schedule_timeout+0x127/0x280 kernel/time/sleep_timeout.c:99
rcu_gp_fqs_loop+0x1a9/0x900 kernel/rcu/tree.c:2123
rcu_gp_kthread+0x179/0x230 kernel/rcu/tree.c:2325
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
rcu: Stack dump where RCU GP kthread last ran:
Sending NMI from CPU 1 to CPUs 0:
NMI backtrace for cpu 0
CPU: 0 UID: 0 PID: 24533 Comm: syz.0.4204 Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/16/2026
RIP: 0010:__lock_acquire+0x4be/0x1a40 kernel/locking/lockdep.c:5207
Code: 48 89 de 48 89 ef e8 f1 ee ff ff 85 c0 0f 84 e9 fe ff ff 44 8b 1d a2 b9 8d 19 45 85 db 75 11 4d 63 e4 4c 0f a3 25 72 0d 85 14 <0f> 83 69 0b 00 00 48 8b b5 90 0b 00 00 45 85 ed 0f 84 93 01 00 00
RSP: 0018:ffffc90000007c58 EFLAGS: 00000047
RAX: 0000000000000001 RBX: ffff88804e300bc8 RCX: 0000000000000100
RDX: 0000000000000000 RSI: ffff88804e300bc8 RDI: ffff88804e300000
RBP: ffff88804e300000 R08: 0000000000000001 R09: 0000000000000002
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001
FS: 00007f218e54e6c0(0000) GS:ffff888123dde000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b30c22ff8 CR3: 0000000055e5a000 CR4: 00000000003526f0
Call Trace:
<IRQ>
lock_acquire kernel/locking/lockdep.c:5868 [inline]
lock_acquire+0x1b9/0x370 kernel/locking/lockdep.c:5825
__raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:132 [inline]
_raw_spin_lock_irqsave+0x3a/0x60 kernel/locking/spinlock.c:166
debug_object_deactivate+0x135/0x3b0 lib/debugobjects.c:936
debug_hrtimer_deactivate kernel/time/hrtimer.c:490 [inline]
__run_hrtimer kernel/time/hrtimer.c:2000 [inline]
__hrtimer_run_queues+0x2e9/0x9c0 kernel/time/hrtimer.c:2096
hrtimer_interrupt+0x3e5/0x940 kernel/time/hrtimer.c:2215
local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1051 [inline]
__sysvec_apic_timer_interrupt+0x109/0x470 arch/x86/kernel/apic/apic.c:1068
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
sysvec_apic_timer_interrupt+0x9e/0xc0 arch/x86/kernel/apic/apic.c:1062
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
RIP: 0010:in_irqentry_text kernel/stacktrace.c:380 [inline]
RIP: 0010:filter_irq_stacks+0x48/0x90 kernel/stacktrace.c:397
Code: ea 03 80 3c 1a 00 75 4a 48 8b 17 48 81 fa 30 02 00 81 72 16 48 81 fa 90 16 00 81 73 0d 83 c0 01 48 83 c4 10 5b c3 cc cc cc cc <48> 81 fa 00 15 be 8b 72 09 48 81 fa 1b 15 be 8b 72 e1 83 c0 01 48
RSP: 0018:ffffc90005667400 EFLAGS: 00000206
RAX: 0000000000000007 RBX: dffffc0000000000 RCX: 0000000000000001
RDX: ffffffff84dc1762 RSI: 0000000000000012 RDI: ffffc900056674b0
RBP: 0000000000082820 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffc90005667478
R13: 0000000000000800 R14: ffff88807f351000 R15: 0000000000000800
stack_depot_save_flags+0x27/0x9d0 lib/stackdepot.c:667
kasan_save_stack+0x3f/0x50 mm/kasan/common.c:58
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__do_kmalloc_node mm/slub.c:5334 [inline]
__kmalloc_node_track_caller_noprof+0x331/0x830 mm/slub.c:5471
kmalloc_reserve+0xe8/0x350 net/core/skbuff.c:637
__alloc_skb+0x185/0x710 net/core/skbuff.c:715
alloc_skb include/linux/skbuff.h:1384 [inline]
nlmsg_new include/net/netlink.h:1055 [inline]
audit_buffer_alloc kernel/audit.c:1846 [inline]
audit_log_start+0x350/0x930 kernel/audit.c:1965
common_lsm_audit+0xb2/0x2b0 security/lsm_audit.c:442
slow_avc_audit+0x186/0x210 security/selinux/avc.c:779
avc_audit security/selinux/include/avc.h:131 [inline]
avc_has_perm+0x1a6/0x1e0 security/selinux/avc.c:1198
__file_map_prot_check+0x368/0x830 security/selinux/hooks.c:3996
file_map_prot_check security/selinux/hooks.c:4022 [inline]
selinux_mmap_file_common security/selinux/hooks.c:4054 [inline]
selinux_mmap_file+0x14d/0x1c0 security/selinux/hooks.c:4061
security_mmap_file+0xc3/0x9b0 security/security.c:2581
vm_mmap_pgoff+0xec/0x470 mm/util.c:575
ksys_mmap_pgoff+0xe4/0x610 mm/mmap.c:606
__do_sys_mmap arch/x86/kernel/sys_x86_64.c:89 [inline]
__se_sys_mmap arch/x86/kernel/sys_x86_64.c:82 [inline]
__x64_sys_mmap+0x125/0x190 arch/x86/kernel/sys_x86_64.c:82
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f218d59de99
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f218e54e028 EFLAGS: 00000246 ORIG_RAX: 0000000000000009
RAX: ffffffffffffffda RBX: 00007f218d825fa0 RCX: 00007f218d59de99
RDX: b635773f06ebbeee RSI: 0000000000b36000 RDI: 0000200000000000
RBP: 00007f218d633eaf R08: ffffffffffffffff R09: 0000000000000000
R10: 0000000000008031 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f218d826038 R14: 00007f218d825fa0 R15: 00007fffcbfdaff8
</TASK>
Reply: Based on the analysis of the bug report and the kernel source code, here is the assessment of the issue:
**Bug Analysis:**
The bug report indicates an RCU stall (soft lockup) occurring in `avtab_search_node()` within the SELinux subsystem. The call trace shows that an unprivileged process is performing a standard file access (`openat2` -> `mmap`), which triggers a SELinux permission check (`security_compute_av` -> `context_struct_compute_av` -> `cond_compute_av` -> `avtab_search_node`).
In `context_struct_compute_av()`, the kernel iterates over all attributes of the source context type and all attributes of the target context type using nested `ebitmap_for_each_positive_bit` loops. For each combination, it searches the SELinux Access Vector (AV) tables (`te_avtab` and `te_cond_avtab`) using `avtab_search_node()` and `avtab_search_node_next()`.
If a loaded SELinux policy contains an abnormally large number of attributes for specific types, or a massive number of conditional rules that hash to the same bucket in `te_cond_avtab`, these nested loops and hash table traversals will execute millions or billions of times. This results in the CPU spending an excessive amount of time in this function without yielding, ultimately triggering an RCU stall / soft lockup.
**Security Impact:**
While this is a Denial of Service (DoS) condition, it is entirely dependent on the contents of the loaded SELinux policy.
- **Privilege Boundary:** Loading or modifying a SELinux policy requires highly privileged capabilities, specifically the `SECURITY__LOAD_POLICY` SELinux permission (typically reserved for processes with `CAP_MAC_ADMIN` or equivalent root-level administrative roles).
- **Unprivileged Access:** An unprivileged user cannot load a malicious policy, nor can they arbitrarily add attributes or rules to an existing policy. They can only trigger the evaluation of the existing policy. Assuming a standard, non-malicious policy, the number of attributes and rules is bounded and will not cause a lockup.
- **User Namespaces:** SELinux policies are global and are not isolated per user namespace. Entering a user namespace does not grant a process the ability to load a SELinux policy.
Since the fuzzer (syzbot) runs with root privileges in the test environment, it is able to load a mutated, malicious SELinux policy that intentionally triggers this pathological performance edge-case. However, in a real-world scenario, an attacker would already need full administrative control over the system to load such a policy, at which point the system is already fully compromised.
Therefore, this is not considered a security vulnerability that crosses a privilege boundary. It is not exploitable for memory corruption, privilege escalation, or information leaks.
**Conclusion:**
- **Exploitable:** False
- **Denial of Service:** True (but requires administrative privileges to set up the malicious policy)
- **Accessible From Unprivileged Processes:** False
- **Accessible From User Namespaces:** False
|
| 6/2 |
2026/07/27 02:10 |
llm |
expert |
0m
Model:
Tokens:
input: 11754
output: 42
thoughts: 2768
Thoughts: **RCU Stall Investigation**
Okay, here's what's happening. I've got an RCU stall report, indicating potential issues on CPUs 0 and 1. The RCU is complaining about tasks blocked on level-0 rcu_node, and specifically, I see task `syz.5.4203`, PID 24535, apparently running but stalled in `avtab_search_node` within `security/selinux/ss/avtab.c:146`. That "state:R running task" is a red flag β a running task shouldn't be stalled.
Looking at the stack trace, this task is getting preempted during a context switch and being interrupted within the SELinux permission checks. The stack traces lead me through `cond_compute_av`, `context_struct_compute_av`, `security_compute_av`, down to the AVC (Access Vector Cache) level. This points directly to SELinux policy evaluation. This task is blocked inside the SELinux subsystem, specifically in `avtab_search_node`, while trying to determine permissions.
Simultaneously, I see another CPU, CPU 0, that's in a Tainted state. It appears to be deep inside the kernel, holding a lock with `__lock_acquire`. This CPU is running `audit_log_start`, which eventually calls `slow_avc_audit`, which in turn calls `avc_has_perm`, suggesting that this CPU is in the middle of writing the results of an SELinux decision to the audit log. The audit trail is then being blocked while the CPU is inside the SELinux path.
Now I believe that one CPU, the blocked one, is making a request to the SELinux system, while the other CPU is stuck holding a lock in the middle of a SELinux decision and audit log. This is almost certainly a deadlock. The stack on the other CPU (CPU 0) involves allocating a SKB from kmalloc which is then being used to log an audit message.
I'm thinking this likely leads to one of two things, and more investigation is needed:
1. **A recursive call scenario:** There's a chance the permission checks are causing an infinite loop within SELinux, bouncing back and forth between tasks.
2. **Locking order inversion:** There may be a locking order issue within SELinux's data structures or the audit logging that leads to a deadlock between the two tasks/CPUs. The `avtab_search_node` and audit logging operations might be contending for the same resources but acquired in the wrong order.
My next step is to examine `security/selinux/ss/avtab.c:146` more closely to understand the access patterns and any potential for recursive calls or contention. I also need to trace the locking behavior more precisely around `audit_log_start` and the AVC code to pinpoint the exact point of the deadlock. This is definitely a race condition within the SELinux subsystem that needs to be resolved.
|
| 7/2 |
2026/07/27 02:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_search_node]
Results: map[SourceCode: 141: /* This search function returns a node pointer, and can be used in
142: * conjunction with avtab_search_next_node()
143: */
144: struct avtab_node *avtab_search_node(struct avtab *h,
145: const struct avtab_key *key)
146: {
147: u32 hvalue;
148: struct avtab_node *cur;
149: int cmp;
150:
151: if (!h || !h->nslot)
152: return NULL;
153:
154: hvalue = avtab_hash(key, h->mask);
155: for (cur = h->htable[hvalue]; cur; cur = cur->next) {
156: cmp = avtab_node_cmp(key, &cur->key);
157: if (cmp == 0)
158: return cur;
159: if (cmp < 0)
160: break;
161: }
162: return NULL;
163: }
SourceFile:security/selinux/ss/avtab.c]
|
| 8/2 |
2026/07/27 02:10 |
llm |
expert |
0m
Model:
Tokens:
input: 15575
output: 40
thoughts: 190
Thoughts: **Analyzing a Potential Vulnerability in SELinux's Access Vector Cache**
Okay, so I'm looking at this C code snippet:
```c
for (cur = h->htable[hvalue]; cur; cur = cur->next) {
cmp = avtab_node_cmp(key, &cur->key);
if (cmp == 0)
return cur;
if (cmp < 0)
break;
}
```
and thinking, "Aha, a potential infinite loop if `cur->next` creates a cycle or points back to the current node". My first thought is "This is bad, potentially a denial of service (DoS) vulnerability!". But this is SELinux policy, and that's loaded by root, right? Which means the attack vector has to involve root somehow.
However, a quick check reminds me that loading SELinux policy requires `CAP_MAC_ADMIN`, meaning unprivileged users can't trigger this directly. So, I have to consider other attack vectors. Let's see if there's anything else that might use this code. The next logical step is to dive into the codebase. I'm going to look for other calls to potentially unsafe areas of this functionality and go from there. Specifically, I'll start by checking `cond_compute_av` in `security/selinux/ss/conditional.c:591` because it is used to compute an access vector.
|
| 9/2 |
2026/07/27 02:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_compute_av]
Results: map[SourceCode: 580: /* Determine whether additional permissions are granted by the conditional
581: * av table, and if so, add them to the result
582: */
583: void cond_compute_av(struct avtab *ctab, struct avtab_key *key,
584: struct av_decision *avd, struct extended_perms *xperms)
585: {
586: struct avtab_node *node;
587:
588: if (!ctab || !key || !avd)
589: return;
590:
591: for (node = avtab_search_node(ctab, key); node;
592: node = avtab_search_node_next(node, key->specified)) {
593: if ((u16)(AVTAB_ALLOWED | AVTAB_ENABLED) ==
594: (node->key.specified & (AVTAB_ALLOWED | AVTAB_ENABLED)))
595: avd->allowed |= node->datum.u.data;
596: if ((u16)(AVTAB_AUDITDENY | AVTAB_ENABLED) ==
597: (node->key.specified & (AVTAB_AUDITDENY | AVTAB_ENABLED)))
598: /* Since a '0' in an auditdeny mask represents a
599: * permission we do NOT want to audit (dontaudit), we use
600: * the '&' operand to ensure that all '0's in the mask
601: * are retained (much unlike the allow and auditallow cases).
602: */
603: avd->auditdeny &= node->datum.u.data;
604: if ((u16)(AVTAB_AUDITALLOW | AVTAB_ENABLED) ==
605: (node->key.specified & (AVTAB_AUDITALLOW | AVTAB_ENABLED)))
606: avd->auditallow |= node->datum.u.data;
607: if (xperms && (node->key.specified & AVTAB_ENABLED) &&
608: (node->key.specified & AVTAB_XPERMS))
609: services_compute_xperms_drivers(xperms, node);
610: }
611: }
SourceFile:security/selinux/ss/conditional.c]
|
| 10/2 |
2026/07/27 02:10 |
llm |
expert |
0m
Model:
Tokens:
input: 16769
output: 44
thoughts: 18
Thoughts: Here's my thought process, summarized as you requested:
**A Realization About Looping and `avtab_search_node_next`**
Okay, wait a minute... I'm tracing through this code, and I've just noticed something potentially significant. The function `avtab_search_node_next` is being called *within a loop*. That's a crucial observation. It immediately raises several questions in my mind, given the context. Is this loop meant to iterate through a data structure? Is it searching for something specific? What is the termination condition of this loop? And what are the implications if this function is called repeatedly like this? I need to analyze how the results from `avtab_search_node_next` are being used *within* the loop to really understand its impact and potential behavior in this specific implementation. I need to dig deeper into the code at this point.
|
| 11/2 |
2026/07/27 02:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_search_node_next]
Results: map[SourceCode: 165: struct avtab_node *avtab_search_node_next(struct avtab_node *node,
166: u16 specified)
167: {
168: struct avtab_key tmp_key;
169: struct avtab_node *cur;
170: int cmp;
171:
172: if (!node)
173: return NULL;
174: tmp_key = node->key;
175: tmp_key.specified = specified;
176: for (cur = node->next; cur; cur = cur->next) {
177: cmp = avtab_node_cmp(&tmp_key, &cur->key);
178: if (cmp == 0)
179: return cur;
180: if (cmp < 0)
181: break;
182: }
183: return NULL;
184: }
SourceFile:security/selinux/ss/avtab.c]
|
| 12/2 |
2026/07/27 02:10 |
llm |
expert |
0m
Model:
Tokens:
input: 17328
output: 40
thoughts: 178
Thoughts: **Analyzing Potential Performance Bottlenecks in the AV Tab**
Okay, so I'm looking at this `avtab_search_node_next` function and the way it's used. Right, it looks like if it returns a node and we call it again, it's designed to search from `node->next`. That makes sense. But then I'm seeing this `cond_compute_av` function, and it's using a loop with `avtab_search_node` and `avtab_search_node_next`.
```c
for (node = avtab_search_node(ctab, key); node;
node = avtab_search_node_next(node, key->specified)) {
```
The thing is, if there are a lot of nodes with the *same* key, that loop could potentially take a significant amount of time, right? It could become a serious performance bottleneck. But... the `avtab` is constructed when the SELinux policy is loaded, which *should* limit this.
So, I'm starting to think... is it possible there's a bug somewhere in the `avtab_read` or `avtab_insert` functions that's *allowing* duplicate keys or even, god forbid, a cycle to form? That would be a nightmare. We need to be able to trust the integrity of this table. I'm going to take a closer look at `avtab_read`. Let's dig into `security/selinux/ss/avtab.c` and see what's going on in there. It's time to check for data integrity issues, just in case.
|
| 13/2 |
2026/07/27 02:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_read]
Results: map[SourceCode: 507: int avtab_read(struct avtab *a, struct policy_file *fp, struct policydb *pol)
508: {
509: int rc;
510: __le32 buf[1];
511: u32 nel, i;
512:
513: rc = next_entry(buf, fp, sizeof(u32));
514: if (rc < 0) {
515: pr_err("SELinux: avtab: truncated table\n");
516: goto bad;
517: }
518: nel = le32_to_cpu(buf[0]);
519: if (!nel) {
520: pr_err("SELinux: avtab: table is empty\n");
521: rc = -EINVAL;
522: goto bad;
523: }
524:
525: /* avtab_read_item() reads at least 96 bytes for any valid entry */
526: rc = size_check(3 * sizeof(u32), nel, fp);
527: if (rc)
528: goto bad;
529:
530: rc = avtab_alloc(a, nel);
531: if (rc)
532: goto bad;
533:
534: for (i = 0; i < nel; i++) {
535: rc = avtab_read_item(a, fp, pol, avtab_insertf, NULL, false);
536: if (rc) {
537: if (rc == -ENOMEM)
538: pr_err("SELinux: avtab: out of memory\n");
539: else if (rc == -EEXIST)
540: pr_err("SELinux: avtab: duplicate entry\n");
541:
542: goto bad;
543: }
544: }
545:
546: rc = 0;
547: out:
548: return rc;
549:
550: bad:
551: avtab_destroy(a);
552: goto out;
553: }
SourceFile:security/selinux/ss/avtab.c]
|
| 14/2 |
2026/07/27 02:10 |
llm |
expert |
0m
Model:
Tokens:
input: 18588
output: 41
thoughts: 18
Thoughts: Here's my thought process, as if I were considering this code:
**Thinking Through Data Structures and Function Calls**
Okay, so I'm tracing through this code, and I see `avtab_read_item` β that's a key function in this module, right? And immediately, a bell goes off. Wait a minute... `avtab_read_item` calls `avtab_insertf`? That's interesting, and it suggests a specific relationship between these two functions and the underlying data structures. My initial understanding is that `avtab_read_item` is intended to look up or retrieve something from the Access Vector Table (AVTAB). Now, the fact that it's calling `avtab_insertf` implies that this lookup process might involve adding an item to the table. Is it a lazy insertion? Is it populating the table based on something it's reading? Or is it conditionally inserting something? This needs more investigation, but my mental model is shifting from purely a read operation to a read-and-potentially-modify operation. This connection between read and insert calls strongly suggests the need to ensure thread safety to ensure that data does not get modified in a manner that will result in concurrent access issues. This could be a critical point for performance as well as consistency.
|
| 15/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_insertf]
Results: map[SourceCode: 501: static int avtab_insertf(struct avtab *a, const struct avtab_key *k,
502: const struct avtab_datum *d, void *p)
503: {
504: return avtab_insert(a, k, d);
505: }
SourceFile:security/selinux/ss/avtab.c]
|
| 16/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 19040
output: 40
thoughts: 10
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Investigating `avtab_insert`**
Alright, time to dig in. The problem's hit a snag, and my first instinct, as always, is to methodically retrace the steps. Let's start with `avtab_insert`. I want to verify that this function, the core of this system, is behaving as expected. Are the assumptions it makes still valid? Are there any obvious off-by-one errors creeping in that I might have missed in the initial review? Let's trace it and confirm the expected values.
|
| 17/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_insert]
Results: map[SourceCode: 87: static int avtab_insert(struct avtab *h, const struct avtab_key *key,
88: const struct avtab_datum *datum)
89: {
90: u32 hvalue;
91: struct avtab_node *prev, *cur, *newnode;
92: int cmp;
93:
94: if (!h || !h->nslot || h->nel == U32_MAX)
95: return -EINVAL;
96:
97: hvalue = avtab_hash(key, h->mask);
98: for (prev = NULL, cur = h->htable[hvalue]; cur;
99: prev = cur, cur = cur->next) {
100: cmp = avtab_node_cmp(key, &cur->key);
101: /* extended perms may not be unique */
102: if (cmp == 0 && !(key->specified & AVTAB_XPERMS))
103: return -EEXIST;
104: if (cmp <= 0)
105: break;
106: }
107:
108: newnode = avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
109: key, datum);
110: if (!newnode)
111: return -ENOMEM;
112:
113: return 0;
114: }
SourceFile:security/selinux/ss/avtab.c]
|
| 18/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 19682
output: 42
thoughts: 313
Thoughts: **Analyzing the Potential for Duplicate Extended Permissions**
Okay, so I've been digging into this code, and it's starting to click. I'm focusing on how the system handles extended permissions within the access vector cache table. My initial thought is that the condition `extended perms may not be unique` is important. Specifically, if a `key`'s specified flags include `AVTAB_XPERMS`, then a simple comparison where `cmp == 0` *shouldn't* immediately throw an `-EEXIST` error. The standard error returns.
The key part is in this loop:
```c
for (prev = NULL, cur = h->htable[hvalue]; cur;
prev = cur, cur = cur->next) {
cmp = avtab_node_cmp(key, &cur->key);
/* extended perms may not be unique */
if (cmp == 0 && !(key->specified & AVTAB_XPERMS))
return -EEXIST;
if (cmp <= 0)
break;
}
```
If `cmp` is zero, which means `key` and `cur->key` are equivalent, then the code breaks out of the loop and the `newnode` is inserted.
Let's break this down. The logic seems to be as follows. If `cmp == 0`, and the `key` is *not* `AVTAB_XPERMS`, then the function correctly returns `-EEXIST`. But, if the flag *is* set, the code should allow insertion.
The crucial bit, though, is how `avtab_insert_node` handles this. It inserts `newnode` *before* `cur` (i.e. at the address pointed to by `prev ? &prev->next : &h->htable[hvalue]`). This effectively means `newnode->next` now points to `cur`.
So, what happens if we *do* have multiple identical keys, but with the `AVTAB_XPERMS` flag set? The code *won't* error out. The `newnode` will be inserted, and it will be prepended to the list. That makes sense. `avtab_node_cmp` is comparing `key` and `cur->key` - it's key based, and it works. I'm confident in the analysis.
|
| 19/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_node_cmp]
Results: map[SourceCode: 65: static int avtab_node_cmp(const struct avtab_key *key1,
66: const struct avtab_key *key2)
67: {
68: u16 specified = key1->specified & ~(AVTAB_ENABLED | AVTAB_ENABLED_OLD);
69:
70: if (key1->source_type == key2->source_type &&
71: key1->target_type == key2->target_type &&
72: key1->target_class == key2->target_class &&
73: (specified & key2->specified))
74: return 0;
75: if (key1->source_type < key2->source_type)
76: return -1;
77: if (key1->source_type == key2->source_type &&
78: key1->target_type < key2->target_type)
79: return -1;
80: if (key1->source_type == key2->source_type &&
81: key1->target_type == key2->target_type &&
82: key1->target_class < key2->target_class)
83: return -1;
84: return 1;
85: }
SourceFile:security/selinux/ss/avtab.c]
|
| 20/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 20941
output: 42
thoughts: 836
Thoughts: **Analyzing `avtab_node_cmp` and Its Implications**
Okay, let's break down this `avtab_node_cmp` function. My initial thought was that if `source_type`, `target_type`, and `target_class` all matched between two `avtab_key` structures, and if `(specified & key2->specified)` was non-zero, then it'd return 0, indicating a match. That makes sense, that's the base case. The function seemed fairly straightforward, or so I thought.
However, I immediately spotted a crucial edge case: if `(specified & key2->specified)` *is* zero, the function *falls through*! This is where things get interesting. So, if the first three `if` conditions are met (meaning all the types and class match), but the `specified` masks are disjoint, then it *doesn't* return 0. It proceeds to the subsequent `<` checks. Since all the types and class match, all those `<` checks will be false. So, it ultimately returns 1.
Let's confirm this by tracing through the code again:
* We have `key1` and `key2`, with identical `source_type`, `target_type`, and `target_class`
* `specified & key2->specified` evaluates to 0 (disjoint specified masks)
* The first `if` statement evaluates to `false` (because of the zero)
* The next three `if` statements (the `<` checks) all evaluate to `false` because the types and class match.
* The function hits `return 1`!
A return of 1! Meaning it's *not* a "match".
Now, let's consider the implications of this in the context of the `avtab_insert` function, using the provided snippet of code. When `avtab_node_cmp` returns 1, `cmp > 0`. Consequently, the `avtab_insert`'s loop will continue. This means that if we insert `key1` and `key2` with identical types and class, but disjoint `specified` masks, they won't be considered equivalent, and they'll both be inserted into the hashtable. The *new* node will be inserted *after* the *existing* node.
So, here's the question: Is this behavior problematic? It appears that it is designed this way. The behavior is not necessarily incorrect; this is a valid case. Let's look at `avtab_search_node` and `avtab_search_node_next` to confirm the design intent.
|
| 21/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_search_node]
Results: map[SourceCode: 141: /* This search function returns a node pointer, and can be used in
142: * conjunction with avtab_search_next_node()
143: */
144: struct avtab_node *avtab_search_node(struct avtab *h,
145: const struct avtab_key *key)
146: {
147: u32 hvalue;
148: struct avtab_node *cur;
149: int cmp;
150:
151: if (!h || !h->nslot)
152: return NULL;
153:
154: hvalue = avtab_hash(key, h->mask);
155: for (cur = h->htable[hvalue]; cur; cur = cur->next) {
156: cmp = avtab_node_cmp(key, &cur->key);
157: if (cmp == 0)
158: return cur;
159: if (cmp < 0)
160: break;
161: }
162: return NULL;
163: }
SourceFile:security/selinux/ss/avtab.c]
|
| 22/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 22751
output: 44
thoughts: 145
Thoughts: **Analyzing the `avtab_search_node` Logic**
Okay, let's break this down. My initial observation is that `avtab_search_node` relies on `avtab_node_cmp` for its comparisons. If `cmp` is zero, it finds a match and returns the current node (`cur`). If `cmp` is less than zero, it's determined that the search key is less than the current node and the search can terminate. If `cmp` is greater than zero, it implies the search key is greater than the current node and the search continues to the right.
The crucial point here is how `avtab_node_cmp` behaves when multiple nodes have identical `source_type`, `target_type`, and `target_class` but *disjoint* `specified` values. In this scenario, `avtab_node_cmp` returns 1, indicating that these nodes are, for the purposes of this comparison, "greater than" each other. This means `avtab_search_node` will *skip* those nodes until it finds one where the bitwise AND of the search key's `specified` and the current node's `key.specified` is non-zero.
This seems efficient *in principle*. It quickly navigates to nodes that *might* be relevant based on the common key fields, and then focuses on the `specified` bits to pinpoint the best match. But, I need to consider `avtab_search_node_next`. How does the logic work when iterating *after* an initial `avtab_search_node` call? What are the implications of the "greater than" behavior in the presence of `avtab_search_node_next`? The implementation is critical because this may influence the access vector's evaluation.
|
| 23/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_search_node_next]
Results: map[SourceCode: 165: struct avtab_node *avtab_search_node_next(struct avtab_node *node,
166: u16 specified)
167: {
168: struct avtab_key tmp_key;
169: struct avtab_node *cur;
170: int cmp;
171:
172: if (!node)
173: return NULL;
174: tmp_key = node->key;
175: tmp_key.specified = specified;
176: for (cur = node->next; cur; cur = cur->next) {
177: cmp = avtab_node_cmp(&tmp_key, &cur->key);
178: if (cmp == 0)
179: return cur;
180: if (cmp < 0)
181: break;
182: }
183: return NULL;
184: }
SourceFile:security/selinux/ss/avtab.c]
|
| 24/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 23628
output: 42
thoughts: 197
Thoughts: **Analyzing the `cond_compute_av` Function**
Okay, let's break down this `cond_compute_av` function. The first thing that jumps out is this loop using `avtab_search_node` and its companion, `avtab_search_node_next`. It appears we're iterating through a table, `ctab`, looking for something based on a `key`.
Wait a minute, `avtab_search_node_next` seems to be creating a temporary key, `tmp_key`, derived from the current node's key (`node->key`) but with `tmp_key.specified` overridden by `specified`. Then, it moves onto the next node. If the keys match, the function returns. If they don't, it either breaks (if `cmp < 0`) or continues the search (if `cmp > 0`).
The question that pops into my head, though, is whether this loop could potentially run forever. We're dealing with a singly linked list (`cur = cur->next`). Normally, with a singly linked list, an infinite loop *shouldn't* happen unless there's a cycle. But how could a cycle even *form* in the first place? That's the critical question here. I need to understand the mechanism by which nodes are added to this table to ascertain if a cyclical linked list structure is even possible. Let's delve into the `avtab_insert_node` function.
|
| 25/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_insert_node]
Results: map[SourceCode: 34: static struct avtab_node *avtab_insert_node(struct avtab *h,
35: struct avtab_node **dst,
36: const struct avtab_key *key,
37: const struct avtab_datum *datum)
38: {
39: struct avtab_node *newnode;
40: struct avtab_extended_perms *xperms;
41: newnode = kmem_cache_zalloc(avtab_node_cachep, GFP_KERNEL);
42: if (newnode == NULL)
43: return NULL;
44: newnode->key = *key;
45:
46: if (key->specified & AVTAB_XPERMS) {
47: xperms = kmem_cache_zalloc(avtab_xperms_cachep, GFP_KERNEL);
48: if (xperms == NULL) {
49: kmem_cache_free(avtab_node_cachep, newnode);
50: return NULL;
51: }
52: *xperms = *(datum->u.xperms);
53: newnode->datum.u.xperms = xperms;
54: } else {
55: newnode->datum.u.data = datum->u.data;
56: }
57:
58: newnode->next = *dst;
59: *dst = newnode;
60:
61: h->nel++;
62: return newnode;
63: }
SourceFile:security/selinux/ss/avtab.c]
|
| 26/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 24646
output: 41
thoughts: 194
Thoughts: **Debugging a Potentially Corrupted Linked List**
Okay, so I'm looking at this insertion logic: `newnode->next = *dst; *dst = newnode;`. This is textbook linked list insertion. It's clean. The only way this could introduce a cycle is if `*dst` somehow already pointed to `newnode`, which, given `newnode` is freshly allocated, is a non-starter.
My mind immediately jumps to, could `h->htable` be corrupted? That's always a possibility in these scenarios. But then I have a hunch. Could `cond_compute_av` be running concurrently with `avtab_insert`? Bingo. That's a classic race condition. I need to figure out if `avtab` is being modified after initialization. This looks like it's where the problem is.
Now, how is the SELinux policy loaded? Ah, right, through `security_load_policy`. Right, and `ctab` is `&policydb->te_cond_avtab`. Let's check if that is modified concurrently. When a new policy is loaded, a new `policydb` is created, populated, and then swapped in. This looks like a race condition and a potential reason for the linked list to be corrupted.
Wait, conditional booleans can be changed at runtime! That's it! Let's check `security_set_bools`. This is where the root cause lies.
|
| 27/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/services.c Name:security_set_bools]
Results: map[SourceCode:2974: int security_set_bools(u32 len, const int *values)
2975: {
2976: struct selinux_state *state = &selinux_state;
2977: struct selinux_policy *newpolicy, *oldpolicy;
2978: int rc;
2979: u32 i, seqno = 0;
2980:
2981: if (!selinux_initialized())
2982: return -EINVAL;
2983:
2984: oldpolicy = rcu_dereference_protected(state->policy,
2985: lockdep_is_held(&state->policy_mutex));
2986:
2987: /* Consistency check on number of booleans, should never fail */
2988: if (WARN_ON(len != oldpolicy->policydb.p_bools.nprim))
2989: return -EINVAL;
2990:
2991: newpolicy = kmemdup(oldpolicy, sizeof(*newpolicy), GFP_KERNEL);
2992: if (!newpolicy)
2993: return -ENOMEM;
2994:
2995: /*
2996: * Deep copy only the parts of the policydb that might be
2997: * modified as a result of changing booleans.
2998: */
2999: rc = cond_policydb_dup(&newpolicy->policydb, &oldpolicy->policydb);
3000: if (rc) {
3001: kfree(newpolicy);
3002: return -ENOMEM;
3003: }
3004:
3005: /* Update the boolean states in the copy */
3006: for (i = 0; i < len; i++) {
3007: int new_state = !!values[i];
3008: int old_state = newpolicy->policydb.bool_val_to_struct[i]->state;
3009:
3010: if (new_state != old_state) {
3011: audit_log(audit_context(), GFP_ATOMIC,
3012: AUDIT_MAC_CONFIG_CHANGE,
3013: "bool=%s val=%d old_val=%d auid=%u ses=%u",
3014: sym_name(&newpolicy->policydb, SYM_BOOLS, i),
3015: new_state,
3016: old_state,
3017: from_kuid(&init_user_ns, audit_get_loginuid(current)),
3018: audit_get_sessionid(current));
3019: newpolicy->policydb.bool_val_to_struct[i]->state = new_state;
3020: }
3021: }
3022:
3023: /* Re-evaluate the conditional rules in the copy */
3024: evaluate_cond_nodes(&newpolicy->policydb);
3025:
3026: /* Set latest granting seqno for new policy */
3027: newpolicy->latest_granting = oldpolicy->latest_granting + 1;
3028: seqno = newpolicy->latest_granting;
3029:
3030: /* Install the new policy */
3031: rcu_assign_pointer(state->policy, newpolicy);
3032:
3033: /*
3034: * Free the conditional portions of the old policydb
3035: * that were copied for the new policy, and the oldpolicy
3036: * structure itself but not what it references.
3037: */
3038: synchronize_rcu();
3039: selinux_policy_cond_free(oldpolicy);
3040:
3041: /* Notify others of the policy change */
3042: selinux_notify_policy_change(seqno);
3043: return 0;
3044: }
SourceFile:security/selinux/ss/services.c]
|
| 28/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 26335
output: 43
thoughts: 35
Thoughts: Okay, here's my take on those thoughts, framed from my expert perspective:
**Diving into the Conditional Policy Database Duplication**
Right, so we're looking at how the policy database is handled, specifically focusing on the conditional aspects. This immediately tells me we're likely dealing with a performance-sensitive area, given the use of Read-Copy-Update (RCU). RCU suggests that frequent reads are prioritized and that updates are handled in a more concurrent-friendly manner. This is classic for something like a security policy where lookups are extremely common.
My initial thought is to zero in on how `cond_policydb_dup` works. The fact that it's handling the "conditional parts" tells me this function is responsible for duplicating the policy information that's context-dependent, perhaps based on attributes or other environmental factors. I need to understand what constitutes these "conditional parts" and *how* the duplication is achieved. Are we talking about deep copies, shallow copies, or some clever pointer manipulation for efficiency? The devil is definitely in the details here. Let's get cracking with `cond_policydb_dup` and see what it's really doing. I have to know.
|
| 29/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_policydb_dup]
Results: map[SourceCode: 752: int cond_policydb_dup(struct policydb *new, const struct policydb *orig)
753: {
754: cond_policydb_init(new);
755:
756: if (duplicate_policydb_bools(new, orig))
757: return -ENOMEM;
758:
759: if (duplicate_policydb_cond_list(new, orig)) {
760: cond_policydb_destroy_dup(new);
761: return -ENOMEM;
762: }
763:
764: return 0;
765: }
SourceFile:security/selinux/ss/conditional.c]
|
| 30/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 26904
output: 43
thoughts: 30
Thoughts: Okay, here's my take on those thoughts, framed as my own mental process:
**Deeper Dive into Policy Initialization**
Wait a second... I was *certain* I'd seen a duplicate of `te_cond_avtab` somewhere in the initialization routines, but it's not popping up here! That's odd. Okay, gotta back up a step. Let's not make assumptions. Time to methodically re-examine `cond_policydb_init`. I need to ensure I haven't missed a crucial detail, especially within the context of conditional policy handling. Double-checking `cond_policydb_init` is the right move before I start assuming some other process or a different module is responsible. Gotta be precise here.
|
| 31/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_policydb_init]
Results: map[SourceCode: 131: void cond_policydb_init(struct policydb *p)
132: {
133: p->bool_val_to_struct = NULL;
134: p->cond_list = NULL;
135: p->cond_list_len = 0;
136:
137: avtab_init(&p->te_cond_avtab);
138: }
SourceFile:security/selinux/ss/conditional.c]
|
| 32/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 27294
output: 40
thoughts: 35
Thoughts: Here's my take on the thought process, as if it were my own:
**Initializing and Populating Conditional Attribute Tables**
Okay, hold on a second. I'm double-checking something in this code. The `avtab_init` function, I *thought* that was responsible for initializing the `te_cond_avtab` to be completely empty. And, yup, that's exactly what it does. But, hang on, wasn't `evaluate_cond_nodes` supposed to be the one *populating* that same table? I need to make sure I understand the interaction between those two functions and how the conditional attribute table is meant to be handled. I need to refresh my memory on what triggers each function call to properly understand this.
|
| 33/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:evaluate_cond_nodes]
Results: map[SourceCode: 123: void evaluate_cond_nodes(struct policydb *p)
124: {
125: u32 i;
126:
127: for (i = 0; i < p->cond_list_len; i++)
128: evaluate_cond_node(p, &p->cond_list[i]);
129: }
SourceFile:security/selinux/ss/conditional.c]
|
| 34/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 27671
output: 40
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:
**Diving into Conditional Node Evaluation**
Alright, time to dig into the `evaluate_cond_node` function. I need to refresh my understanding of its execution flow. My immediate concern is how it handles the various branching conditions. I'm especially interested in how it manages the short-circuiting behavior that's crucial for performance, particularly with more complex nested conditionals. I need to make sure I grasp the interplay between the condition evaluation and the subsequent action selection. I'm focusing on potential optimizations, so I will analyze if the function always needs to completely evaluate every branch, or can it dynamically avoid that, depending on partial results. Finally, I'll scrutinize potential edge cases and error handling within this function; I will need to make sure the structure is robust.
|
| 35/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:evaluate_cond_node]
Results: map[SourceCode: 85: /*
86: * evaluate_cond_node evaluates the conditional stored in
87: * a struct cond_node and if the result is different than the
88: * current state of the node it sets the rules in the true/false
89: * list appropriately. If the result of the expression is undefined
90: * all of the rules are disabled for safety.
91: */
92: static void evaluate_cond_node(struct policydb *p, struct cond_node *node)
93: {
94: struct avtab_node *avnode;
95: int new_state;
96: u32 i;
97:
98: new_state = cond_evaluate_expr(p, &node->expr);
99: if (new_state != node->cur_state) {
100: node->cur_state = new_state;
101: if (new_state == -1)
102: pr_err("SELinux: expression result was undefined - disabling all rules.\n");
103: /* turn the rules on or off */
104: for (i = 0; i < node->true_list.len; i++) {
105: avnode = node->true_list.nodes[i];
106: if (new_state <= 0)
107: avnode->key.specified &= ~AVTAB_ENABLED;
108: else
109: avnode->key.specified |= AVTAB_ENABLED;
110: }
111:
112: for (i = 0; i < node->false_list.len; i++) {
113: avnode = node->false_list.nodes[i];
114: /* -1 or 1 */
115: if (new_state)
116: avnode->key.specified &= ~AVTAB_ENABLED;
117: else
118: avnode->key.specified |= AVTAB_ENABLED;
119: }
120: }
121: }
SourceFile:security/selinux/ss/conditional.c]
|
| 36/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 28512
output: 45
thoughts: 93
Thoughts: Okay, here's my thought process as I digest this...
**Dissecting the Conditional AV Table Population**
Wait a second! I've got a flag in mind β `evaluate_cond_node` β and it seems like it's messing with `avnode->key.specified`. That's a key attribute, so that's got my attention. And, now I remember, `avnode` is *inside* `te_cond_avtab`. Okay, so `te_cond_avtab` is where this potential modification is happening. But... isn't `te_cond_avtab` initialized empty in `cond_policydb_init`? How does this table even *get* populated? This is crucial to understanding the data integrity here. I need to trace back from the initial state to see how this crucial data structure is built up. Let me check `duplicate_policydb_cond_list`. That's likely where the population logic resides. I'll focus on that function.
|
| 37/2 |
2026/07/27 02:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:duplicate_policydb_cond_list]
Results: map[SourceCode: 636: static int duplicate_policydb_cond_list(struct policydb *newp,
637: const struct policydb *origp)
638: {
639: int rc;
640: u32 i;
641:
642: rc = avtab_alloc_dup(&newp->te_cond_avtab, &origp->te_cond_avtab);
643: if (rc)
644: return rc;
645:
646: newp->cond_list_len = 0;
647: newp->cond_list = kzalloc_objs(*newp->cond_list, origp->cond_list_len);
648: if (!newp->cond_list)
649: goto error;
650:
651: for (i = 0; i < origp->cond_list_len; i++) {
652: struct cond_node *newn = &newp->cond_list[i];
653: const struct cond_node *orign = &origp->cond_list[i];
654:
655: newp->cond_list_len++;
656:
657: newn->cur_state = orign->cur_state;
658: newn->expr.nodes =
659: kmemdup(orign->expr.nodes,
660: orign->expr.len * sizeof(*orign->expr.nodes),
661: GFP_KERNEL);
662: if (!newn->expr.nodes)
663: goto error;
664:
665: newn->expr.len = orign->expr.len;
666:
667: rc = cond_dup_av_list(&newn->true_list, &orign->true_list,
668: &newp->te_cond_avtab);
669: if (rc)
670: goto error;
671:
672: rc = cond_dup_av_list(&newn->false_list, &orign->false_list,
673: &newp->te_cond_avtab);
674: if (rc)
675: goto error;
676: }
677:
678: return 0;
679:
680: error:
681: avtab_destroy(&newp->te_cond_avtab);
682: cond_list_destroy(newp);
683: return -ENOMEM;
684: }
SourceFile:security/selinux/ss/conditional.c]
|
| 38/2 |
2026/07/27 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 29646
output: 42
thoughts: 38
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Allocating and Duplicating AV Tables: A Quick Clarification**
Right, so `avtab_alloc_dup` handles the initial allocation of that hash table structure. But, and this is crucial, it *doesn't* actually perform the node copying. It's just setting up the basic container, laying the groundwork, as it were. I always need to keep that distinction clear in my head, I had to double-check my mental model of this part of the code! Then I realized, *aha*, `cond_dup_av_list` is the function that actually dives in and duplicates those nodes themselves, that's where the heavy lifting of the copy operation happens. That's a key distinction I need to remember while debugging.
|
| 39/2 |
2026/07/27 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_dup_av_list]
Results: map[SourceCode: 613: static int cond_dup_av_list(struct cond_av_list *new,
614: const struct cond_av_list *orig,
615: struct avtab *avtab)
616: {
617: u32 i;
618:
619: memset(new, 0, sizeof(*new));
620:
621: new->nodes = kzalloc_objs(*new->nodes, orig->len);
622: if (!new->nodes)
623: return -ENOMEM;
624:
625: for (i = 0; i < orig->len; i++) {
626: new->nodes[i] = avtab_insert_nonunique(
627: avtab, &orig->nodes[i]->key, &orig->nodes[i]->datum);
628: if (!new->nodes[i])
629: return -ENOMEM;
630: new->len++;
631: }
632:
633: return 0;
634: }
SourceFile:security/selinux/ss/conditional.c]
|
| 40/2 |
2026/07/27 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 30256
output: 43
thoughts: 13
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing `avtab_insert_nonunique`**
Okay, time to dive into `avtab_insert_nonunique`. Let's see... the name itself suggests a function designed to handle insertions into the Access Vector Table (AVTAB) where uniqueness isn't enforced. This immediately raises a few questions in my mind:
* **Why non-unique?** What scenarios necessitate duplicate entries in the AVTAB? Is this for performance reasons (e.g., avoiding an expensive lookup in specific cases), or is it a deliberate design choice related to specific SELinux policies or security models? Are we dealing with something like a *permissive* entry, which might allow multiple rules?
* **What are the implications for policy enforcement?** Without uniqueness, how is the *first match* handled? Is there a defined precedence or order? Does this introduce potential vulnerabilities if the order can be manipulated or is unpredictable? Are there checks to see that it doesn't violate ordering on inserts? Does that introduce performance penalties.
* **Memory Management:** Given that we're adding entries without explicit checks for duplicates, how does this function handle memory allocation? Is there a risk of memory leaks or excessive memory usage if a large number of non-unique entries are inserted? What's the garbage collection situation, if any?
* **Concurrency Issues:** If this function is called concurrently, what kind of locking or synchronization mechanisms are in place? Are there potential race conditions if multiple threads are attempting to insert non-unique entries simultaneously? Or if another function is trying to get data from this table, are we safe?
I want to dig into the code and see how `avtab_insert_nonunique` actually implements the insertion, how it handles potential collisions, and what the overall impact is on the AVTAB structure and performance. I need to understand the full context. I'm going to look at the surrounding code for a clearer picture of its role and usage. I'm particularly interested in the caller's responsibilities: what pre-conditions are expected, and what guarantees does this function provide? Let's get cracking.
|
| 41/2 |
2026/07/27 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_insert_nonunique]
Results: map[SourceCode: 116: /* Unlike avtab_insert(), this function allow multiple insertions of the same
117: * key/specified mask into the table, as needed by the conditional avtab.
118: * It also returns a pointer to the node inserted.
119: */
120: struct avtab_node *avtab_insert_nonunique(struct avtab *h,
121: const struct avtab_key *key,
122: const struct avtab_datum *datum)
123: {
124: u32 hvalue;
125: struct avtab_node *prev, *cur;
126: int cmp;
127:
128: if (!h || !h->nslot || h->nel == U32_MAX)
129: return NULL;
130: hvalue = avtab_hash(key, h->mask);
131: for (prev = NULL, cur = h->htable[hvalue]; cur;
132: prev = cur, cur = cur->next) {
133: cmp = avtab_node_cmp(key, &cur->key);
134: if (cmp <= 0)
135: break;
136: }
137: return avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
138: key, datum);
139: }
SourceFile:security/selinux/ss/avtab.c]
|
| 42/2 |
2026/07/27 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 31205
output: 40
thoughts: 301
Thoughts: **Analyzing the Implications of `avtab_insert_nonunique` in Conditional List Duplication**
Okay, so I'm digging into this code, specifically how it handles potentially duplicate keys within attribute-value tables during list duplication. The key point here is that `avtab_insert_nonunique` *allows* multiple insertions with the same key. I had to clarify that point.
My initial thought was, if `cmp == 0`, the insert occurs *before* `cur`, which means repeated keys will all land in the list. Right? And, looking at the call to `cond_dup_av_list`, it uses `avtab_insert_nonunique` for each node in `orig->nodes`. So, if `orig->nodes` has duplicates, they'll all be inserted. Makes sense.
But then I remembered `cond_dup_av_list` gets called for both the `true_list` and `false_list` of *every* `cond_node`. So I thought... what if a node is shared across multiple conditional nodes or within the true/false lists? But that's not quite right. These `orig->nodes` are actually pointers to nodes that live in `origp->te_cond_avtab`, right?
Ah, got it. The real issue is that `cond_dup_av_list` creates a *new* node in `newp->te_cond_avtab` for *each* element in `orig->nodes`. This is the crux. So, even if `origp->te_cond_avtab` only contains one node, but it's referenced by multiple `cond_node`s, `cond_dup_av_list` will insert *multiple* nodes into `newp->te_cond_avtab`. That's the duplication! This could have serious consequences if we expect uniqueness. Now, to make sure this is accurate, I need to understand `cond_read_list`...
|
| 43/2 |
2026/07/27 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_read_list]
Results: map[SourceCode: 420: int cond_read_list(struct policydb *p, struct policy_file *fp)
421: {
422: __le32 buf[1];
423: u32 i, len;
424: int rc;
425:
426: rc = next_entry(buf, fp, sizeof(buf));
427: if (rc)
428: return rc;
429:
430: len = le32_to_cpu(buf[0]);
431:
432: /* cond_read_node() reads at least 128 bytes for any valid node */
433: rc = size_check(4 * sizeof(u32), len, fp);
434: if (rc)
435: return rc;
436:
437: p->cond_list = kzalloc_objs(*p->cond_list, len);
438: if (!p->cond_list)
439: return -ENOMEM;
440:
441: rc = avtab_alloc(&(p->te_cond_avtab), p->te_avtab.nel);
442: if (rc)
443: goto err;
444:
445: p->cond_list_len = len;
446:
447: for (i = 0; i < len; i++) {
448: rc = cond_read_node(p, &p->cond_list[i], fp);
449: if (rc)
450: goto err;
451: }
452: return 0;
453: err:
454: cond_list_destroy(p);
455: return rc;
456: }
SourceFile:security/selinux/ss/conditional.c]
|
| 44/2 |
2026/07/27 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 32516
output: 40
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing the thought process, delivered in the first person, assuming the user is an expert.
**Checking the `cond_read_node` Function**
Alright, let's dive into this. The mental checklist here starts with a critical function β `cond_read_node`. Given the context, I'm already formulating hypotheses about its role within the larger system. I'm likely thinking: *Is it related to conditional data retrieval? Is it responsible for handling reads based on specific criteria or flags? Is this a core component or a more specialized utility function?*
I'm probably anticipating the complexity. I'm assuming it handles more than a simple read; there's a "cond" prefix, which implies some sort of decision-making process embedded within the retrieval. I'm immediately preparing to investigate its logic flow. I'm mentally preparing to verify assumptions, probably assuming there are specific pre-conditions that need to be met. I will need to delve deeper.
|
| 45/2 |
2026/07/27 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_read_node]
Results: map[SourceCode: 374: static int cond_read_node(struct policydb *p, struct cond_node *node, struct policy_file *fp)
375: {
376: __le32 buf[2];
377: u32 i, len;
378: int rc;
379:
380: rc = next_entry(buf, fp, sizeof(u32) * 2);
381: if (rc)
382: return rc;
383:
384: node->cur_state = le32_to_cpu(buf[0]);
385:
386: /* expr */
387: len = le32_to_cpu(buf[1]);
388:
389: /* we will read 64 bytes per node */
390: rc = size_check(2 * sizeof(u32), len, fp);
391: if (rc)
392: return rc;
393:
394: node->expr.nodes = kzalloc_objs(*node->expr.nodes, len);
395: if (!node->expr.nodes)
396: return -ENOMEM;
397:
398: node->expr.len = len;
399:
400: for (i = 0; i < len; i++) {
401: struct cond_expr_node *expr = &node->expr.nodes[i];
402:
403: rc = next_entry(buf, fp, sizeof(u32) * 2);
404: if (rc)
405: return rc;
406:
407: expr->expr_type = le32_to_cpu(buf[0]);
408: expr->boolean = le32_to_cpu(buf[1]);
409:
410: if (!expr_node_isvalid(p, expr))
411: return -EINVAL;
412: }
413:
414: rc = cond_read_av_list(p, fp, &node->true_list, NULL);
415: if (rc)
416: return rc;
417: return cond_read_av_list(p, fp, &node->false_list, &node->true_list);
418: }
SourceFile:security/selinux/ss/conditional.c]
|
| 46/2 |
2026/07/27 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 33484
output: 42
thoughts: 13
Thoughts: Here's my take on those thoughts, tailored for an expert audience:
**Analyzing the `cond_read_av_list` Function**
Okay, so the prompt directs me to examine `cond_read_av_list`. My immediate instinct is to start by understanding its core function. I'm assuming, based on the name, that this likely pertains to conditional reading of an attribute-value list. My brain's already firing on questions:
* What's the context? What data structures is this function operating on? Is this a part of a larger parsing or interpretation system?
* What's the "conditional" aspect? Is it based on the presence, value, or type of certain attributes? Are there complex nested conditions?
* Is it related to access control? Is there any security implications with such conditional reads?
* How is the list structured? Is it key-value pairs, a serialized format, or something else entirely?
* Are there any assumptions about the data's validity, like data constraints or schema restrictions? Does this function perform any kind of validation?
My goal here isn't a surface-level scan; I want to understand the function's *purpose* and its *behavior*, especially in edge cases. I'll need to look at the implementation details, not just the function signature, to get a handle on the real mechanics. I'll be looking for potential performance bottlenecks, areas that may have security vulnerabilities, or logic that could be overly complex. I'll need to follow the code to build a complete mental model of its behavior.
|
| 47/2 |
2026/07/27 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_read_av_list]
Results: map[SourceCode: 316: static int cond_read_av_list(struct policydb *p, struct policy_file *fp,
317: struct cond_av_list *list,
318: struct cond_av_list *other)
319: {
320: int rc;
321: __le32 buf[1];
322: u32 i, len;
323: struct cond_insertf_data data;
324:
325: rc = next_entry(buf, fp, sizeof(u32));
326: if (rc)
327: return rc;
328:
329: len = le32_to_cpu(buf[0]);
330: if (len == 0)
331: return 0;
332:
333: /* avtab_read_item() reads at least 96 bytes for any valid entry */
334: rc = size_check(3 * sizeof(u32), len, fp);
335: if (rc)
336: return rc;
337:
338: list->nodes = kzalloc_objs(*list->nodes, len);
339: if (!list->nodes)
340: return -ENOMEM;
341:
342: data.p = p;
343: data.other = other;
344: for (i = 0; i < len; i++) {
345: data.dst = &list->nodes[i];
346: rc = avtab_read_item(&p->te_cond_avtab, fp, p, cond_insertf,
347: &data, true);
348: if (rc) {
349: kfree(list->nodes);
350: list->nodes = NULL;
351: return rc;
352: }
353: }
354:
355: list->len = len;
356: return 0;
357: }
SourceFile:security/selinux/ss/conditional.c]
|
| 48/2 |
2026/07/27 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 34499
output: 39
thoughts: 10
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert and I'm treating the thought as my own:
**Checking `cond_insertf`**
Alright, let's dive into this. "Let's check `cond_insertf`." This immediately tells me I'm likely debugging or reviewing some code. The name suggests this might be a conditional insertion function, something that's probably part of a larger data structure or algorithm. I need to understand its behavior thoroughly because it's probably key. My focus will be on the conditions under which it inserts and how the insertion itself works. What are the preconditions? Postconditions? Any potential edge cases? I should look for those classic issues: race conditions, off-by-one errors, or maybe even subtle bugs related to concurrency if itβs multithreaded. I need to understand its relationship to the surrounding system and see where `cond_insertf` fits. Time to dig in and scrutinize.
|
| 49/2 |
2026/07/27 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/conditional.c Name:cond_insertf]
Results: map[SourceCode: 250: static int cond_insertf(struct avtab *a, const struct avtab_key *k,
251: const struct avtab_datum *d, void *ptr)
252: {
253: struct cond_insertf_data *data = ptr;
254: struct policydb *p = data->p;
255: struct cond_av_list *other = data->other;
256: struct avtab_node *node_ptr;
257: u32 i;
258: bool found;
259:
260: /*
261: * For type rules we have to make certain there aren't any
262: * conflicting rules by searching the te_avtab and the
263: * cond_te_avtab.
264: */
265: if (k->specified & AVTAB_TYPE) {
266: if (avtab_search_node(&p->te_avtab, k)) {
267: pr_err("SELinux: type rule already exists outside of a conditional.\n");
268: return -EINVAL;
269: }
270: /*
271: * If we are reading the false list other will be a pointer to
272: * the true list. We can have duplicate entries if there is only
273: * 1 other entry and it is in our true list.
274: *
275: * If we are reading the true list (other == NULL) there shouldn't
276: * be any other entries.
277: */
278: if (other) {
279: node_ptr = avtab_search_node(&p->te_cond_avtab, k);
280: if (node_ptr) {
281: if (avtab_search_node_next(node_ptr,
282: k->specified)) {
283: pr_err("SELinux: too many conflicting type rules.\n");
284: return -EINVAL;
285: }
286: found = false;
287: for (i = 0; i < other->len; i++) {
288: if (other->nodes[i] == node_ptr) {
289: found = true;
290: break;
291: }
292: }
293: if (!found) {
294: pr_err("SELinux: conflicting type rules.\n");
295: return -EINVAL;
296: }
297: }
298: } else {
299: if (avtab_search_node(&p->te_cond_avtab, k)) {
300: pr_err("SELinux: conflicting type rules when adding type rule for true.\n");
301: return -EINVAL;
302: }
303: }
304: }
305:
306: node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d);
307: if (!node_ptr) {
308: pr_err("SELinux: could not insert rule.\n");
309: return -ENOMEM;
310: }
311:
312: *data->dst = node_ptr;
313: return 0;
314: }
SourceFile:security/selinux/ss/conditional.c]
|
| 50/2 |
2026/07/27 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 35762
output: 40
thoughts: 4041
Thoughts: **Analysis of Potential Soft Lockup in SELinux AVTAB Search**
Okay, let's break this down. My initial thought was that `cond_insertf` and `cond_dup_av_list`, both using `avtab_insert_nonunique`, might lead to multiple entries with the same key in `te_cond_avtab`. And, of course, these are then searched with `avtab_search_node`. The worry was a potential for an infinite loop if `cond_compute_av` iterated over too many nodes with identical keys. But, wait, the list is singly linked. No cycles. Still, a massive number of these would lead to a very slow `avtab_search_node`.
`cond_dup_av_list` seems like it could create duplicates, especially when booleans change, since it's called during that process. And since `security_compute_av` is called for every permission check, a huge `te_cond_avtab` would be a serious problem. The size of `te_cond_avtab` *is* proportional to policy size, so an administrator's policy design is key here. Attackers can't inject a malicious policy directly. The vulnerability lies in policy construction, then.
But the question is, can `cond_dup_av_list` *expand* the number of nodes beyond the original? No. It seems to just duplicate based on the original nodes in `true_list` and `false_list`. `duplicate_policydb_cond_list` maintains the count. Phew.
Now, let's get into `avtab_node_cmp`. The way it works, identical source/target/class values, but different `specified` values, lead to a return of 1. That's the kicker. That causes `avtab_insert` and `avtab_insert_nonunique` to continue searching the list. So identical source/target/class values with different `specified` values get grouped. The insertion order matters. Nodes with the *same* types but *disjoint* 'specified' values are sorted to the end of the bucket.
Now I am getting that sinking feeling... this isn't a strict weak ordering. *That's* the problem. The comparator is not transitive. If A > B and B > C, it's NOT guaranteed A > C. This is a problem in the insertion process! Nodes might be inserted in the wrong order, but the *search* is correct. The linear scan should always reach the element, if it's present.
I have to trace `avtab_insert_nonunique` though this. It's skipping some values based on the comparison function, but not in a way that *misses* anything. It's just inserting them in a way that's not strictly sorted. It's effectively treating all nodes with identical keys but different `specified` as the *same*. In `avtab_search_node`, the linear scan continues until a matching node is found, ensuring a match. The lack of strict weak ordering only affects the relative positions of elements with the same types and disjoint specified values, and the search function treats those types of entries as *equivalent*.
So why is there a soft lockup? It's the number of nodes in the *same* hash bucket that causes it. With the current logic, *each* node with identical key will be scanned. `cond_compute_av` iterates with `avtab_search_node` and potentially for a long time if there are a *lot* of nodes. The size is directly related to the policy design. And that's the core of the syzbot report. The key is to understand that the policy *itself* must have a lot of conditional rules, resulting in many nodes in `te_cond_avtab`. The issue isn't an infinite loop, but a performance problem if a particular hash bucket has many nodes with similar keys. The administrator's policy design is key here.
|
| 51/2 |
2026/07/27 02:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:avtab_hash]
Results: map[SourceCode: 28: static inline u32 avtab_hash(const struct avtab_key *keyp, u32 mask)
29: {
30: return av_hash((u32)keyp->target_class, (u32)keyp->target_type,
31: (u32)keyp->source_type, mask);
32: }
SourceFile:security/selinux/ss/avtab.c]
|
| 52/2 |
2026/07/27 02:13 |
llm |
expert |
0m
Model:
Tokens:
input: 40832
output: 39
thoughts: 9
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:
**Checking the `av_hash` - A Deep Dive**
Alright, time to dive in. Let's see... the situation presents itself, and before jumping to any major conclusions, the first order of business has to be validating the foundational data. Let's get to the bottom of the `av_hash`. It's a critical component, likely a checksum, digest, or perhaps a more complex cryptographic hash, depending on the context. Its integrity, in this case, is pivotal. I need to quickly assess its construction; is it a simple MD5 or SHA variant, or something more robust and application-specific? Iβm thinking, does it involve salting, or are we dealing with something exposed to known vulnerability vectors?
My immediate line of thought is to check for collisions, or possible issues with implementation. Depending on the data it's hashing, a weak hash could expose serious issues. Does the implementation support a collision resistant hash? Perhaps the `av_hash` will give some insights into data integrity, and potential manipulation.
Next, I need to look at its associated documentation or any prior analysis related to it. Where is the `av_hash` utilized? What does its verification entail? Can I easily reproduce it to validate its current state? Let's check the function's scope to determine its influence, because a critical issue here could cascade quickly. Itβs absolutely essential that I can trace its origins, the inputs, the algorithm itself, and any potential points of weakness or error. Based on what I find, the `av_hash` verification, and what the hash is tied to, will dictate the next steps of this troubleshooting process. From there, I'll know exactly what to do.
|
| 53/2 |
2026/07/27 02:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/avtab.c Name:av_hash]
Results: map[SourceCode: 6: /*
7: * Based on MurmurHash3, written by Austin Appleby and placed in the
8: * public domain.
9: */
10: static inline u32 av_hash(u32 key1, u32 key2, u32 key3, u32 mask)
11: {
12: static const u32 c1 = 0xcc9e2d51;
13: static const u32 c2 = 0x1b873593;
14: static const u32 r1 = 15;
15: static const u32 r2 = 13;
16: static const u32 m = 5;
17: static const u32 n = 0xe6546b64;
18:
19: u32 hash = 0;
20:
21: #define mix(input) \
22: do { \
23: u32 v = input; \
24: v *= c1; \
25: v = (v << r1) | (v >> (32 - r1)); \
26: v *= c2; \
27: hash ^= v; \
28: hash = (hash << r2) | (hash >> (32 - r2)); \
29: hash = hash * m + n; \
30: } while (0)
31:
32: mix(key1);
33: mix(key2);
34: mix(key3);
35:
36: #undef mix
37:
38: hash ^= hash >> 16;
39: hash *= 0x85ebca6b;
40: hash ^= hash >> 13;
41: hash *= 0xc2b2ae35;
42: hash ^= hash >> 16;
43:
44: return hash & mask;
45: }
SourceFile:security/selinux/include/hash.h]
|
| 54/2 |
2026/07/27 02:13 |
llm |
expert |
0m
Model:
Tokens:
input: 41866
output: 42
thoughts: 2210
Thoughts: **Vulnerability Analysis of SELinux Conditional AV Tab Search**
Okay, so MurmurHash3 is the hash function used, which is generally fine, but I see a potential attack vector here. If an attacker crafts a policy with numerous rules sharing the same `source_type`, `target_type`, and `target_class`, those rules will inevitably land in the same hash bucket, regardless of the hash function's quality! The hash key is based solely on those three fields. A policy with, say, 100,000 rules that *only* differ in their `specified` bitmask will still end up in the same bucket. This is a problem because `avtab_search_node` then has to linearly scan through all these rules.
However, how bad is the worst-case scenario? The `specified` field is only a `u16`, so potentially only a few hundred different values at most, given the nature of its bitmask (which contains flags such as `AVTAB_ALLOWED`, `AVTAB_AUDITALLOW`, etc.). But can there even be duplicate keys *including* the `specified` value in the `te_cond_avtab`? The code uses `avtab_insert_nonunique` with `cond_insertf`, which *does* allow duplicate keys! The `avtab_insert_node` function inserts the *same* key 100,000 times will result in 100,000 identical nodes in the same list.
Looking at how this could occur, `cond_read_av_list` allows a malicious policy to specify a `len` field and insert that many identical rules. So a crafted policy file can specify 100,000 identical rules, which is then loaded into `avtab_read_item`.
But wait, a non-privileged user can't *load* a malicious policy, since loading policies requires `CAP_MAC_ADMIN`. So the user cannot directly inject the policy to exploit the vulnerability.
However, the syzbot report is interesting: a normal `mmap` syscall is triggering the slowness within `avtab_search_node` because of the crafted policy. On one CPU, we see `mmap` call stack. The other has `openat2` leading to permission checks and ultimately `avtab_search_node`. So the exploit is triggered *without* needing to load a malicious policy. This confirms the vulnerability is reachable through regular syscalls.
Why is `avtab_search_node` slow? Is it the default policy with many conditional rules, or is there a *bug* that causes an infinite loop in `avtab_search_node`? Let's examine the `avtab_node_cmp` and `avtab_search_node` functions closely.
Looking at `avtab_node_cmp`, something stands out. We're doing a bitwise AND on `specified` which is `key1->specified & ~(AVTAB_ENABLED | AVTAB_ENABLED_OLD)` with `key2->specified`. If only `AVTAB_ENABLED` is set in `key2->specified` , `specified & key2->specified` would be 0, and the comparison would continue. But that can't be, because `AVTAB_ENABLED` is added to existing permissions such as `AVTAB_ALLOWED` or `AVTAB_AUDITALLOW`, and would not be the only bit set.
So a node will always have one of `AVTAB_AV`, `AVTAB_TYPE`, or `AVTAB_XPERMS` bits set. So, we're not dealing with an infinite loop. `key->specified` in `cond_compute_av` is the current permissions requested, and the code iterates through all nodes where `key->specified` & `node->specified` is non-zero.
|
| 55/2 |
2026/07/27 02:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/services.c Name:context_struct_compute_av]
Results: map[SourceCode: 616: /*
617: * Compute access vectors and extended permissions based on a context
618: * structure pair for the permissions in a particular class.
619: */
620: static void context_struct_compute_av(struct policydb *policydb,
621: struct context *scontext,
622: struct context *tcontext,
623: u16 tclass,
624: struct av_decision *avd,
625: struct extended_perms *xperms)
626: {
627: struct constraint_node *constraint;
628: struct role_allow *ra;
629: struct avtab_key avkey;
630: struct avtab_node *node;
631: struct class_datum *tclass_datum;
632: struct ebitmap *sattr, *tattr;
633: struct ebitmap_node *snode, *tnode;
634: unsigned int i, j;
635:
636: avd->allowed = 0;
637: avd->auditallow = 0;
638: avd->auditdeny = 0xffffffff;
639: if (xperms) {
640: memset(xperms, 0, sizeof(*xperms));
641: }
642:
643: if (unlikely(!tclass || tclass > policydb->p_classes.nprim)) {
644: pr_warn_ratelimited("SELinux: Invalid class %u\n", tclass);
645: return;
646: }
647:
648: tclass_datum = policydb->class_val_to_struct[tclass - 1];
649:
650: /*
651: * If a specific type enforcement rule was defined for
652: * this permission check, then use it.
653: */
654: avkey.target_class = tclass;
655: avkey.specified = AVTAB_AV | AVTAB_XPERMS;
656: sattr = &policydb->type_attr_map_array[scontext->type - 1];
657: tattr = &policydb->type_attr_map_array[tcontext->type - 1];
658: ebitmap_for_each_positive_bit(sattr, snode, i) {
659: ebitmap_for_each_positive_bit(tattr, tnode, j) {
660: avkey.source_type = i + 1;
661: avkey.target_type = j + 1;
662: for (node = avtab_search_node(&policydb->te_avtab,
663: &avkey);
664: node;
665: node = avtab_search_node_next(node, avkey.specified)) {
666: if (node->key.specified == AVTAB_ALLOWED)
667: avd->allowed |= node->datum.u.data;
668: else if (node->key.specified == AVTAB_AUDITALLOW)
669: avd->auditallow |= node->datum.u.data;
670: else if (node->key.specified == AVTAB_AUDITDENY)
671: avd->auditdeny &= node->datum.u.data;
672: else if (xperms && (node->key.specified & AVTAB_XPERMS))
673: services_compute_xperms_drivers(xperms, node);
674: }
675:
676: /* Check conditional av table for additional permissions */
677: cond_compute_av(&policydb->te_cond_avtab, &avkey,
678: avd, xperms);
679:
680: }
681: }
682:
683: /*
684: * Remove any permissions prohibited by a constraint (this includes
685: * the MLS policy).
686: */
687: constraint = tclass_datum->constraints;
688: while (constraint) {
689: if ((constraint->permissions & (avd->allowed)) &&
690: !constraint_expr_eval(policydb, scontext, tcontext, NULL,
691: constraint->expr)) {
692: avd->allowed &= ~(constraint->permissions);
693: }
694: constraint = constraint->next;
695: }
696:
697: /*
698: * If checking process transition permission and the
699: * role is changing, then check the (current_role, new_role)
700: * pair.
701: */
702: if (tclass == policydb->process_class &&
703: (avd->allowed & policydb->process_trans_perms) &&
704: scontext->role != tcontext->role) {
705: for (ra = policydb->role_allow; ra; ra = ra->next) {
706: if (scontext->role == ra->role &&
707: tcontext->role == ra->new_role)
708: break;
709: }
710: if (!ra)
711: avd->allowed &= ~policydb->process_trans_perms;
712: }
713:
714: /*
715: * If the given source and target types have boundary
716: * constraint, lazy checks have to mask any violated
717: * permission and notice it to userspace via audit.
718: *
719: * Infinite recursion is avoided via a depth pre-check in
720: * type_bounds_sanity_check().
721: */
722: type_attribute_bounds_av(policydb, scontext, tcontext,
723: tclass, avd);
724: }
SourceFile:security/selinux/ss/services.c]
|
| 56/2 |
2026/07/27 02:13 |
llm |
expert |
0m
Model:
Tokens:
input: 46709
output: 42
thoughts: 2982
Thoughts: **Analyzing a Potential SELinux Soft Lockup**
Okay, so I'm digging into this reported soft lockup and trying to understand the root cause, assuming I'm the one who reported this bug. I see a nested loop that looks concerning: `ebitmap_for_each_positive_bit`, iterating over source and target attributes for SELinux types. This calls `cond_compute_av` which, in turn, calls `avtab_search_node` on `te_cond_avtab`. If a policy defines types with a large number of attributes, this could generate a massive number of calls to `avtab_search_node`, and that could be slow.
My initial thought is that this is triggered by a policy with many attributes, and that an unprivileged user can trigger this. However, this relies on the policy itself, which is loaded by root. So I need to determine if an unprivileged user can *somehow* make this slow code path a problem. I'm wondering if Syzbot, which reported the lockup, might be using a default policy or perhaps even a malicious or very large policy. Syzbot runs as root, however, it's not clear whether it can load a malicious policy. If I can, it's possible that this is easily triggered. If I can't, then maybe this slow code path is just slow.
Then I start thinking about whether there's some *other* kind of bug here. I'm remembering that `avtab_search_node` walks a linked list and my thoughts immediately go to whether this list could be corrupted into a cycle and cause an infinite loop. So, I start tracing the insertion and search logic, specifically focusing on `avtab_node_cmp`. The comparison function looks a bit weird, especially when examining its interaction with `avtab_insert_nonunique` and related functions. I'm thinking, "Could a specific sequence of inserts cause an ordering issue?"
I then look into `avtab_insert_node`, `avtab_insert_nonunique`, and `cond_dup_av_list`. They all seem pretty standard, and don't introduce cycles themselves, but I'm looking for where they insert nodes. And I'm looking for *concurrent* modification!
Then I start looking at whether `cond_compute_av` could be running concurrently with an insertion or modification. I see that `cond_compute_av` accesses the policy under an RCU read lock and the policy is swapped via RCU. I see that `evaluate_cond_node` does modify the `key.specified`, but this is done on a copy of the policy BEFORE publication, so no concurrent issues there either.
I then start to analyze a test insertion sequence that has a non-strict-weak ordering property. After working through the logic, I see that the linked list is built properly! It's simply a linear list. I am also starting to think about whether the list could be very long. Given that, the soft lockup is a possibility if `avtab_search_node` has a very long list to scan, which might occur if the policy has many conditional rules. So a malicious policy could be a trigger for this!
I remember, though, that only root can load a policy. Then I re-remember that this is a *global* resource. So `security_load_policy` checks `CAP_MAC_ADMIN` in the init user namespace. So if I have root, but I'm NOT in the init user namespace, then I don't have this capability. But I do, and this is global.
|
| 57/2 |
2026/07/27 02:13 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:security/selinux/include/security.h Name:mac_admin_ns_capable]
Results: map[SourceCode: SourceFile:]
|
| 58/2 |
2026/07/27 02:13 |
llm |
expert |
0m
Model:
Tokens:
input: 50524
output: 41
thoughts: 26
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into SELinux Policy Loading**
Okay, time to get to the heart of how this SELinux policy loading thing works. I'm going to start digging into the `security/selinux/selinuxfs.c` file. Specifically, I'm focusing in on the `security_load_policy` function. That's the logical entry point for the core loading process, which is where I expect to find the crucial logic. I need to get a clear picture of how the data structures are initialized, how the policy is parsed and verified, how the security attributes are mapped, and how the kernel integrates the loaded policy. This could be where any performance bottlenecks are, or maybe where potential security vulnerabilities lurk. This is going to be my starting point for a deeper dive.
|
| 59/2 |
2026/07/27 02:14 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/selinuxfs.c Name:sel_write_load]
Results: map[SourceCode: 538: static ssize_t sel_write_load(struct file *file, const char __user *buf,
539: size_t count, loff_t *ppos)
540:
541: {
542: struct selinux_fs_info *fsi;
543: struct selinux_load_state load_state;
544: ssize_t length;
545: void *data = NULL;
546:
547: /* no partial writes */
548: if (*ppos)
549: return -EINVAL;
550: /* no empty policies */
551: if (!count)
552: return -EINVAL;
553:
554: length = avc_has_perm(current_sid(), SECINITSID_SECURITY,
555: SECCLASS_SECURITY, SECURITY__LOAD_POLICY, NULL);
556: if (length)
557: return length;
558:
559: data = vmalloc(count);
560: if (!data)
561: return -ENOMEM;
562: if (copy_from_user(data, buf, count) != 0) {
563: length = -EFAULT;
564: goto out;
565: }
566:
567: mutex_lock(&selinux_state.policy_mutex);
568: length = security_load_policy(data, count, &load_state);
569: if (length) {
570: pr_warn_ratelimited("SELinux: failed to load policy\n");
571: goto out_unlock;
572: }
573: fsi = file_inode(file)->i_sb->s_fs_info;
574: length = sel_make_policy_nodes(fsi, load_state.policy);
575: if (length) {
576: pr_warn_ratelimited("SELinux: failed to initialize selinuxfs\n");
577: selinux_policy_cancel(&load_state);
578: goto out_unlock;
579: }
580:
581: selinux_policy_commit(&load_state);
582: length = count;
583: audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
584: "auid=%u ses=%u lsm=selinux res=1",
585: from_kuid(&init_user_ns, audit_get_loginuid(current)),
586: audit_get_sessionid(current));
587:
588: out_unlock:
589: mutex_unlock(&selinux_state.policy_mutex);
590: out:
591: vfree(data);
592: return length;
593: }
SourceFile:security/selinux/selinuxfs.c]
|
| 60/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 51649
output: 48
thoughts: 552
Thoughts: **Analyzing a Potential SELinux Policy Vulnerability**
Okay, so the code first checks if the current security identifier (SID) has the `load_policy` permission using `avc_has_perm`. That's standard SELinux stuff. Since Syzbot runs as root, it *should* have this permission. The immediate assumption is that if Syzbot triggered this, then a malicious policy was loaded, and the problem is in policy parsing or evaluation. But... wait. The Syzbot report is only showing `openat2` in the call trace and the task state is running, which seems unusual.
Hmm, this makes me think of an infinite loop somewhere. Could there be a bug within `context_struct_compute_av` that's triggering an infinite loop, even with a normal policy? Let me check that function again.
Alright, here it is:
```c
ebitmap_for_each_positive_bit(sattr, snode, i) {
ebitmap_for_each_positive_bit(tattr, tnode, j) {
avkey.source_type = i + 1;
avkey.target_type = j + 1;
for (node = avtab_search_node(&policydb->te_avtab,
&avkey);
node;
node = avtab_search_node_next(node, avkey.specified)) {
...
}
/* Check conditional av table for additional permissions */
cond_compute_av(&policydb->te_cond_avtab, &avkey,
avd, xperms);
}
}
```
Okay, so `sattr` and `tattr` are the source and target type attributes. The nested loops run `ebitmap_for_each_positive_bit` which iterates through the set bits within each attribute. So, if `sattr` has `N` bits set, and `tattr` has `M` bits set, this loop does `N * M` iterations.
Could `N` and `M` be large enough to be a problem? SELinux types *can* have many attributes. But aren't `N` and `M` bounded by the number of types and attributes defined in the policy? I wonder if there's any scenario where `ebitmap_for_each_positive_bit` itself might loop infinitely, even if the policy itself isn't *malicious* in the conventional sense. I need to investigate how those bitmaps are structured and whether any conditions can cause an extremely large or infinite number of iterations.
|
| 61/2 |
2026/07/27 02:14 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:security/selinux/ss/ebitmap.h Name:ebitmap_for_each_positive_bit]
Results: map[SourceCode: SourceFile:]
|
| 62/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 52861
output: 25
thoughts: 34
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Diving into the ebitmap Implementation**
Alright, I need to get into the nitty-gritty of how SELinux manages its bitmaps. The target seems to be the `ebitmap_for_each_positive_bit` function. My mental map immediately directs me to the source file: `security/selinux/ss/ebitmap.h`. That header file is the logical place to start, given this function's naming convention. I'm assuming it defines the data structures and perhaps some inline macros used by the function itself. I'm hoping to get a clearer picture of how this function traverses the bitmaps, what optimizations are employed, and understand the general context of its application. I'm particularly interested in seeing how it handles sparse bitmaps or potential edge cases. I'm also hoping it isn't overly complex. Knowing the implementation details will allow me to assess its potential performance implications for other subsystems.
|
| 63/2 |
2026/07/27 02:14 |
tool |
grepper |
0m
Args: map[Expression:define ebitmap_for_each_positive_bit]
Results: map[Output:security/selinux/ss/ebitmap.h=109=static inline void ebitmap_node_clr_bit(struct ebitmap_node *n, u32 bit)
--
security/selinux/ss/ebitmap.h-117-
security/selinux/ss/ebitmap.h:118:#define ebitmap_for_each_positive_bit(e, n, bit) \
security/selinux/ss/ebitmap.h-119- for ((bit) = ebitmap_start_positive(e, &(n)); \
]
|
| 64/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 53287
output: 41
thoughts: 17
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing `ebitmap_for_each_positive_bit`**
Alright, let's dive into `ebitmap_for_each_positive_bit`. Given the name, it's immediately clear this is likely a kernel-level function, probably operating on some sort of efficient bitmap structure. I'm already anticipating a clever bitwise manipulation approach, probably optimized for a specific architecture's word size. The emphasis on "each positive bit" suggests we're iterating through a set of flags or a dense representation of some data's state, maybe for resource management, memory allocation, or some kind of indexing. I'm keen to see how they handle the common performance bottlenecks β particularly cache misses and branch mispredictions within the loop. The "for_each" part suggests an iterator-style pattern, which I'll be looking for and the use of the term "e" in front of bitmap suggests extended or efficient bitmap. I would expect some kind of lookup or a bit-scanning approach. Let's see how they trade space for speed.
|
| 65/2 |
2026/07/27 02:14 |
tool |
read-file |
0m
Args: map[File:security/selinux/ss/ebitmap.h FirstLine:115 LineCount:20]
Results: map[Contents: 115: n->maps[index] &= ~(EBITMAP_BIT << ofs);
116: }
117:
118: #define ebitmap_for_each_positive_bit(e, n, bit) \
119: for ((bit) = ebitmap_start_positive(e, &(n)); \
120: (bit) < ebitmap_length(e); \
121: (bit) = ebitmap_next_positive(e, &(n), bit))
122:
123: bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2);
124: int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src);
125: int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1,
126: const struct ebitmap *e2);
127: int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2,
128: u32 last_e2bit);
129: u32 ebitmap_get_highest_set_bit(const struct ebitmap *e);
130: int ebitmap_get_bit(const struct ebitmap *e, u32 bit);
131: int ebitmap_set_bit(struct ebitmap *e, u32 bit, int value);
132: void ebitmap_destroy(struct ebitmap *e);
133: struct policy_file;
134: int ebitmap_read(struct ebitmap *e, struct policy_file *fp);
]
|
| 66/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 54035
output: 21
thoughts: 23
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing `ebitmap_start_positive` and `ebitmap_next_positive`**
Alright, let's dive into these functions, `ebitmap_start_positive` and `ebitmap_next_positive`. My immediate thought is to consider the context of their use. Are we talking about a simple bitmap implementation, or something more complex with compression or specialized indexing? The naming suggests we're dealing with finding "positive" bits within an ebitmap, which implies a sparse data structure. I need to quickly ascertain the underlying bitmap representation β is it word-aligned, bit-aligned, or something more exotic? Understanding that informs my expectations about performance.
I'm thinking about the potential algorithms used within these functions. `ebitmap_start_positive` is likely the entry point, so I'm interested in how it initializes the search. Does it use a bitscan operation (e.g., `ctz`, `clz`, or equivalent)? Or does it employ a lookup table for faster identification of the first set bit within a word? I'll need to look at how it handles the edge cases β an empty bitmap, a bitmap where no bits are set, and the boundary condition of the very first word.
Then, `ebitmap_next_positive` is the iterative part. Here, I'm anticipating a similar approach, probably a bitscan from the current bit position to find the next set bit. It needs to handle the carry-over across words correctly. Efficiency is key here; frequent branching within the loop is a performance killer. Does it try to unroll any loops, or perhaps use a branchless algorithm? Any optimizations to avoid unnecessary memory accesses will be interesting to see. I also want to check for any potential off-by-one errors or boundary violations. The iterator must handle the end of the bitmap gracefully.
In essence, I need to evaluate the implementation's speed, memory footprint, and correctness, with the understanding that these functions are the core primitives for navigating a sparse bitset. Itβs likely critical to the performance of any operation that uses this data structure.
|
| 67/2 |
2026/07/27 02:14 |
tool |
grepper |
0m
Error:
Args: map[Expression:define ebitmap_start_positive]
Results:
|
| 68/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 54555
output: 21
thoughts: 30
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Investigating `ebitmap_start_positive`**
Alright, time to dig into something specific. I need to get to the bottom of how this bitmask logic is working, and my first step is to locate the declaration of `ebitmap_start_positive`. Since it's a kernel data structure, `security/selinux/ss/ebitmap.h` is the logical place to start. This is likely where the core definition of the bitmap's structure and any related initializations will live. I'll need to understand how `ebitmap_start_positive` interacts with the rest of the ebitmap implementation. This should provide some useful information, allowing me to understand how SELinux uses this structure.
|
| 69/2 |
2026/07/27 02:14 |
tool |
grepper |
0m
Args: map[Expression:ebitmap_start_positive]
Results: map[Output:security/selinux/ss/ebitmap.h=42=struct ebitmap {
--
security/selinux/ss/ebitmap.h-48-
security/selinux/ss/ebitmap.h:49:static inline u32 ebitmap_start_positive(const struct ebitmap *e,
security/selinux/ss/ebitmap.h-50- struct ebitmap_node **n)
--
security/selinux/ss/ebitmap.h=109=static inline void ebitmap_node_clr_bit(struct ebitmap_node *n, u32 bit)
--
security/selinux/ss/ebitmap.h-118-#define ebitmap_for_each_positive_bit(e, n, bit) \
security/selinux/ss/ebitmap.h:119: for ((bit) = ebitmap_start_positive(e, &(n)); \
security/selinux/ss/ebitmap.h-120- (bit) < ebitmap_length(e); \
]
|
| 70/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 55057
output: 40
thoughts: 23
Thoughts: Okay, let's dive into this code. Here's what I'm thinking as I approach this:
**Analyzing `ebitmap_start_positive` and `ebitmap_next_positive`**
Alright, I need to get a clear understanding of how these functions, `ebitmap_start_positive` and `ebitmap_next_positive`, work together. My gut feeling is they are probably responsible for iterating through an ebitmap in a specific, presumably positive, direction. I'll need to confirm that suspicion by carefully dissecting their definitions and understand what they return. Are they finding the first set bit? The next set bit? And how do they handle edge cases, particularly the starting and stopping points of the iteration? I need to look at what data structure they're operating on - the `ebitmap` itself and any supporting parameters. I'll pay close attention to the algorithms employed: are they doing a bitwise search, a lookup table, or something more sophisticated? This could give me hints about performance characteristics. Essentially, I need to fully grasp how a positive-oriented traversal of an ebitmap is initiated and advanced.
|
| 71/2 |
2026/07/27 02:14 |
tool |
read-file |
0m
Args: map[File:security/selinux/ss/ebitmap.h FirstLine:49 LineCount:40]
Results: map[Contents: 49: static inline u32 ebitmap_start_positive(const struct ebitmap *e,
50: struct ebitmap_node **n)
51: {
52: u32 ofs;
53:
54: for (*n = e->node; *n; *n = (*n)->next) {
55: ofs = find_first_bit((*n)->maps, EBITMAP_SIZE);
56: if (ofs < EBITMAP_SIZE)
57: return (*n)->startbit + ofs;
58: }
59: return ebitmap_length(e);
60: }
61:
62: static inline void ebitmap_init(struct ebitmap *e)
63: {
64: memset(e, 0, sizeof(*e));
65: }
66:
67: static inline u32 ebitmap_next_positive(const struct ebitmap *e,
68: struct ebitmap_node **n, u32 bit)
69: {
70: u32 ofs;
71:
72: ofs = find_next_bit((*n)->maps, EBITMAP_SIZE, bit - (*n)->startbit + 1);
73: if (ofs < EBITMAP_SIZE)
74: return ofs + (*n)->startbit;
75:
76: for (*n = (*n)->next; *n; *n = (*n)->next) {
77: ofs = find_first_bit((*n)->maps, EBITMAP_SIZE);
78: if (ofs < EBITMAP_SIZE)
79: return ofs + (*n)->startbit;
80: }
81: return ebitmap_length(e);
82: }
83:
84: #define EBITMAP_NODE_INDEX(node, bit) \
85: (((bit) - (node)->startbit) / EBITMAP_UNIT_SIZE)
86: #define EBITMAP_NODE_OFFSET(node, bit) \
87: (((bit) - (node)->startbit) % EBITMAP_UNIT_SIZE)
88:
]
|
| 72/2 |
2026/07/27 02:14 |
llm |
expert |
0m
Model:
Tokens:
input: 55960
output: 41
thoughts: 4233
Thoughts: **Analysis of RCU Stall in SELinux Conditional Policy Evaluation**
Okay, so I'm looking at this syzbot report about an RCU stall, and the call trace points to `avtab_search_node`, specifically within the SELinux conditional policy code. The problem is that the task is getting preempted by a timer interrupt *while holding the `rcu_read_lock`* for over ten seconds. I can't quite see why at first, because this is just iterating through a bitmap, so it shouldn't be an infinite loop.
My immediate thought is, what's causing this delay? The stack trace shows the function `context_struct_compute_av` is getting called from `security_compute_av` which is protected by the `rcu_read_lock`. So, anything that makes `context_struct_compute_av` take too long, will stall the RCU grace period. I need to understand what's in this function. It looks like it boils down to the interaction between the source and target context attributes, in relation to conditional access rules.
I'm thinking, could this be a malicious policy with a huge number of attributes? But, loading a policy requires `CAP_MAC_ADMIN`, and so that shouldn't be a vulnerability. Still, I consider it. Is it possible for a user to trigger a huge number of iterations by crafting specific source and target contexts? I'm thinking about setting contexts via `setxattr` or `/proc/self/attr/current`. But, context attributes are bounded by the policy itself, so I'm not seeing that either.
I dive into the code. The report shows `cond_compute_av` calling `avtab_search_node`. Okay, so `cond_compute_av` looks at *conditional* access rules, using `te_cond_avtab`. Is there an infinite loop? But no, the list iteration doesn't create cycles. Still, what if something is getting called repeatedly? What if `cond_dup_av_list` inserts nodes into `te_cond_avtab` multiple times? I check `avtab_insert_nonunique` and it does not create a cycle. I think about `avtab_search_node_next`. It doesn't look like it can loop infinitely.
Then I get it, looking at how `avtab_search_node_next` is called. It iterates through the list. What if it is a very LONG list? `cond_read_av_list` *can* insert multiple nodes with the *same* key if the policy is malicious. And, if the policy is malicious, it can contain a massive number of conditional rules that hash to the same bucket. Syzbot *does* load potentially malicious policies, so it's possible. Now, it's making sense.
A carefully crafted malicious policy could result in `avtab_search_node` iterating over *millions* of identical conditional rules in one bucket. `cond_compute_av` is now iterating over all of those rules, which could easily cause it to take 10.5 seconds, triggering the RCU stall.
So, I think I have it, if syzbot loads a malicious policy with a huge number of identical conditional rules, then we can have this issue. But, is it a vulnerability? Loading a policy requires CAP_MAC_ADMIN. This is a denial of service, but probably not considered a security vulnerability. But, I should check whether something in the user namespace could get us here, because I'm not sure if CAP_MAC_ADMIN is set for user namespaces. I am not seeing that it is, so that is not the issue.
|
| 73/2 |
2026/07/27 02:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/selinuxfs.c Name:sel_write_load]
Results: map[SourceCode: 538: static ssize_t sel_write_load(struct file *file, const char __user *buf,
539: size_t count, loff_t *ppos)
540:
541: {
542: struct selinux_fs_info *fsi;
543: struct selinux_load_state load_state;
544: ssize_t length;
545: void *data = NULL;
546:
547: /* no partial writes */
548: if (*ppos)
549: return -EINVAL;
550: /* no empty policies */
551: if (!count)
552: return -EINVAL;
553:
554: length = avc_has_perm(current_sid(), SECINITSID_SECURITY,
555: SECCLASS_SECURITY, SECURITY__LOAD_POLICY, NULL);
556: if (length)
557: return length;
558:
559: data = vmalloc(count);
560: if (!data)
561: return -ENOMEM;
562: if (copy_from_user(data, buf, count) != 0) {
563: length = -EFAULT;
564: goto out;
565: }
566:
567: mutex_lock(&selinux_state.policy_mutex);
568: length = security_load_policy(data, count, &load_state);
569: if (length) {
570: pr_warn_ratelimited("SELinux: failed to load policy\n");
571: goto out_unlock;
572: }
573: fsi = file_inode(file)->i_sb->s_fs_info;
574: length = sel_make_policy_nodes(fsi, load_state.policy);
575: if (length) {
576: pr_warn_ratelimited("SELinux: failed to initialize selinuxfs\n");
577: selinux_policy_cancel(&load_state);
578: goto out_unlock;
579: }
580:
581: selinux_policy_commit(&load_state);
582: length = count;
583: audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
584: "auid=%u ses=%u lsm=selinux res=1",
585: from_kuid(&init_user_ns, audit_get_loginuid(current)),
586: audit_get_sessionid(current));
587:
588: out_unlock:
589: mutex_unlock(&selinux_state.policy_mutex);
590: out:
591: vfree(data);
592: return length;
593: }
SourceFile:security/selinux/selinuxfs.c]
|
| 74/2 |
2026/07/27 02:15 |
llm |
expert |
0m
Model:
Tokens:
input: 61894
output: 40
thoughts: 46
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Diving into the SELinux Policy Load**
Hmm, hold on a second... are you saying that the `security_load_policy` function, the core of how we load an SELinux policy, actually performs a check on `mac_admin_ns_capable`? That's not the first place I'd have looked, but it does make a certain amount of sense considering the potential impact on namespaces. Itβs certainly a critical point to verify.
Right, let's confirm this suspicion. Time to crack open the source code. I need to take a look at the implementation of `security_load_policy` within the SELinux subsystem. I'll head over to `security/selinux/ss/services.c` and dig into that function. See if I can determine precisely how this `mac_admin_ns_capable` check fits into the policy loading process. Knowing the specifics of the conditional will inform the implications of the configuration.
|
| 75/2 |
2026/07/27 02:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:security/selinux/ss/services.c Name:security_load_policy]
Results: map[SourceCode:2296: /**
2297: * security_load_policy - Load a security policy configuration.
2298: * @data: binary policy data
2299: * @len: length of data in bytes
2300: * @load_state: policy load state
2301: *
2302: * Load a new set of security policy configuration data,
2303: * validate it and convert the SID table as necessary.
2304: * This function will flush the access vector cache after
2305: * loading the new policy.
2306: */
2307: int security_load_policy(void *data, size_t len,
2308: struct selinux_load_state *load_state)
2309: {
2310: struct selinux_state *state = &selinux_state;
2311: struct selinux_policy *newpolicy, *oldpolicy;
2312: struct selinux_policy_convert_data *convert_data;
2313: int rc = 0;
2314: struct policy_file file = { data, len }, *fp = &file;
2315:
2316: newpolicy = kzalloc_obj(*newpolicy);
2317: if (!newpolicy)
2318: return -ENOMEM;
2319:
2320: newpolicy->sidtab = kzalloc_obj(*newpolicy->sidtab);
2321: if (!newpolicy->sidtab) {
2322: rc = -ENOMEM;
2323: goto err_policy;
2324: }
2325:
2326: rc = policydb_read(&newpolicy->policydb, fp);
2327: if (rc)
2328: goto err_sidtab;
2329:
2330: newpolicy->policydb.len = len;
2331: rc = selinux_set_mapping(&newpolicy->policydb, secclass_map,
2332: &newpolicy->map);
2333: if (rc)
2334: goto err_policydb;
2335:
2336: rc = policydb_load_isids(&newpolicy->policydb, newpolicy->sidtab);
2337: if (rc) {
2338: pr_err("SELinux: unable to load the initial SIDs\n");
2339: goto err_mapping;
2340: }
2341:
2342: if (!selinux_initialized()) {
2343: /* First policy load, so no need to preserve state from old policy */
2344: load_state->policy = newpolicy;
2345: load_state->convert_data = NULL;
2346: return 0;
2347: }
2348:
2349: oldpolicy = rcu_dereference_protected(state->policy,
2350: lockdep_is_held(&state->policy_mutex));
2351:
2352: /* Preserve active boolean values from the old policy */
2353: rc = security_preserve_bools(oldpolicy, newpolicy);
2354: if (rc) {
2355: pr_err("SELinux: unable to preserve booleans\n");
2356: goto err_free_isids;
2357: }
2358:
2359: /*
2360: * Convert the internal representations of contexts
2361: * in the new SID table.
2362: */
2363:
2364: convert_data = kmalloc_obj(*convert_data);
2365: if (!convert_data) {
2366: rc = -ENOMEM;
2367: goto err_free_isids;
2368: }
2369:
2370: convert_data->args.oldp = &oldpolicy->policydb;
2371: convert_data->args.newp = &newpolicy->policydb;
2372:
2373: convert_data->sidtab_params.args = &convert_data->args;
2374: convert_data->sidtab_params.target = newpolicy->sidtab;
2375:
2376: rc = sidtab_convert(oldpolicy->sidtab, &convert_data->sidtab_params);
2377: if (rc) {
2378: pr_err("SELinux: unable to convert the internal"
2379: " representation of contexts in the new SID"
2380: " table\n");
2381: goto err_free_convert_data;
2382: }
2383:
2384: load_state->policy = newpolicy;
2385: load_state->convert_data = convert_data;
2386: return 0;
2387:
2388: err_free_convert_data:
2389: kfree(convert_data);
2390: err_free_isids:
2391: sidtab_destroy(newpolicy->sidtab);
2392: err_mapping:
2393: kfree(newpolicy->map.mapping);
2394: err_policydb:
2395: policydb_destroy(&newpolicy->policydb);
2396: err_sidtab:
2397: kfree(newpolicy->sidtab);
2398: err_policy:
2399: kfree(newpolicy);
2400:
2401: return rc;
2402: }
SourceFile:security/selinux/ss/services.c]
|
| 76/2 |
2026/07/27 02:15 |
llm |
expert |
0m
Model:
Tokens:
input: 63804
output: 66
thoughts: 2794
Thoughts: **Analysis of SELinux Soft Lockup Vulnerability**
Okay, so it seems like the `security_load_policy` function doesn't directly check `mac_admin_ns_capable`. Instead, the permission check is deeper, within `sel_write_load`, where `avc_has_perm` verifies the `SECURITY__LOAD_POLICY` permission. This permission is typically granted only to very privileged domains, like `load_policy_t`. Therefore, an unprivileged user can't simply load a policy. That's good to know.
Could this soft lockup *not* be triggered by a malicious policy? Maybe itβs a bug in `avtab_node_cmp` causing an infinite loop? But, no, we've already established that `avtab_node_cmp` can't cause that. The list is singly linked and has no cycles.
Okay, what about `avtab_search_node`? Could *it* have a bug leading to an infinite loop? If `cur->next` somehow pointed to `cur` within the loop, that would do it. But we've also already seen that `avtab_insert_node` and `avtab_insert_nonunique` can't create cycles. So, we are ok there.
Wait, what if the `h->htable[hvalue]` data is corrupted due to a data race? `avtab_search_node` is called without any locks! The code does hold an `rcu_read_lock()`! Hmm... is `te_cond_avtab` modified concurrently? Let's check `evaluate_cond_node` and see if the nodes are modified there. Bingo! `evaluate_cond_node` *does* modify `avnode->key.specified`. Now the question: is it called concurrently with `avtab_search_node`? In `security_set_bools`, a new policy is created, duplicated, and then `evaluate_cond_nodes` is called. That update is done *before* the new policy is assigned via `rcu_assign_pointer`. Therefore, `avtab_search_node`, running concurrently, will always see the *old* policy which is not modified. And, `avnode` comes from nodes copied into the *new* policyβs `te_cond_avtab`. It looks like there isnβt a concurrent modification.
What about if `avtab_node_cmp` is called concurrently with `avtab_insert_nonunique`? That shouldn't happen, because `avtab_insert_nonunique` is only called during policy load or `security_set_bools`, which operate on a new and un-published policy. It looks like we are safe there.
So, it doesn't appear there are any data races.
So...why the soft lockup?
Well, what about that syzbot fuzzer generating and loading policies with *huge* numbers of rules? Yeah, syzbot *does* do that frequently. A policy with a million rules could easily soft lock the system. Is this a vulnerability? As we saw, policy loading requires `CAP_MAC_ADMIN` or equivalent permission, and that is a highly privileged operation. Therefore, an unprivileged user can't trigger this.
The question now: Could the issue actually stem from a massive number of *attributes*, rather than rules? If a type has, say, 10,000 attributes, the `ebitmap_for_each_positive_bit` loop will run 10,000 times. If both source and target have 10,000 attributes, the nested loop runs 100 million times. Again, that number of attributes is defined in the policy. So again, it requires a malicious policy.
Is there a bug in `ebitmap_for_each_positive_bit` that causes an infinite loop? We can verify that using `ebitmap_next_positive`. It looks like it is a standard bitmap iteration and cannot loop infinitely.
What if the `ebitmap_node` list has a cycle? That also doesn't seem likely. The list is created during policy load, and there's nothing in that code that would allow a cycle to be created.
So, the only *realistic* explanation is syzbot loading a malicious policy, with either a huge number of rules or a huge number of attributes. And since policy loading needs privileges, it is not something that an unprivileged user can trigger. It's a Denial of Service, but it's *only* available to a privileged user.
Now to verify: Could a malicious filesystem be the trigger? SELinux policies are loaded through `/sys/fs/selin
|
| 77/2 |
2026/07/27 02:15 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 78/2 |
2026/07/27 02:15 |
llm |
expert |
0m
Model:
Tokens:
input: 67753
output: 671
thoughts: 14
Thoughts: Okay, here's the summary, formatted as you requested:
**Final Reasoning: My Post-Analysis Thought Process**
Alright, the data is in, the calculations are complete, and now it's time to solidify my reasoning. I've meticulously reviewed the results; double-checked assumptions, and considered the implications of each significant finding. This isn't just about presenting the "answer," it's about crafting a narrative that logically connects the evidence to the conclusions. I need to ensure that the argument is airtight, acknowledging any limitations or potential alternative interpretations, while firmly grounding the conclusions in the observed phenomena. The process of formulating this final reasoning is where the true value lies, translating technical findings into something meaningful and actionable. I'm aiming for clarity and precision, allowing the audience to fully grasp not just *what* happened, but also *why* it happened, and what that means in the broader context of my field. It's about providing a robust and justifiable framework for understanding.
|
| 79/1 |
2026/07/27 02:15 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the bug report and the kernel source code, here is the
assessment of the issue:
**Bug Analysis:**
The bug report indicates an RCU stall (soft lockup) occurring in
`avtab_search_node()` within the SELinux subsystem. The call trace shows that an
unprivileged process is performing a standard file access (`openat2` -> `mmap`),
which triggers a SELinux permission check (`security_compute_av` ->
`context_struct_compute_av` -> `cond_compute_av` -> `avtab_search_node`).
In `context_struct_compute_av()`, the kernel iterates over all attributes of the
source context type and all attributes of the target context type using nested
`ebitmap_for_each_positive_bit` loops. For each combination, it searches the
SELinux Access Vector (AV) tables (`te_avtab` and `te_cond_avtab`) using
`avtab_search_node()` and `avtab_search_node_next()`.
If a loaded SELinux policy contains an abnormally large number of attributes for
specific types, or a massive number of conditional rules that hash to the same
bucket in `te_cond_avtab`, these nested loops and hash table traversals will
execute millions or billions of times. This results in the CPU spending an
excessive amount of time in this function without yielding, ultimately
triggering an RCU stall / soft lockup.
**Security Impact:**
While this is a Denial of Service (DoS) condition, it is entirely dependent on
the contents of the loaded SELinux policy.
- **Privilege Boundary:** Loading or modifying a SELinux policy requires highly
privileged capabilities, specifically the `SECURITY__LOAD_POLICY` SELinux
permission (typically reserved for processes with `CAP_MAC_ADMIN` or equivalent
root-level administrative roles).
- **Unprivileged Access:** An unprivileged user cannot load a malicious policy,
nor can they arbitrarily add attributes or rules to an existing policy. They can
only trigger the evaluation of the existing policy. Assuming a standard,
non-malicious policy, the number of attributes and rules is bounded and will not
cause a lockup.
- **User Namespaces:** SELinux policies are global and are not isolated per user
namespace. Entering a user namespace does not grant a process the ability to
load a SELinux policy.
Since the fuzzer (syzbot) runs with root privileges in the test environment, it
is able to load a mutated, malicious SELinux policy that intentionally triggers
this pathological performance edge-case. However, in a real-world scenario, an
attacker would already need full administrative control over the system to load
such a policy, at which point the system is already fully compromised.
Therefore, this is not considered a security vulnerability that crosses a
privilege boundary. It is not exploitable for memory corruption, privilege
escalation, or information leaks.
**Conclusion:**
- **Exploitable:** False
- **Denial of Service:** True (but requires administrative privileges to set up
the malicious policy)
- **Accessible From Unprivileged Processes:** False
- **Accessible From User Namespaces:** False]
|