Skip to contentSkip to conversation

x86/ima: require signed kernel modules

PATCH Superseded Mimi Zohar 3 participants 8 messages Feb 13, 2019 – Mar 7, 2019

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Mimi Zohar

author maintainer
#0 lore raw

PATCH v2 1/1 x86/ima: require signed kernel modules

Require signed kernel modules on systems with secure boot mode enabled.

Requiring appended kernel module signatures may be configured, enabled on the boot command line, or with this patch enabled in secure boot mode. This patch defines set_module_sig_enforced().

To coordinate between appended kernel module signatures and IMA signatures, only define an IMA MODULE_CHECK policy rule if CONFIG_MODULE_SIG is not enabled.

---

Changelog:
- Removed new "sig_required" flag and associated functions, directly set sig_enforce.

 arch/x86/kernel/ima_arch.c | 9 ++++++++-
 include/linux/module.h     | 1 +
 kernel/module.c            | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)
arch/x86/kernel/ima_arch.c +8 -1
index e47cd9390ab4..3fb9847f1cad 100644
@@ -64,12 +64,19 @@ static const char * const sb_arch_rules[] = {
 	"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
 #endif /* CONFIG_KEXEC_VERIFY_SIG */
 	"measure func=KEXEC_KERNEL_CHECK",
+#if !IS_ENABLED(CONFIG_MODULE_SIG)
+	"appraise func=MODULE_CHECK appraise_type=imasig",
+#endif
+	"measure func=MODULE_CHECK",
 	NULL
 };
 
 const char * const *arch_get_ima_policy(void)
 {
-	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+		if (IS_ENABLED(CONFIG_MODULE_SIG))
+			set_module_sig_enforced();
 		return sb_arch_rules;
+	}
 	return NULL;
 }
include/linux/module.h +1 -0
index 8fa38d3e7538..75e2a5c24a2b 100644
@@ -660,6 +660,7 @@ static inline bool is_livepatch_module(struct module *mod)
 #endif /* CONFIG_LIVEPATCH */
 
 bool is_module_sig_enforced(void);
+void set_module_sig_enforced(void);
 
 #else /* !CONFIG_MODULES... */
 
kernel/module.c +5 -0
index 2ad1b5239910..4cb5b733fb18 100644
@@ -286,6 +286,11 @@ bool is_module_sig_enforced(void)
 }
 EXPORT_SYMBOL(is_module_sig_enforced);
 
+void set_module_sig_enforced(void)
+{
+       sig_enforce = true;
+}
+
 /* Block module loading/unloading? */
 int modules_disabled = 0;
 core_param(nomodule, modules_disabled, bint, 0);
Signature · 1 line
2.7.5
maintainer
#1 lore raw
Quoted 5 lines · Mimi Zohar

Require signed kernel modules on systems with secure boot mode enabled.

Requiring appended kernel module signatures may be configured, enabled on the boot command line, or with this patch enabled in secure boot mode.

But only if IMA is enabled? If so, should this statement be true if IMA is disabled?

Either way, this is not clear from the commit log and code, can the commit log be clear if set_module_sig_enforced() will be set if IMA is disabled but secure boot mode enabled?

Quoted 48 lines

This patch defines set_module_sig_enforced().

To coordinate between appended kernel module signatures and IMA signatures, only define an IMA MODULE_CHECK policy rule if CONFIG_MODULE_SIG is not enabled.

---

Changelog:
- Removed new "sig_required" flag and associated functions, directly set sig_enforce.

 arch/x86/kernel/ima_arch.c | 9 ++++++++-
 include/linux/module.h     | 1 +
 kernel/module.c            | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)
arch/x86/kernel/ima_arch.c +8 -1
index e47cd9390ab4..3fb9847f1cad 100644
@@ -64,12 +64,19 @@ static const char * const sb_arch_rules[] = {
 	"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
 #endif /* CONFIG_KEXEC_VERIFY_SIG */
 	"measure func=KEXEC_KERNEL_CHECK",
+#if !IS_ENABLED(CONFIG_MODULE_SIG)
+	"appraise func=MODULE_CHECK appraise_type=imasig",
+#endif
+	"measure func=MODULE_CHECK",
 	NULL
 };
 
 const char * const *arch_get_ima_policy(void)
 {
-	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+		if (IS_ENABLED(CONFIG_MODULE_SIG))
+			set_module_sig_enforced();
 		return sb_arch_rules;
+	}
 	return NULL;
 }
