Skip to contentSkip to conversation

ima: requiring signed kernel modules

PATCH New Mimi Zohar 5 participants 17 messages Jan 31, 2019 – Feb 11, 2019

Subsystems (6)
lore
Share & tools
lore

Mimi Zohar

author maintainer
#0 lore raw

PATCH 1/1 ima: requiring signed kernel modules

The kernel can be configured to verify the appended kernel module signature, the IMA signature stored as an xattr, both types of signatures, or none. On systems with secure boot enabled AND the IMA architecture specific policy enabled, this patch set requires the file to be signed.

Both methods of loading kernel modules - init_module and finit_module syscalls - need to either verify the kernel module signature or prevent the kernel module from being loaded.

"modprobe" first tries loading the kernel module via the finit_module syscall and falls back to the init_module syscall, making it difficult to test one syscall and then the other.

Mimi Zohar (1):
x86/ima: require signed kernel modules

 arch/x86/kernel/ima_arch.c        |  9 ++++++++-
 include/linux/module.h            |  7 ++++++-
 kernel/module.c                   | 15 +++++++++++----
 security/integrity/ima/ima_main.c |  2 +-
 4 files changed, 26 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.5
author maintainer
#1 lore raw

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

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

---
 arch/x86/kernel/ima_arch.c        |  9 ++++++++-
 include/linux/module.h            |  7 ++++++-
 kernel/module.c                   | 15 +++++++++++----
 security/integrity/ima/ima_main.c |  2 +-
 4 files changed, 26 insertions(+), 7 deletions(-)
arch/x86/kernel/ima_arch.c +8 -1
index e47cd9390ab4..96a023238a83 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_required();
 		return sb_arch_rules;
+	}
 	return NULL;
 }
include/linux/module.h +6 -1
index 8fa38d3e7538..af51c8ec755f 100644
@@ -659,7 +659,8 @@ static inline bool is_livepatch_module(struct module *mod)
 }
 #endif /* CONFIG_LIVEPATCH */
 
-bool is_module_sig_enforced(void);
+bool is_module_sig_enforced_or_required(void);
+void set_module_sig_required(void);
 
 #else /* !CONFIG_MODULES... */
 
@@ -780,6 +781,10 @@ static inline bool is_module_sig_enforced(void)
 	return false;
 }
 
+static inline void set_module_sig_required(void)
+{
+}
+
 /* Dereference module function descriptor */
 static inline
 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
kernel/module.c +11 -4
index 2ad1b5239910..70a9709d19eb 100644
@@ -275,16 +275,23 @@ static void module_assert_mutex_or_preempt(void)
 
 static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 module_param(sig_enforce, bool_enable_only, 0644);
+static bool sig_required;
 
 /*
  * Export sig_enforce kernel cmdline parameter to allow other subsystems rely
  * on that instead of directly to CONFIG_MODULE_SIG_FORCE config.
  */
-bool is_module_sig_enforced(void)
+bool is_module_sig_enforced_or_required(void)
 {
-	return sig_enforce;
+	return sig_enforce || sig_required;
 }
-EXPORT_SYMBOL(is_module_sig_enforced);
+EXPORT_SYMBOL(is_module_sig_enforced_or_required);
+
+void set_module_sig_required(void)
+{
+	sig_required = true;
+}
+EXPORT_SYMBOL(set_module_sig_required);
 
 /* Block module loading/unloading? */
 int modules_disabled = 0;
@@ -2789,7 +2796,7 @@ static int module_sig_check(struct load_info *info, int flags)
 	}
 
 	/* Not having a signature is only an error if we're strict. */
-	if (err == -ENOKEY && !is_module_sig_enforced())
+	if (err == -ENOKEY && !is_module_sig_enforced_or_required())
 		err = 0;
 
 	return err;
security/integrity/ima/ima_main.c +1 -1
index 357edd140c09..bbaf87f688be 100644
@@ -563,7 +563,7 @@ int ima_load_data(enum kernel_load_data_id id)
 		}
 		break;
 	case LOADING_MODULE:
