modsig: signature based kernel module integrity verfication
Subsystems (5)
v2 cover modsig: signature based kernel module integrity verfication
Hello,
IMA measures/appraises modules when modprobe or insmod opens and reads them. Unfortunately, there are no guarantees between what is read by userspace and what is passed to the kernel via load_module system call. This patch adds support for digital signature verification of kernel modules.
It uses the upstreamed digital signature verification support, which is also used by IMA/EVM. There is no dependency on IMA/EVM, but both use the same signature and key formats, defined by digital signature verification support.
These patches are intended to support the different use cases, from an individual developer creating ephemeral keys, to the distro having an existing signing mechanism in place.
For the distro, a well known public key can simply be embedded in the kernel during the 'make' process.
For the developer, these patches create an ephemeral key during module install, in order to limit the duration of the private key's existence. Unfortunately, this necessitates embedding the public key in the kernel, after the kernel has already been built. A new make target called 'signed_modules_install', creates the keypair, signs the modules, removes the private key, and then, for now, recompiles the kernel using 'make bzImage'. For the developer, instead of doing 'make modules_install', the new build process would be 'make', followed by 'make signed_modules_install' and 'make install'.
Scripts:
- new scripts/ksign.sh and scripts/genkey.sh scripts
- new targets signed_module_install and genkey for the top Makefile
- scripts/Makefile.modinst changes
Changelog v2:
- Replaces passing the signature as a separate argument, with appending the signature to the kernel module during module install, as suggested by Rusty Russell. (No module-init-tools changes required.)
- The signature is created during module install, after the module was possibly stripped.
- Added support for using a builtin public key. (No requirement for an initramfs to load the public key.)
- Added key creation and signing support to kernel Makefiles.
- Permits developers to conveniently sign their own modules with an ephemeral key using "make signed_modules_install".
- Dmitry & Mimi
Dmitry Kasatkin (4):
integrity: added digest calculation function
modsig: add integrity_module_check hook
modsig: verify module integrity based on signature
modsig: build rules and scripts to generate keys and sign modules
Mimi Zohar (3):
keys: initialize root uid and session keyrings early
integrity: create and inititialize a keyring with builtin public key
modsig: initialize the _module public key keyring
Makefile | 38 ++++++++++ include/linux/integrity.h | 10 +++ kernel/module.c | 9 +++ scripts/Makefile.modinst | 1 + scripts/genkey.sh | 135 ++++++++++++++++++++++++++++++++++++ scripts/ksign.sh | 64 +++++++++++++++++ security/integrity/Kconfig | 21 ++++++ security/integrity/Makefile | 18 +++++ security/integrity/digsig.c | 31 ++++++++- security/integrity/digsig_pubkey.c | 96 +++++++++++++++++++++++++ security/integrity/integrity.h | 13 ++++ security/integrity/module.c | 91 ++++++++++++++++++++++++ security/keys/Makefile | 1 + security/keys/root_keyring.c | 18 +++++ 14 files changed, 544 insertions(+), 2 deletions(-) create mode 100755 scripts/genkey.sh create mode 100755 scripts/ksign.sh create mode 100644 security/integrity/digsig_pubkey.c create mode 100644 security/integrity/module.c create mode 100644 security/keys/root_keyring.c
Signature · 1 line
1.7.9.5
RFC v2 1/7 integrity: added digest calculation function
There are several functions, that need to calculate digest. This patch adds common function for use by integrity subsystem.
--- security/integrity/digsig.c | 31 +++++++++++++++++++++++++++++-- security/integrity/integrity.h | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)
security/integrity/digsig.c +29 -2
@@ -13,9 +13,9 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/err.h> -#include <linux/rbtree.h> #include <linux/key-type.h> #include <linux/digsig.h> +#include <crypto/hash.h> #include "integrity.h"
@@ -28,7 +28,7 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = { };int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen, -const char *digest,int digestlen) +const char *digest,int digestlen) {if (id >=INTEGRITY_KEYRING_MAX )return -EINVAL ;
@@ -46,3 +46,30 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,return digsig_verify (keyring[id], sig, siglen, digest, digestlen); } + +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest) +{ +int rc = -ENOMEM ; +struct crypto_shash *tfm; + + tfm =crypto_alloc_shash (algo,0 ,0 ); +if (IS_ERR (tfm)) { + rc =PTR_ERR (tfm); +pr_err ("Can not allocate %s (reason: %d)\n" , algo, rc); +return rc; + }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc; + + desc.shash.tfm = tfm; + desc.shash.flags =0 ; + + rc =crypto_shash_digest (&desc.shash, data, len, digest); + } + +crypto_free_shash (tfm); +return rc; +}
security/integrity/integrity.h +3 -0
@@ -59,6 +59,9 @@ struct integrity_iint_cache *integrity_iint_find(struct inode *inode);#ifdef CONFIG_INTEGRITY_SIGNATURE +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest); +int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen,const char *digest,int digestlen);
Signature · 1 line
1.7.9.5
Re: [RFC v2 1/7] integrity: added digest calculation function
Quoted 44 lines · Dmitry Kasatkin
There are several functions, that need to calculate digest. This patch adds common function for use by integrity subsystem.
Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/digsig.c | 31 +++++++++++++++++++++++++++++-- security/integrity/integrity.h | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)security/integrity/digsig.c +9
-2@@ -13,9 +13,9 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/err.h> -#include <linux/rbtree.h> #include <linux/key-type.h> #include <linux/digsig.h> +#include <crypto/hash.h> #include "integrity.h" @@ -28,7 +28,7 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = { };int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen, -const char *digest,int digestlen) +const char *digest,int digestlen) {if (id >=INTEGRITY_KEYRING_MAX )return -EINVAL ;@@ -46,3 +46,30 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,return digsig_verify (keyring[id], sig, siglen, digest, digestlen); } + +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest) +{ +int rc = -ENOMEM ; +struct crypto_shash *tfm; +
security/integrity/digsig.c int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, · line 65
Quoted 10 lines
security/integrity/digsig.c +10
-0+ tfm =crypto_alloc_shash (algo,0 ,0 ); +if (IS_ERR (tfm)) { + rc =PTR_ERR (tfm); +pr_err ("Can not allocate %s (reason: %d)\n" , algo, rc); +return rc; + }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc;
Needless confusing indentation here. Just move the struct {} desc; to the top and drop the else. That will make it much more readable.
Quoted 30 lines
security/integrity/digsig.c +9
-0+ desc.shash.tfm = tfm; + desc.shash.flags =0 ; + + rc =crypto_shash_digest (&desc.shash, data, len, digest); + } + +crypto_free_shash (tfm); +return rc; +}security/integrity/integrity.h +3
-0@@ -59,6 +59,9 @@ struct integrity_iint_cache *integrity_iint_find(struct inode *inode);#ifdef CONFIG_INTEGRITY_SIGNATURE +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest); +int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen,const char *digest,int digestlen);Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v2 1/7] integrity: added digest calculation function
Quoted 50 lines · Serge Hallyn
Quoted 49 lines · Dmitry Kasatkin
There are several functions, that need to calculate digest. This patch adds common function for use by integrity subsystem.
Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/digsig.c | 31 +++++++++++++++++++++++++++++-- security/integrity/integrity.h | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)security/integrity/digsig.c +14
-2@@ -13,9 +13,9 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/err.h> -#include <linux/rbtree.h> #include <linux/key-type.h> #include <linux/digsig.h> +#include <crypto/hash.h> #include "integrity.h" @@ -28,7 +28,7 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = { };int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen, -const char *digest,int digestlen) +const char *digest,int digestlen) {if (id >=INTEGRITY_KEYRING_MAX )return -EINVAL ;@@ -46,3 +46,30 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,return digsig_verify (keyring[id], sig, siglen, digest, digestlen); } + +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest) +{ +int rc = -ENOMEM ; +struct crypto_shash *tfm; + + tfm =crypto_alloc_shash (algo,0 ,0 ); +if (IS_ERR (tfm)) { + rc =PTR_ERR (tfm); +pr_err ("Can not allocate %s (reason: %d)\n" , algo, rc); +return rc;
Quoted 9 lines
security/integrity/digsig.c int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, · line 65
Quoted 5 lines
security/integrity/digsig.c +5
-0+ }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc;Needless confusing indentation here. Just move the struct {} desc; to the top and drop the else. That will make it much more readable.
Intention was to allocate it only if tfm allocation succeeded.. But indeed failure very unlikely..
thanks.
Quoted 30 lines
Quoted 30 lines
security/integrity/digsig.c +9
-0+ desc.shash.tfm = tfm; + desc.shash.flags =0 ; + + rc =crypto_shash_digest (&desc.shash, data, len, digest); + } + +crypto_free_shash (tfm); +return rc; +}security/integrity/integrity.h +3
-1@@ -59,6 +59,9 @@ struct integrity_iint_cache *integrity_iint_find(struct inode *inode);#ifdef CONFIG_INTEGRITY_SIGNATURE +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest); +int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen,const char *digest,int digestlen); --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v2 1/7] integrity: added digest calculation function
Quoted 62 lines · Dmitry
Quoted 50 lines · Serge Hallyn
Quoted 49 lines · Dmitry Kasatkin
There are several functions, that need to calculate digest. This patch adds common function for use by integrity subsystem.
Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/digsig.c | 31 +++++++++++++++++++++++++++++-- security/integrity/integrity.h | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)security/integrity/digsig.c +14
-2@@ -13,9 +13,9 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/err.h> -#include <linux/rbtree.h> #include <linux/key-type.h> #include <linux/digsig.h> +#include <crypto/hash.h> #include "integrity.h" @@ -28,7 +28,7 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = { };int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen, -const char *digest,int digestlen) +const char *digest,int digestlen) {if (id >=INTEGRITY_KEYRING_MAX )return -EINVAL ;@@ -46,3 +46,30 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,return digsig_verify (keyring[id], sig, siglen, digest, digestlen); } + +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest) +{ +int rc = -ENOMEM ; +struct crypto_shash *tfm; + + tfm =crypto_alloc_shash (algo,0 ,0 ); +if (IS_ERR (tfm)) { + rc =PTR_ERR (tfm); +pr_err ("Can not allocate %s (reason: %d)\n" , algo, rc); +return rc;Quoted 9 lines
security/integrity/digsig.c int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, · line 65
Quoted 5 lines
security/integrity/digsig.c +5
-0+ }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc;Needless confusing indentation here. Just move the struct {} desc; to the top and drop the else. That will make it much more readable.
Quoted 3 lines
Intention was to allocate it only if tfm allocation succeeded.. But indeed failure very unlikely..
BTW.. The reason for such code is that ctx member uses function in the parameter:
char ctx[crypto_shash_descsize(tfm)];
It is not possible to do it before tfm allocation... So I cannot move it up..
I can only kmalloc it then.
There are many places of such allocation on stack in the kernel code. sparse also complains. I know..
But it looks for me reasonable, as descriptor size is not big...
- Dmitry
Quoted 32 lines
thanks.
Quoted 30 lines
Quoted 30 lines
security/integrity/digsig.c +9
-0+ desc.shash.tfm = tfm; + desc.shash.flags =0 ; + + rc =crypto_shash_digest (&desc.shash, data, len, digest); + } + +crypto_free_shash (tfm); +return rc; +}security/integrity/integrity.h +3
-1@@ -59,6 +59,9 @@ struct integrity_iint_cache *integrity_iint_find(struct inode *inode);#ifdef CONFIG_INTEGRITY_SIGNATURE +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest); +int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen,const char *digest,int digestlen); --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v2 1/7] integrity: added digest calculation function
Quoted 68 lines · Kasatkin, Dmitry
Quoted 62 lines · Dmitry
Quoted 50 lines · Serge Hallyn
Quoted 49 lines · Dmitry Kasatkin
There are several functions, that need to calculate digest. This patch adds common function for use by integrity subsystem.
Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/digsig.c | 31 +++++++++++++++++++++++++++++-- security/integrity/integrity.h | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-)security/integrity/digsig.c +14
-2@@ -13,9 +13,9 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/err.h> -#include <linux/rbtree.h> #include <linux/key-type.h> #include <linux/digsig.h> +#include <crypto/hash.h> #include "integrity.h" @@ -28,7 +28,7 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = { };int integrity_digsig_verify (const unsigned int id,const char *sig,int siglen, -const char *digest,int digestlen) +const char *digest,int digestlen) {if (id >=INTEGRITY_KEYRING_MAX )return -EINVAL ;@@ -46,3 +46,30 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,return digsig_verify (keyring[id], sig, siglen, digest, digestlen); } + +int integrity_calc_digest (const char *algo,const void *data,const int len, +char *digest) +{ +int rc = -ENOMEM ; +struct crypto_shash *tfm; + + tfm =crypto_alloc_shash (algo,0 ,0 ); +if (IS_ERR (tfm)) { + rc =PTR_ERR (tfm); +pr_err ("Can not allocate %s (reason: %d)\n" , algo, rc); +return rc;Quoted 9 lines
security/integrity/digsig.c int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, · line 65
Quoted 5 lines
security/integrity/digsig.c +5
-0+ }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc;Needless confusing indentation here. Just move the struct {} desc; to the top and drop the else. That will make it much more readable.
Quoted 3 lines
Intention was to allocate it only if tfm allocation succeeded.. But indeed failure very unlikely..
Quoted 7 lines
BTW.. The reason for such code is that ctx member uses function in the parameter:
char ctx[crypto_shash_descsize(tfm)];
It is not possible to do it before tfm allocation... So I cannot move it up..
Ah, I see. Cool :)
Quoted 1 line
I can only kmalloc it then.
Well no, you could use another function I suppose.
But if you're going to leave it as is, please at least move the whole rest of the function into the else{} :) Yes, no functional change, but a change in how it looks to the eye of someone trying to review and look for actual free-unallocated-memory errors or leaks.
-serge
Re: [RFC v2 1/7] integrity: added digest calculation function
In reply to Dmitry Kasatkinsecurity/integrity/digsig.c int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, · line 65
Quoted 5 lines · Dmitry Kasatkin
security/integrity/digsig.c +5
-0+ }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc;
Linus had a rant a while ago about using variable-sized stack vars in the kernel (can't find a reference right now, sorry).
The problem is that either you know there's a limit to crypto_shash_descsize(), in which case you can just use this here, or you don't know, in which case, this risks a stack oveflow.
Cheers,
Rusty.
Re: [RFC v2 1/7] integrity: added digest calculation function
Quoted 10 lines · Rusty Russell
security/integrity/digsig.c int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, · line 65
Quoted 5 lines · Dmitry Kasatkin
security/integrity/digsig.c +5
-0+ }else { +struct { +struct shash_desc shash; +char ctx[crypto_shash_descsize (tfm)]; + } desc;Linus had a rant a while ago about using variable-sized stack vars in the kernel (can't find a reference right now, sorry).
Quoted 6 lines
The problem is that either you know there's a limit to
crypto_shash_descsize(), in which case you can just use this here, or you don't know, in which case, this risks a stack oveflow.Cheers,
Rusty.
Well... descriptor size is a algo specific but constant... just sizeof(some struct).
So there is no possibility to force overflow unless someone implement some algo driver which
uses too big descriptor size.
- Dmitry
RFC v2 2/7 keys: initialize root uid and session keyrings early
In reply to Dmitry KasatkinFrom: Mimi Zohar <[email protected]>
In order to create the integrity keyrings (eg. _evm, _ima, _modules), root's uid and session keyrings need to be initialized early.
--- security/keys/Makefile | 1 + security/keys/root_keyring.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 security/keys/root_keyring.c
security/keys/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-y := \ obj-$(CONFIG_KEYS_COMPAT) += compat.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSCTL) += sysctl.o +obj-$(CONFIG_INTEGRITY_SIGNATURE) += root_keyring.o # # Key types
security/keys/root_keyring.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (C) 2012 IBM Corporation +* +* Author: +* Mimi Zohar <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, version 2 of the License. +*/ + +#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring);
Signature · 1 line
1.7.9.5
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 39 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
In order to create the integrity keyrings (eg.
_evm,_ima,_modules), root's uid and session keyrings need to be initialized early.Signed-off-by Mimi Zohar <[email protected]>--- security/keys/Makefile | 1 + security/keys/root_keyring.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 security/keys/root_keyring.csecurity/keys/Makefile +1
-0@@ -18,6 +18,7 @@ obj-y := \ obj-$(CONFIG_KEYS_COMPAT) += compat.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSCTL) += sysctl.o +obj-$(CONFIG_INTEGRITY_SIGNATURE) += root_keyring.o # # Key typessecurity/keys/root_keyring.c new file +9
-0@@ -0,0 +1,18 @@ +/* +* Copyright (C) 2012 IBM Corporation +* +* Author: +* Mimi Zohar <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, version 2 of the License.
security/keys/root_keyring.c
Quoted 10 lines
security/keys/root_keyring.c new file +9
-1+*/ + +#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring); --
Why is this in an entirely new file instead of just being added to process_keys.c ?
josh
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 55 lines · Josh Boyer
Quoted 39 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
In order to create the integrity keyrings (eg.
_evm,_ima,_modules), root's uid and session keyrings need to be initialized early.Signed-off-by Mimi Zohar <[email protected]>--- security/keys/Makefile | 1 + security/keys/root_keyring.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 security/keys/root_keyring.csecurity/keys/Makefile +1
-0@@ -18,6 +18,7 @@ obj-y := \ obj-$(CONFIG_KEYS_COMPAT) += compat.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSCTL) += sysctl.o +obj-$(CONFIG_INTEGRITY_SIGNATURE) += root_keyring.o # # Key typessecurity/keys/root_keyring.c new file +9
-0@@ -0,0 +1,18 @@ +/* +* Copyright (C) 2012 IBM Corporation +* +* Author: +* Mimi Zohar <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, version 2 of the License. security/keys/root_keyring.c
Quoted 10 lines
security/keys/root_keyring.c new file +9
-1+*/ + +#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring); --Why is this in an entirely new file instead of just being added to
process_keys.c?
Quoted 1 line
josh
Only when "CONFIG_INTEGRITY_SIGNATURE" is selected, does this get built.
Mimi
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 12 lines · Mimi Zohar
Quoted 12 lines
security/keys/root_keyring.c
Quoted 8 lines
security/keys/root_keyring.c new file +7
-1+#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring); --Why is this in an entirely new file instead of just being added to
process_keys.c?
Quoted 3 lines
Quoted 1 line
josh
Only when "
CONFIG_INTEGRITY_SIGNATURE" is selected, does this get built.
Yes, I noticed that. It doesn't explain why it's in its own file. You could accomplish the same thing by wrapping the function and initcall in #ifdef CONFIG_INTEGRITY_SIGNATURE in process_keys.c.
josh
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 13 lines · Josh Boyer
Quoted 12 lines · Mimi Zohar
Quoted 12 lines
security/keys/root_keyring.c
Quoted 8 lines
security/keys/root_keyring.c new file +7
-1+#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring); --Why is this in an entirely new file instead of just being added to
process_keys.c?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
josh
Only when "
CONFIG_INTEGRITY_SIGNATURE" is selected, does this get built.Yes, I noticed that. It doesn't explain why it's in its own file. You could accomplish the same thing by wrapping the function and initcall in #ifdef
CONFIG_INTEGRITY_SIGNATUREinprocess_keys.c.
I was under the impression using 'ifdefs' in 'C' code was frowned upon (Documentation/SubmittingPatches section 2.2). This would be an exception?
Mimi
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 18 lines · Mimi Zohar
Quoted 17 lines · Josh Boyer
Quoted 15 lines · Mimi Zohar
Quoted 12 lines
security/keys/root_keyring.c
Quoted 8 lines
security/keys/root_keyring.c new file +7
-1+#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring); --Why is this in an entirely new file instead of just being added to
process_keys.c?Quoted 1 line
josh
Only when "
CONFIG_INTEGRITY_SIGNATURE" is selected, does this get built.
Quoted 7 lines
Quoted 3 lines
Yes, I noticed that. It doesn't explain why it's in its own file. You could accomplish the same thing by wrapping the function and initcall in #ifdef
CONFIG_INTEGRITY_SIGNATUREinprocess_keys.c.I was under the impression using 'ifdefs' in 'C' code was frowned upon (
Documentation/SubmittingPatchessection 2.2). This would be an exception?
If it makes a big ugly mess it's frowned upon. But if you're adding 7 lines of code in a new file that will almost certainly never get more code added to it, I'm not sure. IMHO, it can go into an existing file. Others might disagree. Isn't Linux development fun?!
josh
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 23 lines · Josh Boyer
Quoted 22 lines · Mimi Zohar
Quoted 20 lines · Josh Boyer
Quoted 12 lines · Mimi Zohar
Quoted 12 lines
security/keys/root_keyring.c
Quoted 8 lines
security/keys/root_keyring.c new file +7
-1+#include "internal.h" +static int __init init_root_keyring (void ) +{ +return install_user_keyrings (); +} + +late_initcall (init_root_keyring); --Why is this in an entirely new file instead of just being added to
process_keys.c?Quoted 3 lines
Quoted 1 line
josh
Only when "
CONFIG_INTEGRITY_SIGNATURE" is selected, does this get built.Yes, I noticed that. It doesn't explain why it's in its own file. You could accomplish the same thing by wrapping the function and initcall in #ifdef
CONFIG_INTEGRITY_SIGNATUREinprocess_keys.c.
Quoted 8 lines
Quoted 3 lines
I was under the impression using 'ifdefs' in 'C' code was frowned upon (
Documentation/SubmittingPatchessection 2.2). This would be an exception?If it makes a big ugly mess it's frowned upon. But if you're adding 7 lines of code in a new file that will almost certainly never get more code added to it, I'm not sure. IMHO, it can go into an existing file. Others might disagree. Isn't Linux development fun?!
This is just a case where if I had 'ifdef's in 'C' code, I'm sure someone would have complained. :)
Mimi
Re: [RFC v2 2/7] keys: initialize root uid and session keyrings early
Quoted 28 lines · Mimi Zohar
Quoted 27 lines · Josh Boyer
Quoted 25 lines · Mimi Zohar
Quoted 13 lines · Josh Boyer
Quoted 12 lines · Mimi Zohar
Quoted 12 lines
Review
Quoted 8 lines
(quoted diff) +7
-1+#include "internal.h" +static int __init init_root_keyring(void) +{ + return install_user_keyrings(); +} + +late_initcall(init_root_keyring); --Why is this in an entirely new file instead of just being added to
process_keys.c?Quoted 7 lines
Quoted 3 lines
Quoted 1 line
josh
Only when "
CONFIG_INTEGRITY_SIGNATURE" is selected, does this get built.Yes, I noticed that. It doesn't explain why it's in its own file. You could accomplish the same thing by wrapping the function and initcall in #ifdef
CONFIG_INTEGRITY_SIGNATUREinprocess_keys.c.I was under the impression using 'ifdefs' in 'C' code was frowned upon (
Documentation/SubmittingPatchessection 2.2). This would be an exception?
Quoted 7 lines
Quoted 4 lines
If it makes a big ugly mess it's frowned upon. But if you're adding 7 lines of code in a new file that will almost certainly never get more code added to it, I'm not sure. IMHO, it can go into an existing file. Others might disagree. Isn't Linux development fun?!
This is just a case where if I had 'ifdef's in 'C' code, I'm sure someone would have complained. :)
Why does the code need to be dependent on security modules at all. The code should work regardless either way.
Eric
RFC v2 3/7 integrity: create and inititialize a keyring with builtin public key
In reply to Dmitry KasatkinFrom: Mimi Zohar <[email protected]>
Create and initialize a keyring with the builtin public key. This could be an ephemeral key, created and destroyed during module install for custom built kernels, or a key used to label the entire filesystem for EVM/IMA-appraisal. Uses .incbin based on David Howell's post.
Load the builtin public key on the specified keyring, creating the keyring if it doesn't already exist.
--- security/integrity/Kconfig | 10 ++++ security/integrity/Makefile | 17 +++++++ security/integrity/digsig_pubkey.c | 96 ++++++++++++++++++++++++++++++++++++ security/integrity/integrity.h | 10 ++++ 4 files changed, 133 insertions(+) create mode 100644 security/integrity/digsig_pubkey.c
security/integrity/Kconfig +10 -0
@@ -17,5 +17,15 @@ config INTEGRITY_SIGNATURE This is useful for evm and module keyrings, when keys are usually only added from initramfs. +config INTEGRITY_PUBKEY + boolean "Create a keyring and initialize with builtin public key" + depends on INTEGRITY_SIGNATURE + default n + help + Create and initialize a keyring with the builtin public key. This could + be an ephemeral key, created and destroyed during module install for + custom built kernels, or a key used to label the entire filesystem for + EVM/IMA-appraisal. + source security/integrity/ima/Kconfig source security/integrity/evm/Kconfig
security/integrity/Makefile +17 -0
@@ -11,3 +11,20 @@ subdir-$(CONFIG_IMA) += ima obj-$(CONFIG_IMA) += ima/built-in.o subdir-$(CONFIG_EVM) += evm obj-$(CONFIG_EVM) += evm/built-in.o + +ifeq ($(CONFIG_INTEGRITY_PUBKEY),y) + +obj-y += digsig_pubkey.o + +pubkeybin = pubkey.bin + +$(obj)/digsig_pubkey.o: $(pubkeybin) + +$(pubkeybin): FORCE + @if [ ! -s $(pubkeybin) ]; then \ + echo "$(pubkeybin) is missing or empty..."; \ + if [ ! -f $(pubkeybin) ]; then touch $(pubkeybin); fi; \ + fi + +endif +
security/integrity/digsig_pubkey.c new file +96 -0
96 lines not on this page · raw message
security/integrity/integrity.h +10 -0
@@ -13,6 +13,7 @@#include <linux/types.h> #include <linux/integrity.h> +#include <linux/rbtree.h> #include <crypto/sha.h> /* iint cache flags */
@@ -76,5 +77,14 @@ static inline int integrity_digsig_verify(const unsigned int id,#endif /* CONFIG_INTEGRITY_SIGNATURE */ +#ifdef CONFIG_INTEGRITY_PUBKEY +int integrity_init_keyring (const unsigned int id); +#else +static inline int integrity_init_keyring (const unsigned int id) +{ +return 0 ; +} +#endif /* CONFIG_INTEGRITY_PUBKEY */ +/* set during initialization */ extern int iint_initialized;
Signature · 1 line
1.7.9.5
Re: [RFC v2 3/7] integrity: create and inititialize a keyring with builtin public key
Quoted 28 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
Create and initialize a keyring with the builtin public key. This could be an ephemeral key, created and destroyed during module install for custom built kernels, or a key used to label the entire filesystem for EVM/IMA-appraisal. Uses .incbin based on David Howell's post.
Load the builtin public key on the specified keyring, creating the keyring if it doesn't already exist.
Signed-off-by Mimi Zohar <[email protected]>Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/Kconfig | 10 ++++ security/integrity/Makefile | 17 +++++++ security/integrity/digsig_pubkey.c | 96 ++++++++++++++++++++++++++++++++++++ security/integrity/integrity.h | 10 ++++ 4 files changed, 133 insertions(+) create mode 100644 security/integrity/digsig_pubkey.csecurity/integrity/Kconfig +0
-0@@ -17,5 +17,15 @@ config INTEGRITY_SIGNATURE This is useful for evm and module keyrings, when keys are usually only added from initramfs.
security/integrity/Kconfig config INTEGRITY_SIGNATURE · line 29
Quoted 10 lines
security/integrity/Kconfig +10
-0+config INTEGRITY_PUBKEY + boolean "Create a keyring and initialize with builtin public key" + depends on INTEGRITY_SIGNATURE + default n + help + Create and initialize a keyring with the builtin public key. This could + be an ephemeral key, created and destroyed during module install for + custom built kernels, or a key used to label the entire filesystem for + EVM/IMA-appraisal. +
It could also be a key that is reused explicitly for signing kernels and kernel modules but has nothing to do with EVM/IMA filesystem labels, right? E.g. a distro key. I think the commit log and help text is a bit too restrictive here.
Quoted 17 lines
security/integrity/Kconfig +17
-0+int integrity_init_keyring(const unsigned int id) +{ + const struct cred *cred = current_cred(); + struct user_struct *user = cred->user; + struct key *new_keyring, *key; + u8 digest[SHA1_DIGEST_SIZE]; + char keyid[20]; + int ret, pubkey_size = pubkey_end - pubkey; + + if (pubkey_size == 0) { + pr_info("pubkey is missing, skipping...\n"); + return 0; + } + + new_keyring = keyring_alloc(keyring_name[id], user->uid, (gid_t) -1, + cred, KEY_ALLOC_NOT_IN_QUOTA, + user->uid_keyring);
security/integrity/Kconfig config INTEGRITY_SIGNATURE
Quoted 10 lines
security/integrity/Kconfig +10
-0+ if (IS_ERR(new_keyring)) { + ret = PTR_ERR(new_keyring); + goto out; + } + + ret = integrity_calc_digest("sha1", pubkey, pubkey_size, digest); + if (ret < 0) + goto out; + + sprintf(keyid, "%llX", __be64_to_cpup((uint64_t *)(digest+12)));
keyid is only 20 bytes. Is there a guarantee somewhere that restricts the digest+12 value to be 20 bytes or less and NUL termintated? If not, should you use snprintf?
security/integrity/Kconfig
Quoted 8 lines
security/integrity/Kconfig +8
-0+ + key = key_alloc(&key_type_user, keyid, 0, 0, current_cred(), + (KEY_POS_ALL & ~KEY_POS_SETATTR) | + KEY_USR_VIEW | KEY_USR_SEARCH | KEY_USR_READ, + KEY_ALLOC_NOT_IN_QUOTA); + if (IS_ERR(key)) { + ret = PTR_ERR(key); + goto out;
You leak new_keyring if here, right?
security/integrity/Kconfig
Quoted 9 lines
security/integrity/Kconfig +9
-0+ } + + ret = key_instantiate_and_link(key, pubkey, pubkey_end - pubkey, + new_keyring, NULL); +out: + pr_info("integrity: loaded public key %s on %s %s\n", keyid, + keyring_name[id], !ret ? "succeeded" : "failed"); + return ret; +}
josh
Re: [RFC v2 3/7] integrity: create and inititialize a keyring with builtin public key
Quoted 30 lines · Josh Boyer
Quoted 28 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
Create and initialize a keyring with the builtin public key. This could be an ephemeral key, created and destroyed during module install for custom built kernels, or a key used to label the entire filesystem for EVM/IMA-appraisal. Uses .incbin based on David Howell's post.
Load the builtin public key on the specified keyring, creating the keyring if it doesn't already exist.
Signed-off-by Mimi Zohar <[email protected]>Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/Kconfig | 10 ++++ security/integrity/Makefile | 17 +++++++ security/integrity/digsig_pubkey.c | 96 ++++++++++++++++++++++++++++++++++++ security/integrity/integrity.h | 10 ++++ 4 files changed, 133 insertions(+) create mode 100644 security/integrity/digsig_pubkey.csecurity/integrity/Kconfig +0
-0@@ -17,5 +17,15 @@ config INTEGRITY_SIGNATURE This is useful for evm and module keyrings, when keys are usually only added from initramfs.
Quoted 15 lines
security/integrity/Kconfig config INTEGRITY_SIGNATURE · line 29
Quoted 10 lines
security/integrity/Kconfig +10
-0+config INTEGRITY_PUBKEY + boolean "Create a keyring and initialize with builtin public key" + depends on INTEGRITY_SIGNATURE + default n + help + Create and initialize a keyring with the builtin public key. This could + be an ephemeral key, created and destroyed during module install for + custom built kernels, or a key used to label the entire filesystem for + EVM/IMA-appraisal. +It could also be a key that is reused explicitly for signing kernels and kernel modules but has nothing to do with EVM/IMA filesystem labels, right? E.g. a distro key. I think the commit log and help text is a bit too restrictive here.
Definitely! The cover letter included the distro scenario, but I missed updating it here.
Quoted 23 lines
Quoted 23 lines
security/integrity/Kconfig +23
-0+int integrity_init_keyring(const unsigned int id) +{ + const struct cred *cred = current_cred(); + struct user_struct *user = cred->user; + struct key *new_keyring, *key; + u8 digest[SHA1_DIGEST_SIZE]; + char keyid[20]; + int ret, pubkey_size = pubkey_end - pubkey; + + if (pubkey_size == 0) { + pr_info("pubkey is missing, skipping...\n"); + return 0; + } + + new_keyring = keyring_alloc(keyring_name[id], user->uid, (gid_t) -1, + cred, KEY_ALLOC_NOT_IN_QUOTA, + user->uid_keyring); + if (IS_ERR(new_keyring)) { + ret = PTR_ERR(new_keyring); + goto out; + } + + ret = integrity_calc_digest("sha1", pubkey, pubkey_size, digest);
Quoted 8 lines
security/integrity/Kconfig
Quoted 4 lines
security/integrity/Kconfig +4
-0+ if (ret < 0) + goto out; + + sprintf(keyid, "%llX", __be64_to_cpup((uint64_t *)(digest+12)));keyid is only 20 bytes. Is there a guarantee somewhere that restricts the digest+12 value to be 20 bytes or less and NUL termintated? If not, should you use snprintf?
Correct, and SHA1 shouldn't be hardcoded either, but configurable.
Quoted 11 lines
security/integrity/Kconfig
Quoted 9 lines
security/integrity/Kconfig +8
-0+ + key = key_alloc(&key_type_user, keyid, 0, 0, current_cred(), + (KEY_POS_ALL & ~KEY_POS_SETATTR) | + KEY_USR_VIEW | KEY_USR_SEARCH | KEY_USR_READ, + KEY_ALLOC_NOT_IN_QUOTA); + if (IS_ERR(key)) { + ret = PTR_ERR(key); + goto out;You leak
new_keyringif here, right?
thanks
Quoted 11 lines
security/integrity/Kconfig
Quoted 9 lines
security/integrity/Kconfig +9
-0+ } + + ret = key_instantiate_and_link(key, pubkey, pubkey_end - pubkey, + new_keyring, NULL); +out: + pr_info("integrity: loaded public key %s on %s %s\n", keyid, + keyring_name[id], !ret ? "succeeded" : "failed"); + return ret; +}josh
Mimi
Re: [RFC v2 3/7] integrity: create and inititialize a keyring with builtin public key
Quoted 94 lines · Mimi Zohar
Quoted 30 lines · Josh Boyer
Quoted 28 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
Create and initialize a keyring with the builtin public key. This could be an ephemeral key, created and destroyed during module install for custom built kernels, or a key used to label the entire filesystem for EVM/IMA-appraisal. Uses .incbin based on David Howell's post.
Load the builtin public key on the specified keyring, creating the keyring if it doesn't already exist.
Signed-off-by Mimi Zohar <[email protected]>Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/Kconfig | 10 ++++ security/integrity/Makefile | 17 +++++++ security/integrity/digsig_pubkey.c | 96 ++++++++++++++++++++++++++++++++++++ security/integrity/integrity.h | 10 ++++ 4 files changed, 133 insertions(+) create mode 100644 security/integrity/digsig_pubkey.csecurity/integrity/Kconfig +0
-0@@ -17,5 +17,15 @@ config INTEGRITY_SIGNATURE This is useful for evm and module keyrings, when keys are usually only added from initramfs.Quoted 15 lines
security/integrity/Kconfig config INTEGRITY_SIGNATURE · line 29
Quoted 10 lines
security/integrity/Kconfig +10
-0+config INTEGRITY_PUBKEY + boolean "Create a keyring and initialize with builtin public key" + depends on INTEGRITY_SIGNATURE + default n + help + Create and initialize a keyring with the builtin public key. This could + be an ephemeral key, created and destroyed during module install for + custom built kernels, or a key used to label the entire filesystem for + EVM/IMA-appraisal. +It could also be a key that is reused explicitly for signing kernels and kernel modules but has nothing to do with EVM/IMA filesystem labels, right? E.g. a distro key. I think the commit log and help text is a bit too restrictive here.
Definitely! The cover letter included the distro scenario, but I missed updating it here.
Quoted 23 lines
Quoted 23 lines
security/integrity/Kconfig +23
-0+int integrity_init_keyring(const unsigned int id) +{ + const struct cred *cred = current_cred(); + struct user_struct *user = cred->user; + struct key *new_keyring, *key; + u8 digest[SHA1_DIGEST_SIZE]; + char keyid[20]; + int ret, pubkey_size = pubkey_end - pubkey; + + if (pubkey_size == 0) { + pr_info("pubkey is missing, skipping...\n"); + return 0; + } + + new_keyring = keyring_alloc(keyring_name[id], user->uid, (gid_t) -1, + cred, KEY_ALLOC_NOT_IN_QUOTA, + user->uid_keyring); + if (IS_ERR(new_keyring)) { + ret = PTR_ERR(new_keyring); + goto out; + } + + ret = integrity_calc_digest("sha1", pubkey, pubkey_size, digest);Quoted 8 lines
security/integrity/Kconfig
Quoted 4 lines
security/integrity/Kconfig +4
-0+ if (ret < 0) + goto out; + + sprintf(keyid, "%llX", __be64_to_cpup((uint64_t *)(digest+12)));keyid is only 20 bytes. Is there a guarantee somewhere that restricts the digest+12 value to be 20 bytes or less and NUL termintated? If not, should you use snprintf?
Correct, and SHA1 shouldn't be hardcoded either, but configurable.
Quoted 10 lines
Quoted 9 lines
security/integrity/Kconfig +8
-0+ + key = key_alloc(&key_type_user, keyid, 0, 0, current_cred(), + (KEY_POS_ALL & ~KEY_POS_SETATTR) | + KEY_USR_VIEW | KEY_USR_SEARCH | KEY_USR_READ, + KEY_ALLOC_NOT_IN_QUOTA); + if (IS_ERR(key)) { + ret = PTR_ERR(key); + goto out;
Quoted 4 lines
Quoted 1 line
You leak
new_keyringif here, right?thanks
Actually we are not leaking.new_keyring is instantiated and linked to the uid keyring..
Another question is, do we want to leave keyring there for "may be later" use, or just destroy...
Quoted 14 lines
Quoted 11 lines
security/integrity/Kconfig
Quoted 9 lines
security/integrity/Kconfig +9
-0+ } + + ret = key_instantiate_and_link(key, pubkey, pubkey_end - pubkey, + new_keyring, NULL); +out: + pr_info("integrity: loaded public key %s on %s %s\n", keyid, + keyring_name[id], !ret ? "succeeded" : "failed"); + return ret; +}josh
Mimi
Re: [RFC v2 3/7] integrity: create and inititialize a keyring with builtin public key
In reply to Josh BoyerQuoted 69 lines · Josh Boyer
Quoted 28 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
Create and initialize a keyring with the builtin public key. This could be an ephemeral key, created and destroyed during module install for custom built kernels, or a key used to label the entire filesystem for EVM/IMA-appraisal. Uses .incbin based on David Howell's post.
Load the builtin public key on the specified keyring, creating the keyring if it doesn't already exist.
Signed-off-by Mimi Zohar <[email protected]>Signed-off-by Dmitry Kasatkin <[email protected]>--- security/integrity/Kconfig | 10 ++++ security/integrity/Makefile | 17 +++++++ security/integrity/digsig_pubkey.c | 96 ++++++++++++++++++++++++++++++++++++ security/integrity/integrity.h | 10 ++++ 4 files changed, 133 insertions(+) create mode 100644 security/integrity/digsig_pubkey.csecurity/integrity/Kconfig +0
-0@@ -17,5 +17,15 @@ config INTEGRITY_SIGNATURE This is useful for evm and module keyrings, when keys are usually only added from initramfs.security/integrity/Kconfig config INTEGRITY_SIGNATURE · line 29
Quoted 10 lines
security/integrity/Kconfig +10
-0+config INTEGRITY_PUBKEY + boolean "Create a keyring and initialize with builtin public key" + depends on INTEGRITY_SIGNATURE + default n + help + Create and initialize a keyring with the builtin public key. This could + be an ephemeral key, created and destroyed during module install for + custom built kernels, or a key used to label the entire filesystem for + EVM/IMA-appraisal. +It could also be a key that is reused explicitly for signing kernels and kernel modules but has nothing to do with EVM/IMA filesystem labels, right? E.g. a distro key. I think the commit log and help text is a bit too restrictive here.
Quoted 23 lines
security/integrity/Kconfig +23
-0+int integrity_init_keyring(const unsigned int id) +{ + const struct cred *cred = current_cred(); + struct user_struct *user = cred->user; + struct key *new_keyring, *key; + u8 digest[SHA1_DIGEST_SIZE]; + char keyid[20]; + int ret, pubkey_size = pubkey_end - pubkey; + + if (pubkey_size == 0) { + pr_info("pubkey is missing, skipping...\n"); + return 0; + } + + new_keyring = keyring_alloc(keyring_name[id], user->uid, (gid_t) -1, + cred, KEY_ALLOC_NOT_IN_QUOTA, + user->uid_keyring); + if (IS_ERR(new_keyring)) { + ret = PTR_ERR(new_keyring); + goto out; + } + + ret = integrity_calc_digest("sha1", pubkey, pubkey_size, digest);
Quoted 9 lines
security/integrity/Kconfig
Quoted 4 lines
security/integrity/Kconfig +4
-0+ if (ret < 0) + goto out; + + sprintf(keyid, "%llX", __be64_to_cpup((uint64_t *)(digest+12)));keyid is only 20 bytes. Is there a guarantee somewhere that restricts the digest+12 value to be 20 bytes or less and NUL termintated? If not, should you use snprintf?
No.. Digest here is 20 bytes, but keyid is 8 bytes - it is u64... It cannot go beyond here...
Quoted 22 lines
security/integrity/Kconfig
Quoted 8 lines
security/integrity/Kconfig +8
-0+ + key = key_alloc(&key_type_user, keyid, 0, 0, current_cred(), + (KEY_POS_ALL & ~KEY_POS_SETATTR) | + KEY_USR_VIEW | KEY_USR_SEARCH | KEY_USR_READ, + KEY_ALLOC_NOT_IN_QUOTA); + if (IS_ERR(key)) { + ret = PTR_ERR(key); + goto out;You leak
new_keyringif here, right?security/integrity/Kconfig
Quoted 9 lines
security/integrity/Kconfig +9
-0+ } + + ret = key_instantiate_and_link(key, pubkey, pubkey_end - pubkey, + new_keyring, NULL); +out: + pr_info("integrity: loaded public key %s on %s %s\n", keyid, + keyring_name[id], !ret ? "succeeded" : "failed"); + return ret; +}josh
RFC v2 4/7 modsig: add integrity_module_check hook
In reply to Dmitry KasatkinIMA measures/appraises modules when modprobe or insmod opens and read them. Unfortunately, there are no guarantees between what is read by userspace and what is passed to the kernel via load_module system call. This patch adds a hook called integrity_module_check() to verify the integrity of the module being loaded.
--- include/linux/integrity.h | 10 ++++++++++ kernel/module.c | 9 +++++++++ 2 files changed, 19 insertions(+)
include/linux/integrity.h +10 -0
@@ -37,4 +37,14 @@ static inline void integrity_inode_free(struct inode *inode)return ; }#endif /* CONFIG_INTEGRITY_H */ + +#ifdef CONFIG_INTEGRITY_MODULES +int integrity_module_check (const void *hdr,const unsigned long len); +#else +static inline int integrity_module_check (const void *buf,unsigned long len) +{ +return 0 ; +} +#endif +#endif /* _LINUX_INTEGRITY_H */
kernel/module.c +9 -0
@@ -58,6 +58,7 @@#include <linux/jump_label.h> #include <linux/pfn.h> #include <linux/bsearch.h> +#include <linux/integrity.h> #define CREATE_TRACE_POINTS #include <trace/events/module.h>
@@ -2437,6 +2438,14 @@ static int copy_and_check(struct load_info *info, info->hdr = hdr; info->len = len; + + err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err; +return 0 ; free_hdr:
Signature · 1 line
1.7.9.5
Re: [RFC v2 4/7] modsig: add integrity_module_check hook
Quoted 17 lines · Dmitry Kasatkin
IMA measures/appraises modules when modprobe or insmod opens and read them. Unfortunately, there are no guarantees between what is read by userspace and what is passed to the kernel via
load_modulesystem call. This patch adds a hook calledintegrity_module_check()to verify the integrity of the module being loaded.Signed-off-by Dmitry Kasatkin <[email protected]>--- include/linux/integrity.h | 10 ++++++++++ kernel/module.c | 9 +++++++++ 2 files changed, 19 insertions(+)include/linux/integrity.h +0
-0
include/linux/integrity.h static inline void integrity_inode_free(struct inode *inode) · line 42
Quoted 6 lines
include/linux/integrity.h +3
-0@@ -37,4 +37,14 @@ static inline void integrity_inode_free(struct inode *inode) return; }#endif /* CONFIG_INTEGRITY_H */ + +#ifdef CONFIG_INTEGRITY_MODULES +int integrity_module_check (const void *hdr,const unsigned long len);
sadly not bisect-safe, since integrity_module_check() is defined in the next patch.
Quoted 42 lines
include/linux/integrity.h +7
-0+#else +static inline int integrity_module_check (const void *buf,unsigned long len) +{ +return 0 ; +} +#endif +#endif /* _LINUX_INTEGRITY_H */ kernel/module.c +9
-0@@ -58,6 +58,7 @@#include <linux/jump_label.h> #include <linux/pfn.h> #include <linux/bsearch.h> +#include <linux/integrity.h> #define CREATE_TRACE_POINTS #include <trace/events/module.h> @@ -2437,6 +2438,14 @@ static int copy_and_check(struct load_info *info, info->hdr = hdr; info->len = len; + + err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err; +return 0 ; free_hdr:Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v2 4/7] modsig: add integrity_module_check hook
Quoted 13 lines · Serge Hallyn
Quoted 12 lines · Dmitry Kasatkin
IMA measures/appraises modules when modprobe or insmod opens and read them. Unfortunately, there are no guarantees between what is read by userspace and what is passed to the kernel via
load_modulesystem call. This patch adds a hook calledintegrity_module_check()to verify the integrity of the module being loaded.Signed-off-by Dmitry Kasatkin <[email protected]>--- include/linux/integrity.h | 10 ++++++++++ kernel/module.c | 9 +++++++++ 2 files changed, 19 insertions(+)
Quoted 15 lines
include/linux/integrity.h static inline void integrity_inode_free(struct inode *inode) · line 42
Quoted 11 lines
include/linux/integrity.h +3
-0@@ -37,4 +37,14 @@ static inline void integrity_inode_free(struct inode *inode) return; }#endif /* CONFIG_INTEGRITY_H */ + +#ifdef CONFIG_INTEGRITY_MODULES +int integrity_module_check (const void *hdr,const unsigned long len);sadly not bisect-safe, since
integrity_module_check()is defined in the next patch.
Ok.. Hooks come after implementation...
Will swap.
Thanks.
Quoted 42 lines
Quoted 42 lines
include/linux/integrity.h +7
-0+#else +static inline int integrity_module_check (const void *buf,unsigned long len) +{ +return 0 ; +} +#endif +#endif /* _LINUX_INTEGRITY_H */ kernel/module.c +9
-1@@ -58,6 +58,7 @@#include <linux/jump_label.h> #include <linux/pfn.h> #include <linux/bsearch.h> +#include <linux/integrity.h> #define CREATE_TRACE_POINTS #include <trace/events/module.h> @@ -2437,6 +2438,14 @@ static int copy_and_check(struct load_info *info, info->hdr = hdr; info->len = len; + + err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err; +return 0 ; free_hdr: --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v2 4/7] modsig: add integrity_module_check hook
Quoted 31 lines · Dmitry
Quoted 13 lines · Serge Hallyn
Quoted 12 lines · Dmitry Kasatkin
IMA measures/appraises modules when modprobe or insmod opens and read them. Unfortunately, there are no guarantees between what is read by userspace and what is passed to the kernel via
load_modulesystem call. This patch adds a hook calledintegrity_module_check()to verify the integrity of the module being loaded.Signed-off-by Dmitry Kasatkin <[email protected]>--- include/linux/integrity.h | 10 ++++++++++ kernel/module.c | 9 +++++++++ 2 files changed, 19 insertions(+)Quoted 15 lines
include/linux/integrity.h static inline void integrity_inode_free(struct inode *inode) · line 42
Quoted 11 lines
include/linux/integrity.h +3
-0@@ -37,4 +37,14 @@ static inline void integrity_inode_free(struct inode *inode) return; }#endif /* CONFIG_INTEGRITY_H */ + +#ifdef CONFIG_INTEGRITY_MODULES +int integrity_module_check (const void *hdr,const unsigned long len);sadly not bisect-safe, since
integrity_module_check()is defined in the next patch.
Quoted 3 lines
Ok.. Hooks come after implementation...
Will swap.
Hi Serge.
Actually Kconfig option is defined in following implementation patch, so CONFIG_INTEGRITY_MODULES is not defined and it will compile inline empty function.
Why is it not bisect-safe?
- Dmitry
Quoted 44 lines
Thanks.
Quoted 42 lines
Quoted 42 lines
include/linux/integrity.h +7
-0+#else +static inline int integrity_module_check (const void *buf,unsigned long len) +{ +return 0 ; +} +#endif +#endif /* _LINUX_INTEGRITY_H */ kernel/module.c +9
-1@@ -58,6 +58,7 @@#include <linux/jump_label.h> #include <linux/pfn.h> #include <linux/bsearch.h> +#include <linux/integrity.h> #define CREATE_TRACE_POINTS #include <trace/events/module.h> @@ -2437,6 +2438,14 @@ static int copy_and_check(struct load_info *info, info->hdr = hdr; info->len = len; + + err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err; +return 0 ; free_hdr: --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC v2 4/7] modsig: add integrity_module_check hook
In reply to Dmitry KasatkinQuoted 5 lines · Dmitry Kasatkin
kernel/module.c +1
-0@@ -2437,6 +2438,14 @@ static int copy_and_check(struct load_info *info, info->hdr = hdr; info->len = len; +
kernel/module.c static int copy_and_check(struct load_info *info, · line 2451
Quoted 10 lines
kernel/module.c +7
-0+ err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err; +return 0 ; free_hdr:
So if I'm reading this correctly, any module that fails signature verification will fail to load. That makes sense, but I wonder if you intend to support a non-enforcing mode for module signatures at all? Actually, a brief document in Documentation describing how this whole mechanism works and what the fail states are would be good. David's patches have it nicely spelled out and I don't see anything similar in your patch set.
josh
Re: [RFC v2 4/7] modsig: add integrity_module_check hook
Quoted 26 lines · Josh Boyer
Quoted 5 lines · Dmitry Kasatkin
kernel/module.c +1
-0@@ -2437,6 +2438,14 @@ static int copy_and_check(struct load_info *info, info->hdr = hdr; info->len = len; +kernel/module.c static int copy_and_check(struct load_info *info, · line 2451
Quoted 10 lines
kernel/module.c +7
-0+ err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err; +return 0 ; free_hdr:So if I'm reading this correctly, any module that fails signature verification will fail to load. That makes sense, but I wonder if you intend to support a non-enforcing mode for module signatures at all? Actually, a brief document in Documentation describing how this whole mechanism works and what the fail states are would be good. David's patches have it nicely spelled out and I don't see anything similar in your patch set.
Quoted 1 line
josh
Hi,
I had enable and enforce mode in my previous patches. I have removed them just before posting.
I added now enforcing back..
- Dmitry
Re: [RFC v2 4/7] modsig: add integrity_module_check hook
In reply to Dmitry KasatkinQuoted 6 lines · Dmitry Kasatkin
include/linux/integrity.h +6
-0+#else +static inline int integrity_module_check (const void *buf,unsigned long len) +{ +return 0 ; +} +#endif
...
kernel/module.c static int copy_and_check(struct load_info *info, · line 2447
Quoted 6 lines
kernel/module.c +6
-0+ err =integrity_module_check (hdr, len); +if (err <0 ) + goto free_hdr; + +/* cut signature tail */ + info->len = err;
This is a bug.
Firstly, you want the 'long' not 'int' as the return vale from integrity_module_check(). But mainly, you want it to return 'len' not 0.
I'd also prefer it to be *immediately* after we copy from userspace.
Cheers,
Rusty.
RFC v2 5/7 modsig: verify module integrity based on signature
In reply to Dmitry KasatkinThis patch adds support for verifying module integrity using the upstreamed digital signature support. Signatures are appended to the kernel module binary, as suggested by Rusty Russell. Using of this functionality does not require changes to insmod and modprobe. The module hash is calculated and verified against the signature. Public key and signature format can found in Documentation/digsig.txt
--- security/integrity/Kconfig | 11 ++++++ security/integrity/Makefile | 1 + security/integrity/module.c | 91 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 security/integrity/module.c
security/integrity/Kconfig +11 -0
@@ -27,5 +27,16 @@ config INTEGRITY_PUBKEY custom built kernels, or a key used to label the entire filesystem for EVM/IMA-appraisal. +config INTEGRITY_MODULES + bool "Module integrity checking" + depends on SECURITY + select INTEGRITY_SIGNATURE + default n + help + This option enables module integrity checking, + using digital signatures + + If unsure, say N. + source security/integrity/ima/Kconfig source security/integrity/evm/Kconfig
security/integrity/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_INTEGRITY) += integrity.o obj-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o +obj-$(CONFIG_INTEGRITY_MODULES) += module.o integrity-y := iint.o
security/integrity/module.c new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.9.5
RFC v2 6/7 modsig: initialize the _module public key keyring
In reply to Dmitry KasatkinFrom: Mimi Zohar <[email protected]>
Create and initialize the _module public key keyring with the builtin public key.
--- security/integrity/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/module.c +1 -1
@@ -82,7 +82,7 @@ err1:static int __init module_check_init (void ) { -return 0 ; +return integrity_init_keyring (INTEGRITY_KEYRING_MODULE ); }late_initcall (module_check_init);
Signature · 1 line
1.7.9.5
Re: [RFC v2 6/7] modsig: initialize the _module public key keyring
Quoted 6 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
Create and initialize the
_modulepublic key keyring with the builtin public key.Signed-off-by Mimi Zohar <[email protected]>
This seems like it could be folded into "modsig: add integrity_module_check hook" or "modsig: verify module integrity based on signature". Not sure why it needs to be a separate patch at first glance.
josh
Re: [RFC v2 6/7] modsig: initialize the _module public key keyring
Quoted 7 lines · Josh Boyer
Quoted 5 lines · Dmitry Kasatkin
From: Mimi Zohar <[email protected]>
Create and initialize the
_modulepublic key keyring with the builtin public key.
Quoted 6 lines
Quoted 1 line
Signed-off-by Mimi Zohar <[email protected]>This seems like it could be folded into "modsig: add
integrity_module_checkhook" or "modsig: verify module integrity based on signature". Not sure why it needs to be a separate patch at first glance.
No reason other than my sending it to Dmitry. I'm sure he can squash it with his own patches.
thanks,
Mimi
RFC v2 7/7 modsig: build rules and scripts to generate keys and sign modules
In reply to Dmitry KasatkinThis patch adds build rules and scripts to generate keys and sign modules.
Two scripts has been added. genkey.sh is used to generate private and public keys. ksign.sh is used to sign kernel modules. Both scripts use only standard utilites from coreutils and additionally requires openssl tool for RSA keys creation and signing.
The patch modifies 'modules_install' target and adds two new targets to the main kernel Makefile.
1. signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)
2. modules_install
When CONFIG_INTEGRITY_MODULES is anabled, this target uses an existing private key to sign kernel modules.
3. genkey
This target is automatically called for signed_modules_install to generate ephemeral key pair, or can be called manually to generate new private and public keypair for using with modules_install.
--- Makefile | 38 +++++++++++++ scripts/Makefile.modinst | 1 + scripts/genkey.sh | 135 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/ksign.sh | 64 ++++++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100755 scripts/genkey.sh create mode 100755 scripts/ksign.sh
Makefile +38 -0
@@ -939,10 +939,31 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin) PHONY += modules_prepare modules_prepare: prepare scripts +privkey = privkey.pem +pubkeybin = pubkey.bin + +ifeq ($(CONFIG_INTEGRITY_MODULES),y) +# command to sign modules +export quiet_cmd_sign_module = SIGN $$(@) +export cmd_sign_module = $(srctree)/scripts/ksign.sh $$(2) +endif + # Target to install modules PHONY += modules_install +ifeq ($(CONFIG_INTEGRITY_MODULES),y) +modules_install: _checkkey_ +endif modules_install: _modinst_ _modinst_post +PHONY += _checkkey_ +_checkkey_: + @if [ ! -f $(privkey) -o ! -f $(pubkeybin) ]; then \ + echo "Keys are missing. Run 'make genkey' first."; exit 1; \ + fi; \ + if [ $(pubkeybin) -nt vmlinux ]; then \ + echo "$(pubkeybin) is newer than vmlinux. Run 'make bzImage' again."; exit 1; \ + fi + PHONY += _modinst_ _modinst_: @rm -rf $(MODLIB)/kernel
@@ -957,6 +978,23 @@ _modinst_: @cp -f $(objtree)/modules.builtin $(MODLIB)/ $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst +# Target to install signed modules using new ephemeral key +# It will force to generate new key pair and re-generate bzImage +# Private key is removed after installing modules +PHONY += signed_modules_install +signed_modules_install: genkey _modinst_ _modinst_post _rmprivkey_ bzImage + +PHONY += genkey +genkey: $(privkey) $(pubkeybin) + +$(privkey): FORCE + @if [ -f $(privkey) ]; then echo "$(privkey) already exists. Remove it first."; exit 1; fi + @$(srctree)/scripts/genkey.sh + +PHONY += _rmprivkey_ +_rmprivkey_: + @rm $(privkey) + # This depmod is only for convenience to give the initial # boot a modules.dep even before / is mounted read-write. However the # boot script depmod is the master version.
scripts/Makefile.modinst +1 -0
@@ -27,6 +27,7 @@ modinst_dir = $(if $(KBUILD_EXTMOD),$(ext-mod-dir),kernel/$(@D)) $(modules): $(call cmd,modules_install,$(MODLIB)/$(modinst_dir)) + $(call cmd,sign_module,$(MODLIB)/$(modinst_dir)/$(notdir $@)) # Declare the contents of the .PHONY variable as phony. We keep that
scripts/genkey.sh new file +135 -0
135 lines not on this page · raw message
scripts/ksign.sh new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 7 lines · Dmitry Kasatkin
This patch adds build rules and scripts to generate keys and sign modules.
Two scripts has been added.
genkey.shis used to generate private and public keys.ksign.shis used to sign kernel modules. Both scripts use only standard utilites from coreutils and additionally requires openssl tool for RSA keys creation and signing.
Quoted 7 lines
The patch modifies '
modules_install' target and adds two new targets to the main kernelMakefile.1.
signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)
This requires CONFIG_INTEGRITY_MODULES to be enabled to actually do anything useful with the signed modules, correct?
Quoted 4 lines
2.
modules_install
WhenCONFIG_INTEGRITY_MODULESis enabled, this target uses an existing private key to sign kernel modules.
If the answer to the above question is yes, then why can't we stick with a single modules_install command for signing? It would seem to me that calling signed_modules_install could use an existing key or generate an ephemeral key in the absence of one and install the signed modules, and modules_install would simply install unsigned modules.
Or, alternatively, just make modules_install sign or not sign depending on whether CONFIG_INTEGRITY_MODULES is enabled. I don't see why you would overload a target or create two different ones when both depend on that option.
Could you explain the reasoning behind that a bit more?
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 12 lines · Josh Boyer
Quoted 10 lines · Dmitry Kasatkin
This patch adds build rules and scripts to generate keys and sign modules.
Two scripts has been added.
genkey.shis used to generate private and public keys.ksign.shis used to sign kernel modules. Both scripts use only standard utilites from coreutils and additionally requires openssl tool for RSA keys creation and signing.The patch modifies '
modules_install' target and adds two new targets to the main kernelMakefile.
Quoted 8 lines
Quoted 4 lines
1.
signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)This requires
CONFIG_INTEGRITY_MODULESto be enabled to actually do anything useful with the signed modules, correct?
Correct. It does not make sense to sign module if module support is disabled. But there scripts/genkey.sh and ksign.sh which works without Makefiles. So possible to generate keys and sign a module...
Quoted 5 lines
Quoted 4 lines
2.
modules_install
WhenCONFIG_INTEGRITY_MODULESis enabled, this target uses an existing private key to sign kernel modules.
Quoted 8 lines
If the answer to the above question is yes, then why can't we stick with a single
modules_installcommand for signing? It would seem to me that callingsigned_modules_installcould use an existing key or generate an ephemeral key in the absence of one and install the signed modules, andmodules_installwould simply install unsigned modules.Or, alternatively, just make
modules_installsign or not sign depending on whetherCONFIG_INTEGRITY_MODULESis enabled.
This is what "make modules_install" does. It uses existing private key and does not remove it after install.
Quoted 5 lines
I don't see why you
would overload a target or create two different ones when both depend on that option.Could you explain the reasoning behind that a bit more?
The reason for "signed_modules_install" is to limit existence of private key. Private key is generate just before install, modules installed and signed, then key is destroyed.
So existence of private key is limited to "time make signed_modules_install" execution time.
We had a debate about it, and strong message was that we might want to do it like that...
With the "modules_install", it will not generate new private key before install, but uses which is already in the directory.. And it will not remove the private key after install.
- Dmitry
Quoted 2 lines
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 5 lines · Dmitry
Quoted 5 lines
Quoted 4 lines
1.
signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)
Quoted 7 lines
Quoted 3 lines
This requires
CONFIG_INTEGRITY_MODULESto be enabled to actually do anything useful with the signed modules, correct?Correct. It does not make sense to sign module if module support is disabled. But there
scripts/genkey.shandksign.shwhich works without Makefiles. So possible to generate keys and sign a module...
Right, but it won't actually do anything if the config option isn't set. Which means someone calling 'make signed_modules_install' won't actually get signed modules. That's confusing.
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
2.
modules_install
WhenCONFIG_INTEGRITY_MODULESis enabled, this target uses an existing private key to sign kernel modules.If the answer to the above question is yes, then why can't we stick with a single
modules_installcommand for signing? It would seem to me that callingsigned_modules_installcould use an existing key or generate an ephemeral key in the absence of one and install the signed modules, andmodules_installwould simply install unsigned modules.
Quoted 5 lines
Quoted 2 lines
Or, alternatively, just make
modules_installsign or not sign depending on whetherCONFIG_INTEGRITY_MODULESis enabled.This is what "make
modules_install" does. It uses existing private key and does not remove it after install.
Right. I should have been more clear. I was suggesting that "make modules_install" generate a key as well if one does not already exist. Essentially removing the necessity for sign_modules_install.
Quoted 6 lines
Quoted 5 lines
I don't see why you
would overload a target or create two different ones when both depend on that option.Could you explain the reasoning behind that a bit more?
Quoted 8 lines
The reason for "
signed_modules_install" is to limit existence of private key. Private key is generate just before install, modules installed and signed, then key is destroyed.
So existence of private key is limited to "time makesigned_modules_install" execution time.We had a debate about it, and strong message was that we might want to do it like that...
I guess I personally don't see the need to destroy they key so quickly. Is the concern that an intruder might grab the key and use it to sign a module that the developer would then later on somehow load? Or similarly someone would grab a temporary key from a distro build machine? That limits the attack surface, sure, but I'm not sure it's really reasonable.
For a developer that isn't distributing kernels to others, it's just adding more time to the compile (which I know can be disabled, but still). For a distribution, most of them are either using a private key already or they have a buildsystem that destroys a buildroot after a build completes. The key is already going to be destroyed in that scenario.
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 11 lines · Josh Boyer
Quoted 9 lines · Dmitry
Quoted 8 lines
Quoted 4 lines
1.
signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)This requires
CONFIG_INTEGRITY_MODULESto be enabled to actually do anything useful with the signed modules, correct?
Quoted 8 lines
Quoted 3 lines
Correct. It does not make sense to sign module if module support is disabled. But there
scripts/genkey.shandksign.shwhich works without Makefiles. So possible to generate keys and sign a module...Right, but it won't actually do anything if the config option isn't set. Which means someone calling 'make
signed_modules_install' won't actually get signed modules. That's confusing.
Yes.. It had to be behind "ifeq CONFIG_INTEGRITY_MODULES"
Quoted 42 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
2.
modules_install
WhenCONFIG_INTEGRITY_MODULESis enabled, this target uses an existing private key to sign kernel modules.If the answer to the above question is yes, then why can't we stick with a single
modules_installcommand for signing? It would seem to me that callingsigned_modules_installcould use an existing key or generate an ephemeral key in the absence of one and install the signed modules, andmodules_installwould simply install unsigned modules.Quoted 5 lines
Quoted 2 lines
Or, alternatively, just make
modules_installsign or not sign depending on whetherCONFIG_INTEGRITY_MODULESis enabled.This is what "make
modules_install" does. It uses existing private key and does not remove it after install.Right. I should have been more clear. I was suggesting that "make
modules_install" generate a key as well if one does not already exist. Essentially removing the necessity forsign_modules_install.Quoted 6 lines
Quoted 5 lines
I don't see why you
would overload a target or create two different ones when both depend on that option.Could you explain the reasoning behind that a bit more?
Quoted 8 lines
The reason for "
signed_modules_install" is to limit existence of private key. Private key is generate just before install, modules installed and signed, then key is destroyed.
So existence of private key is limited to "time makesigned_modules_install" execution time.We had a debate about it, and strong message was that we might want to do it like that...
I guess I personally don't see the need to destroy they key so quickly. Is the concern that an intruder might grab the key and use it to sign a module that the developer would then later on somehow load? Or similarly someone would grab a temporary key from a distro build machine? That limits the attack surface, sure, but I'm not sure it's really reasonable.
Quoted 8 lines
For a developer that isn't distributing kernels to others, it's just adding more time to the compile (which I know can be disabled, but still). For a distribution, most of them are either using a private key already or they have a buildsystem that destroys a buildroot after a build completes. The key is already going to be destroyed in that scenario.
josh
Well... Will not argue here. I had similar opinion as well.
Mimi strongly wanted really to "reduce" the existence time of the key...
- Dmitry
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 72 lines · Dmitry
Quoted 11 lines · Josh Boyer
Quoted 9 lines · Dmitry
Quoted 8 lines
Quoted 4 lines
1.
signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)This requires
CONFIG_INTEGRITY_MODULESto be enabled to actually do anything useful with the signed modules, correct?Quoted 8 lines
Quoted 3 lines
Correct. It does not make sense to sign module if module support is disabled. But there
scripts/genkey.shandksign.shwhich works without Makefiles. So possible to generate keys and sign a module...Right, but it won't actually do anything if the config option isn't set. Which means someone calling 'make
signed_modules_install' won't actually get signed modules. That's confusing.Yes.. It had to be behind "ifeq
CONFIG_INTEGRITY_MODULES"Quoted 49 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
2.
modules_install
WhenCONFIG_INTEGRITY_MODULESis enabled, this target uses an existing private key to sign kernel modules.If the answer to the above question is yes, then why can't we stick with a single
modules_installcommand for signing? It would seem to me that callingsigned_modules_installcould use an existing key or generate an ephemeral key in the absence of one and install the signed modules, andmodules_installwould simply install unsigned modules.Quoted 5 lines
Quoted 2 lines
Or, alternatively, just make
modules_installsign or not sign depending on whetherCONFIG_INTEGRITY_MODULESis enabled.This is what "make
modules_install" does. It uses existing private key and does not remove it after install.Right. I should have been more clear. I was suggesting that "make
modules_install" generate a key as well if one does not already exist. Essentially removing the necessity forsign_modules_install.Quoted 6 lines
Quoted 5 lines
I don't see why you
would overload a target or create two different ones when both depend on that option.Could you explain the reasoning behind that a bit more?
Quoted 8 lines
The reason for "
signed_modules_install" is to limit existence of private key. Private key is generate just before install, modules installed and signed, then key is destroyed.
So existence of private key is limited to "time makesigned_modules_install" execution time.We had a debate about it, and strong message was that we might want to do it like that...
I guess I personally don't see the need to destroy they key so quickly. Is the concern that an intruder might grab the key and use it to sign a module that the developer would then later on somehow load? Or similarly someone would grab a temporary key from a distro build machine? That limits the attack surface, sure, but I'm not sure it's really reasonable.
For a developer that isn't distributing kernels to others, it's just adding more time to the compile (which I know can be disabled, but still). For a distribution, most of them are either using a private key already or they have a buildsystem that destroys a buildroot after a build completes. The key is already going to be destroyed in that scenario.
Quoted 5 lines
Quoted 1 line
josh
Well... Will not argue here. I had similar opinion as well.
Mimi strongly wanted really to "reduce" the existence time of the key...
The options are creating the key during 'make' or 'make modules_install'. If you create the key during 'make', then you have no way of knowing whether or not it is a persistent or ephemeral key, and whether it should be deleted after signing the modules.
You could create a persistent key using 'make genkey', before 'make', and never delete the private key. Then there wouldn't be any overhead. :) If 'CONFIG_INTEGRITY_MODULE' is configured, 'make modules_install' would use the existing key.
'make signed_modules_install' would be for creating and using ephemeral keys.
What do you think?
Mimi
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 25 lines · Mimi Zohar
Quoted 25 lines
Quoted 24 lines
Quoted 8 lines
The reason for "
signed_modules_install" is to limit existence of private key. Private key is generate just before install, modules installed and signed, then key is destroyed.
So existence of private key is limited to "time makesigned_modules_install" execution time.We had a debate about it, and strong message was that we might want to do it like that...
I guess I personally don't see the need to destroy they key so quickly. Is the concern that an intruder might grab the key and use it to sign a module that the developer would then later on somehow load? Or similarly someone would grab a temporary key from a distro build machine? That limits the attack surface, sure, but I'm not sure it's really reasonable.
For a developer that isn't distributing kernels to others, it's just adding more time to the compile (which I know can be disabled, but still). For a distribution, most of them are either using a private key already or they have a buildsystem that destroys a buildroot after a build completes. The key is already going to be destroyed in that scenario.
josh
Quoted 8 lines
Quoted 3 lines
Well... Will not argue here. I had similar opinion as well.
Mimi strongly wanted really to "reduce" the existence time of the key...
The options are creating the key during 'make' or 'make
modules_install'. If you create the key during 'make', then you have no way of knowing whether or not it is a persistent or ephemeral key, and whether it should be deleted after signing the modules.
The buildsystem doesn't really _need_ to know that though.
Quoted 9 lines
You could create a persistent key using 'make genkey', before 'make', and never delete the private key. Then there wouldn't be any overhead. :) If '
CONFIG_INTEGRITY_MODULE' is configured, 'makemodules_install' would use the existing key.'make
signed_modules_install' would be for creating and using ephemeral keys.What do you think?
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 45 lines · Josh Boyer
Quoted 25 lines · Mimi Zohar
Quoted 25 lines
Quoted 24 lines
Quoted 8 lines
The reason for "
signed_modules_install" is to limit existence of private key. Private key is generate just before install, modules installed and signed, then key is destroyed.
So existence of private key is limited to "time makesigned_modules_install" execution time.We had a debate about it, and strong message was that we might want to do it like that...
I guess I personally don't see the need to destroy they key so quickly. Is the concern that an intruder might grab the key and use it to sign a module that the developer would then later on somehow load? Or similarly someone would grab a temporary key from a distro build machine? That limits the attack surface, sure, but I'm not sure it's really reasonable.
For a developer that isn't distributing kernels to others, it's just adding more time to the compile (which I know can be disabled, but still). For a distribution, most of them are either using a private key already or they have a buildsystem that destroys a buildroot after a build completes. The key is already going to be destroyed in that scenario.
josh
Quoted 8 lines
Quoted 3 lines
Well... Will not argue here. I had similar opinion as well.
Mimi strongly wanted really to "reduce" the existence time of the key...
The options are creating the key during 'make' or 'make
modules_install'. If you create the key during 'make', then you have no way of knowing whether or not it is a persistent or ephemeral key, and whether it should be deleted after signing the modules.The buildsystem doesn't really _need_ to know that though.
Quoted 8 lines
You could create a persistent key using 'make genkey', before 'make', and never delete the private key. Then there wouldn't be any overhead. :) If '
CONFIG_INTEGRITY_MODULE' is configured, 'makemodules_install' would use the existing key.'make
signed_modules_install' would be for creating and using ephemeral keys.
Quoted 6 lines
Quoted 1 line
What do you think?
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
Ok. Other than generating a key the first time, the normal development build process now uses the same key, never requiring the developer to do anything additional. The developer controls the frequency the keys are created/deleted. I wonder how often that will be ...
Quoted 6 lines
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
Sorry, I disagree. Without the signed_modules_install target, the developer would need to do each step manually - create new key, sign modules, remove private key, and embed the new public key in the bzImage.
I still think the signed_modules_install script, renamed to something like ephemeral_signed_modules_install, is worthwhile and becomes a convience tool for the developer, wanting to use ephemeral keys. The private key, in Dmitry's updated patches soon to be posted, will be password protected with a random number, that is only accessible to the current shell.
thanks,
Mimi
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 9 lines · Mimi Zohar
Quoted 4 lines
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
Ok. Other than generating a key the first time, the normal development build process now uses the same key, never requiring the developer to do anything additional. The developer controls the frequency the keys are created/deleted. I wonder how often that will be ...
For a developer, probably not often. Though in reality, the usage of this by a single developer seems fair small. A much wider, already existing usage is distribution kernel signing.
For a distribution kernel there are normally two cases:
1) Existing permanent company/distro key. This is already handled.
2) per-kernel-build key (equivalent to your ephemeral key). This would be handled fine if the key was generated if it didn't already exist and left alone. The distro build system would remove it when it cleaned up the buildroot.
Quoted 11 lines
Quoted 6 lines
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
Sorry, I disagree. Without the
signed_modules_installtarget, the developer would need to do each step manually - create new key, sign modules, remove private key, and embed the new public key in the bzImage.
Not if the buildsystem just made the key for them at 'make' time. I'm still missing why it isn't done until 'modules_install' time. Seems pretty sub-optimal.
Quoted 6 lines
I still think the
signed_modules_installscript, renamed to something likeephemeral_signed_modules_install, is worthwhile and becomes a convience tool for the developer, wanting to use ephemeral keys. The private key, in Dmitry's updated patches soon to be posted, will be password protected with a random number, that is only accessible to the current shell.
I think the existence of an additional make target for signed modules is really confusing. Particularly when you consider the target still exists even if the kernel isn't setup to work with signed modules. If the config options are set, just have 'make modules_install' do it and create a key if one doesn't exist (or better yet, have 'make' do it).
Also... password protecting the key that only responds to the current shell really sounds like a show-stopper for this being used by distros. There is no way a distro is going to be able to type a password in during a kernel build. It completely removes the usability of distros that want to use a per-kernel build ephemeral key. If you're going to do this, please wrap it in a kconfig option so the second distro case I mentio above is still possible.
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 13 lines · Josh Boyer
Quoted 6 lines
I still think the
signed_modules_installscript, renamed to something likeephemeral_signed_modules_install, is worthwhile and becomes a convience tool for the developer, wanting to use ephemeral keys. The private key, in Dmitry's updated patches soon to be posted, will be password protected with a random number, that is only accessible to the current shell.I think the existence of an additional make target for signed modules is really confusing. Particularly when you consider the target still exists even if the kernel isn't setup to work with signed modules. If the config options are set, just have 'make
modules_install' do it and create a key if one doesn't exist (or better yet, have 'make' do it).
Quoted 7 lines
Also... password protecting the key that only responds to the current shell really sounds like a show-stopper for this being used by distros. There is no way a distro is going to be able to type a password in during a kernel build. It completely removes the usability of distros that want to use a per-kernel build ephemeral key. If you're going to do this, please wrap it in a kconfig option so the second distro case I mentio above is still possible.
Here's a suggestion that might help the discussion. In the next revision of the patch set, include a document in Documentation/ that covers the module signing design, the purposes it's intended to fit, and a high level description of the various module loading scenarios (signed, unsigned, signed with a key not in the keyring, etc). That way we can at least see at a higher level what the thinking behind the implemenation is. I think some of our back and forth (while good!) is because we see signed modules being used for different purposes.
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
In reply to Josh BoyerQuoted 6 lines · Josh Boyer
Quoted 5 lines · Mimi Zohar
Quoted 4 lines
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
Quoted 8 lines
Quoted 4 lines
Ok. Other than generating a key the first time, the normal development build process now uses the same key, never requiring the developer to do anything additional. The developer controls the frequency the keys are created/deleted. I wonder how often that will be ...
For a developer, probably not often. Though in reality, the usage of this by a single developer seems fair small. A much wider, already existing usage is distribution kernel signing.
This seems to be the real issue. Do developers need to sign their own
builds? Nobody is forcing the developer to enable signed modules. If,
however, the developer decides to enforce signed modules, leaving the private key lying around kind of defeats the purpose.
Quoted 7 lines
For a distribution kernel there are normally two cases:
1) Existing permanent company/distro key. This is already handled.
2) per-kernel-build key (equivalent to your ephemeral key). This would be handled fine if the key was generated if it didn't already exist and left alone. The distro build system would remove it when it cleaned up the buildroot.
Ok, I think we agree here, with the normal 'make', 'make modules_install install', using an existing key or creating a new key if needed.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
Quoted 8 lines
Quoted 4 lines
Sorry, I disagree. Without the
signed_modules_installtarget, the developer would need to do each step manually - create new key, sign modules, remove private key, and embed the new public key in the bzImage.Not if the buildsystem just made the key for them at 'make' time. I'm still missing why it isn't done until '
modules_install' time. Seems pretty sub-optimal.
Using a private key that has been lying around for an unknown period of time, kind of defeats the purpose.
Quoted 10 lines
Quoted 6 lines
I still think the
signed_modules_installscript, renamed to something likeephemeral_signed_modules_install, is worthwhile and becomes a convience tool for the developer, wanting to use ephemeral keys. The private key, in Dmitry's updated patches soon to be posted, will be password protected with a random number, that is only accessible to the current shell.I think the existence of an additional make target for signed modules is really confusing. Particularly when you consider the target still exists even if the kernel isn't setup to work with signed modules.
Ok, I see your concern.
Quoted 3 lines
If
the config options are set, just have 'makemodules_install' do it and create a key if one doesn't exist (or better yet, have 'make' do it).
If creating the key is deferred to 'make modules_install', for the reason given above or any other reason, the public key wasn't available at the time the bzImage was created. 'make modules_install' would now need to rebuild the bzImage.
thanks,
Mimi
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 12 lines · Mimi Zohar
Quoted 11 lines · Josh Boyer
Quoted 9 lines · Mimi Zohar
Quoted 4 lines
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
Ok. Other than generating a key the first time, the normal development build process now uses the same key, never requiring the developer to do anything additional. The developer controls the frequency the keys are created/deleted. I wonder how often that will be ...
Quoted 8 lines
Quoted 3 lines
For a developer, probably not often. Though in reality, the usage of this by a single developer seems fair small. A much wider, already existing usage is distribution kernel signing.
This seems to be the real issue. Do developers need to sign their own
builds? Nobody is forcing the developer to enable signed modules. If,
however, the developer decides to enforce signed modules, leaving the private key lying around kind of defeats the purpose.
Right. The issue is that you're making the kernel buildsystem do key management policy instead of trusting the developers using the keys mechanism to know what they're doing.
Quoted 23 lines
Quoted 7 lines
For a distribution kernel there are normally two cases:
1) Existing permanent company/distro key. This is already handled.
2) per-kernel-build key (equivalent to your ephemeral key). This would be handled fine if the key was generated if it didn't already exist and left alone. The distro build system would remove it when it cleaned up the buildroot.Ok, I think we agree here, with the normal 'make', 'make
modules_installinstall', using an existing key or creating a new key if needed.Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
Sorry, I disagree. Without the
signed_modules_installtarget, the developer would need to do each step manually - create new key, sign modules, remove private key, and embed the new public key in the bzImage.
Quoted 6 lines
Quoted 3 lines
Not if the buildsystem just made the key for them at 'make' time. I'm still missing why it isn't done until '
modules_install' time. Seems pretty sub-optimal.Using a private key that has been lying around for an unknown period of time, kind of defeats the purpose.
Why is that? Again, you're enforcing policy instead of leaving it up to the developers. In the existing key case, you have no idea how long that key has been sitting around either, so I really see a disconnect between "existing company/private key" and "no key, create one for them during build time" cases.
Quoted 13 lines
Quoted 10 lines
Quoted 6 lines
I still think the
signed_modules_installscript, renamed to something likeephemeral_signed_modules_install, is worthwhile and becomes a convience tool for the developer, wanting to use ephemeral keys. The private key, in Dmitry's updated patches soon to be posted, will be password protected with a random number, that is only accessible to the current shell.I think the existence of an additional make target for signed modules is really confusing. Particularly when you consider the target still exists even if the kernel isn't setup to work with signed modules.
Ok, I see your concern.
Quoted 8 lines
Quoted 3 lines
If
the config options are set, just have 'makemodules_install' do it and create a key if one doesn't exist (or better yet, have 'make' do it).If creating the key is deferred to 'make
modules_install', for the reason given above or any other reason, the public key wasn't available at the time the bzImage was created. 'makemodules_install' would now need to rebuild the bzImage.
Right, which is an utter pain and backwards. That's why I suggested it be done at 'make' time.
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 53 lines · Josh Boyer
Quoted 12 lines · Mimi Zohar
Quoted 11 lines · Josh Boyer
Quoted 9 lines · Mimi Zohar
Quoted 4 lines
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
Ok. Other than generating a key the first time, the normal development build process now uses the same key, never requiring the developer to do anything additional. The developer controls the frequency the keys are created/deleted. I wonder how often that will be ...
Quoted 8 lines
Quoted 3 lines
For a developer, probably not often. Though in reality, the usage of this by a single developer seems fair small. A much wider, already existing usage is distribution kernel signing.
This seems to be the real issue. Do developers need to sign their own
builds? Nobody is forcing the developer to enable signed modules. If,
however, the developer decides to enforce signed modules, leaving the private key lying around kind of defeats the purpose.Right. The issue is that you're making the kernel buildsystem do key management policy instead of trusting the developers using the keys mechanism to know what they're doing.
Quoted 27 lines
Quoted 7 lines
For a distribution kernel there are normally two cases:
1) Existing permanent company/distro key. This is already handled.
2) per-kernel-build key (equivalent to your ephemeral key). This would be handled fine if the key was generated if it didn't already exist and left alone. The distro build system would remove it when it cleaned up the buildroot.Ok, I think we agree here, with the normal 'make', 'make
modules_installinstall', using an existing key or creating a new key if needed.Quoted 15 lines
Quoted 11 lines
Quoted 6 lines
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
Sorry, I disagree. Without the
signed_modules_installtarget, the developer would need to do each step manually - create new key, sign modules, remove private key, and embed the new public key in the bzImage.Not if the buildsystem just made the key for them at 'make' time. I'm still missing why it isn't done until '
modules_install' time. Seems pretty sub-optimal.
Quoted 8 lines
Quoted 2 lines
Using a private key that has been lying around for an unknown period of time, kind of defeats the purpose.
Why is that? Again, you're enforcing policy instead of leaving it up to the developers. In the existing key case, you have no idea how long that key has been sitting around either, so I really see a disconnect between "existing company/private key" and "no key, create one for them during build time" cases.
Either the company build process, creates and cleans up after the build, removing the private key, as you described above, or the "private key" is held securely using an existing signing process (or some combination of the two).
In the "no key, create one for them during build time", there is no process in place cleaning up, other than the suggested new make target.
Quoted 17 lines
Quoted 17 lines
Quoted 10 lines
Quoted 6 lines
I still think the
signed_modules_installscript, renamed to something likeephemeral_signed_modules_install, is worthwhile and becomes a convience tool for the developer, wanting to use ephemeral keys. The private key, in Dmitry's updated patches soon to be posted, will be password protected with a random number, that is only accessible to the current shell.I think the existence of an additional make target for signed modules is really confusing. Particularly when you consider the target still exists even if the kernel isn't setup to work with signed modules.
Ok, I see your concern.
Quoted 3 lines
If
the config options are set, just have 'makemodules_install' do it and create a key if one doesn't exist (or better yet, have 'make' do it).
Quoted 7 lines
Quoted 4 lines
If creating the key is deferred to 'make
modules_install', for the reason given above or any other reason, the public key wasn't available at the time the bzImage was created. 'makemodules_install' would now need to rebuild the bzImage.Right, which is an utter pain and backwards. That's why I suggested it be done at 'make' time.
Agreed, no doubt about it being a pain or backwards, but the solution isn't to deny the problem, but to address it. I'm open to suggestions. :)
Mimi
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
Quoted 63 lines · Mimi Zohar
Quoted 53 lines · Josh Boyer
Quoted 12 lines · Mimi Zohar
Quoted 11 lines · Josh Boyer
Quoted 9 lines · Mimi Zohar
Quoted 4 lines
I don't see a need for the kernel make system to ever delete a key. If one doesn't exist, it should create one if the config options are set and leave it alone entirely after that. If one exists already, then it should leave it alone as it already does.
Ok. Other than generating a key the first time, the normal development build process now uses the same key, never requiring the developer to do anything additional. The developer controls the frequency the keys are created/deleted. I wonder how often that will be ...
Quoted 8 lines
Quoted 3 lines
For a developer, probably not often. Though in reality, the usage of this by a single developer seems fair small. A much wider, already existing usage is distribution kernel signing.
This seems to be the real issue. Do developers need to sign their own
builds? Nobody is forcing the developer to enable signed modules. If,
however, the developer decides to enforce signed modules, leaving the private key lying around kind of defeats the purpose.Right. The issue is that you're making the kernel buildsystem do key management policy instead of trusting the developers using the keys mechanism to know what they're doing.
Quoted 27 lines
Quoted 7 lines
For a distribution kernel there are normally two cases:
1) Existing permanent company/distro key. This is already handled.
2) per-kernel-build key (equivalent to your ephemeral key). This would be handled fine if the key was generated if it didn't already exist and left alone. The distro build system would remove it when it cleaned up the buildroot.Ok, I think we agree here, with the normal 'make', 'make
modules_installinstall', using an existing key or creating a new key if needed.Quoted 15 lines
Quoted 11 lines
Quoted 6 lines
If you really want to enforce ephemeral keys in the make system, then doing it via 'make clean' or 'make distclean' would make more sense to me. But I personally think key management is something the developers or distros should be handling on their own. Creating a key for them is a convenience so it's worthwhile, but removing it should be done by them.
Sorry, I disagree. Without the
signed_modules_installtarget, the developer would need to do each step manually - create new key, sign modules, remove private key, and embed the new public key in the bzImage.Not if the buildsystem just made the key for them at 'make' time. I'm still missing why it isn't done until '
modules_install' time. Seems pretty sub-optimal.Quoted 8 lines
Quoted 2 lines
Using a private key that has been lying around for an unknown period of time, kind of defeats the purpose.
Why is that? Again, you're enforcing policy instead of leaving it up to the developers. In the existing key case, you have no idea how long that key has been sitting around either, so I really see a disconnect between "existing company/private key" and "no key, create one for them during build time" cases.
Quoted 7 lines
Either the company build process, creates and cleans up after the build, removing the private key, as you described above, or the "private key" is held securely using an existing signing process (or some combination of the two).
In the "no key, create one for them during build time", there is no process in place cleaning up, other than the suggested new make target.
You could have 'make clean/distclean' remove the key if you really wanted.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
If
the config options are set, just have 'makemodules_install' do it and create a key if one doesn't exist (or better yet, have 'make' do it).If creating the key is deferred to 'make
modules_install', for the reason given above or any other reason, the public key wasn't available at the time the bzImage was created. 'makemodules_install' would now need to rebuild the bzImage.
Quoted 6 lines
Quoted 2 lines
Right, which is an utter pain and backwards. That's why I suggested it be done at 'make' time.
Agreed, no doubt about it being a pain or backwards, but the solution isn't to deny the problem, but to address it. I'm open to suggestions. :)
I've made multiple suggestions. I have no more. Either you agree with them or your don't. Our fundamental disagreement is the management of automatically created keys. You want them removed ASAP, I suggest that people/companies/distributions using that mechanism should be aware of what they're doing and be responsible for removing keys when they see fit. Aside from making the behavior dependent on perhaps some kind of "expert" config setting, I don't see a way past that difference.
josh
Re: [RFC v2 7/7] modsig: build rules and scripts to generate keys and sign modules
In reply to Josh BoyerQuoted 31 lines · Josh Boyer
Quoted 7 lines · Dmitry Kasatkin
This patch adds build rules and scripts to generate keys and sign modules.
Two scripts has been added.
genkey.shis used to generate private and public keys.ksign.shis used to sign kernel modules. Both scripts use only standard utilites from coreutils and additionally requires openssl tool for RSA keys creation and signing.Quoted 7 lines
The patch modifies '
modules_install' target and adds two new targets to the main kernelMakefile.1.
signed_modules_install
This target creates an ephemeral key pair, signs the kernel modules with the private key, destroys the private key, and embeds the public key in the kernel. (Thanks to Dave Hansen for the target name.)This requires
CONFIG_INTEGRITY_MODULESto be enabled to actually do anything useful with the signed modules, correct?Quoted 4 lines
2.
modules_install
WhenCONFIG_INTEGRITY_MODULESis enabled, this target uses an existing private key to sign kernel modules.If the answer to the above question is yes, then why can't we stick with a single
modules_installcommand for signing? It would seem to me that callingsigned_modules_installcould use an existing key or generate an ephemeral key in the absence of one and install the signed modules, andmodules_installwould simply install unsigned modules.
Quoted 6 lines
Or, alternatively, just make
modules_installsign or not sign depending on whetherCONFIG_INTEGRITY_MODULESis enabled. I don't see why you would overload a target or create two different ones when both depend on that option.Could you explain the reasoning behind that a bit more?
If the key exists during the build, there is no need for the additional 'make bzImage'. I'll update the patch description based on the following explaination taken from the cover letter:
For the developer, these patches create an ephemeral key during module install, in order to limit the duration of the private key's existence. Unfortunately, this necessitates embedding the public key in the kernel, after the kernel has already been built. A new make target called 'signed_modules_install', creates the keypair, signs the modules, removes the private key, and then, for now, recompiles the kernel using 'make bzImage'. For the developer, instead of doing 'make modules_install', the new build process would be 'make', followed by 'make signed_modules_install' and 'make install'.
thanks,
Mimi