Skip to content

Commit f062bca

Browse files
xjamesmorrisJames Morris
authored andcommitted
Merge tag 'modsign-pkcs7-20150814' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs into ra-next
2 parents 3e5f206 + 3ee550f commit f062bca

11 files changed

Lines changed: 212 additions & 198 deletions

File tree

‎Documentation/module-signing.txt‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ This has a number of options available:
9292
(4) "File name or PKCS#11 URI of module signing key" (CONFIG_MODULE_SIG_KEY)
9393

9494
Setting this option to something other than its default of
95-
"signing_key.pem" will disable the autogeneration of signing keys and
96-
allow the kernel modules to be signed with a key of your choosing.
97-
The string provided should identify a file containing both a private
98-
key and its corresponding X.509 certificate in PEM form, or — on
99-
systems where the OpenSSL ENGINE_pkcs11 is functional — a PKCS#11 URI
100-
as defined by RFC7512. In the latter case, the PKCS#11 URI should
101-
reference both a certificate and a private key.
95+
"certs/signing_key.pem" will disable the autogeneration of signing keys
96+
and allow the kernel modules to be signed with a key of your choosing.
97+
The string provided should identify a file containing both a private key
98+
and its corresponding X.509 certificate in PEM form, or — on systems where
99+
the OpenSSL ENGINE_pkcs11 is functional — a PKCS#11 URI as defined by
100+
RFC7512. In the latter case, the PKCS#11 URI should reference both a
101+
certificate and a private key.
102102

103103
If the PEM file containing the private key is encrypted, or if the
104104
PKCS#11 token requries a PIN, this can be provided at build time by
@@ -130,12 +130,12 @@ Under normal conditions, when CONFIG_MODULE_SIG_KEY is unchanged from its
130130
default, the kernel build will automatically generate a new keypair using
131131
openssl if one does not exist in the file:
132132

133-
signing_key.pem
133+
certs/signing_key.pem
134134

135135
during the building of vmlinux (the public part of the key needs to be built
136136
into vmlinux) using parameters in the:
137137

138-
x509.genkey
138+
certs/x509.genkey
139139

140140
file (which is also generated if it does not already exist).
141141

‎MAINTAINERS‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,15 @@ S: Supported
25892589
F: Documentation/filesystems/ceph.txt
25902590
F: fs/ceph/
25912591

2592+
CERTIFICATE HANDLING:
2593+
M: David Howells <dhowells@redhat.com>
2594+
M: David Woodhouse <dwmw2@infradead.org>
2595+
L: keyrings@linux-nfs.org
2596+
S: Maintained
2597+
F: Documentation/module-signing.txt
2598+
F: certs/
2599+
F: scripts/extract-cert.c
2600+
25922601
CERTIFIED WIRELESS USB (WUSB) SUBSYSTEM:
25932602
L: linux-usb@vger.kernel.org
25942603
S: Orphan

‎Makefile‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,18 +870,17 @@ INITRD_COMPRESS-$(CONFIG_RD_LZ4) := lz4
870870
# export INITRD_COMPRESS := $(INITRD_COMPRESS-y)
871871

872872
ifdef CONFIG_MODULE_SIG_ALL
873-
MODSECKEY = $(CONFIG_MODULE_SIG_KEY)
874-
MODPUBKEY = ./signing_key.x509
875-
export MODPUBKEY
876-
mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)
873+
$(eval $(call config_filename,MODULE_SIG_KEY))
874+
875+
mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509
877876
else
878877
mod_sign_cmd = true
879878
endif
880879
export mod_sign_cmd
881880

882881

883882
ifeq ($(KBUILD_EXTMOD),)
884-
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
883+
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
885884

886885
vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
887886
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \

