Linux-KBuild Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] Preloaded revocation keys
@ 2020-09-30 20:15 Eric Snowberg
  2020-09-30 20:15 ` [PATCH 1/2] certs: Move load_system_certificate_list to a common function Eric Snowberg
  2020-09-30 20:15 ` [PATCH 2/2] certs: Add ability to preload revocation certs Eric Snowberg
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Snowberg @ 2020-09-30 20:15 UTC (permalink / raw)
  To: dhowells, dwmw2
  Cc: masahiroy, michal.lkml, keyrings, linux-kernel, linux-kbuild,
	jarkko.sakkinen, eric.snowberg

The Secure Boot Forbidden Signature Database, dbx, contains a list of
now revoked signatures and keys previously approved to boot with UEFI
Secure Boot enabled.  Currently EFI_CERT_X509_SHA256_GUID and
EFI_CERT_SHA256_GUID can be preloaded (at build time) into the system
blacklist keyring.

Add the ability to also preload EFI_CERT_X509_GUID dbx entries.

This series can be applied on its own; however to use preloaded
revocation certificates, [1] should be applied first.

[1] https://www.spinics.net/lists/keyrings/msg08422.html


Eric Snowberg (2):
  certs: Move load_system_certificate_list to a common function
  certs: Add ability to preload revocation certs

 certs/Kconfig                   |  8 +++++
 certs/Makefile                  | 20 ++++++++++--
 certs/blacklist.c               | 17 ++++++++++
 certs/common.c                  | 56 +++++++++++++++++++++++++++++++++
 certs/common.h                  |  9 ++++++
 certs/revocation_certificates.S | 21 +++++++++++++
 certs/system_keyring.c          | 49 ++---------------------------
 scripts/Makefile                |  1 +
 8 files changed, 132 insertions(+), 49 deletions(-)
 create mode 100644 certs/common.c
 create mode 100644 certs/common.h
 create mode 100644 certs/revocation_certificates.S


base-commit: 02de58b24d2e1b2cf947d57205bd2221d897193c
-- 
2.18.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] certs: Move load_system_certificate_list to a common function
  2020-09-30 20:15 [PATCH 0/2] Preloaded revocation keys Eric Snowberg
