Commit d8e9bbd4 authored by Kees Cook's avatar Kees Cook

LSM: Split LSM preparation from initialization

Since we already have to do a pass through the LSMs to figure out if
exclusive LSMs should be disabled after the first one is seen as enabled,
this splits the logic up a bit more cleanly. Now we do a full "prepare"
pass through the LSMs (which also allows for later use by the blob-sharing
code), before starting the LSM initialization pass.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent c91d8106
...@@ -139,22 +139,28 @@ static bool __init lsm_allowed(struct lsm_info *lsm) ...@@ -139,22 +139,28 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
return true; return true;
} }
/* Check if LSM should be initialized. */ /* Prepare LSM for initialization. */
static void __init maybe_initialize_lsm(struct lsm_info *lsm) static void __init prepare_lsm(struct lsm_info *lsm)
{ {
int enabled = lsm_allowed(lsm); int enabled = lsm_allowed(lsm);
/* Record enablement (to handle any following exclusive LSMs). */ /* Record enablement (to handle any following exclusive LSMs). */
set_enabled(lsm, enabled); set_enabled(lsm, enabled);
/* If selected, initialize the LSM. */ /* If enabled, do pre-initialization work. */
if (enabled) { if (enabled) {
int ret;
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) { if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
exclusive = lsm; exclusive = lsm;
init_debug("exclusive chosen: %s\n", lsm->name); init_debug("exclusive chosen: %s\n", lsm->name);
} }
}
}
/* Initialize a given LSM, if it is enabled. */
static void __init initialize_lsm(struct lsm_info *lsm)
{
if (is_enabled(lsm)) {
int ret;
init_debug("initializing %s\n", lsm->name); init_debug("initializing %s\n", lsm->name);
ret = lsm->init(); ret = lsm->init();
...@@ -240,7 +246,10 @@ static void __init ordered_lsm_init(void) ...@@ -240,7 +246,10 @@ static void __init ordered_lsm_init(void)
ordered_lsm_parse(builtin_lsm_order, "builtin"); ordered_lsm_parse(builtin_lsm_order, "builtin");
for (lsm = ordered_lsms; *lsm; lsm++) for (lsm = ordered_lsms; *lsm; lsm++)
maybe_initialize_lsm(*lsm); prepare_lsm(*lsm);
for (lsm = ordered_lsms; *lsm; lsm++)
initialize_lsm(*lsm);
kfree(ordered_lsms); kfree(ordered_lsms);
} }
......
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