include/linux/module.h +0 -0
index 8fa38d3e7538..75e2a5c24a2b 100644

include/linux/module.h static inline bool is_livepatch_module(struct module *mod) · line 665

Quoted 6 lines
include/linux/module.h +1 -0
@@ -660,6 +660,7 @@ static inline bool is_livepatch_module(struct module *mod)
 #endif /* CONFIG_LIVEPATCH */
 
 bool is_module_sig_enforced(void);
+void set_module_sig_enforced(void);
 
 #else /* !CONFIG_MODULES... */

I think you need the !CONFIG_MODULES definition of set_module_sig_enforced() then...

kernel/module.c bool is_module_sig_enforced(void) · line 292

Quoted 12 lines
kernel/module.c +4 -0
index 2ad1b5239910..4cb5b733fb18 100644
@@ -286,6 +286,11 @@ bool is_module_sig_enforced(void)
 }
 EXPORT_SYMBOL(is_module_sig_enforced);
 
+void set_module_sig_enforced(void)
+{
+       sig_enforce = true;
+}

The export is not needed as it is bool eh?

Luis

author maintainer
#2 lore raw
Quoted 8 lines · Luis Chamberlain
Quoted 5 lines · Mimi Zohar

Require signed kernel modules on systems with secure boot mode enabled.

Requiring appended kernel module signatures may be configured, enabled on the boot command line, or with this patch enabled in secure boot mode.

But only if IMA is enabled?

The patch subject line indicates this is for IMA, but sure I can amend the patch description, making it clearer.

Quoted 2 lines

If so, should this statement be true if
IMA is disabled?

This patch coordinates the PE and IMA signatures so that both signature types aren't required.  Only if "CONFIG_KEXEC_VERIFY_SIGNATURE" is not enabled, is an IMA policy rule defined.  A custom IMA policy can still define an IMA kexec rule, requiring an IMA signature, even if the PE signature is required.

For the case when IMA is disabled and PE signatures are required, then there isn't a problem.  The issue is when neither signature verification method is enabled.  I'll leave that for someone else to address.

Quoted 55 lines

Either way, this is not clear from the commit log and code, can the commit log be clear if set_module_sig_enforced() will be set if IMA is disabled but secure boot mode enabled?

Quoted 50 lines

This patch defines set_module_sig_enforced().

To coordinate between appended kernel module signatures and IMA signatures, only define an IMA MODULE_CHECK policy rule if CONFIG_MODULE_SIG is not enabled.

---

Changelog:
- Removed new "sig_required" flag and associated functions, directly set sig_enforce.

 arch/x86/kernel/ima_arch.c | 9 ++++++++-
 include/linux/module.h     | 1 +
 kernel/module.c            | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)
arch/x86/kernel/ima_arch.c +8 -1
index e47cd9390ab4..3fb9847f1cad 100644
@@ -64,12 +64,19 @@ static const char * const sb_arch_rules[] = {
 	"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
 #endif /* CONFIG_KEXEC_VERIFY_SIG */
 	"measure func=KEXEC_KERNEL_CHECK",
+#if !IS_ENABLED(CONFIG_MODULE_SIG)
+	"appraise func=MODULE_CHECK appraise_type=imasig",
+#endif
+	"measure func=MODULE_CHECK",
 	NULL
 };
 
 const char * const *arch_get_ima_policy(void)
 {
-	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+		if (IS_ENABLED(CONFIG_MODULE_SIG))
+			set_module_sig_enforced();
 		return sb_arch_rules;
+	}
 	return NULL;
 }
include/linux/module.h +0 -0
index 8fa38d3e7538..75e2a5c24a2b 100644
@@ -660,6 +660,7 @@ static inline bool is_livepatch_module(struct module *mod)
 #endif /* CONFIG_LIVEPATCH */
 
