Commit 2d4d5119 authored by Kees Cook's avatar Kees Cook

LSM: Build ordered list of LSMs to initialize

This constructs an ordered list of LSMs to initialize, using a hard-coded
list of only "integrity": minor LSMs continue to have direct hook calls,
and major LSMs continue to initialize separately.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
parent f4941d75
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
/* Maximum number of letters for an LSM name string */ /* Maximum number of letters for an LSM name string */
#define SECURITY_NAME_MAX 10 #define SECURITY_NAME_MAX 10
/* How many LSMs were built into the kernel? */
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
struct security_hook_heads security_hook_heads __lsm_ro_after_init; struct security_hook_heads security_hook_heads __lsm_ro_after_init;
static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain); static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain);
...@@ -45,6 +48,9 @@ char *lsm_names; ...@@ -45,6 +48,9 @@ char *lsm_names;
static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] = static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
CONFIG_DEFAULT_SECURITY; CONFIG_DEFAULT_SECURITY;
/* Ordered list of LSMs to initialize. */
static __initdata struct lsm_info **ordered_lsms;
static __initdata bool debug; static __initdata bool debug;
#define init_debug(...) \ #define init_debug(...) \
do { \ do { \
...@@ -85,6 +91,34 @@ static void __init set_enabled(struct lsm_info *lsm, bool enabled) ...@@ -85,6 +91,34 @@ static void __init set_enabled(struct lsm_info *lsm, bool enabled)
} }
} }
/* Is an LSM already listed in the ordered LSMs list? */
static bool __init exists_ordered_lsm(struct lsm_info *lsm)
{
struct lsm_info **check;
for (check = ordered_lsms; *check; check++)
if (*check == lsm)
return true;
return false;
}
/* Append an LSM to the list of ordered LSMs to initialize. */
static int last_lsm __initdata;
static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from)
{
/* Ignore duplicate selections. */
if (exists_ordered_lsm(lsm))
return;
if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from))
return;
ordered_lsms[last_lsm++] = lsm;
init_debug("%s ordering: %s (%sabled)\n", from, lsm->name,
is_enabled(lsm) ? "en" : "dis");
}
/* Is an LSM allowed to be initialized? */ /* Is an LSM allowed to be initialized? */
static bool __init lsm_allowed(struct lsm_info *lsm) static bool __init lsm_allowed(struct lsm_info *lsm)
{ {
...@@ -121,18 +155,32 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm) ...@@ -121,18 +155,32 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm)
} }
} }
static void __init ordered_lsm_init(void) /* Populate ordered LSMs list from single LSM name. */
static void __init ordered_lsm_parse(const char *order, const char *origin)
{ {
struct lsm_info *lsm; struct lsm_info *lsm;
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) != 0) if (strcmp(lsm->name, order) == 0)
continue; append_ordered_lsm(lsm, origin);
maybe_initialize_lsm(lsm);
} }
} }
static void __init ordered_lsm_init(void)
{
struct lsm_info **lsm;
ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms),
GFP_KERNEL);
ordered_lsm_parse("integrity", "builtin");
for (lsm = ordered_lsms; *lsm; lsm++)
maybe_initialize_lsm(*lsm);
kfree(ordered_lsms);
}
static void __init major_lsm_init(void) static void __init major_lsm_init(void)
{ {
struct lsm_info *lsm; struct lsm_info *lsm;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment