KCSAN: data-race in selinux_inode_permission / selinux_task_to_inode

Status: moderation: reported on 2026/12/02 19:27
Subsystems: selinux
Labels: prio:low race:harmful
[Documentation on labels]
Reported-by: syzbot+3bb9c120788b0aae0c77@syzkaller.appspotmail.com
First crash: 5h11m, last: 5h11m
✨ AI-generated root cause summary:

selinux_task_to_inode() in security/selinux/hooks.c updates isec->sid (and isec->sclass) on /proc inodes under isec->lock using plain writes during pid_revalidate() / pid_update_inode(). Concurrently, selinux_inode_permission() (and its inlined helpers task_avdcache_search() and task_avdcache_update()) reads isec->sid and isec->sclass locklessly and without READ_ONCE() or data_race() during VFS path lookup. Because isec->sid is also read multiple times across avc_has_perm_noaudit() and task_avdcache_update(), a concurrent update can also pair an av_decision computed for the old SID with the new SID in the task's avdcache.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 693c2e04e3f1:

Root Cause Analysis

The KCSAN data race occurs on the 4-byte sid field (u32 sid, offset 28 bytes) of struct inode_security_struct (security/selinux/include/objsec.h:72-80) between concurrent /proc/<pid> dentry revalidation and inode permission checks during VFS path lookup.

1. Writer path (selinux_task_to_inode)

When a task walks /proc/<pid>, lookup_fast() (fs/namei.c:1874) invokes d_revalidate() -> pid_revalidate() (fs/proc/base.c:2043-2063) -> pid_update_inode() (fs/proc/base.c:2030-2036) -> security_task_to_inode() -> selinux_task_to_inode() (security/selinux/hooks.c:4732-4743):

static void selinux_task_to_inode(struct task_struct *p,
				  struct inode *inode)
{
	struct inode_security_struct *isec = selinux_inode(inode);
	u32 sid = task_sid_obj(p);

	spin_lock(&isec->lock);
	isec->sclass = inode_mode_to_security_class(inode->i_mode);
	isec->sid = sid;
	isec->initialized = LABEL_INITIALIZED;
	spin_unlock(&isec->lock);
}

pid_revalidate() runs under rcu_read_lock() (and even in non-RCU mode does not hold an exclusive lock across concurrent path-walk readers). selinux_task_to_inode() acquires isec->lock and writes isec->sclass, isec->sid (line 4740), and isec->initialized with plain stores (WRITE_ONCE() is not used).

2. Reader path (selinux_inode_permission)

Concurrently, another task traversing the same /proc/<pid> directory enters link_path_walk() -> may_lookup() -> lookup_inode_permission_may_exec() -> inode_permission() -> security_inode_permission() -> selinux_inode_permission() (security/selinux/hooks.c:3266-3320).

selinux_inode_permission() obtains isec via inode_security_rcu(inode, requested & MAY_NOT_BLOCK) (security/selinux/hooks.c:311-324), which only checks data_race(likely(isec->initialized == LABEL_INITIALIZED)) without taking isec->lock. It then reads isec->sid (and isec->sclass) locklessly and without READ_ONCE() across multiple places:

3. Invariant violation

isec->lock is used by writers (selinux_task_to_inode(), as well as selinux_inode_post_setxattr() and selinux_inode_setsecurity()) to serialize updates to isec->sid and isec->sclass, but lockless RCU/path-walk readers such as selinux_inode_permission() read isec->sid and isec->sclass without isec->lock and without READ_ONCE()/WRITE_ONCE() synchronization.

In addition to the KCSAN-reported data race (and potential compiler reload/tearing), reading isec->sid separately in avc_has_perm_noaudit() and task_avdcache_update() allows a concurrent selinux_task_to_inode() update between the two reads to store the new isec->sid alongside the av_decision (avdp) computed for the old isec->sid in tsec->avdcache.

(Note: Other lockless readers of isec->sid and isec->sclass in security/selinux/hooks.c, such as selinux_inode_follow_link() and selinux_file_permission(), share this same pattern against concurrent isec->lock-protected isec->sid updates.)

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
41d9ce4b assessment-kcsan Benign: ❌ ❓ KCSAN: data-race in selinux_inode_permission / selinux_task_to_inode 2026/12/02 14:59 2026/12/02 14:59 2026/12/02 19:27 35891725
81d6a1a3 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in selinux_inode_permission / selinux_task_to_inode 2026/12/02 14:56 2026/12/02 14:56 2026/12/02 14:59 35891725

Sample crash report:
==================================================================
BUG: KCSAN: data-race in selinux_inode_permission / selinux_task_to_inode

write to 0xffff88810d82b7d4 of 4 bytes by task 4030 on cpu 0:
 selinux_task_to_inode+0x160/0x1a0 security/selinux/hooks.c:4740
 security_task_to_inode+0x39/0x50 security/security.c:3374
 pid_update_inode fs/proc/base.c:2035 [inline]
 pid_revalidate+0x82/0xb0 fs/proc/base.c:2057
 d_revalidate fs/namei.c:1041 [inline]
 lookup_fast+0x232/0x320 fs/namei.c:1874
 walk_component fs/namei.c:2284 [inline]
 link_path_walk+0x528/0xde0 fs/namei.c:2662
 path_openat+0x142/0x11e0 fs/namei.c:5012
 do_file_open+0x16c/0x290 fs/namei.c:5045
 do_sys_openat2+0xa1/0x140 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0xf2/0x120 fs/open.c:1460
 x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff88810d82b7d4 of 4 bytes by task 4029 on cpu 1:
 selinux_inode_permission+0x3e6/0x740 security/selinux/hooks.c:-1
 security_inode_permission+0x73/0xb0 security/security.c:1865
 inode_permission+0x1e3/0x3c0 fs/namei.c:661
 lookup_inode_permission_may_exec fs/namei.c:-1 [inline]
 may_lookup fs/namei.c:1967 [inline]
 link_path_walk+0x881/0xde0 fs/namei.c:2610
 path_openat+0x142/0x11e0 fs/namei.c:5012
 do_file_open+0x16c/0x290 fs/namei.c:5045
 do_sys_openat2+0xa1/0x140 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0xf2/0x120 fs/open.c:1460
 x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 4029 Comm: syz.4.97 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/12/02 14:56 upstream 693c2e04e3f1 35891725 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in selinux_inode_permission / selinux_task_to_inode
* Struck through repros no longer work on HEAD.