-		sig_enforce = is_module_sig_enforced();
+		sig_enforce = is_module_sig_enforced_or_required();
 
 		if (ima_enforce && (!sig_enforce
 				    && (ima_appraise & IMA_APPRAISE_MODULES))) {
Signature · 1 line
2.7.5
maintainer
#2 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 282

Quoted 13 lines · Mimi Zohar
kernel/module.c +1 -0
index 2ad1b5239910..70a9709d19eb 100644
@@ -275,16 +275,23 @@ static void module_assert_mutex_or_preempt(void)
 
 static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 module_param(sig_enforce, bool_enable_only, 0644);
+static bool sig_required;
 
 /*
  * Export sig_enforce kernel cmdline parameter to allow other subsystems rely
  * on that instead of directly to CONFIG_MODULE_SIG_FORCE config.

But the docs were't updated.

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 288

Quoted 9 lines
kernel/module.c +3 -3
  */
-bool is_module_sig_enforced(void)
+bool is_module_sig_enforced_or_required(void)
 {
-	return sig_enforce;
+	return sig_enforce || sig_required;
 }
-EXPORT_SYMBOL(is_module_sig_enforced);
+EXPORT_SYMBOL(is_module_sig_enforced_or_required);

Meh, this is getting sloppy, the module signing infrastructure should just be LSM'ified now that we have stacked LSMs. That would compartamentaliz that code and make this much easier to read / understand and mantain.

Can you take a look at doing it that way instead?

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 294

Quoted 6 lines
kernel/module.c +6 -0
+
+void set_module_sig_required(void)
+{
+	sig_required = true;
+}
+EXPORT_SYMBOL(set_module_sig_required);

Since this is a *new* symbol, not yet used, and only used by IMA I'd prefer this to be EXPORT_SYMBOL_GPL().

kernel/module.c static int module_sig_check(struct load_info *info, int flags) · line 2799

Quoted 8 lines
kernel/module.c +1 -1
 /* Block module loading/unloading? */
 int modules_disabled = 0;
@@ -2789,7 +2796,7 @@ static int module_sig_check(struct load_info *info, int flags)
 	}
 
 	/* Not having a signature is only an error if we're strict. */
-	if (err == -ENOKEY && !is_module_sig_enforced())
+	if (err == -ENOKEY && !is_module_sig_enforced_or_required())

This is where I think a proper LSM hook would make sense. I think that these "questions" model for signing don't work well on the LSM hook model, perhaps just:

kernel_module_signed()

Suffices, therefore if not enforced or required its signed. If its enforced or required and really signed, then it signed.

security/integrity/ima/ima_main.c int ima_load_data(enum kernel_load_data_id id) · line 566

Quoted 13 lines
kernel/module.c +0 -0
 		err = 0;
 
 	return err;
security/integrity/ima/ima_main.c +1 -1
index 357edd140c09..bbaf87f688be 100644
@@ -563,7 +563,7 @@ int ima_load_data(enum kernel_load_data_id id)
 		}
 		break;
 	case LOADING_MODULE:
-		sig_enforce = is_module_sig_enforced();
+		sig_enforce = is_module_sig_enforced_or_required();

Yet another user.