@ 2020-09-30 20:15 ` Eric Snowberg
  2020-09-30 21:02   ` Jarkko Sakkinen
  2020-09-30 20:15 ` [PATCH 2/2] certs: Add ability to preload revocation certs Eric Snowberg
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Snowberg @ 2020-09-30 20:15 UTC (permalink / raw)
  To: dhowells, dwmw2
  Cc: masahiroy, michal.lkml, keyrings, linux-kernel, linux-kbuild,
	jarkko.sakkinen, eric.snowberg

Move functionality within load_system_certificate_list to a common
function, so it can be reused in the future.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 certs/Makefile         |  2 +-
 certs/common.c         | 56 ++++++++++++++++++++++++++++++++++++++++++
 certs/common.h         |  9 +++++++
 certs/system_keyring.c | 49 +++---------------------------------
 4 files changed, 69 insertions(+), 47 deletions(-)
 create mode 100644 certs/common.c
 create mode 100644 certs/common.h

diff --git a/certs/Makefile b/certs/Makefile
index f4c25b67aad9..f4b90bad8690 100644
--- a/certs/Makefile
+++ b/certs/Makefile
@@ -3,7 +3,7 @@
 # Makefile for the linux kernel signature checking certificates.
 #
 
-obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
+obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
 ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
diff --git a/certs/common.c b/certs/common.c
new file mode 100644
index 000000000000..83800f51a1a1
--- /dev/null
+++ b/certs/common.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/kernel.h>
+#include <linux/key.h>
+
+int load_certificate_list(const u8 cert_list[],
+			  const unsigned long list_size,
+			  const struct key *keyring)
+{
+	key_ref_t key;
+	const u8 *p, *end;
+	size_t plen;
+
+	p = cert_list;
+	end = p + list_size;
+	while (p < end) {
+		/* Each cert begins with an ASN.1 SEQUENCE tag and must be more
+		 * than 256 bytes in size.
+		 */
+		if (end - p < 4)
+			goto dodgy_cert;
+		if (p[0] != 0x30 &&
+		    p[1] != 0x82)
+			goto dodgy_cert;
+		plen = (p[2] << 8) | p[3];
+		plen += 4;
+		if (plen > end - p)
+			goto dodgy_cert;
+
+		key = key_create_or_update(make_key_ref(keyring, 1),
+					   "asymmetric",
+					   NULL,
+					   p,
+					   plen,
+					   ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
+					   KEY_USR_VIEW | KEY_USR_READ),
+					   KEY_ALLOC_NOT_IN_QUOTA |
+					   KEY_ALLOC_BUILT_IN |
+					   KEY_ALLOC_BYPASS_RESTRICTION);
+		if (IS_ERR(key)) {
+			pr_err("Problem loading in-kernel X.509 certificate (%ld)\n",
+			       PTR_ERR(key));
+		} else {
+			pr_notice("Loaded X.509 cert '%s'\n",
+				  key_ref_to_ptr(key)->description);
+			key_ref_put(key);
+		}
+		p += plen;
+	}
+
+	return 0;
+
+dodgy_cert:
+	pr_err("Problem parsing in-kernel X.509 certificate list\n");
+	return 0;
+}
diff --git a/certs/common.h b/certs/common.h
new file mode 100644
index 000000000000..abdb5795936b
--- /dev/null
+++ b/certs/common.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _CERT_COMMON_H
+#define _CERT_COMMON_H
+
+int load_certificate_list(const u8 cert_list[], const unsigned long list_size,
+			  const struct key *keyring);
+
+#endif
diff --git a/certs/system_keyring.c b/certs/system_keyring.c
index 798291177186..4510fb5462fb 100644
--- a/certs/system_keyring.c
+++ b/certs/system_keyring.c
@@ -15,6 +15,7 @@
 #include <keys/asymmetric-type.h>
 #include <keys/system_keyring.h>
 #include <crypto/pkcs7.h>
+#include "common.h"
 
 static struct key *builtin_trusted_keys;
 #ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
@@ -136,54 +137,10 @@ device_initcall(system_trusted_keyring_init);
  */
 static __init int load_system_certificate_list(void)
 {
-	key_ref_t key;
-	const u8 *p, *end;
-	size_t plen;
-
 	pr_notice("Loading compiled-in X.509 certificates\n");
 
-	p = system_certificate_list;
-	end = p + system_certificate_list_size;
-	while (p < end) {
-		/* Each cert begins with an ASN.1 SEQUENCE tag and must be more
-		 * than 256 bytes in size.
-		 */
-		if (end - p < 4)
-			goto dodgy_cert;
-		if (p[0] != 0x30 &&
-		    p[1] != 0x82)
-			goto dodgy_cert;
-		plen = (p[2] << 8) | p[3];
-		plen += 4;
-		if (plen > end - p)
-			goto dodgy_cert;
-
-		key = key_create_or_update(make_key_ref(builtin_trusted_keys, 1),
-					   "asymmetric",
-					   NULL,
-					   p,
-					   plen,
-					   ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
-					   KEY_USR_VIEW | KEY_USR_READ),
-					   KEY_ALLOC_NOT_IN_QUOTA |
-					   KEY_ALLOC_BUILT_IN |
-					   KEY_ALLOC_BYPASS_RESTRICTION);
-		if (IS_ERR(key)) {
-			pr_err("Problem loading in-kernel X.509 certificate (%ld)\n",
-			       PTR_ERR(key));
-		} else {
-			pr_notice("Loaded X.509 cert '%s'\n",
-				  key_ref_to_ptr(key)->description);
-			key_ref_put(key);
-		}
-		p += plen;
-	}
-
-	return 0;
-
-dodgy_cert:
-	pr_err("Problem parsing in-kernel X.509 certificate list\n");
-	return 0;
+	return load_certificate_list(system_certificate_list, system_certificate_list_size,
+				     builtin_trusted_keys);
 }
 late_initcall(load_system_certificate_list);
 
-- 
2.18.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] certs: Add ability to preload revocation certs
  2020-09-30 20:15 [PATCH 0/2] Preloaded revocation keys Eric Snowberg
  2020-09-30 20:15 ` [PATCH 1/2] certs: Move load_system_certificate_list to a common function Eric Snowberg
@ 2020-09-30 20:15 ` Eric Snowberg
  2020-09-30 20:56   ` Jarkko Sakkinen
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Snowberg @ 2020-09-30 20:15 UTC (permalink / raw)
  To: dhowells, dwmw2
  Cc: masahiroy, michal.lkml, keyrings, linux-kernel, linux-kbuild,
	jarkko.sakkinen, eric.snowberg

Add a new Kconfig option called SYSTEM_REVOCATION_KEYS. If set,
this option should be the filename of a PEM-formated file containing
X.509 certificates to be included in the default blacklist keyring.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 certs/Kconfig                   |  8 ++++++++
 certs/Makefile                  | 18 ++++++++++++++++--
 certs/blacklist.c               | 17 +++++++++++++++++
 certs/revocation_certificates.S | 21 +++++++++++++++++++++
 scripts/Makefile                |  1 +
 5 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 certs/revocation_certificates.S

diff --git a/certs/Kconfig b/certs/Kconfig
index c94e93d8bccf..379a6e198459 100644
--- a/certs/Kconfig
+++ b/certs/Kconfig
@@ -83,4 +83,12 @@ config SYSTEM_BLACKLIST_HASH_LIST
 	  wrapper to incorporate the list into the kernel.  Each <hash> should
 	  be a string of hex digits.
 
