Skip to content

Commit d1f0441

Browse files
esnowbergdhowells
authored andcommitted
certs: Add ability to preload revocation certs
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 <[email protected]> Acked-by: Jarkko Sakkinen <[email protected]> Signed-off-by: David Howells <[email protected]> cc: Randy Dunlap <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/[email protected]/ [1] Link: https://lore.kernel.org/r/[email protected]/ [2] Link: https://lore.kernel.org/r/[email protected]/ [3] Link: https://lore.kernel.org/r/[email protected]/ Link: https://lore.kernel.org/r/[email protected]/ # 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
1 parent 2565ca7 commit d1f0441

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

certs/Kconfig

+8
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

+17-2
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

+21
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
#include <linux/uidgid.h>
1818
#include <keys/system_keyring.h>
1919
#include "blacklist.h"
20+
#include "common.h"
2021

2122
static struct key *blacklist_keyring;
2223

24+
#ifdef CONFIG_SYSTEM_REVOCATION_LIST
25+
extern __initconst const u8 revocation_certificate_list[];
26+
extern __initconst const unsigned long revocation_certificate_list_size;
27+
#endif
28+
2329
/*
2430
* The description must be a type prefix, a colon and then an even number of
2531
* 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

+21
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

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
1111
hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
1212
hostprogs-always-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += extract-cert
1313
hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
14+
hostprogs-always-$(CONFIG_SYSTEM_REVOCATION_LIST) += extract-cert
1415

1516
HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
1617
HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include

0 commit comments

Comments
 (0)