Quoted 4 lines
security/integrity/ima/ima_main.c +0 -0
 		if (ima_enforce && (!sig_enforce
 				    && (ima_appraise & IMA_APPRAISE_MODULES))) {
Signature · 1 line
2.7.5

Plus I think LSM'ifying module signing may help cleaning up some of the #ifdery and config options around module signing. I'm suggestin this now as this has been on my mental TODO list for a while, and just not sure when we'd get to it, if not you, not sure when it'd get done.

Then, do we have proper unit tests for the mixture of options to ensure we can easily ensure we don't regress?

Luis

author maintainer
#3 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 11 lines · Luis Chamberlain
Quoted 10 lines · Mimi Zohar
kernel/module.c +1 -0
index 2ad1b5239910..70a9709d19eb 100644
@@ -275,16 +275,23 @@ static void module_assert_mutex_or_preempt(void)
 
 static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 module_param(sig_enforce, bool_enable_only, 0644);
+static bool sig_required;
 
Quoted 5 lines

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 282

Quoted 3 lines
kernel/module.c +0 -0
 /*
  * Export sig_enforce kernel cmdline parameter to allow other subsystems rely
  * on that instead of directly to CONFIG_MODULE_SIG_FORCE config.

But the docs were't updated.

Neither "CONFIG_MODULE_SIG_FORCE" nor "module.sig_enforce" has changed.  Which docs are you referring to?

Quoted 16 lines

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 288

Quoted 10 lines
kernel/module.c +3 -3
  */
-bool is_module_sig_enforced(void)
+bool is_module_sig_enforced_or_required(void)
 {
-	return sig_enforce;
+	return sig_enforce || sig_required;
 }
-EXPORT_SYMBOL(is_module_sig_enforced);
+EXPORT_SYMBOL(is_module_sig_enforced_or_required);

Meh, this is getting sloppy, the module signing infrastructure should just be LSM'ified now that we have stacked LSMs. That would compartamentaliz that code and make this much easier to read / understand and mantain.

Quoted 1 line

Can you take a look at doing it that way instead?

This patch is about coordinating the existing methods of verifying kernel module signatures.

Quoted 10 lines

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 294

Quoted 7 lines
kernel/module.c +6 -0
+
+void set_module_sig_required(void)
+{
+	sig_required = true;
+}
+EXPORT_SYMBOL(set_module_sig_required);

Since this is a *new* symbol, not yet used, and only used by IMA I'd prefer this to be EXPORT_SYMBOL_GPL().

Oops, this function shouldn't be exported.

Quoted 40 lines

kernel/module.c static int module_sig_check(struct load_info *info, int flags) · line 2799

Quoted 9 lines
kernel/module.c +1 -1
 /* Block module loading/unloading? */
 int modules_disabled = 0;
@@ -2789,7 +2796,7 @@ static int module_sig_check(struct load_info *info, int flags)
 	}
 
 	/* Not having a signature is only an error if we're strict. */
-	if (err == -ENOKEY && !is_module_sig_enforced())
+	if (err == -ENOKEY && !is_module_sig_enforced_or_required())

This is where I think a proper LSM hook would make sense. I think that these "questions" model for signing don't work well on the LSM hook model, perhaps just:

kernel_module_signed()

Suffices, therefore if not enforced or required its signed. If its enforced or required and really signed, then it signed.

security/integrity/ima/ima_main.c int ima_load_data(enum kernel_load_data_id id) · line 566

Quoted 13 lines
kernel/module.c +0 -0
 		err = 0;
 
 	return err;
security/integrity/ima/ima_main.c +1 -1
index 357edd140c09..bbaf87f688be 100644
@@ -563,7 +563,7 @@ int ima_load_data(enum kernel_load_data_id id)
 		}
 		break;
 	case LOADING_MODULE:
-		sig_enforce = is_module_sig_enforced();
+		sig_enforce = is_module_sig_enforced_or_required();

Yet another user.