+config SYSTEM_REVOCATION_KEYS
+	string "X.509 certificates to be preloaded into the system blacklist keyring"
+	depends on SYSTEM_BLACKLIST_KEYRING
+	help
+	  If set, this option should be the filename of a PEM-formatted file
+	  containing X.509 certificates to be included in the default blacklist
+	  keyring.
+
 endmenu
diff --git a/certs/Makefile b/certs/Makefile
index f4b90bad8690..e3f4926fd21e 100644
--- a/certs/Makefile
+++ b/certs/Makefile
@@ -4,7 +4,7 @@
 #
 
 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
-obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
+obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o revocation_certificates.o common.o
 ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
 else
@@ -29,7 +29,7 @@ $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREF
 	$(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
 endif # CONFIG_SYSTEM_TRUSTED_KEYRING
 
-clean-files := x509_certificate_list .x509.list
+clean-files := x509_certificate_list .x509.list x509_revocation_list
 
 ifeq ($(CONFIG_MODULE_SIG),y)
 ###############################################################################
@@ -104,3 +104,17 @@ targets += signing_key.x509
 $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
 	$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
 endif # CONFIG_MODULE_SIG
+
+ifeq ($(CONFIG_SYSTEM_BLACKLIST_KEYRING),y)
+
+$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS))
+
+$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
+
+quiet_cmd_extract_certs  = EXTRACT_CERTS   $(patsubst "%",%,$(2))
+      cmd_extract_certs  = scripts/extract-cert $(2) $@
+
+targets += x509_revocation_list
+$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE
+	$(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS))
+endif
diff --git a/certs/blacklist.c b/certs/blacklist.c
index 6514f9ebc943..a0e7770895ce 100644
--- a/certs/blacklist.c
+++ b/certs/blacklist.c
@@ -16,9 +16,13 @@
 #include <linux/seq_file.h>
 #include <keys/system_keyring.h>
 #include "blacklist.h"
+#include "common.h"
 
 static struct key *blacklist_keyring;
 
+extern __initconst const u8 revocation_certificate_list[];
+extern __initconst const unsigned long revocation_certificate_list_size;
+
 /*
  * The description must be a type prefix, a colon and then an even number of
  * hex digits.  The hash is kept in the description.
@@ -177,3 +181,16 @@ static int __init blacklist_init(void)
  * Must be initialised before we try and load the keys into the keyring.
  */
 device_initcall(blacklist_init);
+
+/*
+ * Load the compiled-in list of revocation X.509 certificates.
+ */
+static __init int load_revocation_certificate_list(void)
+{
+	if (revocation_certificate_list_size)
+		pr_notice("Loading compiled-in revocation X.509 certificates\n");
+
+	return load_certificate_list(revocation_certificate_list, revocation_certificate_list_size,
+				     blacklist_keyring);
+}
+late_initcall(load_revocation_certificate_list);
diff --git a/certs/revocation_certificates.S b/certs/revocation_certificates.S
new file mode 100644
index 000000000000..f21aae8a8f0e
--- /dev/null
+++ b/certs/revocation_certificates.S
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/export.h>
+#include <linux/init.h>
+
+	__INITRODATA
+
+	.align 8
+	.globl revocation_certificate_list
+revocation_certificate_list:
+__revocation_list_start:
+	.incbin "certs/x509_revocation_list"
+__revocation_list_end:
+
+	.align 8
+	.globl revocation_certificate_list_size
+revocation_certificate_list_size:
+#ifdef CONFIG_64BIT
+	.quad __revocation_list_end - __revocation_list_start
+#else
+	.long __revocation_list_end - __revocation_list_start
+#endif
diff --git a/scripts/Makefile b/scripts/Makefile
index bc018e4b733e..fb105b2bc006 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -11,6 +11,7 @@ hostprogs-always-$(CONFIG_ASN1)				+= asn1_compiler
 hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT)		+= sign-file
 hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING)	+= extract-cert
 hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)	+= insert-sys-cert
+ hostprogs-always-$(CONFIG_SYSTEM_BLACKLIST_KEYRING)	+= extract-cert
 
 HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
 HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
-- 
2.18.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] certs: Add ability to preload revocation certs
  2020-09-30 20:15 ` [PATCH 2/2] certs: Add ability to preload revocation certs Eric Snowberg
@ 2020-09-30 20:56   ` Jarkko Sakkinen
  0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2020-09-30 20:56 UTC (permalink / raw)
  To: Eric Snowberg
  Cc: dhowells, dwmw2, masahiroy, michal.lkml, keyrings, linux-kernel,
	linux-kbuild

