Skip to content

Commit c6ae6f8

Browse files
esnowbergSasha Levin
authored andcommitted
certs: Add ability to preload revocation certs
[ Upstream commit d1f0441 ] 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. DH Changes: - Make the new Kconfig option depend on SYSTEM_REVOCATION_LIST. - Fix SYSTEM_REVOCATION_KEYS=n, but CONFIG_SYSTEM_REVOCATION_LIST=y[1][2]. - Use CONFIG_SYSTEM_REVOCATION_LIST for extract-cert[3]. - Use CONFIG_SYSTEM_REVOCATION_LIST for revocation_certificates.o[3]. Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com> Acked-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: David Howells <dhowells@redhat.com> cc: Randy Dunlap <rdunlap@infradead.org> cc: keyrings@vger.kernel.org Link: https://lore.kernel.org/r/e1c15c74-82ce-3a69-44de-a33af9b320ea@infradead.org/ [1] Link: https://lore.kernel.org/r/20210303034418.106762-1-eric.snowberg@oracle.com/ [2] Link: https://lore.kernel.org/r/20210304175030.184131-1-eric.snowberg@oracle.com/ [3] Link: https://lore.kernel.org/r/20200930201508.35113-3-eric.snowberg@oracle.com/ Link: https://lore.kernel.org/r/20210122181054.32635-4-eric.snowberg@oracle.com/ # v5 Link: https://lore.kernel.org/r/161428673564.677100.4112098280028451629.stgit@warthog.procyon.org.uk/ Link: https://lore.kernel.org/r/161433312452.902181.4146169951896577982.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/161529606657.163428.3340689182456495390.stgit@warthog.procyon.org.uk/ # v3 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 72d6f5d commit c6ae6f8

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

certs/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,12 @@ config SYSTEM_REVOCATION_LIST
9292
blacklist keyring and implements a hook whereby a PKCS#7 message can
9393
be checked to see if it matches such a certificate.
9494

95+
config SYSTEM_REVOCATION_KEYS
96+
string "X.509 certificates to be preloaded into the system blacklist keyring"
97+
depends on SYSTEM_REVOCATION_LIST
98+
help
99+
If set, this option should be the filename of a PEM-formatted file
100+
containing X.509 certificates to be included in the default blacklist
101+
keyring.
102+
95103
endmenu

certs/Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#
55

66
obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
7-
obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
7+
obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o
8+
obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
89
ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
910
obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
1011
else
@@ -29,7 +30,7 @@ $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREF
2930
$(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
3031
endif # CONFIG_SYSTEM_TRUSTED_KEYRING
3132

32-
clean-files := x509_certificate_list .x509.list
33+
clean-files := x509_certificate_list .x509.list x509_revocation_list
3334

3435
ifeq ($(CONFIG_MODULE_SIG),y)
3536
###############################################################################
@@ -104,3 +105,17 @@ targets += signing_key.x509
104105
$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
105106
$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
106107
endif # CONFIG_MODULE_SIG
108+
109+
ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y)
110+
111+
$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS))
112+
113+
$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
114+
115+
quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
116+
cmd_extract_certs = scripts/extract-cert $(2) $@
117+
118+
targets += x509_revocation_list
119+
$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE
120+
$(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS))
121+
endif

certs/blacklist.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
#include <linux/seq_file.h>
1717
#include <keys/system_keyring.h>
1818
#include "blacklist.h"
19+
#include "common.h"
1920

2021
static struct key *blacklist_keyring;
2122

23+
#ifdef CONFIG_SYSTEM_REVOCATION_LIST
24+
extern __initconst const u8 revocation_certificate_list[];
25+
extern __initconst const unsigned long revocation_certificate_list_size;
26+
#endif
27+
2228
/*
2329
* The description must be a type prefix, a colon and then an even number of
2430
* hex digits. The hash is kept in the description.
@@ -220,3 +226,18 @@ static int __init blacklist_init(void)
220226
* Must be initialised before we try and load the keys into the keyring.
221227
*/
222228
device_initcall(blacklist_init);
229+
230+
#ifdef CONFIG_SYSTEM_REVOCATION_LIST
231+
/*
232+
* Load the compiled-in list of revocation X.509 certificates.
233+
*/
234+
static __init int load_revocation_certificate_list(void)
235+
{
236+
if (revocation_certificate_list_size)
237+
pr_notice("Loading compiled-in revocation X.509 certificates\n");
238+
239+
return load_certificate_list(revocation_certificate_list, revocation_certificate_list_size,
240+
blacklist_keyring);
241+
}
242+
late_initcall(load_revocation_certificate_list);
243+
#endif

certs/revocation_certificates.S

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#include <linux/export.h>
3+
#include <linux/init.h>
4+
5+
__INITRODATA
6+
7+
.align 8
8+
.globl revocation_certificate_list
9+
revocation_certificate_list:
10+
__revocation_list_start:
11+
.incbin "certs/x509_revocation_list"
12+
__revocation_list_end:
13+
14+
.align 8
15+
.globl revocation_certificate_list_size
16+
revocation_certificate_list_size:
17+
#ifdef CONFIG_64BIT
18+
.quad __revocation_list_end - __revocation_list_start
19+
#else
20+
.long __revocation_list_end - __revocation_list_start
21+
#endif

scripts/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
1414
hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
1515
hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert
1616
hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
17+
hostprogs-always-$(CONFIG_SYSTEM_REVOCATION_LIST) += extract-cert
1718

1819
HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
1920
HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include

0 commit comments

Comments
 (0)