Quoted 4 lines
security/integrity/ima/ima_main.c +0 -0
 		if (ima_enforce && (!sig_enforce
 				    && (ima_appraise & IMA_APPRAISE_MODULES))) {
Signature · 1 line
2.7.5
Quoted 8 lines

Plus I think LSM'ifying module signing may help cleaning up some of the #ifdery and config options around module signing. I'm suggestin this now as this has been on my mental TODO list for a while, and just not sure when we'd get to it, if not you, not sure when it'd get done.

Then, do we have proper unit tests for the mixture of options to ensure we can easily ensure we don't regress?

There are already two methods  - appended signatures and IMA xattrs - for validating kernel modules.

Kernel modules shouldn't be treated any differently than any other file.  Based on the IMA policy, the kernel module signature can be verified.  Also based on the IMA policy, the file hash added to the measurement list, and the file hash used to extend the TPM PCR.  Lastly, based on policy the file hash can be added to the audit log.

I don't see a need for an additional LSM just for verifying kernel module signatures.

Mimi

maintainer
#4 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 12 lines · Mimi Zohar
Quoted 11 lines · Luis Chamberlain
Quoted 10 lines · Mimi Zohar
kernel/module.c +1 -0
index 2ad1b5239910..70a9709d19eb 100644
@@ -275,16 +275,23 @@ static void module_assert_mutex_or_preempt(void)
 
 static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 module_param(sig_enforce, bool_enable_only, 0644);
+static bool sig_required;
 
Quoted 8 lines
Quoted 5 lines

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 282

Quoted 3 lines
kernel/module.c +0 -0
 /*
  * Export sig_enforce kernel cmdline parameter to allow other subsystems rely
  * on that instead of directly to CONFIG_MODULE_SIG_FORCE config.

But the docs were't updated.

Neither "CONFIG_MODULE_SIG_FORCE" nor "module.sig_enforce" has changed.  Which docs are you referring to?

You renamed is_module_sig_enforced() to is_module_sig_enforced_or_required() and left the above doc which only justifies the enforced path.

Quoted 15 lines
Quoted 15 lines

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 288

Quoted 9 lines
kernel/module.c +3 -3
  */
-bool is_module_sig_enforced(void)
+bool is_module_sig_enforced_or_required(void)
 {
-	return sig_enforce;
+	return sig_enforce || sig_required;
 }
-EXPORT_SYMBOL(is_module_sig_enforced);
+EXPORT_SYMBOL(is_module_sig_enforced_or_required);

Meh, this is getting sloppy, the module signing infrastructure should just be LSM'ified now that we have stacked LSMs. That would compartamentaliz that code and make this much easier to read / understand and mantain.

Quoted 4 lines
Quoted 1 line

Can you take a look at doing it that way instead?

This patch is about coordinating the existing methods of verifying kernel module signatures.

I understand.

Quoted 49 lines
Quoted 40 lines

kernel/module.c static int module_sig_check(struct load_info *info, int flags) · line 2799

Quoted 9 lines
kernel/module.c +1 -1
 /* Block module loading/unloading? */
 int modules_disabled = 0;
@@ -2789,7 +2796,7 @@ static int module_sig_check(struct load_info *info, int flags)
 	}
 
 	/* Not having a signature is only an error if we're strict. */
-	if (err == -ENOKEY && !is_module_sig_enforced())
+	if (err == -ENOKEY && !is_module_sig_enforced_or_required())

This is where I think a proper LSM hook would make sense. I think that these "questions" model for signing don't work well on the LSM hook model, perhaps just:

kernel_module_signed()

Suffices, therefore if not enforced or required its signed. If its enforced or required and really signed, then it signed.

security/integrity/ima/ima_main.c int ima_load_data(enum kernel_load_data_id id) · line 566

Quoted 13 lines
kernel/module.c +0 -0
 		err = 0;
 
 	return err;
security/integrity/ima/ima_main.c +1 -1
index 357edd140c09..bbaf87f688be 100644
@@ -563,7 +563,7 @@ int ima_load_data(enum kernel_load_data_id id)
 		}
 		break;
 	case LOADING_MODULE:
-		sig_enforce = is_module_sig_enforced();
+		sig_enforce = is_module_sig_enforced_or_required();

Yet another user.