On Wed, Sep 30, 2020 at 04:15:08PM -0400, Eric Snowberg wrote:
> Add a new Kconfig option called SYSTEM_REVOCATION_KEYS. If set,
> this option should be the filename of a PEM-formated file containing
> X.509 certificates to be included in the default blacklist keyring.
> 
> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>

Acked-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] certs: Move load_system_certificate_list to a common function
  2020-09-30 20:15 ` [PATCH 1/2] certs: Move load_system_certificate_list to a common function Eric Snowberg
@ 2020-09-30 21:02   ` Jarkko Sakkinen
  2020-09-30 21:15     ` Eric Snowberg
  0 siblings, 1 reply; 7+ messages in thread
From: Jarkko Sakkinen @ 2020-09-30 21:02 UTC (permalink / raw)
  To: Eric Snowberg
  Cc: dhowells, dwmw2, masahiroy, michal.lkml, keyrings, linux-kernel,
	linux-kbuild

On Wed, Sep 30, 2020 at 04:15:07PM -0400, Eric Snowberg wrote:
> Move functionality within load_system_certificate_list to a common
> function, so it can be reused in the future.
> 
> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>

I rather think now rather than the future. I think this should be part
of a patch set where the re-use actually happens.

Without that context, I rather not say anything about this patch.
Neither an issue for me if it gets applied. This is just a guideline
that I follow (in order to manage this chaos).

Looking at the code change, I do not see anything strikingly wrong in
it.

/Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] certs: Move load_system_certificate_list to a common function
  2020-09-30 21:02   ` Jarkko Sakkinen
@ 2020-09-30 21:15     ` Eric Snowberg
  2020-09-30 21:49       ` Jarkko Sakkinen
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Snowberg @ 2020-09-30 21:15 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: dhowells, dwmw2, masahiroy, michal.lkml, keyrings, linux-kernel,
	linux-kbuild, Eric Snowberg


> On Sep 30, 2020, at 3:02 PM, Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> wrote:
> 
> On Wed, Sep 30, 2020 at 04:15:07PM -0400, Eric Snowberg wrote:
>> Move functionality within load_system_certificate_list to a common
>> function, so it can be reused in the future.
>> 
>> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
> 
> I rather think now rather than the future. I think this should be part
> of a patch set where the re-use actually happens.

load_certificate_list is being used in the second patch in the series [1].
It uses the now common code, to load the revocation certificates, just like
the system certificates are being loaded in this patch.


> Without that context, I rather not say anything about this patch.
> Neither an issue for me if it gets applied. This is just a guideline
> that I follow (in order to manage this chaos).
> 
> Looking at the code change, I do not see anything strikingly wrong in
> it.

Thanks

[1] https://lore.kernel.org/patchwork/patch/1315486/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] certs: Move load_system_certificate_list to a common function
  2020-09-30 21:15     ` Eric Snowberg
@ 2020-09-30 21:49       ` Jarkko Sakkinen
  0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2020-09-30 21:49 UTC (permalink / raw)
  To: Eric Snowberg
  Cc: dhowells, dwmw2, masahiroy, michal.lkml, keyrings, linux-kernel,
	linux-kbuild

On Wed, Sep 30, 2020 at 03:15:10PM -0600, Eric Snowberg wrote:
> 
> > On Sep 30, 2020, at 3:02 PM, Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> wrote:
> > 
> > On Wed, Sep 30, 2020 at 04:15:07PM -0400, Eric Snowberg wrote:
> >> Move functionality within load_system_certificate_list to a common
> >> function, so it can be reused in the future.
> >> 
> >> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
> > 
> > I rather think now rather than the future. I think this should be part
> > of a patch set where the re-use actually happens.
> 
> load_certificate_list is being used in the second patch in the series [1].
> It uses the now common code, to load the revocation certificates, just like
> the system certificates are being loaded in this patch.

Ugh, better to get some sleep. Double checked 2/2 and ack still holds.
Sorry about this.

Acked-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 20:15 [PATCH 0/2] Preloaded revocation keys Eric Snowberg
2020-09-30 20:15 ` [PATCH 1/2] certs: Move load_system_certificate_list to a common function Eric Snowberg
2020-09-30 21:02   ` Jarkko Sakkinen
2020-09-30 21:15     ` Eric Snowberg
2020-09-30 21:49       ` Jarkko Sakkinen
2020-09-30 20:15 ` [PATCH 2/2] certs: Add ability to preload revocation certs Eric Snowberg
2020-09-30 20:56   ` Jarkko Sakkinen

Linux-KBuild Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kbuild/0 linux-kbuild/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kbuild linux-kbuild/ https://lore.kernel.org/linux-kbuild \
		linux-kbuild@vger.kernel.org
	public-inbox-index linux-kbuild

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kbuild


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git