Skip to content

Commit

Permalink
selinux: don't sleep when CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE …
Browse files Browse the repository at this point in the history
…is true

Unfortunately commit 81200b0 ("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: 81200b0 ("selinux: checkreqprot is deprecated, add some ssleep() discomfort")
Reported-by: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
pcmoore committed Apr 14, 2022
1 parent 81200b0 commit 6a9e261
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 1 addition & 3 deletions security/selinux/include/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions security/selinux/selinuxfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6a9e261

Please sign in to comment.