Quoted 4 lines
security/integrity/ima/ima_main.c +0 -0
 		if (ima_enforce && (!sig_enforce
 				    && (ima_appraise & IMA_APPRAISE_MODULES))) {
Signature · 1 line
2.7.5
Quoted 8 lines

Plus I think LSM'ifying module signing may help cleaning up some of the #ifdery and config options around module signing. I'm suggestin this now as this has been on my mental TODO list for a while, and just not sure when we'd get to it, if not you, not sure when it'd get done.

Then, do we have proper unit tests for the mixture of options to ensure we can easily ensure we don't regress?

Quoted 5 lines

There are already two methods  - appended signatures and IMA xattrs - for validating kernel modules.

Kernel modules shouldn't be treated any differently than any other file.

The good 'ol kernel module signing code *does* treat it as such.

Quoted 4 lines

Based on the IMA policy, the kernel module signature can be verified.  Also based on the IMA policy, the file hash added to the measurement list, and the file hash used to extend the TPM PCR. Lastly, based on policy the file hash can be added to the audit log.

Sure...

Quoted 2 lines

I don't see a need for an additional LSM just for verifying kernel module signatures.

But it is one, module signing was just spawned pre the boom of LSMs.

I do believe that treating the code as such would help with its reading and long term maintenance.

Anyway, I had to try to convince you.

Luis

author maintainer
#5 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 6 lines · Luis Chamberlain
Quoted 4 lines · Mimi Zohar

On Mon, 2019-02-04 at 12:38 -0800, Luis Chamberlain wrote:

I don't see a need for an additional LSM just for verifying kernel module signatures.

Quoted 6 lines

But it is one, module signing was just spawned pre the boom of LSMs.

I do believe that treating the code as such would help with its reading and long term maintenance.

Anyway, I had to try to convince you.

Perhaps, after IMA supports appended signatures (for kernel modules), I could see making the existing kernel module appended signature verification an LSM.

For now, other than updating the comment, would you be willing to add your Review/Ack to this patch?

Mimi

maintainer
#6 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 9 lines · Mimi Zohar
Quoted 8 lines · Luis Chamberlain
Quoted 4 lines · Mimi Zohar

On Mon, 2019-02-04 at 12:38 -0800, Luis Chamberlain wrote:

I don't see a need for an additional LSM just for verifying kernel module signatures.

But it is one, module signing was just spawned pre the boom of LSMs.

Quoted 8 lines
Quoted 4 lines

I do believe that treating the code as such would help with its reading and long term maintenance.

Anyway, I had to try to convince you.

Perhaps, after IMA supports appended signatures (for kernel modules), I could see making the existing kernel module appended signature verification an LSM.

I don't see why wait.

Quoted 2 lines

For now, other than updating the comment, would you be willing to add your Review/Ack to this patch?

But I don't particularly like the changes, I still believe trying to LSM'ify kernel module signing would be a better start to help with long term maintenace on this code.

Also, do we have selftests implemented to ensure we don't regress with your changes?

Luis

author maintainer
#7 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 2 lines · Luis Chamberlain

Also, do we have selftests implemented to ensure we don't regress with your changes?

We're working on a regression test.  "modprobe" currently first attempts to use finit_module, and then falls back to using init_module.  Before writing a small program to load kernel modules, are you aware of any that allows you to specify the syscall?

Mimi

#8 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

In reply to Mimi Zohar
Quoted 6 lines · Mimi Zohar

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

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.

Quoted 6 lines

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

With respect to interactions with the kernel lockdown patches, this looks better than the patches I saw previously. I don't feel like I know enough about what's going on with IMA to ack the patch, but I feel confident that it's at least not going to break signature enforcement for us.

Thanks,
Seth

author maintainer
#9 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Hi Seth,

Quoted 12 lines · Seth Forshee
Quoted 11 lines · Mimi Zohar

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

Quoted 7 lines
Quoted 1 line

With respect to interactions with the kernel lockdown patches, this looks better than the patches I saw previously. I don't feel like I know enough about what's going on with IMA to ack the patch, but I feel confident that it's at least not going to break signature enforcement for us.

Thank you for testing!  Could this be translated into a "tested-by" "(for w/lockdown patches)"?

Mimi

Tested-by
#10 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 17 lines · Mimi Zohar

Hi Seth,

Quoted 14 lines · Seth Forshee
Quoted 12 lines · Mimi Zohar

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

Quoted 8 lines
Quoted 5 lines

With respect to interactions with the kernel lockdown patches, this looks better than the patches I saw previously. I don't feel like I know enough about what's going on with IMA to ack the patch, but I feel confident that it's at least not going to break signature enforcement for us.

Thank you for testing!  Could this be translated into a "tested-by" "(for w/lockdown patches)"?

Yeah, that's fine. To be clear about what I tested, I've confirmed that it doesn't interfere with requiring signed modules under lockdown with CONFIG_IMA_ARCH_POLICY=n and IMA appraisal enabled.

author maintainer
#11 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 24 lines · Seth Forshee
Quoted 23 lines · Mimi Zohar

Hi Seth,

Quoted 19 lines · Seth Forshee
Quoted 6 lines · Mimi Zohar

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

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.

Quoted 6 lines

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

With respect to interactions with the kernel lockdown patches, this looks better than the patches I saw previously. I don't feel like I know enough about what's going on with IMA to ack the patch, but I feel confident that it's at least not going to break signature enforcement for us.

Quoted 8 lines
Quoted 2 lines

Thank you for testing!  Could this be translated into a "tested-by" "(for w/lockdown patches)"?

Yeah, that's fine. To be clear about what I tested, I've confirmed that it doesn't interfere with requiring signed modules under lockdown with CONFIG_IMA_ARCH_POLICY=n and IMA appraisal enabled.

Oh!  You've disabled the coordination of the two signature verification methods.  Any chance you could test with "CONFIG_IMA_ARCH_POLICY" enabled?

Mimi

#12 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 32 lines · Mimi Zohar
Quoted 31 lines · Seth Forshee
Quoted 17 lines · Mimi Zohar

Hi Seth,

Quoted 14 lines · Seth Forshee
Quoted 12 lines · Mimi Zohar

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

Quoted 8 lines
Quoted 5 lines

With respect to interactions with the kernel lockdown patches, this looks better than the patches I saw previously. I don't feel like I know enough about what's going on with IMA to ack the patch, but I feel confident that it's at least not going to break signature enforcement for us.

Thank you for testing!  Could this be translated into a "tested-by" "(for w/lockdown patches)"?

Yeah, that's fine. To be clear about what I tested, I've confirmed that it doesn't interfere with requiring signed modules under lockdown with CONFIG_IMA_ARCH_POLICY=n and IMA appraisal enabled.

Quoted 5 lines
Quoted 1 line

Oh!  You've disabled the coordination of the two signature verification methods.  Any chance you could test with "CONFIG_IMA_ARCH_POLICY" enabled?

Ok, I've tested this now and it also seems to be working. However it does seem redundant to have CONFIG_IMA_ARCH_POLICY alongside lockdown, as it doesn't enforce anything not already being enforced by lockdown.

Seth

author maintainer
#13 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

[Cc'ing Bruno E. O. Meneguele]

Quoted 35 lines · Seth Forshee
Quoted 34 lines · Mimi Zohar
Quoted 32 lines · Seth Forshee
Quoted 17 lines · Mimi Zohar

Hi Seth,

Quoted 14 lines · Seth Forshee
Quoted 12 lines · Mimi Zohar

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

Quoted 8 lines
Quoted 5 lines

With respect to interactions with the kernel lockdown patches, this looks better than the patches I saw previously. I don't feel like I know enough about what's going on with IMA to ack the patch, but I feel confident that it's at least not going to break signature enforcement for us.

Thank you for testing!  Could this be translated into a "tested-by" "(for w/lockdown patches)"?

Yeah, that's fine. To be clear about what I tested, I've confirmed that it doesn't interfere with requiring signed modules under lockdown with CONFIG_IMA_ARCH_POLICY=n and IMA appraisal enabled.

Quoted 7 lines
Quoted 3 lines

Oh!  You've disabled the coordination of the two signature verification methods.  Any chance you could test with "CONFIG_IMA_ARCH_POLICY" enabled?

Ok, I've tested this now and it also seems to be working. However it does seem redundant to have CONFIG_IMA_ARCH_POLICY alongside lockdown, as it doesn't enforce anything not already being enforced by lockdown.

Ok.  Based on Luis' and your comments, I'll defer this discussion to after IMA appended signature support is upstreamed.  At that point, for the finit_module syscall, IMA-appraisal at least won't fail the signature verification.  The same appended signature will be verified not once, but twice - once on the LSM security_kernel_read_file() hook and then again by module_sig_check().

For the init_module() syscall, the only coordination needed will be updating is_module_sig_enforced(), based on either the "lockdown" or some other flag.

Mimi

Reviewed-by Nayna Jain on v1 1/1
#14 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

In reply to Mimi Zohar
Quoted 6 lines · Mimi Zohar

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

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.

Quoted 8 lines

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

---

Thanks & Regards,
     - Nayna

#15 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

In reply to Mimi Zohar

+++ Mimi Zohar [31/01/19 14:18 -0500]:

Quoted 79 lines

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

---

arch/x86/kernel/ima_arch.c        |  9 ++++++++-
include/linux/module.h            |  7 ++++++-
kernel/module.c                   | 15 +++++++++++----
security/integrity/ima/ima_main.c |  2 +-
4 files changed, 26 insertions(+), 7 deletions(-)
arch/x86/kernel/ima_arch.c +8 -1
index e47cd9390ab4..96a023238a83 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_required();
 		return sb_arch_rules;
+	}
 	return NULL;
 }
