security: Introduce LSM_ORDER_LAST and set it for the integrity LSM
authorRoberto Sassu <roberto.sassu@huawei.com>
Fri, 10 Mar 2023 08:53:59 +0000 (09:53 +0100)
committerPaul Moore <paul@paul-moore.com>
Fri, 10 Mar 2023 23:31:35 +0000 (18:31 -0500)
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: 79f7865d844c ("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>
include/linux/lsm_hooks.h
security/integrity/iint.c
security/security.c

index ddbbe89a7a48e0e8e4ad84485f02c28a2ba776ce..c2be66c669ae1e61879df16c63a7c7079cd4bc01 100644 (file)
@@ -92,6 +92,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count,
 enum lsm_order {
        LSM_ORDER_FIRST = -1,   /* This is only for capabilities. */
        LSM_ORDER_MUTABLE = 0,
+       LSM_ORDER_LAST = 1,     /* This is only for integrity. */
 };
 
 struct lsm_info {
index 8638976f7990b76b44cc30beb74d3ec6ad62325f..b97eb59e0e32300377e4f653893c217c8c10dcfd 100644 (file)
@@ -182,6 +182,7 @@ static int __init integrity_iintcache_init(void)
 DEFINE_LSM(integrity) = {
        .name = "integrity",
        .init = integrity_iintcache_init,
+       .order = LSM_ORDER_LAST,
 };
 
 
index e6c275fff001a8e950513fdee034cbf859f1499e..b808e1b865514e260d6e82970fec027413e89173 100644 (file)
@@ -285,9 +285,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
                bool found = false;
 
                for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
-                       if (lsm->order == LSM_ORDER_MUTABLE &&
-                           strcmp(lsm->name, name) == 0) {
-                               append_ordered_lsm(lsm, origin);
+                       if (strcmp(lsm->name, name) == 0) {
+                               if (lsm->order == LSM_ORDER_MUTABLE)
+                                       append_ordered_lsm(lsm, origin);
                                found = true;
                        }
                }
@@ -307,6 +307,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
                }
        }
 
+       /* LSM_ORDER_LAST is always last. */
+       for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
+               if (lsm->order == LSM_ORDER_LAST)
+                       append_ordered_lsm(lsm, "   last");
+       }
+
        /* Disable all LSMs not in the ordered list. */
        for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) {
                if (exists_ordered_lsm(lsm))