Quoted 7 lines

include/linux/module.h static inline bool is_livepatch_module(struct module *mod) · line 665

Quoted 4 lines
include/linux/module.h +1 -0
 bool is_module_sig_enforced(void);
+void set_module_sig_enforced(void);
 
 #else /* !CONFIG_MODULES... */

I think you need the !CONFIG_MODULES definition of set_module_sig_enforced() then...

Good catch, thanks.

Quoted 9 lines
Quoted 9 lines
kernel/module.c +0 -0
index 2ad1b5239910..4cb5b733fb18 100644
@@ -286,6 +286,11 @@ bool is_module_sig_enforced(void)
 }
 EXPORT_SYMBOL(is_module_sig_enforced);
 
Quoted 6 lines

kernel/module.c bool is_module_sig_enforced(void) · line 292

Quoted 4 lines
kernel/module.c +4 -0
+void set_module_sig_enforced(void)
+{
+       sig_enforce = true;
+}

The export is not needed as it is bool eh?

IMA is builtin, so it doesn't need to be exported.

Mimi

#3 lore raw
In reply to Mimi Zohar

arch/x86/kernel/ima_arch.c static const char * const sb_arch_rules[] = { · line 79

Quoted 5 lines · Mimi Zohar
arch/x86/kernel/ima_arch.c +3 -1
-       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+               if (IS_ENABLED(CONFIG_MODULE_SIG))
+                       set_module_sig_enforced();
                return sb_arch_rules;

Linus previously pushed back on having the lockdown features automatically enabled on secure boot systems. Why are we doing the same in IMA?

author maintainer
#4 lore raw
Quoted 10 lines · Matthew Garrett

arch/x86/kernel/ima_arch.c static const char * const sb_arch_rules[] = { · line 79

Quoted 5 lines · Mimi Zohar
arch/x86/kernel/ima_arch.c +3 -1
-       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+               if (IS_ENABLED(CONFIG_MODULE_SIG))
+                       set_module_sig_enforced();
                return sb_arch_rules;

Linus previously pushed back on having the lockdown features automatically enabled on secure boot systems. Why are we doing the same in IMA?

IMA-appraisal is extending the "secure boot" concept to the running system.

Mimi

#5 lore raw
Quoted 9 lines · Mimi Zohar
Quoted 7 lines · Matthew Garrett
Quoted 5 lines · Mimi Zohar
arch/x86/kernel/ima_arch.c +3 -1
-       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+               if (IS_ENABLED(CONFIG_MODULE_SIG))
+                       set_module_sig_enforced();
                return sb_arch_rules;
Quoted 6 lines
Quoted 3 lines

Linus previously pushed back on having the lockdown features automatically enabled on secure boot systems. Why are we doing the same in IMA?

IMA-appraisal is extending the "secure boot" concept to the running system.

Right, but how is this different to what Linus was objecting to?

author maintainer
#6 lore raw
Quoted 10 lines · Matthew Garrett
Quoted 9 lines · Mimi Zohar
Quoted 7 lines · Matthew Garrett
Quoted 5 lines · Mimi Zohar
arch/x86/kernel/ima_arch.c +3 -1
-       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+       if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot()) {
+               if (IS_ENABLED(CONFIG_MODULE_SIG))
+                       set_module_sig_enforced();
                return sb_arch_rules;
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Linus previously pushed back on having the lockdown features automatically enabled on secure boot systems. Why are we doing the same in IMA?

IMA-appraisal is extending the "secure boot" concept to the running system.

Right, but how is this different to what Linus was objecting to?

Both Andy Lutomirski and Linus objected to limiting the "lockdown" patch set to secure boot enabled systems.

Mimi

#7 lore raw
Quoted 5 lines · Mimi Zohar
Quoted 1 line · Matthew Garrett

Right, but how is this different to what Linus was objecting to?

Both Andy Lutomirski and Linus objected to limiting the "lockdown" patch set to secure boot enabled systems.

No, Linus objected to it being automatically enabled when secure boot was enabled. It was always possible to enable it at boot on any platform.