‎certs/Kconfig‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
menu "Certificates for signature checking"
2+
3+
config MODULE_SIG_KEY
4+
string "File name or PKCS#11 URI of module signing key"
5+
default "certs/signing_key.pem"
6+
depends on MODULE_SIG
7+
help
8+
Provide the file name of a private key/certificate in PEM format,
9+
or a PKCS#11 URI according to RFC7512. The file should contain, or
10+
the URI should identify, both the certificate and its corresponding
11+
private key.
12+
13+
If this option is unchanged from its default "certs/signing_key.pem",
14+
then the kernel will automatically generate the private key and
15+
certificate as described in Documentation/module-signing.txt
16+
17+
config SYSTEM_TRUSTED_KEYRING
18+
bool "Provide system-wide ring of trusted keys"
19+
depends on KEYS
20+
help
21+
Provide a system keyring to which trusted keys can be added. Keys in
22+
the keyring are considered to be trusted. Keys may be added at will
23+
by the kernel from compiled-in data and from hardware key stores, but
24+
userspace may only add extra keys if those keys can be verified by
25+
keys already in the keyring.
26+
27+
Keys in this keyring are used by module signature checking.
28+
29+
config SYSTEM_TRUSTED_KEYS
30+
string "Additional X.509 keys for default system keyring"
31+
depends on SYSTEM_TRUSTED_KEYRING
32+
help
33+
If set, this option should be the filename of a PEM-formatted file
34+
containing trusted X.509 certificates to be included in the default
35+
system keyring. Any certificate used for module signing is implicitly
36+
also trusted.
37+
38+
NOTE: If you previously provided keys for the system keyring in the
39+
form of DER-encoded *.x509 files in the top-level build directory,
40+
those are no longer used. You will need to set this option instead.
41+
42+
endmenu