include/linux/module.h +6 -1
index 8fa38d3e7538..af51c8ec755f 100644
@@ -659,7 +659,8 @@ static inline bool is_livepatch_module(struct module *mod)
 }
 #endif /* CONFIG_LIVEPATCH */
 
-bool is_module_sig_enforced(void);
+bool is_module_sig_enforced_or_required(void);
+void set_module_sig_required(void);
 
 #else /* !CONFIG_MODULES... */
 
@@ -780,6 +781,10 @@ static inline bool is_module_sig_enforced(void)
 	return false;
 }
 
+static inline void set_module_sig_required(void)
+{
+}
+
 /* Dereference module function descriptor */

static inline
void *dereference_module_function_descriptor(struct module *mod, void *ptr)

kernel/module.c +1 -0
index 2ad1b5239910..70a9709d19eb 100644
@@ -275,16 +275,23 @@ static void module_assert_mutex_or_preempt(void)
 
 static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 module_param(sig_enforce, bool_enable_only, 0644);
+static bool sig_required;
 

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 287

Quoted 10 lines
kernel/module.c +2 -2
 /*
 * Export sig_enforce kernel cmdline parameter to allow other subsystems rely
 * on that instead of directly to CONFIG_MODULE_SIG_FORCE config.
 */
-bool is_module_sig_enforced(void)
+bool is_module_sig_enforced_or_required(void)
 {
-	return sig_enforce;
+	return sig_enforce || sig_required;
 }

