Skip to content

Commit a8027fb

Browse files
committed
LSM: Tie enabling logic to presence in ordered list
Until now, any LSM without an enable storage variable was considered enabled. This inverts the logic and sets defaults to true only if the LSM gets added to the ordered initialization list. (And an exception continues for the major LSMs until they are integrated into the ordered initialization in a later patch.) Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 79f7865 commit a8027fb

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎include/linux/lsm_hooks.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
20472047
struct lsm_info {
20482048
const char *name; /* Required. */
20492049
unsigned long flags; /* Optional: flags describing LSM */
2050-
int *enabled; /* Optional: NULL means enabled. */
2050+
int *enabled; /* Optional: controlled by CONFIG_LSM */
20512051
int (*init)(void); /* Required. */
20522052
};
20532053

‎security/security.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ static __initdata bool debug;
6363

6464
static bool __init is_enabled(struct lsm_info *lsm)
6565
{
66-
if (!lsm->enabled || *lsm->enabled)
67-
return true;
66+
if (!lsm->enabled)
67+
return false;
6868

69-
return false;
69+
return *lsm->enabled;
7070
}
7171

7272
/* Mark an LSM's enabled flag. */
@@ -117,7 +117,11 @@ static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
117117
if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
118118
return;
119119

120+
/* Enable this LSM, if it is not already set. */
121+
if (!lsm->enabled)
122+
lsm->enabled = &lsm_enabled_true;
120123
ordered_lsms[last_lsm++] = lsm;
124+
121125
init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
122126
is_enabled(lsm) ? "en" : "dis");
123127
}
@@ -210,6 +214,10 @@ static void __init major_lsm_init(void)
210214
if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) == 0)
211215
continue;
212216

217+
/* Enable this LSM, if it is not already set. */
218+
if (!lsm->enabled)
219+
lsm->enabled = &lsm_enabled_true;
220+
213221
maybe_initialize_lsm(lsm);
214222
}
215223
}

0 commit comments

Comments
 (0)