firmware: add PKCS#7 firmware signature support
Subsystems (5)
v2 cover firmware: add PKCS#7 firmware signature support
From: "Luis R. Rodriguez" <[email protected]>
Upon review of the v1 series David Howells requested I re-work the code on top of his PKCS#7 branch [1] which moves module signing to support and use PKCS#7. This v2 series is based on top of that branch. Other than David's own changes this series depends on some other changes Rusty has taken in already but not yet visible on linux-next:
kernel/params: constify struct kernel_param_ops uses kernel/module.c: use generic module param operaters for sig_enforce kernel/params.c: generalize bool_enable_onlymoduleparam.h: add module_param_config_*() helpers kernel/workqueue.c: remove ifdefs over wq_power_efficient kernel/workqueue.c: use module_param_config_on_off() for power_efficient kernel/module.c: avoid ifdefs for sig_enforce declaration kernel/params.c: export param_ops_bool_enable_only
This series also depends on the fixes recently posted for the firmware_class driver:
firmware: fix __getname() missing failure check
firmware: check for file truncation on direct firmware loading
firmware: fix possible use after free on name on asynchronous request
firmware: use const for remaining firmware names
Since that is quite a bit of delta, if folks want to help test / review this on a tree, you can use this tree with the fw-signing-v2-20150513 branch:
https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux.git/
This v2 modifies the way we do firmware signature checking from the v1 RFCs by using separate detached files for the signatures of the firmware files, as suggested by David. If you have foo.bin, you'll need foo.bin.pkcs7 present when firmware signature checks are enabled.
Since it is based on David's modsign-pkcs7 branch and since these are not yet upstream I think its best if David took what he can as part of his series and squashed commits when and where possible. For instance the sign-file.c changes can likely be squashed. Patch 2, which generalizes module signing as system data signing is based on David's own series, in my previous series I addressed code in place upstream which lacked PKCS#7 support, I'll leave it up to David to decide if / when to merge this into his series but I think that if this is reasonable it can go in prior to addition of PKCS#7 support, in which case my v1 patch can be used. Otherwise this v2 will need to be used. Also, patch 2 in this v2 series changes the config SYSDATA_SIG to def_bool n as noted by Paul Bolle.
Patch 3 simply has the commit log massaged to account for the discussions on the recursive issue it tries to fix. Based on discussions the recursive issue reported by the code is real [2], however since FW_LOADER is an EXPERT option it is reasonable to make this change anyway. A change for now seems reasonable.
Lastly, we'll need to export data_verify_pkcs7() as we are dealing with a split between that data and signature. The last patch adds firmware signature support. I like to think it works as expected, with a simple requirement to have you sign-file -s the binaries. As with module signing there are 3 modes of operation with firmware signature support:
a) signature disabled
b) signature enabled - but permissive - we'll let things slide if not signed
c) signature enforced - firmware not signed will not be allowed
In the permissive case though the only difference from the module signing code / logic is that we *do not* taint the kernel. The reason for this is technical. First of all add_taint_module() is not exported, are we OK to export it? If not what users do we wish to grant access to it? If we wish to provide a mechanism by which we can have a say in that the old module namespace work by Andi Kleen comes to mind as useful for that [3]. If we're OK with wide access to add_taint_kernel() as an exported symbol there are yet other technical questions to address, add_taint_kernel() requires a module passed and only *one* of the 3 request_firmware*() APIs peg the correct module caller of the API onto firmware_class, the others use the firmware_class struct module.
We have a few options then:
1) Extend the firmware_class driver API to require the correct module to always be set. Doing this IMHO is worthy, but its not just worthy for firmware signing tainting, it may come in handy in the future. There's an issue with extending the firmware_class APIs though which make me nervous about just doing this change even if we wanted this alone for firmware signature checks -- the firmware_class APIs keep being extended requiring collateral evolutions which IMHO can be avoided if we sat and thought about a decent API which can be grown for our requirements.
2) Use add_taint_module() with the firmware_class module for the two synchrounous APIs, while using the right module for the async call.
3) Use the firmware_class module for all 3 API calls when using add_taint_module()
4) Skip tainting the kernel for unsigned firmware files
The approach I've decided to take here is a combination of 4) and 1). I've decided that extending the firmware_class API even more is not a good idea anymore. Part of this is because I have some other uses cases for firmware_class's use and having the right module is not the only thing I'd want to extend firmware_class with support for. I address a spring cleaning of the firmware_class API in my next series, while also enabling passing the right module always, and enabling use of tainting. I think its best to leave the old APIs as-is then, and only if folks really require a shift to taint they can then consider the new APIs. If we *really* want to taint the kernel even for the old APIs I recommend just dealing with using the firmware_class (THIS_MODULE) for now -- I don't think making the taint specific to a module for firmware is worth the collateral evolutions required using and extending the old APIs.
The new extensible firmware_class APIs go in my next series, that enables tainting the specific caller module, among other things, as you'll see.
[0] https://lkml.org/lkml/2015/5/5/1345
[1] http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=modsign-pkcs7
[2] https://lkml.org/lkml/2015/5/5/1353
[3] https://backports.wiki.kernel.org/index.php/Documentation/backports/hacking/todo#Module_namespaces
Luis R. Rodriguez (6):
firmware: generalize reading file contents as a helper
kernel: generalize module signing as system data signing
crypto: qat - address recursive dependency when fw signing is enabled scripts/sign-file.c: add support to only create signature file kernel/sysdata_signing: export data_verify_pkcs7()
firmware: add firmware signature checking support
Documentation/firmware_class/signing.txt | 88 ++++++++
drivers/base/Kconfig | 18 ++
drivers/base/firmware_class.c | 237 ++++++++++++++++++++-
drivers/crypto/qat/Kconfig | 2 +-
.../module-internal.h => include/linux/sysdata.h | 6 +-
init/Kconfig | 24 ++-
kernel/Makefile | 2 +-
kernel/module.c | 4 +-
kernel/{module_signing.c => sysdata_signing.c} | 60 +++---
kernel/system_keyring.c | 2 +-
scripts/sign-file.c | 17 +-
11 files changed, 399 insertions(+), 61 deletions(-)
create mode 100644 Documentation/firmware_class/signing.txt
rename kernel/module-internal.h => include/linux/sysdata.h (64%)
rename kernel/{module_signing.c => sysdata_signing.c} (63%)Signature · 1 line
2.3.2.209.gd67f9d5.dirty
RFC v2 1/6 firmware: generalize reading file contents as a helper
From: "Luis R. Rodriguez" <[email protected]>
We'll want to reuse this same code later in order to read two separate types of file contents. Although we can simplify fw_read_file_contents() to do a direct return we leave a bit of boilerplate code to make the next changes easier to review. In this case we'll later extend the firmware specific read to also go and fetch the signature file when required.
This commit introduces no functional changes.
--- drivers/base/firmware_class.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/base/firmware_class.c +20 -3
@@ -291,7 +291,8 @@ static const char * const fw_path[] = {module_param_string (path, fw_path_para,sizeof (fw_path_para),0644 );MODULE_PARM_DESC (path,"customized firmware image search path with a higher priority than default path" ); -static int fw_read_file_contents (struct file *file,struct firmware_buf *fw_buf) +static int __read_file_contents (struct file *file, +void **dest_buf,size_t *dest_size) {int size;char *buf;
@@ -314,14 +315,30 @@ static int fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf) rc =security_kernel_fw_from_file (file, buf, size);if (rc) goto fail; - fw_buf->data = buf; - fw_buf->size = size; + + *dest_buf = buf; + *dest_size = size; +return 0 ; fail:vfree (buf);return rc; } +static int fw_read_file_contents (struct file *file, +struct firmware_buf *fw_buf) +{ +int rc; + + rc =__read_file_contents (file, + &fw_buf->data, + &fw_buf->size); +if (rc) +return rc; + +return 0 ; +} +static int fw_get_filesystem_firmware (struct device *device,struct firmware_buf *buf) {
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
RFC v2 2/6 kernel: generalize module signing as system data signing
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This generalizes the module signing code as helpers, we do this as we'll later re-use this same code for firmware and other system data signing.
---
init/Kconfig | 24 ++++++----
kernel/Makefile | 2 +-
kernel/module.c | 4 +-
kernel/{module-internal.h => sysdata-internal.h} | 4 +-
kernel/{module_signing.c => sysdata_signing.c} | 58 ++++++++++++------------
kernel/system_keyring.c | 2 +-
6 files changed, 49 insertions(+), 45 deletions(-)
rename kernel/{module-internal.h => sysdata-internal.h} (79%)
rename kernel/{module_signing.c => sysdata_signing.c} (64%)init/Kconfig +14 -10
@@ -1793,6 +1793,19 @@ config BASE_SMALL default 0 if BASE_FULL default 1 if !BASE_FULL +config SYSDATA_SIG + def_bool n + select SYSTEM_TRUSTED_KEYRING + select KEYS + select CRYPTO + select ASYMMETRIC_KEY_TYPE + select ASYMMETRIC_PUBLIC_KEY_SUBTYPE + select PUBLIC_KEY_ALGO_RSA + select ASN1 + select OID_REGISTRY + select X509_CERTIFICATE_PARSER + select PKCS7_MESSAGE_PARSER + menuconfig MODULES bool "Enable loadable module support" option modules
@@ -1866,16 +1879,7 @@ config MODULE_SRCVERSION_ALL config MODULE_SIG bool "Module signature verification" depends on MODULES - select SYSTEM_TRUSTED_KEYRING - select KEYS - select CRYPTO - select ASYMMETRIC_KEY_TYPE - select ASYMMETRIC_PUBLIC_KEY_SUBTYPE - select PUBLIC_KEY_ALGO_RSA - select ASN1 - select OID_REGISTRY - select X509_CERTIFICATE_PARSER - select PKCS7_MESSAGE_PARSER + select SYSDATA_SIG help Check modules for valid signatures upon load: the signature is simply appended to the module. For more information see
kernel/Makefile +1 -1
@@ -47,7 +47,7 @@ endif obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o obj-$(CONFIG_MODULES) += module.o -obj-$(CONFIG_MODULE_SIG) += module_signing.o +obj-$(CONFIG_SYSDATA_SIG) += sysdata_signing.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o
kernel/module.c +2 -2
@@ -60,7 +60,7 @@#include <linux/pfn.h> #include <linux/bsearch.h> #include <uapi/linux/module.h> -#include "module-internal.h" +#include "sysdata-internal.h" #define CREATE_TRACE_POINTS #include <trace/events/module.h>
@@ -2404,7 +2404,7 @@ static int module_sig_check(struct load_info *info) memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {/* We truncate the module to discard the signature */ info->len -= markerlen; - err =mod_verify_sig (mod, &info->len); + err =sysdata_verify_sig (mod, &info->len); }if (!err) {
kernel/sysdata-internal.h renamed from kernel/module-internal.h +2 -2
@@ -1,4 +1,4 @@ -/* Module internals +/* System Data internals * * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
@@ -9,4 +9,4 @@* 2 of the Licence, or (at your option) any later version. */ -extern int mod_verify_sig (const void *mod,unsigned long *_modlen); +extern int sysdata_verify_sig (const void *data,unsigned long *_len);
kernel/sysdata_signing.c renamed from kernel/module_signing.c +29 -29
109 lines not on this page · raw message
kernel/system_keyring.c +1 -1
@@ -16,7 +16,7 @@#include <linux/err.h> #include <keys/asymmetric-type.h> #include <keys/system_keyring.h> -#include "module-internal.h" +#include "sysdata-internal.h" struct key *system_trusted_keyring;EXPORT_SYMBOL_GPL (system_trusted_keyring);
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
RFC v2 3/6 crypto: qat - address recursive dependency when fw signing is enabled
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We're going to add firmware module signing support, but when we do this we end up with the following recursive dependency. Fix this by just depending on FW_LOADER, which is typically always enabled anyway. We do this as a compromise for now as FW_LOADER is only selectable when EXPERT is enabled and the recursive dependency issue below is actually real and valid, its proper fix however requires a bit of work.
This technically means this change is likely welcomed for other parts of the kernel but this is really only needed for now here.
mcgrof@ergon ~/linux-next (git::master)$ make allnoconfig scripts/kconfig/conf --allnoconfig Kconfig crypto/Kconfig:15:error: recursive dependency detected!crypto/Kconfig:15: symbol CRYPTO is selected by SYSDATA_SIG
init/Kconfig:1880: symbol SYSDATA_SIG is selected by FIRMWARE_SIG
drivers/base/Kconfig:88: symbol FIRMWARE_SIG depends on FW_LOADER drivers/base/Kconfig:80: symbol FW_LOADER is selected by CRYPTO_DEV_QAT drivers/crypto/qat/Kconfig:1: symbol CRYPTO_DEV_QAT is selected by CRYPTO_DEV_QAT_DH895xCC drivers/crypto/qat/Kconfig:13: symbol CRYPTO_DEV_QAT_DH895xCC depends on CRYPTO
--- drivers/crypto/qat/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/qat/Kconfig +1 -1
@@ -8,7 +8,7 @@ config CRYPTO_DEV_QAT select CRYPTO_SHA1 select CRYPTO_SHA256 select CRYPTO_SHA512 - select FW_LOADER + depends on FW_LOADER config CRYPTO_DEV_QAT_DH895xCC tristate "Support for Intel(R) DH895xCC"
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
RFC v2 4/6 scripts/sign-file.c: add support to only create signature file
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
You can create a file.pkcs7 file with the -d option right now but that still modifies the file. If all you want is the signature file you can use -s now, that will leave the file passed as-is.
This will be useful when firmware signature support is added upstream as firmware will be left intact, and we'll only require the signature file. The descriptor is implicit by file extension and the file's own size.
--- scripts/sign-file.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
scripts/sign-file.c +12 -5
@@ -41,7 +41,7 @@ static __attribute__((noreturn))void format (void ) {fprintf (stderr, -"Usage: scripts/sign-file [-dp] <hash algo> <key> <x509> <module> [<dest>]\n" ); +"Usage: scripts/sign-file [-dps] <hash algo> <key> <x509> <module> [<dest>]\n" );exit (2 ); }
@@ -86,22 +86,24 @@ int main(int argc, char **argv)char *hash_algo =NULL ;char *private_key_name, *x509_name, *module_name, *dest_name;bool save_pkcs7 = false, replace_orig; +bool sign_only = false;unsigned char buf[4096 ];unsigned long module_size, pkcs7_size;const EVP_MD *digest_algo;EVP_PKEY *private_key;PKCS7 *pkcs7;X509 *x509; -BIO *b, *bd, *bm; +BIO *b, *bd=NULL , *bm;int opt, n;ERR_load_crypto_strings ();ERR_clear_error (); do { - opt = getopt(argc, argv, "dp"); + opt = getopt(argc, argv, "dps"); switch (opt) { case 'p': save_pkcs7 = true; break; + case 's': sign_only = true; save_pkcs7 = true; break; case -1: break; default: format(); }
@@ -148,8 +150,10 @@ int main(int argc, char **argv)/* Open the destination file now so that we can shovel the module data * across as we read it. */ - bd =BIO_new_file (dest_name,"wb" ); -ERR (!bd,"%s" , dest_name); +if (!sign_only) { + bd =BIO_new_file (dest_name,"wb" ); +ERR (!bd,"%s" , dest_name); + }/* Digest the module data. */ OpenSSL_add_all_digests ();
@@ -180,6 +184,9 @@ int main(int argc, char **argv)BIO_free (b); } +if (sign_only) +return 0 ; +/* Append the marker and the PKCS#7 message to the destination file */ ERR (BIO_reset (bm) <0 ,"%s" , module_name); while ((n = BIO_read(bm, buf, sizeof(buf))),
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
RFC v2 5/6 kernel/sysdata_signing: export data_verify_pkcs7()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This will be used for firmware signature check support.
--- kernel/sysdata-internal.h | 2 ++ kernel/sysdata_signing.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/sysdata-internal.h +2 -0
@@ -10,3 +10,5 @@*/ extern int sysdata_verify_sig (const void *data,unsigned long *_len); +int data_verify_pkcs7 (const void *data,unsigned long len, +const void *raw_pkcs7,size_t pkcs7_len);
kernel/sysdata_signing.c +3 -2
@@ -39,8 +39,8 @@ struct sysdata_signature {/* * Verify a PKCS#7-based signature on system data. */ -static int data_verify_pkcs7 (const void *data,unsigned long len, -const void *raw_pkcs7,size_t pkcs7_len) +int data_verify_pkcs7 (const void *data,unsigned long len, +const void *raw_pkcs7,size_t pkcs7_len) {struct pkcs7_message *pkcs7;bool trusted;
@@ -75,6 +75,7 @@ error:pr_devel ("<==%s() = %d\n" , __func__, ret);return ret; } +EXPORT_SYMBOL_GPL (data_verify_pkcs7);/* * Verify the signature on system data.
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
RFC v2 6/6 firmware: add firmware signature checking support
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Systems that have module signing currently enabled may wish to extend vetting of firmware passed to the kernel as well. We can re-use most of the code for module signing for firmware signature verification and signing. This will also later enable re-use of this same code for subsystems that wish to provide their own cryptographic verification mechanisms on userspace data needed.
As with module signing, we do a very simple search for a particular string appended to the firmware. There's both a config option and a boot parameter which control whether we accept or fail with unsigned firmware and firmware that are signed with an unknown key.
If firmware signing is enabled, the kernel will be tainted if a firmware is loaded that is unsigned or has a signature for which we don't have the key.
--- Documentation/firmware_class/signing.txt | 88 +++++++++ drivers/base/Kconfig | 18 ++ drivers/base/firmware_class.c | 214 ++++++++++++++++++++- .../sysdata-internal.h => include/linux/sysdata.h | 0 kernel/module.c | 2 +- kernel/sysdata_signing.c | 3 +- kernel/system_keyring.c | 2 +- 7 files changed, 317 insertions(+), 10 deletions(-) create mode 100644 Documentation/firmware_class/signing.txt rename kernel/sysdata-internal.h => include/linux/sysdata.h (100%)
Documentation/firmware_class/signing.txt new file +88 -0
@@ -0,0 +1,88 @@ + ================================ + KERNEL FIRMWARE SIGNING FACILITY + ================================ + +CONTENTS + + - Overview. + - Configuring firmware signing. + - Using signing keys. + - Signing firmware files. + + +======== +OVERVIEW +======== + +Device drivers which require a firmware to be uploaded onto a device as its own +device's microcode use any of the following APIs: + + * request_firmware() + * request_firmware_direct() + * request_firmware_nowait() + +The kernel firmware signing facility enables to cryptographically sign +firmware files on a system using the same keys used for module signing. +Firmware files's signatures consist of PKCS#7 messages of the respective +firmware file. A firmware file named foo.bin, would have its respective +signature on the filesystem as foo.bin.pkcs7. When firmware signature +checking is enabled (FIRMWARE_SIG) when one of the above APIs is used +against foo.bin, the file foo.bin.pkcs7 will also be looked for. If +FIRMWARE_SIG_FORCE is enabled the foo.bin file will only be allowed to +be returned to callers of the above APIs if and only if the foo.bin.pkcs7 +file is confirmed to be a valid signature of the foo.bin file. If +FIRMWARE_SIG_FORCE is not enabled and only FIRMWARE_SIG is enabled the +kernel will be permissive and enabled unsiged firmware files, or firmware +files with incorrect signatures. If FIRMWARE_SIG is not enabled the +signature file is ignored completely. + +Firmware signing increases security by making it harder to load a malicious +firmware into the kernel. The firmware signature checking is done by the +kernel so that it is not necessary to have trusted userspace bits. + +============================ +CONFIGURING FIRMWARE SIGNING +============================ + +The firmware signing facility is enabled by going to the section: + +-> Device Drivers + -> Generic Driver Options + -> Userspace firmware loading support (FW_LOADER [=y]) + -> Firmware signature verification (FIRMWARE_SIG [=y]) + +If you want to not allow unsigned firmware to be loaded you should +enable: + +"Require all firmware to be validly signed", under the same menu. + +================== +USING SIGNING KEYS +================== + +For details on the types of keys used, allowed, and how to generate them +refer to Documentation/module-signing.txt. We end up with two keys: + + signing_key.priv + signing_key.x509 + +====================== +SIGNING FIRMWARE FILES +====================== + +To sign a firmware, use the scripts/sign-file tool available in +the Linux kernel source tree. The script requires 4 arguments: + + 1. The hash algorithm (e.g., sha256) + 2. The private key filename + 3. The public key filename + 4. The firmware file to be signed + +We want to sign the firmware file as a new detached file, for that be +sure to use the -s flag. The following is an example of how to sign a +kernel firmware file: + + scripts/sign-file -s sha512 kernel-signkey.priv \ + kernel-signkey.x509 /lib/firmware/foo.bin + +That should have created for you a /lib/firmware/foo.bin.pkcs7 file.
drivers/base/Kconfig +18 -0
@@ -85,6 +85,24 @@ config FW_LOADER require userspace firmware loading support, but a module built out-of-tree does. +config FIRMWARE_SIG + bool "Firmware signature verification" + depends on FW_LOADER + select SYSDATA_SIG + help + Check firmware files for valid signatures upon load: if the firmware + was called foo.bin, a respective foo.bin.pkcs7 is expected to be + present as the signature. For more information see + Documentation/firmware_class/signing.txt + +config FIRMWARE_SIG_FORCE + bool "Require all firmware to be validly signed" + depends on FIRMWARE_SIG + help + Reject unsigned files or signed files for which we don't have a + key. Without this, you'll only get a record on the kernel ring + buffer of firmware files loaded without a signature. + config FIRMWARE_IN_KERNEL bool "Include in-kernel firmware blobs in kernel binary" depends on FW_LOADER
drivers/base/firmware_class.c +207 -7
329 lines not on this page · raw message
include/linux/sysdata.h renamed from kernel/sysdata-internal.h +0 -0
kernel/module.c +1 -1
@@ -59,8 +59,8 @@#include <linux/jump_label.h> #include <linux/pfn.h> #include <linux/bsearch.h> +#include <linux/sysdata.h> #include <uapi/linux/module.h> -#include "sysdata-internal.h" #define CREATE_TRACE_POINTS #include <trace/events/module.h>
kernel/sysdata_signing.c +2 -1
@@ -11,10 +11,10 @@#include <linux/kernel.h> #include <linux/err.h> +#include <linux/sysdata.h> #include <keys/system_keyring.h> #include <crypto/public_key.h> #include <crypto/pkcs7.h> -#include "sysdata-internal.h" /* * System Data signature information block.
@@ -117,3 +117,4 @@ int sysdata_verify_sig(const void *data, unsigned long *_len)return data_verify_pkcs7 (data, len, data + len, sig_len); } +EXPORT_SYMBOL_GPL (sysdata_verify_sig);
kernel/system_keyring.c +1 -1
@@ -14,9 +14,9 @@#include <linux/sched.h> #include <linux/cred.h> #include <linux/err.h> +#include <linux/sysdata.h> #include <keys/asymmetric-type.h> #include <keys/system_keyring.h> -#include "sysdata-internal.h" struct key *system_trusted_keyring;EXPORT_SYMBOL_GPL (system_trusted_keyring);
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [RFC v2 6/6] firmware: add firmware signature checking support
Quoted 11 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
As with module signing, we do a very simple search for a particular string appended to the firmware. There's both a config option and a boot parameter which control whether we accept or fail with unsigned firmware and firmware that are signed with an unknown key.
If firmware signing is enabled, the kernel will be tainted if a firmware is loaded that is unsigned or has a signature for which we don't have the key.
Sorry this commit log is obviously still from the v1, the cover letter addresses the changes best...
Luis
Re: [RFC v2 6/6] firmware: add firmware signature checking support
In reply to Luis R. RodriguezHi Luis,
Quoted 91 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Systems that have module signing currently enabled may wish to extend vetting of firmware passed to the kernel as well. We can re-use most of the code for module signing for firmware signature verification and signing. This will also later enable re-use of this same code for subsystems that wish to provide their own cryptographic verification mechanisms on userspace data needed.
As with module signing, we do a very simple search for a particular string appended to the firmware. There's both a config option and a boot parameter which control whether we accept or fail with unsigned firmware and firmware that are signed with an unknown key.
If firmware signing is enabled, the kernel will be tainted if a firmware is loaded that is unsigned or has a signature for which we don't have the key.
Cc Rusty Russell <[email protected]>Cc David Howells <[email protected]>Cc Ming Lei <[email protected]>Cc Seth Forshee <[email protected]>Cc Kyle McMartin <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- Documentation/firmware_class/signing.txt | 88 +++++++++ drivers/base/Kconfig | 18 ++ drivers/base/firmware_class.c | 214 ++++++++++++++++++++- .../sysdata-internal.h => include/linux/sysdata.h | 0 kernel/module.c | 2 +- kernel/sysdata_signing.c | 3 +- kernel/system_keyring.c | 2 +- 7 files changed, 317 insertions(+), 10 deletions(-) create mode 100644 Documentation/firmware_class/signing.txt rename kernel/sysdata-internal.h => include/linux/sysdata.h (100%)Documentation/firmware_class/signing.txt new file +47
-0@@ -0,0 +1,88 @@ + ================================ + KERNEL FIRMWARE SIGNING FACILITY + ================================ + +CONTENTS + + - Overview. + - Configuring firmware signing. + - Using signing keys. + - Signing firmware files. + + +======== +OVERVIEW +======== + +Device drivers which require a firmware to be uploaded onto a device as its own +device's microcode use any of the following APIs: + + * request_firmware() + * request_firmware_direct() + * request_firmware_nowait() + +The kernel firmware signing facility enables to cryptographically sign +firmware files on a system using the same keys used for module signing. +Firmware files's signatures consist of PKCS#7 messages of the respective +firmware file. A firmware file named foo.bin, would have its respective +signature on the filesystem as foo.bin.pkcs7. When firmware signature +checking is enabled (FIRMWARE_SIG) when one of the above APIs is used +against foo.bin, the file foo.bin.pkcs7 will also be looked for. If +FIRMWARE_SIG_FORCE is enabled the foo.bin file will only be allowed to +be returned to callers of the above APIs if and only if the foo.bin.pkcs7 +file is confirmed to be a valid signature of the foo.bin file. If +FIRMWARE_SIG_FORCE is not enabled and only FIRMWARE_SIG is enabled the +kernel will be permissive and enabled unsiged firmware files, or firmware +files with incorrect signatures. If FIRMWARE_SIG is not enabled the +signature file is ignored completely. + +Firmware signing increases security by making it harder to load a malicious +firmware into the kernel. The firmware signature checking is done by the +kernel so that it is not necessary to have trusted userspace bits. + +============================ +CONFIGURING FIRMWARE SIGNING +============================ + +The firmware signing facility is enabled by going to the section:
Documentation/firmware_class/signing.txt line 57
Quoted 10 lines
Documentation/firmware_class/signing.txt new file +10
-0+ +-> Device Drivers + -> Generic Driver Options + -> Userspace firmware loading support (FW_LOADER [=y]) + -> Firmware signature verification (FIRMWARE_SIG [=y]) + +If you want to not allow unsigned firmware to be loaded you should +enable: + +"Require all firmware to be validly signed", under the same menu.
You reference the relevant Kconfig symbols above, do you want to add it here too?
Thanks,
Signature · 4 lines
Julian Calaby Email: [email protected] Profile: http://www.google.com/profiles/julian.calaby/
Re: [RFC v2 6/6] firmware: add firmware signature checking support
Quoted 6 lines · Julian Calaby
Quoted 1 line · Luis R. Rodriguez
+"Require all firmware to be validly signed", under the same menu.
You reference the relevant
Kconfigsymbols above, do you want to add it here too?
Sure, amended, thanks.
Luis
Herbert Xu
maintainerRe: [RFC v2 3/6] crypto: qat - address recursive dependency when fw signing is enabled
In reply to Luis R. RodriguezQuoted 10 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
We're going to add firmware module signing support, but when we do this we end up with the following recursive dependency. Fix this by just depending on
FW_LOADER, which is typically always enabled anyway. We do this as a compromise for now asFW_LOADERis only selectable when EXPERT is enabled and the recursive dependency issue below is actually real and valid, its proper fix however requires a bit of work.
Quoted 2 lines
This technically means this change is likely welcomed for other parts of the kernel but this is really only needed for now here.
Nack. Either fix kbuild or make every user of FW_LOADER use a dependency. Singling out a single crypto device makes zero sense.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
David Howells
maintainerRe: [RFC v2 4/6] scripts/sign-file.c: add support to only create signature file
In reply to Luis R. RodriguezQuoted 3 lines · Luis R. Rodriguez
You can create a file.pkcs7 file with the -d option right now but that still modifies the file. If all you want is the signature file you can use -s now, that will leave the file passed as-is.
I would recommend you use something other than "-s" - that belongs to the code that is temporarily removed from the old perl script that allowed an external signature to be passed.
David
David Howells
maintainerRe: [RFC v2 4/6] scripts/sign-file.c: add support to only create signature file
Quoted 9 lines · David Howells
Quoted 3 lines · Luis R. Rodriguez
You can create a file.pkcs7 file with the -d option right now but that still modifies the file. If all you want is the signature file you can use -s now, that will leave the file passed as-is.
I would recommend you use something other than "-s" - that belongs to the code that is temporarily removed from the old perl script that allowed an external signature to be passed.
Use "-d". I added the flag but then never made it do anything.
David
Re: [RFC v2 4/6] scripts/sign-file.c: add support to only create signature file
Quoted 1 line · David Howells
Use "-d". I added the flag but then never made it do anything.
Sure, but since this C file is not upstream, how about just squashing the commit with yours that adds the C file?
Luis
David Howells
maintainerRe: [RFC v2 4/6] scripts/sign-file.c: add support to only create signature file
Quoted 4 lines · Luis R. Rodriguez
Quoted 1 line
Use "-d". I added the flag but then never made it do anything.
Sure, but since this C file is not upstream, how about just squashing the commit with yours that adds the C file?
I've got various Tested-by's on that.
Anyway, I'm going to stack the attached patch on my branch if that's okay by you...
David
---
commit 092c720a627b913918eb22f6700f189b34f70693
Author: Luis R. Rodriguez <[email protected]> Date: Wed May 13 11:23:54 2015 -0700
sign-file: Add option to only create signature file
Make the -d option (which currently isn't actually wired to anything) write out the PKCS#7 message as per the -p option and then exit without either modifying the source or writing out a compound file of the source, signature and metadata.
This will be useful when firmware signature support is added upstream as firmware will be left intact, and we'll only require the signature file. The descriptor is implicit by file extension and the file's own size.
scripts/sign-file.c +10 -3
@@ -86,13 +86,14 @@ int main(int argc, char **argv)char *hash_algo =NULL ;char *private_key_name, *x509_name, *module_name, *dest_name;bool save_pkcs7 = false, replace_orig; +bool sign_only = false;unsigned char buf[4096 ];unsigned long module_size, pkcs7_size;const EVP_MD *digest_algo;EVP_PKEY *private_key;PKCS7 *pkcs7;X509 *x509; -BIO *b, *bd, *bm; +BIO *b, *bd =NULL , *bm;int opt, n;ERR_load_crypto_strings ();
@@ -102,6 +103,7 @@ int main(int argc, char **argv) opt =getopt (argc, argv,"dp" );switch (opt) {case 'p' : save_pkcs7 = true;break ; +case 'd' : sign_only = true; save_pkcs7 = true;break ;case -1 :break ;default :format (); }
@@ -148,8 +150,10 @@ int main(int argc, char **argv)/* Open the destination file now so that we can shovel the module data * across as we read it. */ - bd =BIO_new_file (dest_name,"wb" ); -ERR (!bd,"%s" , dest_name); +if (!sign_only) { + bd =BIO_new_file (dest_name,"wb" ); +ERR (!bd,"%s" , dest_name); + }/* Digest the module data. */ OpenSSL_add_all_digests ();
@@ -180,6 +184,9 @@ int main(int argc, char **argv)BIO_free (b); } +if (sign_only) +return 0 ; +/* Append the marker and the PKCS#7 message to the destination file */ ERR (BIO_reset (bm) <0 ,"%s" , module_name); while ((n = BIO_read(bm, buf, sizeof(buf))),
Re: [RFC v2 4/6] scripts/sign-file.c: add support to only create signature file
Quoted 1 line · David Howells
I've got various Tested-by's on that.
Didn't know that would stop people from asking us from squashing them but if so I'll try to use that some other time :)
Quoted 2 lines
Anyway, I'm going to stack the attached patch on my branch if that's okay by you...
Sure thing. Let me know what you think about patch 2 and 5 as well, as they might share similar fate.
Luis
Re: [RFC v2 3/6] crypto: qat - address recursive dependency when fw signing is enabled
In reply to Herbert XuQuoted 11 lines · Herbert Xu
Quoted 10 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
We're going to add firmware module signing support, but when we do this we end up with the following recursive dependency. Fix this by just depending on
FW_LOADER, which is typically always enabled anyway. We do this as a compromise for now asFW_LOADERis only selectable when EXPERT is enabled and the recursive dependency issue below is actually real and valid, its proper fix however requires a bit of work.
Quoted 6 lines
Quoted 2 lines
This technically means this change is likely welcomed for other parts of the kernel but this is really only needed for now here.
Nack. Either fix kbuild or make every user of
FW_LOADERuse a dependency. Singling out a single crypto device makes zero sense.
I think that's fair... Paul, did you get to look into the recursive issue some more by any chance? Any preference for what path to take here?
Luis