‎certs/Makefile‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#
2+
# Makefile for the linux kernel signature checking certificates.
3+
#
4+
5+
obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
6+
7+
ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
8+
9+
$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
10+
11+
# GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
12+
$(obj)/system_certificates.o: $(obj)/x509_certificate_list
13+
14+
# Cope with signing_key.x509 existing in $(srctree) not $(objtree)
15+
AFLAGS_system_certificates.o := -I$(srctree)
16+
17+
quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
18+
cmd_extract_certs = scripts/extract-cert $(2) $@ || ( rm $@; exit 1)
19+
20+
targets += x509_certificate_list
21+
$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
22+
$(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
23+
endif
24+
25+
clean-files := x509_certificate_list .x509.list
26+
27+
ifeq ($(CONFIG_MODULE_SIG),y)
28+
###############################################################################
29+
#
30+
# If module signing is requested, say by allyesconfig, but a key has not been
31+
# supplied, then one will need to be generated to make sure the build does not
32+
# fail and that the kernel may be used afterwards.
33+
#
34+
###############################################################################
35+
ifndef CONFIG_MODULE_SIG_HASH
36+
$(error Could not determine digest type to use from kernel config)
37+
endif
38+
39+
# We do it this way rather than having a boolean option for enabling an
40+
# external private key, because 'make randconfig' might enable such a
41+
# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
42+
ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
43+
$(obj)/signing_key.pem: $(obj)/x509.genkey
44+
@echo "###"
45+
@echo "### Now generating an X.509 key pair to be used for signing modules."
46+
@echo "###"
47+
@echo "### If this takes a long time, you might wish to run rngd in the"
48+
@echo "### background to keep the supply of entropy topped up. It"
49+
@echo "### needs to be run as root, and uses a hardware random"
50+
@echo "### number generator if one is available."
51+
@echo "###"
52+
openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
53+
-batch -x509 -config $(obj)/x509.genkey \
54+
-outform PEM -out $(obj)/signing_key.pem \
55+
-keyout $(obj)/signing_key.pem 2>&1
56+
@echo "###"
57+
@echo "### Key pair generated."
58+
@echo "###"
59+
60+
$(obj)/x509.genkey:
61+
@echo Generating X.509 key generation config
62+
@echo >$@ "[ req ]"
63+
@echo >>$@ "default_bits = 4096"
64+
@echo >>$@ "distinguished_name = req_distinguished_name"
65+
@echo >>$@ "prompt = no"
66+
@echo >>$@ "string_mask = utf8only"
67+
@echo >>$@ "x509_extensions = myexts"
68+
@echo >>$@
69+
@echo >>$@ "[ req_distinguished_name ]"
70+
@echo >>$@ "#O = Unspecified company"
71+
@echo >>$@ "CN = Build time autogenerated kernel key"
72+
@echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
73+
@echo >>$@
74+
@echo >>$@ "[ myexts ]"
75+
@echo >>$@ "basicConstraints=critical,CA:FALSE"
76+
@echo >>$@ "keyUsage=digitalSignature"
77+
@echo >>$@ "subjectKeyIdentifier=hash"
78+
@echo >>$@ "authorityKeyIdentifier=keyid"
79+
endif
80+
81+
$(eval $(call config_filename,MODULE_SIG_KEY))
82+
83+
# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
84+
ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
85+
X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
86+
endif
87+
88+
# GCC PR#66871 again.
89+
$(obj)/system_certificates.o: $(obj)/signing_key.x509
90+
91+
targets += signing_key.x509
92+
$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
93+
$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
94+
endif
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
VMLINUX_SYMBOL(system_certificate_list):
99
__cert_list_start:
1010
#ifdef CONFIG_MODULE_SIG
11-
.incbin "signing_key.x509"
11+
.incbin "certs/signing_key.x509"
1212
#endif
13-
.incbin "kernel/x509_certificate_list"
13+
.incbin "certs/x509_certificate_list"
1414
__cert_list_end:
1515

1616
.align 8

‎crypto/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,5 +1601,6 @@ config CRYPTO_HASH_INFO
16011601

16021602
source "drivers/crypto/Kconfig"
16031603
source crypto/asymmetric_keys/Kconfig
1604+
source certs/Kconfig
16041605

16051606
endif # if CRYPTO

‎init/Kconfig‎

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,31 +1740,6 @@ config MMAP_ALLOW_UNINITIALIZED
17401740

17411741
See Documentation/nommu-mmap.txt for more information.
17421742

1743-
config SYSTEM_TRUSTED_KEYRING
1744-
bool "Provide system-wide ring of trusted keys"
1745-
depends on KEYS
1746-
help
1747-
Provide a system keyring to which trusted keys can be added. Keys in
1748-
the keyring are considered to be trusted. Keys may be added at will
1749-
by the kernel from compiled-in data and from hardware key stores, but
1750-
userspace may only add extra keys if those keys can be verified by
1751-
keys already in the keyring.
1752-
1753-
Keys in this keyring are used by module signature checking.
1754-
1755-
config SYSTEM_TRUSTED_KEYS
1756-
string "Additional X.509 keys for default system keyring"
1757-
depends on SYSTEM_TRUSTED_KEYRING
1758-
help
1759-
If set, this option should be the filename of a PEM-formatted file
1760-
containing trusted X.509 certificates to be included in the default
1761-
system keyring. Any certificate used for module signing is implicitly
1762-
also trusted.
1763-
1764-
NOTE: If you previously provided keys for the system keyring in the
1765-
form of DER-encoded *.x509 files in the top-level build directory,
1766-
those are no longer used. You will need to set this option instead.
1767-
17681743
config SYSTEM_DATA_VERIFICATION
17691744
def_bool n
17701745
select SYSTEM_TRUSTED_KEYRING
@@ -1965,20 +1940,6 @@ config MODULE_SIG_HASH
19651940
default "sha384" if MODULE_SIG_SHA384
19661941
default "sha512" if MODULE_SIG_SHA512
19671942

1968-
config MODULE_SIG_KEY
1969-
string "File name or PKCS#11 URI of module signing key"
1970-
default "signing_key.pem"
1971-
depends on MODULE_SIG
1972-
help
1973-
Provide the file name of a private key/certificate in PEM format,
1974-
or a PKCS#11 URI according to RFC7512. The file should contain, or
1975-
the URI should identify, both the certificate and its corresponding
1976-
private key.
1977-
1978-
If this option is unchanged from its default "signing_key.pem",
1979-
then the kernel will automatically generate the private key and
1980-
certificate as described in Documentation/module-signing.txt
1981-
19821943
config MODULE_COMPRESS
19831944
bool "Compress modules on installation"
19841945
depends on MODULES

0 commit comments

Comments
 (0)