Skip to content

Commit 60c8eb3

Browse files
committed
Merge branch 'ima-module-signing-v4' into next-integrity
From the series cover letter: Kernel modules are currently only signed when CONFIG_MODULE_SIG is enabled. The kernel module signing key is a self-signed CA only loaded onto the .builtin_trusted_key keyring. On secure boot enabled systems with an arch specific IMA policy enabled, but without MODULE_SIG enabled, kernel modules are not signed, nor is the kernel module signing public key loaded onto the IMA keyring. In order to load the the kernel module signing key onto the IMA trusted keyring ('.ima'), the certificate needs to be signed by a CA key either on the builtin or secondary keyrings. The original version of this patch set created and loaded a kernel-CA key onto the builtin keyring. The kernel-CA key signed the kernel module signing key, allowing it to be loaded onto the IMA trusted keyring. However, missing from this version was support for the kernel-CA to sign the hardware token certificate. Adding that support would add additional complexity. Since the kernel module signing key is embedded into the Linux kernel at build time, instead of creating and loading a kernel-CA onto the builtin trusted keyring, this version makes an exception and allows the self-signed kernel module signing key to be loaded directly onto the trusted IMA keyring.
2 parents 7990cca + 6cbdfb3 commit 60c8eb3

File tree

8 files changed

+76
-18
lines changed

8 files changed

+76
-18
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,9 @@ MRPROPER_FILES += include/config include/generated \
15231523
debian snap tar-install \
15241524
.config .config.old .version \
15251525
Module.symvers \
1526-
signing_key.pem signing_key.priv signing_key.x509 \
1527-
x509.genkey extra_certificates signing_key.x509.keyid \
1528-
signing_key.x509.signer vmlinux-gdb.py \
1526+
certs/signing_key.pem certs/signing_key.x509 \
1527+
certs/x509.genkey \
1528+
vmlinux-gdb.py \
15291529
*.spec
15301530

15311531
# Directories & files removed with 'make distclean'

certs/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ menu "Certificates for signature checking"
44
config MODULE_SIG_KEY
55
string "File name or PKCS#11 URI of module signing key"
66
default "certs/signing_key.pem"
7-
depends on MODULE_SIG
7+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
88
help
99
Provide the file name of a private key/certificate in PEM format,
1010
or a PKCS#11 URI according to RFC7512. The file should contain, or

certs/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ endif # CONFIG_SYSTEM_TRUSTED_KEYRING
3232
clean-files := x509_certificate_list .x509.list
3333

3434
ifeq ($(CONFIG_MODULE_SIG),y)
35+
SIGN_KEY = y
36+
endif
37+
38+
ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y)
39+
SIGN_KEY = y
40+
endif
41+
42+
ifdef SIGN_KEY
3543
###############################################################################
3644
#
3745
# If module signing is requested, say by allyesconfig, but a key has not been

certs/system_certificates.S

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
.globl system_certificate_list
99
system_certificate_list:
1010
__cert_list_start:
11-
#ifdef CONFIG_MODULE_SIG
11+
__module_cert_start:
12+
#if defined(CONFIG_MODULE_SIG) || defined(CONFIG_IMA_APPRAISE_MODSIG)
1213
.incbin "certs/signing_key.x509"
1314
#endif
15+
__module_cert_end:
1416
.incbin "certs/x509_certificate_list"
1517
__cert_list_end:
1618

@@ -35,3 +37,12 @@ system_certificate_list_size:
3537
#else
3638
.long __cert_list_end - __cert_list_start
3739
#endif
40+
41+
.align 8
42+
.globl module_cert_size
43+
module_cert_size:
44+
#ifdef CONFIG_64BIT
45+
.quad __module_cert_end - __module_cert_start
46+
#else
47+
.long __module_cert_end - __module_cert_start
48+
#endif

certs/system_keyring.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static struct key *platform_trusted_keys;
2727

2828
extern __initconst const u8 system_certificate_list[];
2929
extern __initconst const unsigned long system_certificate_list_size;
30+
extern __initconst const unsigned long module_cert_size;
3031

3132
/**
3233
* restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA
@@ -132,19 +133,11 @@ static __init int system_trusted_keyring_init(void)
132133
*/
133134
device_initcall(system_trusted_keyring_init);
134135

