ima: Fallback to the builtin hash algorithm
[muen/linux.git] / security / integrity / ima / ima_main.c
index 5d122daf5c8ae1d1d4045f303766cb8014e52fb1..74d0bd7e76d7159234c036df6c053532f58ab4a4 100644 (file)
@@ -16,6 +16,9 @@
  *     implements the IMA hooks: ima_bprm_check, ima_file_mmap,
  *     and ima_file_check.
  */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/file.h>
 #include <linux/binfmts.h>
@@ -504,6 +507,16 @@ static int __init init_ima(void)
        ima_init_template_list();
        hash_setup(CONFIG_IMA_DEFAULT_HASH);
        error = ima_init();
+
+       if (error && strcmp(hash_algo_name[ima_hash_algo],
+                           CONFIG_IMA_DEFAULT_HASH) != 0) {
+               pr_info("Allocating %s failed, going to use default hash algorithm %s\n",
+                       hash_algo_name[ima_hash_algo], CONFIG_IMA_DEFAULT_HASH);
+               hash_setup_done = 0;
+               hash_setup(CONFIG_IMA_DEFAULT_HASH);
+               error = ima_init();
+       }
+
        if (!error) {
                ima_initialized = 1;
                ima_update_policy_flag();