]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selinux: annotate false positive data race to avoid KCSAN warnings
authorStephen Smalley <stephen.smalley.work@gmail.com>
Mon, 26 Aug 2024 12:47:09 +0000 (08:47 -0400)
committerPaul Moore <paul@paul-moore.com>
Mon, 26 Aug 2024 22:39:16 +0000 (18:39 -0400)
KCSAN flags the check of isec->initialized by
__inode_security_revalidate() as a data race. This is indeed a racy
check, but inode_doinit_with_dentry() will recheck with isec->lock held.
Annotate the check with the data_race() macro to silence the KCSAN false
positive.

Reported-by: syzbot+319ed1769c0078257262@syzkaller.appspotmail.com
Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/hooks.c

index 55c78c318ccd78b8dcec24886c0ff5e919c67b85..70c335846336da7e236f79991efd9de93c496ce6 100644 (file)
@@ -282,8 +282,13 @@ static int __inode_security_revalidate(struct inode *inode,
 
        might_sleep_if(may_sleep);
 
+       /*
+        * The check of isec->initialized below is racy but
+        * inode_doinit_with_dentry() will recheck with
+        * isec->lock held.
+        */
        if (selinux_initialized() &&
-           isec->initialized != LABEL_INITIALIZED) {
+           data_race(isec->initialized != LABEL_INITIALIZED)) {
                if (!may_sleep)
                        return -ECHILD;