135-
/*
136-
* Load the compiled-in list of X.509 certificates.
137-
*/
138-
static __init int load_system_certificate_list(void)
136+
static __init int load_cert(const u8 *p, const u8 *end, struct key *keyring)
139137
{
140138
key_ref_t key;
141-
const u8 *p, *end;
142139
size_t plen;
143140

144-
pr_notice("Loading compiled-in X.509 certificates\n");
145-
146-
p = system_certificate_list;
147-
end = p + system_certificate_list_size;
148141
while (p < end) {
149142
/* Each cert begins with an ASN.1 SEQUENCE tag and must be more
150143
* than 256 bytes in size.
@@ -159,7 +152,7 @@ static __init int load_system_certificate_list(void)
159152
if (plen > end - p)
160153
goto dodgy_cert;
161154

162-
key = key_create_or_update(make_key_ref(builtin_trusted_keys, 1),
155+
key = key_create_or_update(make_key_ref(keyring, 1),
163156
"asymmetric",
164157
NULL,
165158
p,
@@ -186,6 +179,43 @@ static __init int load_system_certificate_list(void)
186179
pr_err("Problem parsing in-kernel X.509 certificate list\n");
187180
return 0;
188181
}
182+
183+
__init int load_module_cert(struct key *keyring)
184+
{
185+
const u8 *p, *end;
186+
187+
if (!IS_ENABLED(CONFIG_IMA_APPRAISE_MODSIG))
188+
return 0;
189+
190+
pr_notice("Loading compiled-in module X.509 certificates\n");
191+
192+
p = system_certificate_list;
193+
end = p + module_cert_size;
194+
195+
return load_cert(p, end, keyring);
196+
}
197+
198+
/*
199+
* Load the compiled-in list of X.509 certificates.
200+
*/
201+
static __init int load_system_certificate_list(void)
202+
{
203+
const u8 *p, *end;
204+
unsigned long size;
205+
206+
pr_notice("Loading compiled-in X.509 certificates\n");
207+
208+
#ifdef CONFIG_MODULE_SIG
209+
p = system_certificate_list;
210+
size = system_certificate_list_size;
211+
#else
212+
p = system_certificate_list + module_cert_size;
213+
size = system_certificate_list_size - module_cert_size;
214+
#endif
215+
216+
end = p + size;
217+
return load_cert(p, end, builtin_trusted_keys);
218+
}
189219
late_initcall(load_system_certificate_list);
190220

191221
#ifdef CONFIG_SYSTEM_DATA_VERIFICATION

include/keys/system_keyring.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ extern int restrict_link_by_builtin_trusted(struct key *keyring,
1616
const struct key_type *type,
1717
const union key_payload *payload,
1818
struct key *restriction_key);
19+
extern __init int load_module_cert(struct key *keyring);
1920

2021
#else
2122
#define restrict_link_by_builtin_trusted restrict_link_reject
23+
24+
static inline __init int load_module_cert(struct key *keyring)
25+
{
26+
return 0;
27+
}
28+
2229
#endif
2330

2431
#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING

init/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ config MODULE_SIG_FORCE
21642164
config MODULE_SIG_ALL
21652165
bool "Automatically sign all modules"
21662166
default y
2167-
depends on MODULE_SIG
2167+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
21682168
help
21692169
Sign all modules during make modules_install. Without this option,
21702170
modules must be signed manually, using the scripts/sign-file tool.
@@ -2174,7 +2174,7 @@ comment "Do not forget to sign required modules with scripts/sign-file"
21742174

21752175
choice
21762176
prompt "Which hash algorithm should modules be signed with?"
2177-
depends on MODULE_SIG
2177+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
21782178
help
21792179
This determines which sort of hashing algorithm will be used during
21802180
signature generation. This algorithm _must_ be built into the kernel
@@ -2206,7 +2206,7 @@ endchoice
22062206

22072207
config MODULE_SIG_HASH
22082208
string
2209-
depends on MODULE_SIG
2209+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
22102210
default "sha1" if MODULE_SIG_SHA1
22112211
default "sha224" if MODULE_SIG_SHA224
22122212
default "sha256" if MODULE_SIG_SHA256

security/integrity/digsig.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ static int __init __integrity_init_keyring(const unsigned int id,
111111
} else {
112112
if (id == INTEGRITY_KEYRING_PLATFORM)
113113
set_platform_trusted_keys(keyring[id]);
114+
if (id == INTEGRITY_KEYRING_IMA)
115+
load_module_cert(keyring[id]);
114116
}
115117

116118
return err;

0 commit comments

Comments
 (0)