Skip to content

Commit d8e9bbd

Browse files
committed
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: Kees Cook <keescook@chromium.org>
1 parent c91d810 commit d8e9bbd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

security/security.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,28 @@ static bool __init lsm_allowed(struct lsm_info *lsm)
139139
return true;
140140
}
141141

142-
/* Check if LSM should be initialized. */
143-
static void __init maybe_initialize_lsm(struct lsm_info *lsm)
142+
/* Prepare LSM for initialization. */
143+
static void __init prepare_lsm(struct lsm_info *lsm)
144144
{
145145
int enabled = lsm_allowed(lsm);
146146

147147
/* Record enablement (to handle any following exclusive LSMs). */
148148
set_enabled(lsm, enabled);
149149

150-
/* If selected, initialize the LSM. */
150+
/* If enabled, do pre-initialization work. */
151151
if (enabled) {
152-
int ret;
153-
154152
if ((lsm->flags & LSM_FLAG_EXCLUSIVE) && !exclusive) {
155153
exclusive = lsm;
156154
init_debug("exclusive chosen: %s\n", lsm->name);
157155
}
156+
}
157+
}
158+
159+
/* Initialize a given LSM, if it is enabled. */
160+
static void __init initialize_lsm(struct lsm_info *lsm)
161+
{
162+
if (is_enabled(lsm)) {
163+
int ret;
158164

159165
init_debug("initializing %s\n", lsm->name);
160166
ret = lsm->init();
@@ -240,7 +246,10 @@ static void __init ordered_lsm_init(void)
240246
ordered_lsm_parse(builtin_lsm_order, "builtin");
241247

242248
for (lsm = ordered_lsms; *lsm; lsm++)
243-
maybe_initialize_lsm(*lsm);
249+
prepare_lsm(*lsm);
250+
251+
for (lsm = ordered_lsms; *lsm; lsm++)
252+
initialize_lsm(*lsm);
244253

245254
kfree(ordered_lsms);
246255
}

0 commit comments

Comments
 (0)