selinux: annotate false positive data race to avoid KCSAN warnings
Stephen Smalley
maintainerPATCH 1/1 selinux: annotate false positive data race to avoid KCSAN warnings
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.
--- security/selinux/hooks.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
security/selinux/hooks.c +6 -1
@@ -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 ;
Signature · 1 line
2.40.1
Stephen Smalley
maintainerQuoted 9 lines · Stephen Smalley
KCSAN flags the check of
isec->initializedby__inode_security_revalidate()as a data race. This is indeed a racy check, butinode_doinit_with_dentry()will recheck withisec->lockheld. Annotate the check with thedata_race()macro to silence the KCSAN false positive.Reported-by [email protected]Signed-off-by Stephen Smalley <[email protected]>
With this patch applied and the following KCSAN-related configuration, I don't see any data-race warnings in SELinux functions during the selinux-testsuite (lots of them elsewhere though).
CONFIG_KCSAN=y
# CONFIG_KCSAN_VERBOSE is not setCONFIG_KCSAN_SELFTEST=yCONFIG_KCSAN_EARLY_ENABLE=yCONFIG_KCSAN_NUM_WATCHPOINTS=64CONFIG_KCSAN_UDELAY_TASK=80CONFIG_KCSAN_UDELAY_INTERRUPT=20CONFIG_KCSAN_DELAY_RANDOMIZE=yCONFIG_KCSAN_SKIP_WATCH=4000CONFIG_KCSAN_SKIP_WATCH_RANDOMIZE=y
# CONFIG_KCSAN_INTERRUPT_WATCHER is not setCONFIG_KCSAN_REPORT_ONCE_IN_MS=3000CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN=y
# CONFIG_KCSAN_STRICT is not setCONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=yCONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=y
# CONFIG_KCSAN_IGNORE_ATOMICS is not set
# CONFIG_KCSAN_PERMISSIVE is not set
Quoted 7 lines · On Aug 26, 2024 Stephen Smalley <[email protected]> wrote:
KCSAN flags the check of
isec->initializedby__inode_security_revalidate()as a data race. This is indeed a racy check, butinode_doinit_with_dentry()will recheck withisec->lockheld. Annotate the check with thedata_race()macro to silence the KCSAN false positive.
Quoted 5 lines
Reported-by [email protected]Signed-off-by Stephen Smalley <[email protected]>--- security/selinux/hooks.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Merged into selinux/dev, thanks Stephen.
--
paul-moore.com