Allow automatic kernel taint on unsigned module load to be disabled
PATCH 1/1 Allow automatic kernel taint on unsigned module load to be disabled
Distributions may wish to provide kernels that permit loading of unsigned modules based on certain policy decisions. Right now that results in the kernel being tainted whenever an unsigned module is loaded, which may not be desirable. Add a config option to disable that.
--- init/Kconfig | 13 ++++++++++++- kernel/module.c | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-)
init/Kconfig +12 -1
@@ -1749,12 +1749,23 @@ config MODULE_SIG debuginfo strip done by some packagers (such as rpmbuild) and inclusion into an initramfs that wants the module size reduced. +config MODULE_UNSIGNED_TAINT + bool "Taint the kernel if unsigned modules are loaded" + default y + depends on MODULE_SIG + help + Taint the kernel if an unsigned kernel module is loaded. If this + option is enabled, the kernel will be tainted on an attempt to load + an unsigned module or signed modules for which we don't have a key + even if signature enforcement is disabled. + config MODULE_SIG_FORCE bool "Require modules to be validly signed" depends on MODULE_SIG help Reject unsigned modules or signed modules for which we don't have a - key. Without this, such modules will simply taint the kernel. + key. Without this, such modules will be loaded successfully but will + (if MODULE_UNSIGNED_TAINT is set) taint the kernel. config MODULE_SIG_ALL bool "Automatically sign all modules"
kernel/module.c +2 -0
@@ -3660,12 +3660,14 @@ static int load_module(struct load_info *info, const char __user *uargs,#ifdef CONFIG_MODULE_SIG mod->sig_ok = info->sig_ok; +#ifdef CONFIG_MODULE_UNSIGNED_TAINT if (!mod->sig_ok) {pr_notice_once ("%s: module verification failed: signature " "and/or required key missing - tainting " "kernel\n" , mod->name);add_taint_module (mod,TAINT_UNSIGNED_MODULE ,LOCKDEP_STILL_OK ); } +#endif #endif /* To avoid stressing percpu allocator, do this once we're unique. */
Signature · 1 line
2.14.0.rc1.383.gd1ce394fe2-goog
Quoted 2 lines · Matthew Garrett
Distributions may wish to provide kernels that permit loading of unsigned modules based on certain policy decisions.
Sorry, that's way too vague to accept this patch.
So I'm guessing a binary module is behind this vagueness. If you want some other method than signing to vet modules, please do it in userspace. You can do arbitrary things that way...
Cheers,
Rusty.
Quoted 60 lines
Right now that
results in the kernel being tainted whenever an unsigned module is loaded, which may not be desirable. Add a config option to disable that.Signed-off-by Matthew Garrett <[email protected]>--- init/Kconfig | 13 ++++++++++++- kernel/module.c | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-)init/Kconfig +12
-1@@ -1749,12 +1749,23 @@ config MODULE_SIG debuginfo strip done by some packagers (such as rpmbuild) and inclusion into an initramfs that wants the module size reduced. +config MODULE_UNSIGNED_TAINT + bool "Taint the kernel if unsigned modules are loaded" + default y + depends on MODULE_SIG + help + Taint the kernel if an unsigned kernel module is loaded. If this + option is enabled, the kernel will be tainted on an attempt to load + an unsigned module or signed modules for which we don't have a key + even if signature enforcement is disabled. + config MODULE_SIG_FORCE bool "Require modules to be validly signed" depends on MODULE_SIG help Reject unsigned modules or signed modules for which we don't have a - key. Without this, such modules will simply taint the kernel. + key. Without this, such modules will be loaded successfully but will + (if MODULE_UNSIGNED_TAINT is set) taint the kernel. config MODULE_SIG_ALL bool "Automatically sign all modules"kernel/module.c +2
-0@@ -3660,12 +3660,14 @@ static int load_module(struct load_info *info, const char __user *uargs,#ifdef CONFIG_MODULE_SIG mod->sig_ok = info->sig_ok; +#ifdef CONFIG_MODULE_UNSIGNED_TAINT if (!mod->sig_ok) {pr_notice_once ("%s: module verification failed: signature " "and/or required key missing - tainting " "kernel\n" , mod->name);add_taint_module (mod,TAINT_UNSIGNED_MODULE ,LOCKDEP_STILL_OK ); } +#endif #endif /* To avoid stressing percpu allocator, do this once we're unique. */ Signature · 1 line
2.14.0.rc1.383.gd1ce394fe2-goog
Quoted 9 lines · Rusty Russell
Quoted 2 lines · Matthew Garrett
Distributions may wish to provide kernels that permit loading of unsigned modules based on certain policy decisions.
Sorry, that's way too vague to accept this patch.
So I'm guessing a binary module is behind this vagueness. If you want some other method than signing to vet modules, please do it in userspace. You can do arbitrary things that way...
Binary modules will still be tainted by the license checker. The issue is that if you want to enforce module signatures under *some* circumstances, you need to build with CONFIG_MODULE_SIG, but that changes the behaviour of the kernel even when you're not enforcing module signatures. The same kernel may be used in environments where you can verify the kernel and environments where you can't, and in the latter you may not care that modules are unsigned. In that scenario, tainting doesn't buy you anything.
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Rusty Russell
Quoted 2 lines · Matthew Garrett
Distributions may wish to provide kernels that permit loading of unsigned modules based on certain policy decisions.
Sorry, that's way too vague to accept this patch.
Quoted 7 lines
Quoted 3 lines
So I'm guessing a binary module is behind this vagueness. If you want some other method than signing to vet modules, please do it in userspace. You can do arbitrary things that way...
Binary modules will still be tainted by the license checker. The issue is that if you want to enforce module signatures under *some* circumstances, you need to build with
CONFIG_MODULE_SIG
Not at all! You can validate them in userspace.
Quoted 6 lines
but that
changes the behaviour of the kernel even when you're not enforcing module signatures. The same kernel may be used in environments where you can verify the kernel and environments where you can't, and in the latter you may not care that modules are unsigned. In that scenario, tainting doesn't buy you anything.
With your patch, you don't get tainting in the environment where you can verify.
You'd be better adding a sysctl or equiv. to turn off force loading, and use that in your can-verify system.
Cheers,
Rusty.
Quoted 6 lines · Rusty Russell
Quoted 3 lines · Matthew Garrett
Binary modules will still be tainted by the license checker. The issue is that if you want to enforce module signatures under *some* circumstances, you need to build with
CONFIG_MODULE_SIGNot at all! You can validate them in userspace.
And then you need an entire trusted userland, at which point you can assert that the modules are trustworthy without having to validate them so you don't need CONFIG_MODULE_SIG anyway.
Quoted 9 lines
Quoted 6 lines
but that
changes the behaviour of the kernel even when you're not enforcing module signatures. The same kernel may be used in environments where you can verify the kernel and environments where you can't, and in the latter you may not care that modules are unsigned. In that scenario, tainting doesn't buy you anything.With your patch, you don't get tainting in the environment where you can verify.
You don't anyway, do you? Loading has already failed before this point if sig_enforce is set.
Quoted 2 lines
You'd be better adding a sysctl or equiv. to turn off force loading, and use that in your can-verify system.
I'm not sure what you mean by "force loading" here - if sig_enforce is set, you can't force load an unsigned module. If sig_enforce isn't set, you'll taint regardless of whether or not you force.
Wait. Hang on - are you confusing CONFIG_MODULE_SIG with CONFIG_MODVERSIONS?
Quoted 11 lines · Matthew Garrett
Quoted 6 lines · Rusty Russell
Quoted 3 lines · Matthew Garrett
Binary modules will still be tainted by the license checker. The issue is that if you want to enforce module signatures under *some* circumstances, you need to build with
CONFIG_MODULE_SIGNot at all! You can validate them in userspace.
And then you need an entire trusted userland, at which point you can assert that the modules are trustworthy without having to validate them so you don't need
CONFIG_MODULE_SIGanyway.
Yep. But your patch already gives userland that power, to silently load unsigned modules.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
but that
changes the behaviour of the kernel even when you're not enforcing module signatures. The same kernel may be used in environments where you can verify the kernel and environments where you can't, and in the latter you may not care that modules are unsigned. In that scenario, tainting doesn't buy you anything.
Quoted 5 lines
Quoted 2 lines
With your patch, you don't get tainting in the environment where you can verify.
You don't anyway, do you? Loading has already failed before this point if
sig_enforceis set.
No. You used to get a warning and a taint when you had a kernel configured to expect signatures and it didn't get one. You want to remove that warning, to silently accept unsigned modules.
Quoted 8 lines
Quoted 2 lines
You'd be better adding a sysctl or equiv. to turn off force loading, and use that in your can-verify system.
I'm not sure what you mean by "force loading" here - if
sig_enforceis set, you can't force load an unsigned module. Ifsig_enforceisn't set, you'll taint regardless of whether or not you force.Wait. Hang on - are you confusing
CONFIG_MODULE_SIGwithCONFIG_MODVERSIONS?
No, I mean stripping the signatures. (I thought modprobe could do this these days, but apparently not!)
So, you're actually building the same kernel, but building two sets of
modules: one without signatures, one with?
And when deploying the one with signatures, you're setting sig_enforce. On the other, you don't want signatures because um, reasons? And you want to suppress the message?
This seems so convoluted already, I can see how you considered an upstream patch your most productive path forward.
But it's possible that this scenario makes sense to Jeyu and I'm just incapable of seeing its beauty?
Cheers,
Rusty.
Quoted 7 lines · Rusty Russell
Quoted 3 lines · Matthew Garrett
And then you need an entire trusted userland, at which point you can assert that the modules are trustworthy without having to validate them so you don't need
CONFIG_MODULE_SIGanyway.Yep. But your patch already gives userland that power, to silently load unsigned modules.
Only if sig_enforce isn't set.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
With your patch, you don't get tainting in the environment where you can verify.
You don't anyway, do you? Loading has already failed before this point if
sig_enforceis set.No. You used to get a warning and a taint when you had a kernel configured to expect signatures and it didn't get one. You want to remove that warning, to silently accept unsigned modules.
I'm very confused here. If sig_enforce is set, the kernel will refuse to load an unsigned module - it won't be tainted, modprobe will just return an error. If sig_enforce is not set, any attacker in a position to provide unsigned modules is also in a position to just subvert modprobe, so you aren't in an environment where you can verify anything. The taint is informational, not any form of security. You're only able to securely verify module signatures in userland in very constrainted setups.
Quoted 12 lines
Quoted 8 lines
Quoted 2 lines
You'd be better adding a sysctl or equiv. to turn off force loading, and use that in your can-verify system.
I'm not sure what you mean by "force loading" here - if
sig_enforceis set, you can't force load an unsigned module. Ifsig_enforceisn't set, you'll taint regardless of whether or not you force.Wait. Hang on - are you confusing
CONFIG_MODULE_SIGwithCONFIG_MODVERSIONS?No, I mean stripping the signatures. (I thought modprobe could do this these days, but apparently not!)
Quoted 6 lines
So, you're actually building the same kernel, but building two sets of
modules: one without signatures, one with?And when deploying the one with signatures, you're setting
sig_enforce. On the other, you don't want signatures because um, reasons? And you want to suppress the message?
No. A distribution may ship a kernel with signed modules. In some configurations, the signatures are irrelevant - there's no mechanism to verify that the correct kernel was loaded in the first place, so for all you know the signature validation code has already been removed at runtime. In that scenario you're fine with users loading unsigned kernel modules and there's no benefit in tainting the kernel. But the same kernel may be booted under circumstances where it *is* possible to validate the kernel, and in those circumstances you want to enforce module signatures and so sig_enforce is set.
Right now you have two choices:
1) unsigned modules taint the kernel if sig_enforce is false, unsigned modules can't be loaded if sig_enforce is true (ie, CONFIG_MODULE_SIG is set)
2) unsigned modules do not taint the kernel, unsigned modules can always be loaded (ie, CONFIG_MODULE_SIG is unset)
What I want is:
3) unsigned modules do not taint the kernel if sig_enforce is false, unsigned modules can't be loaded if sig_enforce is true
This is currently impossible to express, and as a result some distributions ship with CONFIG_MODULE_SIG disabled in order to avoid dealing with user questions about why loading locally built modules now taints the kernel. Being able to build a single kernel that satisfies more use cases seems like a win.
But maybe there's a cleaner way. How about adding a paramter like sig_enforce (say taint_on_unsigned) and then adding a config parameter equivalent to CONFIG_MODULE_SIG_FORCE? That way the default policy can be set at build time, but can also be overridden by end users who still want to be able to taint on unsigned module load.
+++ Matthew Garrett [04/08/17 11:07 -0700]:
Quoted 4 lines
Distributions may wish to provide kernels that permit loading of unsigned modules based on certain policy decisions. Right now that results in the kernel being tainted whenever an unsigned module is loaded, which may not be desirable. Add a config option to disable that.
Hi Matthew!
I think I'm missing some context here. Could you provide some more background and help me understand why we want to go into all this trouble just to avoid a taint? Was there a recent bug report, mailing list discussion, etc. that spurred you to write this patch? I'm not understanding why this particular taint is undesirable.
I still think there is informational value in providing the unsigned module taint on a kernel that supports module signatures (CONFIG_MODULE_SIG). When debugging or trawling through crash dumps, module taints are useful for developers to immediately identify which modules were out-of-tree, which were unsigned and therefore not originally shipped by the distro etc, which often applies to e.g. 3rd party/dkms modules. And if a user for example locally compiles a module without signing it why would the unsigned module taint bother them more than the out-of-tree one (because that module would get both taints)?
If it is the "module verification failed" message that is actually scaring users, we could perhaps "soften" it to say something like "loading unsigned module X".
Jessica
Quoted 57 lines
Signed-off-by Matthew Garrett <[email protected]>---
init/Kconfig | 13 ++++++++++++-kernel/module.c| 2 ++2 files changed, 14 insertions(+), 1 deletion(-)init/Kconfig +10
-0@@ -1749,12 +1749,23 @@ config MODULE_SIG debuginfo strip done by some packagers (such as rpmbuild) and inclusion into an initramfs that wants the module size reduced. +config MODULE_UNSIGNED_TAINT + bool "Taint the kernel if unsigned modules are loaded" + default y + depends on MODULE_SIG + help + Taint the kernel if an unsigned kernel module is loaded. If this + option is enabled, the kernel will be tainted on an attempt to load + an unsigned module or signed modules for which we don't have a key + even if signature enforcement is disabled. +config
MODULE_SIG_FORCE
bool "Require modules to be validly signed"
depends onMODULE_SIG
help
Reject unsigned modules or signed modules for which we don't have ainit/Kconfig +2
-1- key. Without this, such modules will simply taint the kernel. + key. Without this, such modules will be loaded successfully but will + (if MODULE_UNSIGNED_TAINT is set) taint the kernel.config
MODULE_SIG_ALL
bool "Automatically sign all modules"kernel/module.c +2
-0@@ -3660,12 +3660,14 @@ static int load_module(struct load_info *info, const char __user *uargs,#ifdef CONFIG_MODULE_SIG mod->sig_ok = info->sig_ok; +#ifdef CONFIG_MODULE_UNSIGNED_TAINT if (!mod->sig_ok) {pr_notice_once ("%s: module verification failed: signature " "and/or required key missing - tainting " "kernel\n" , mod->name);add_taint_module (mod,TAINT_UNSIGNED_MODULE ,LOCKDEP_STILL_OK ); } +#endif #endif /* To avoid stressing percpu allocator, do this once we're unique. */ Signature · 1 line
2.14.0.rc1.383.gd1ce394fe2-goog
Quoted 5 lines · Jessica Yu
I think I'm missing some context here. Could you provide some more background and help me understand why we want to go into all this trouble just to avoid a taint? Was there a recent bug report, mailing list discussion, etc. that spurred you to write this patch? I'm not understanding why this particular taint is undesirable.
Hi Jessica,
Does the version in https://lkml.org/lkml/2017/8/7/764 make this clearer?
+++ Matthew Garrett [14/08/17 12:50 -0400]:
Quoted 10 lines · Jessica Yu
Quoted 5 lines
I think I'm missing some context here. Could you provide some more background and help me understand why we want to go into all this trouble just to avoid a taint? Was there a recent bug report, mailing list discussion, etc. that spurred you to write this patch? I'm not understanding why this particular taint is undesirable.
Hi Jessica,
Does the version in https://lkml.org/lkml/2017/8/7/764 make this clearer?
Hi Matthew,
Sorry for the delay, I'm currently on leave traveling.
I understand what the patch is doing, what I don't yet understand is _why_ you would want to remove the unsigned module taint when CONFIG_MODULE_SIG is enabled. Which distributions are asking for this exactly, and for what use cases? I find it a bit contradictory to have CONFIG_MODULE_SIG enabled and at the same time expect the kernel to behave as if the option wasn't enabled.
I would really prefer not to add extra code to remove what is cosmetic and still has informational/debug value. If the unsigned module taint is for whatever reason that bothersome, why can't distro(s) carry a 2-line patch removing the message and taint for those particular setups where signatures are considered "irrelevant" even with CONFIG_MODULE_SIG=y?
Thanks,
Jessica
Quoted 6 lines · Jessica Yu
I understand what the patch is doing, what I don't yet understand is _why_ you would want to remove the unsigned module taint when
CONFIG_MODULE_SIGis enabled. Which distributions are asking for this exactly, and for what use cases? I find it a bit contradictory to haveCONFIG_MODULE_SIGenabled and at the same time expect the kernel to behave as if the option wasn't enabled.
Debian disable CONFIG_MODULE_SIG because of this additional taint (I've Cc:ed Ben who made this change).
Quoted 6 lines
I would really prefer not to add extra code to remove what is cosmetic and still has informational/debug value. If the unsigned module taint is for whatever reason that bothersome, why can't distro(s) carry a 2-line patch removing the message and taint for those particular setups where signatures are considered "irrelevant" even with
CONFIG_MODULE_SIG=y?
If it's functionality that distributions want to patch out, it makes sense to provide them with a config option rather than forcing them to maintain a patch separately.
Quoted 10 lines · Matthew Garrett
Quoted 7 lines · Jessica Yu
I understand what the patch is doing, what I don't yet understand is _why_ you would want to remove the unsigned module taint when
CONFIG_MODULE_SIGis enabled. Which distributions are asking for this exactly, and for what use cases? I find it a bit contradictory to haveCONFIG_MODULE_SIGenabled and at the same time expect the kernel to behave as if the option wasn't enabled.Debian disable
CONFIG_MODULE_SIGbecause of this additional taint (I've Cc:ed Ben who made this change).
The current state of affairs is that Debian doesn't have the mechanism in place to sign modules with a trusted key. If we were to allow third parties to add signatures in some way (I think that's what Matthew's interested in doing) we would have to enabled CONFIG_MODULE_SIG, but that would cause modules to be tainted by default.
Quoted 10 lines
Quoted 6 lines
I would really prefer not to add extra code to remove what is cosmetic and still has informational/debug value. If the unsigned module taint is for whatever reason that bothersome, why can't distro(s) carry a 2-line patch removing the message and taint for those particular setups where signatures are considered "irrelevant" even with
CONFIG_MODULE_SIG=y?If it's functionality that distributions want to patch out, it makes sense to provide them with a config option rather than forcing them to maintain a patch separately.
We could use this in Debian. It would likely be a temporary stage until we do our own centralised module signing (or someone implements a Merkle tree for in-tree modules).
Ben.
Signature · 2 lines
Ben Hutchings Teamwork is essential - it allows you to blame someone else.
Hi Jessica,
It seems that there's distribution interest in this - any feedback?
Quoted 3 lines · Matthew Garrett
Hi Jessica,
It seems that there's distribution interest in this - any feedback?
Hi,
I think we'd still benefit from this being available, so just checking whether you had any further feelings on it.