Hi Mimi,

Just wondering, is there any particular reason why a distinction is made between sig_enforce and sig_required? Doesn't sig_enforce imply that signed modules are required? In other words, why introduce another variable instead of just using sig_enforce? It may be confusing in the case of a user looking at /sys/module/module/parameters/sig_enforce and it having a value of 0 yet module signatures are being required by ima.

Thanks,

Jessica

Quoted 36 lines
kernel/module.c +8 -2
-EXPORT_SYMBOL(is_module_sig_enforced);
+EXPORT_SYMBOL(is_module_sig_enforced_or_required);
+
+void set_module_sig_required(void)
+{
+	sig_required = true;
+}
+EXPORT_SYMBOL(set_module_sig_required);
 
 /* Block module loading/unloading? */
 int modules_disabled = 0;
@@ -2789,7 +2796,7 @@ static int module_sig_check(struct load_info *info, int flags)
 	}
 
 	/* Not having a signature is only an error if we're strict. */
-	if (err == -ENOKEY && !is_module_sig_enforced())
+	if (err == -ENOKEY && !is_module_sig_enforced_or_required())
 		err = 0;
 
 	return err;
security/integrity/ima/ima_main.c +1 -1
index 357edd140c09..bbaf87f688be 100644
@@ -563,7 +563,7 @@ int ima_load_data(enum kernel_load_data_id id)
 		}
 		break;
 	case LOADING_MODULE:
-		sig_enforce = is_module_sig_enforced();
+		sig_enforce = is_module_sig_enforced_or_required();
 
 		if (ima_enforce && (!sig_enforce
 				    && (ima_appraise & IMA_APPRAISE_MODULES))) {
Signature · 1 line
2.7.5
author maintainer
#16 lore raw

Re: [PATCH] x86/ima: require signed kernel modules

Quoted 93 lines · Jessica Yu

+++ Mimi Zohar [31/01/19 14:18 -0500]:

Quoted 79 lines

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

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.

This patch defines a function named set_module_sig_required() and renames is_module_sig_enforced() to is_module_sig_enforced_or_required(). The call to set_module_sig_required() is dependent on CONFIG_IMA_ARCH_POLICY being enabled.

---

arch/x86/kernel/ima_arch.c        |  9 ++++++++-
include/linux/module.h            |  7 ++++++-
kernel/module.c                   | 15 +++++++++++----
security/integrity/ima/ima_main.c |  2 +-
4 files changed, 26 insertions(+), 7 deletions(-)
arch/x86/kernel/ima_arch.c +8 -1
index e47cd9390ab4..96a023238a83 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_required();
 		return sb_arch_rules;
+	}
 	return NULL;
 }
