Skip to content

Commit 752db06

Browse files
committed
lsm: rename/rework ordered_lsm_parse() to lsm_order_parse()
Rename ordered_lsm_parse() to lsm_order_parse() for the sake of consistency with the other LSM initialization routines, and also do some minor rework of the function. Aside from some minor style decisions, the majority of the rework involved shuffling the order of the LSM_FLAG_LEGACY and LSM_ORDER_FIRST code so that the LSM_FLAG_LEGACY checks are handled first; it is important to note that this doesn't affect the order in which the LSMs are registered. Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: John Johansen <john.johhansen@canonical.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 24a9c58 commit 752db06

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

security/lsm_init.c

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -228,83 +228,75 @@ static void __init initialize_lsm(struct lsm_info *lsm)
228228
}
229229
}
230230

231-
/* Populate ordered LSMs list from comma-separated LSM name list. */
232-
static void __init ordered_lsm_parse(const char *order, const char *origin)
231+
/**
232+
* lsm_order_parse - Parse the comma delimited LSM list
233+
* @list: LSM list
234+
* @src: source of the list
235+
*/
236+
static void __init lsm_order_parse(const char *list, const char *src)
233237
{
234238
struct lsm_info *lsm;
235239
char *sep, *name, *next;
236240

237-
/* LSM_ORDER_FIRST is always first. */
238-
lsm_for_each_raw(lsm) {
239-
if (lsm->order == LSM_ORDER_FIRST)
240-
lsm_order_append(lsm, " first");
241-
}
242-
243-
/* Process "security=", if given. */
241+
/* Handle any Legacy LSM exclusions if one was specified. */
244242
if (lsm_order_legacy) {
245-
struct lsm_info *major;
246-
247243
/*
248-
* To match the original "security=" behavior, this
249-
* explicitly does NOT fallback to another Legacy Major
250-
* if the selected one was separately disabled: disable
251-
* all non-matching Legacy Major LSMs.
244+
* To match the original "security=" behavior, this explicitly
245+
* does NOT fallback to another Legacy Major if the selected
246+
* one was separately disabled: disable all non-matching
247+
* Legacy Major LSMs.
252248
*/
253-
lsm_for_each_raw(major) {
254-
if ((major->flags & LSM_FLAG_LEGACY_MAJOR) &&
255-
strcmp(major->id->name, lsm_order_legacy) != 0) {
256-
lsm_enabled_set(major, false);
249+
lsm_for_each_raw(lsm) {
250+
if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) &&
251+
strcmp(lsm->id->name, lsm_order_legacy)) {
252+
lsm_enabled_set(lsm, false);
257253
init_debug("security=%s disabled: %s (only one legacy major LSM)\n",
258-
lsm_order_legacy, major->id->name);
254+
lsm_order_legacy, lsm->id->name);
259255
}
260256
}
261257
}
262258

263-
sep = kstrdup(order, GFP_KERNEL);
259+
/* LSM_ORDER_FIRST */
260+
lsm_for_each_raw(lsm) {
261+
if (lsm->order == LSM_ORDER_FIRST)
262+
lsm_order_append(lsm, "first");
263+
}
264+
265+
/* Normal or "mutable" LSMs */
266+
sep = kstrdup(list, GFP_KERNEL);
264267
next = sep;
265268
/* Walk the list, looking for matching LSMs. */
266269
while ((name = strsep(&next, ",")) != NULL) {
267-
bool found = false;
268-
269270
lsm_for_each_raw(lsm) {
270-
if (strcmp(lsm->id->name, name) == 0) {
271-
if (lsm->order == LSM_ORDER_MUTABLE)
272-
lsm_order_append(lsm, origin);
273-
found = true;
274-
}
271+
if (!strcmp(lsm->id->name, name) &&
272+
lsm->order == LSM_ORDER_MUTABLE)
273+
lsm_order_append(lsm, src);
275274
}
276-
277-
if (!found)
278-
init_debug("%s ignored: %s (not built into kernel)\n",
279-
origin, name);
280275
}
276+
kfree(sep);
281277

282-
/* Process "security=", if given. */
278+
/* Legacy LSM if specified. */
283279
if (lsm_order_legacy) {
284280
lsm_for_each_raw(lsm) {
285-
if (lsm_order_exists(lsm))
286-
continue;
287-
if (strcmp(lsm->id->name, lsm_order_legacy) == 0)
288-
lsm_order_append(lsm, "security=");
281+
if (!strcmp(lsm->id->name, lsm_order_legacy))
282+
lsm_order_append(lsm, src);
289283
}
290284
}
291285

292-
/* LSM_ORDER_LAST is always last. */
286+
/* LSM_ORDER_LAST */
293287
lsm_for_each_raw(lsm) {
294288
if (lsm->order == LSM_ORDER_LAST)
295-
lsm_order_append(lsm, " last");
289+
lsm_order_append(lsm, "last");
296290
}
297291

298-
/* Disable all LSMs not in the ordered list. */
292+
/* Disable all LSMs not previously enabled. */
299293
lsm_for_each_raw(lsm) {
300294
if (lsm_order_exists(lsm))
301295
continue;
302296
lsm_enabled_set(lsm, false);
303297
init_debug("%s skipped: %s (not in requested order)\n",
304-
origin, lsm->id->name);
298+
src, lsm->id->name);
305299
}
306-
307-
kfree(sep);
308300
}
309301

310302
/**
@@ -322,9 +314,9 @@ static void __init lsm_init_ordered(void)
322314
lsm_order_legacy, lsm_order_cmdline);
323315
lsm_order_legacy = NULL;
324316
}
325-
ordered_lsm_parse(lsm_order_cmdline, "cmdline");
317+
lsm_order_parse(lsm_order_cmdline, "cmdline");
326318
} else
327-
ordered_lsm_parse(lsm_order_builtin, "builtin");
319+
lsm_order_parse(lsm_order_builtin, "builtin");
328320

329321
lsm_order_for_each(lsm) {
330322
lsm_prepare(*lsm);

0 commit comments

Comments
 (0)