History

ima: force signature verification when CONFIG_KEXEC_SIG is configured

Currently, an unsigned kernel could be kexec'ed when IMA arch specific policy is configured unless lockdown is enabled. Enforce kernel signature verification check in the kexec_file_load syscall when IMA arch specific policy is configured.

Coiby Xu committed 4 years ago

Commit af16df51 parent d2ee2cf3 files · +18 −1Browse files

Unified · Split

3 files
  1. include/linux/kexec.h +6 −0
  2. kernel/kexec_file.c +10 −1
  3. security/integrity/ima/ima_efi.c +2 −0
include/linux/kexec.h+6−0
@@ -452,6 +452,12 @@ static inline int kexec_crash_loaded(void) { return 0; } · 451 unmodified lines
452452 #define kexec_in_progress false
453453 #endif /* CONFIG_KEXEC_CORE */
454454
455+#ifdef CONFIG_KEXEC_SIG
456+void set_kexec_sig_enforced(void);
457+#else
458+static inline void set_kexec_sig_enforced(void) {}
459+#endif
460+
455461 #endif /* !defined(__ASSEBMLY__) */
456462
457463 #endif /* LINUX_KEXEC_H */
kernel/kexec_file.c+10−1
@@ -29,6 +29,15 @@ · 28 unmodified lines
2929 #include <linux/vmalloc.h>
3030 #include "kexec_internal.h"
3131
32+#ifdef CONFIG_KEXEC_SIG
33+static bool sig_enforce = IS_ENABLED(CONFIG_KEXEC_SIG_FORCE);
34+
35+void set_kexec_sig_enforced(void)
36+{
37+ sig_enforce = true;
38+}
39+#endif
40+
3241 static int kexec_calculate_store_digests(struct kimage *image);
3342
3443 /*
@@ -159,7 +168,7 @@ kimage_validate_signature(struct kimage *image) · 124 unmodified lines
159168 image->kernel_buf_len);
160169 if (ret) {
161170
162− if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) {
171+ if (sig_enforce) {
163172 pr_notice("Enforced kernel signature verification failed (%d).\n", ret);
164173 return ret;
165174 }
security/integrity/ima/ima_efi.c+2−0
@@ -67,6 +67,8 @@ const char * const *arch_get_ima_policy(void) · 66 unmodified lines
6767 if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
6868 if (IS_ENABLED(CONFIG_MODULE_SIG))
6969 set_module_sig_enforced();
70+ if (IS_ENABLED(CONFIG_KEXEC_SIG))
71+ set_kexec_sig_enforced();
7072 return sb_arch_rules;
7173 }
7274 return NULL;