include/linux/module.h +6 -1
index 8fa38d3e7538..af51c8ec755f 100644
@@ -659,7 +659,8 @@ static inline bool is_livepatch_module(struct module *mod)
 }
 #endif /* CONFIG_LIVEPATCH */
 
-bool is_module_sig_enforced(void);
+bool is_module_sig_enforced_or_required(void);
+void set_module_sig_required(void);
 
 #else /* !CONFIG_MODULES... */
 
@@ -780,6 +781,10 @@ static inline bool is_module_sig_enforced(void)
 	return false;
 }
 
+static inline void set_module_sig_required(void)
+{
+}
+
 /* Dereference module function descriptor */

static inline
void *dereference_module_function_descriptor(struct module *mod, void *ptr)

kernel/module.c +1 -0
index 2ad1b5239910..70a9709d19eb 100644
@@ -275,16 +275,23 @@ static void module_assert_mutex_or_preempt(void)
 
 static bool sig_enforce = IS_ENABLED(CONFIG_MODULE_SIG_FORCE);
 module_param(sig_enforce, bool_enable_only, 0644);
+static bool sig_required;
 

kernel/module.c static void module_assert_mutex_or_preempt(void) · line 287

Quoted 10 lines
kernel/module.c +2 -2
 /*
 * Export sig_enforce kernel cmdline parameter to allow other subsystems rely
 * on that instead of directly to CONFIG_MODULE_SIG_FORCE config.
 */
-bool is_module_sig_enforced(void)
+bool is_module_sig_enforced_or_required(void)
 {
-	return sig_enforce;
+	return sig_enforce || sig_required;
 }

Hi Mimi,

Quoted 6 lines

Just wondering, is there any particular reason why a distinction is made between sig_enforce and sig_required? Doesn't sig_enforce imply that signed modules are required? In other words, why introduce another variable instead of just using sig_enforce? It may be confusing in the case of a user looking at /sys/module/module/parameters/sig_enforce and it having a value of 0 yet module signatures are being required by ima.

Hi Jessica,

It would definitely be a lot better not having to differentiate between the builtin CONFIG/module parm enforced and runtime enforced. For some reason the "lockdown" patch doesn't directly modify sig_enforce.

Mimi

Quoted 38 lines
Quoted 37 lines
kernel/module.c +8 -2
-EXPORT_SYMBOL(is_module_sig_enforced);
+EXPORT_SYMBOL(is_module_sig_enforced_or_required);
+
+void set_module_sig_required(void)
+{
+	sig_required = true;
+}
+EXPORT_SYMBOL(set_module_sig_required);
 
 /* Block module loading/unloading? */
 int modules_disabled = 0;
@@ -2789,7 +2796,7 @@ static int module_sig_check(struct load_info *info, int flags)
 	}
 
 	/* Not having a signature is only an error if we're strict. */
-	if (err == -ENOKEY && !is_module_sig_enforced())
+	if (err == -ENOKEY && !is_module_sig_enforced_or_required())
 		err = 0;
 
 	return err;
security/integrity/ima/ima_main.c +1 -1
index 357edd140c09..bbaf87f688be 100644
@@ -563,7 +563,7 @@ int ima_load_data(enum kernel_load_data_id id)
 		}
 		break;
 	case LOADING_MODULE:
-		sig_enforce = is_module_sig_enforced();
+		sig_enforce = is_module_sig_enforced_or_required();
 
 		if (ima_enforce && (!sig_enforce
 				    && (ima_appraise & IMA_APPRAISE_MODULES))) {
Signature · 1 line
2.7.5