Skip to content

Commit 42994ee

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce LSM_ORDER_LAST and set it for the integrity LSM
Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs needing to be last, e.g. the 'integrity' LSM, without changing the kernel command line or configuration. Also, set this order for the 'integrity' LSM. While not enforced, this is the only LSM expected to use it. Similarly to LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put at the end of the LSM list, if selected in the kernel configuration. Setting one of these orders alone, does not cause the LSMs to be selected and compiled built-in in the kernel. Finally, for LSM_ORDER_MUTABLE LSMs, set the found variable to true if an LSM is found, regardless of its order. In this way, the kernel would not wrongly report that the LSM is not built-in in the kernel if its order is LSM_ORDER_LAST. Fixes: 79f7865 ("LSM: Introduce "lsm=" for boottime LSM selection") Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Acked-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent f89f8e1 commit 42994ee

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

include/linux/lsm_hooks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
9292
enum lsm_order {
9393
LSM_ORDER_FIRST = -1, /* This is only for capabilities. */
9494
LSM_ORDER_MUTABLE = 0,
95+
LSM_ORDER_LAST = 1, /* This is only for integrity. */
9596
};
9697

9798
struct lsm_info {

security/integrity/iint.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static int __init integrity_iintcache_init(void)
182182
DEFINE_LSM(integrity) = {
183183
.name = "integrity",
184184
.init = integrity_iintcache_init,
185+
.order = LSM_ORDER_LAST,
185186
};
186187

187188

security/security.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
285285
bool found = false;
286286

287287
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
288-
if (lsm->order == LSM_ORDER_MUTABLE &&
289-
strcmp(lsm->name, name) == 0) {
290-
append_ordered_lsm(lsm, origin);
288+
if (strcmp(lsm->name, name) == 0) {
289+
if (lsm->order == LSM_ORDER_MUTABLE)
290+
append_ordered_lsm(lsm, origin);
291291
found = true;
292292
}
293293
}
@@ -307,6 +307,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
307307
}
308308
}
309309

310+
/* LSM_ORDER_LAST is always last. */
311+
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
312+
if (lsm->order == LSM_ORDER_LAST)
313+
append_ordered_lsm(lsm, " last");
314+
}
315+
310316
/* Disable all LSMs not in the ordered list. */
311317
for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
312318
if (exists_ordered_lsm(lsm))

0 commit comments

Comments
 (0)