Skip to contentSkip to conversation

selinux: don't sleep when CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE is true

PATCH In review Paul Moore 1 participant 4 messages Apr 14, 2022 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 selinux: don't sleep when CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE is true

Unfortunately commit 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort") added a five second sleep during early kernel boot, e.g. start_kernel(), which could cause a "scheduling while atomic" panic. This patch fixes this problem by moving the sleep out of checkreqprot_set() and into sel_write_checkreqprot() so that we only sleep when the checkreqprot setting is set during runtime, after the kernel has booted. The error message remains the same in both cases.

Fixes 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort")
---
 security/selinux/include/security.h |    4 +---
 security/selinux/selinuxfs.c        |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
security/selinux/include/security.h +1 -3
index f7e6be63adfb..393aff41d3ef 100644
@@ -152,10 +152,8 @@ static inline bool checkreqprot_get(const struct selinux_state *state)
 
 static inline void checkreqprot_set(struct selinux_state *state, bool value)
 {
-	if (value) {
+	if (value)
 		pr_err("SELinux: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-checkreqprot\n");
-		ssleep(5);
-	}
 	WRITE_ONCE(state->checkreqprot, value);
 }
 
security/selinux/selinuxfs.c +2 -0
index 6c8b6a0ddecf..8fcdd494af27 100644
@@ -762,6 +762,8 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
 	}
 
 	checkreqprot_set(fsi->state, (new_value ? 1 : 0));
+	if (new_value)
+		ssleep(5);
 	length = count;
 
 	selinux_ima_measure_state(fsi->state);
author maintainer
#1 lore raw
Quoted 10 lines · Paul Moore

Unfortunately commit 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort") added a five second sleep during early kernel boot, e.g. start_kernel(), which could cause a "scheduling while atomic" panic. This patch fixes this problem by moving the sleep out of checkreqprot_set() and into sel_write_checkreqprot() so that we only sleep when the checkreqprot setting is set during runtime, after the kernel has booted. The error message remains the same in both cases.

Quoted 7 lines
Fixes 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort")
---
 security/selinux/include/security.h |    4 +---
 security/selinux/selinuxfs.c        |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)

This patch is very trivial, but just a word of warning that I haven't actually tested it yet, so YMMV ... my test kernel is building now.

Quoted 30 lines
security/selinux/include/security.h +1 -3
index f7e6be63adfb..393aff41d3ef 100644
@@ -152,10 +152,8 @@ static inline bool checkreqprot_get(const struct selinux_state *state)
 
 static inline void checkreqprot_set(struct selinux_state *state, bool value)
 {
-       if (value) {
+       if (value)
                pr_err("SELinux: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-checkreqprot\n");
-               ssleep(5);
-       }
        WRITE_ONCE(state->checkreqprot, value);
 }
 
security/selinux/selinuxfs.c +2 -0
index 6c8b6a0ddecf..8fcdd494af27 100644
@@ -762,6 +762,8 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf,
        }
 
        checkreqprot_set(fsi->state, (new_value ? 1 : 0));
+       if (new_value)
+               ssleep(5);
        length = count;
 
        selinux_ima_measure_state(fsi->state);
Signature · 1 line
paul-moore.com
author maintainer
#2 lore raw
Quoted 19 lines · Paul Moore
Quoted 10 lines · Paul Moore

Unfortunately commit 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort") added a five second sleep during early kernel boot, e.g. start_kernel(), which could cause a "scheduling while atomic" panic. This patch fixes this problem by moving the sleep out of checkreqprot_set() and into sel_write_checkreqprot() so that we only sleep when the checkreqprot setting is set during runtime, after the kernel has booted. The error message remains the same in both cases.

Quoted 7 lines
Fixes 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort")
---
 security/selinux/include/security.h |    4 +---
 security/selinux/selinuxfs.c        |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 2 lines

This patch is very trivial, but just a word of warning that I haven't actually tested it yet, so YMMV ... my test kernel is building now.

Everything is behaving sanely on my Rawhide VM, both when built with 0 and 1 values for checkreqprot, so unless I hear any objections I'll merge this later tonight.

Signature · 1 line
paul-moore.com
author maintainer
#3 lore raw
Quoted 20 lines · Paul Moore
Quoted 19 lines · Paul Moore
Quoted 17 lines · Paul Moore

Unfortunately commit 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort") added a five second sleep during early kernel boot, e.g. start_kernel(), which could cause a "scheduling while atomic" panic. This patch fixes this problem by moving the sleep out of checkreqprot_set() and into sel_write_checkreqprot() so that we only sleep when the checkreqprot setting is set during runtime, after the kernel has booted. The error message remains the same in both cases.

Fixes 81200b0265b1 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort")
---
 security/selinux/include/security.h |    4 +---
 security/selinux/selinuxfs.c        |    2 ++
 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 6 lines
Quoted 2 lines

This patch is very trivial, but just a word of warning that I haven't actually tested it yet, so YMMV ... my test kernel is building now.

Everything is behaving sanely on my Rawhide VM, both when built with 0 and 1 values for checkreqprot, so unless I hear any objections I'll merge this later tonight.

.... aaaand it's merged.

Signature · 1 line
paul-moore.com