Skip to content

Commit 782191c

Browse files
committed
landlock: Warn once if a Landlock action is requested while disabled
Because sandboxing can be used as an opportunistic security measure, user space may not log unsupported features. Let the system administrator know if an application tries to use Landlock but failed because it isn't enabled at boot time. This may be caused by boot loader configurations with outdated "lsm" kernel's command-line parameter. Cc: [email protected] Fixes: 265885d ("landlock: Add syscall implementations") Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 0e89ef6 commit 782191c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

security/landlock/syscalls.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
#include "ruleset.h"
3434
#include "setup.h"
3535

36+
static bool is_initialized(void)
37+
{
38+
if (likely(landlock_initialized))
39+
return true;
40+
41+
pr_warn_once(
42+
"Disabled but requested by user space. "
43+
"You should enable Landlock at boot time: "
44+
"https://docs.kernel.org/userspace-api/landlock.html#boot-time-configuration\n");
45+
return false;
46+
}
47+
3648
/**
3749
* copy_min_struct_from_user - Safe future-proof argument copying
3850
*
@@ -173,7 +185,7 @@ SYSCALL_DEFINE3(landlock_create_ruleset,
173185
/* Build-time checks. */
174186
build_check_abi();
175187

176-
if (!landlock_initialized)
188+
if (!is_initialized())
177189
return -EOPNOTSUPP;
178190

179191
if (flags) {
@@ -398,7 +410,7 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd,
398410
struct landlock_ruleset *ruleset;
399411
int err;
400412

401-
if (!landlock_initialized)
413+
if (!is_initialized())
402414
return -EOPNOTSUPP;
403415

404416
/* No flag for now. */
@@ -458,7 +470,7 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,
458470
struct landlock_cred_security *new_llcred;
459471
int err;
460472

461-
if (!landlock_initialized)
473+
if (!is_initialized())
462474
return -EOPNOTSUPP;
463475

464476
/*

0 commit comments

Comments
 (0)