]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
lsm: cleanup initialize_lsm() and rename to lsm_init_single()
authorPaul Moore <paul@paul-moore.com>
Tue, 11 Feb 2025 23:24:04 +0000 (18:24 -0500)
committerPaul Moore <paul@paul-moore.com>
Wed, 22 Oct 2025 23:24:22 +0000 (19:24 -0400)
Rename initialize_lsm() to be more consistent with the rest of the LSM
initialization changes and rework the function itself to better fit
with the "exit on fail" coding pattern.

Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: John Johansen <john.johansen@canonical.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/lsm_init.c

index 6b1f8f18a43c3a7067039af586a107ac7445d71f..eb473f982ddbe16554209188ac59da1e49f87720 100644 (file)
@@ -169,6 +169,7 @@ out:
                   lsm_is_enabled(lsm) ? "enabled" : "disabled");
 }
 
+
 /**
  * lsm_blob_size_update - Update the LSM blob size and offset information
  * @sz_req: the requested additional blob size
@@ -225,16 +226,20 @@ static void __init lsm_prepare(struct lsm_info *lsm)
        lsm_blob_size_update(&blobs->lbs_bpf_token, &blob_sizes.lbs_bpf_token);
 }
 
-/* Initialize a given LSM, if it is enabled. */
-static void __init initialize_lsm(struct lsm_info *lsm)
+/**
+ * lsm_init_single - Initialize a given LSM
+ * @lsm: LSM definition
+ */
+static void __init lsm_init_single(struct lsm_info *lsm)
 {
-       if (lsm_is_enabled(lsm)) {
-               int ret;
+       int ret;
 
-               init_debug("initializing %s\n", lsm->id->name);
-               ret = lsm->init();
-               WARN(ret, "%s failed to initialize: %d\n", lsm->id->name, ret);
-       }
+       if (!lsm_is_enabled(lsm))
+               return;
+
+       init_debug("initializing %s\n", lsm->id->name);
+       ret = lsm->init();
+       WARN(ret, "%s failed to initialize: %d\n", lsm->id->name, ret);
 }
 
 /**
@@ -379,7 +384,7 @@ static void __init lsm_init_ordered(void)
                panic("%s: early task alloc failed.\n", __func__);
 
        lsm_order_for_each(lsm) {
-               initialize_lsm(*lsm);
+               lsm_init_single(*lsm);
        }
 }
 
@@ -429,7 +434,7 @@ int __init early_security_init(void)
                lsm_enabled_set(lsm, true);
                lsm_order_append(lsm, "early");
                lsm_prepare(lsm);
-               initialize_lsm(lsm);
+               lsm_init_single(lsm);
        }
 
        return 0;