Skip to content

Commit e6f0bf0

Browse files
committed
Merge tag 'integrity-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity
Pull IMA updates from Mimi Zohar: "In addition to loading the kernel module signing key onto the builtin keyring, load it onto the IMA keyring as well. Also six trivial changes and bug fixes" * tag 'integrity-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity: ima: ensure IMA_APPRAISE_MODSIG has necessary dependencies ima: Fix fall-through warnings for Clang integrity: Add declarations to init_once void arguments. ima: Fix function name error in comment. ima: enable loading of build time generated key on .ima keyring ima: enable signing of modules with build time generated key keys: cleanup build time module signing keys ima: Fix the error code for restoring the PCR value ima: without an IMA policy loaded, return quickly
2 parents 10a3efd + 781a573 commit e6f0bf0

File tree

12 files changed

+75
-14
lines changed

12 files changed

+75
-14
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,9 @@ MRPROPER_FILES += include/config include/generated \
15071507
debian snap tar-install \
15081508
.config .config.old .version \
15091509
Module.symvers \
1510-
signing_key.pem signing_key.priv signing_key.x509 \
1511-
x509.genkey extra_certificates signing_key.x509.keyid \
1512-
signing_key.x509.signer vmlinux-gdb.py \
1510+
certs/signing_key.pem certs/signing_key.x509 \
1511+
certs/x509.genkey \
1512+
vmlinux-gdb.py \
15131513
*.spec
15141514

15151515
# 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 && MODULES)
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ endif # CONFIG_SYSTEM_TRUSTED_KEYRING
3333
clean-files := x509_certificate_list .x509.list x509_revocation_list
3434

3535
ifeq ($(CONFIG_MODULE_SIG),y)
36+
SIGN_KEY = y
37+
endif
38+
39+
ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y)
40+
ifeq ($(CONFIG_MODULES),y)
41+
SIGN_KEY = y
42+
endif
43+
endif
44+
45+
ifdef SIGN_KEY
3646
###############################################################################
3747
#
3848
# If module signing is requested, say by allyesconfig, but a key has not been

certs/system_certificates.S

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
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) \
13+
&& defined(CONFIG_MODULES))
1214
.incbin "certs/signing_key.x509"
1315
#endif
16+
__module_cert_end:
1417
.incbin "certs/x509_certificate_list"
1518
__cert_list_end:
1619

@@ -35,3 +38,12 @@ system_certificate_list_size:
3538
#else
3639
.long __cert_list_end - __cert_list_start
3740
#endif
41+
42+
.align 8
43+
.globl module_cert_size
44+
module_cert_size:
45+
#ifdef CONFIG_64BIT
46+
.quad __module_cert_end - __module_cert_start
47+
#else
48+
.long __module_cert_end - __module_cert_start
49+
#endif

certs/system_keyring.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static struct key *platform_trusted_keys;
2828

2929
extern __initconst const u8 system_certificate_list[];
3030
extern __initconst const unsigned long system_certificate_list_size;
31+
extern __initconst const unsigned long module_cert_size;
3132

3233
/**
3334
* restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA
@@ -133,15 +134,35 @@ static __init int system_trusted_keyring_init(void)
133134
*/
134135
device_initcall(system_trusted_keyring_init);
135136

137+
__init int load_module_cert(struct key *keyring)
138+
{
139+
if (!IS_ENABLED(CONFIG_IMA_APPRAISE_MODSIG))
140+
return 0;
141+
142+
pr_notice("Loading compiled-in module X.509 certificates\n");
143+
144+
return load_certificate_list(system_certificate_list, module_cert_size, keyring);
145+
}
146+
136147
/*
137148
* Load the compiled-in list of X.509 certificates.
138149
*/
139150
static __init int load_system_certificate_list(void)
140151
{
152+
const u8 *p;
153+
unsigned long size;
154+
141155
pr_notice("Loading compiled-in X.509 certificates\n");
142156

143-
return load_certificate_list(system_certificate_list, system_certificate_list_size,
144-
builtin_trusted_keys);
157+
#ifdef CONFIG_MODULE_SIG
158+
p = system_certificate_list;
159+
size = system_certificate_list_size;
160+
#else
161+
p = system_certificate_list + module_cert_size;
162+
size = system_certificate_list_size - module_cert_size;
163+
#endif
164+
165+
return load_certificate_list(p, size, builtin_trusted_keys);
145166
}
146167
late_initcall(load_system_certificate_list);
147168

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
@@ -2182,7 +2182,7 @@ config MODULE_SIG_FORCE
21822182
config MODULE_SIG_ALL
21832183
bool "Automatically sign all modules"
21842184
default y
2185-
depends on MODULE_SIG
2185+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
21862186
help
21872187
Sign all modules during make modules_install. Without this option,
21882188
modules must be signed manually, using the scripts/sign-file tool.
@@ -2192,7 +2192,7 @@ comment "Do not forget to sign required modules with scripts/sign-file"
21922192

21932193
choice
21942194
prompt "Which hash algorithm should modules be signed with?"
2195-
depends on MODULE_SIG
2195+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
21962196
help
21972197
This determines which sort of hashing algorithm will be used during
21982198
signature generation. This algorithm _must_ be built into the kernel
@@ -2224,7 +2224,7 @@ endchoice
22242224

22252225
config MODULE_SIG_HASH
22262226
string
2227-
depends on MODULE_SIG
2227+
depends on MODULE_SIG || IMA_APPRAISE_MODSIG
22282228
default "sha1" if MODULE_SIG_SHA1
22292229
default "sha224" if MODULE_SIG_SHA224
22302230
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;

security/integrity/iint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void integrity_inode_free(struct inode *inode)
160160

161161
static void init_once(void *foo)
162162
{
163-
struct integrity_iint_cache *iint = foo;
163+
struct integrity_iint_cache *iint = (struct integrity_iint_cache *) foo;
164164

165165
memset(iint, 0, sizeof(*iint));
166166
iint->ima_file_status = INTEGRITY_UNKNOWN;

security/integrity/ima/ima_main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ int ima_bprm_check(struct linux_binprm *bprm)
482482
}
483483

484484
/**
485-
* ima_path_check - based on policy, collect/store measurement.
485+
* ima_file_check - based on policy, collect/store measurement.
486486
* @file: pointer to the file to be measured
487487
* @mask: contains MAY_READ, MAY_WRITE, MAY_EXEC or MAY_APPEND
488488
*
@@ -606,6 +606,9 @@ void ima_post_create_tmpfile(struct user_namespace *mnt_userns,
606606
struct integrity_iint_cache *iint;
607607
int must_appraise;
608608

609+
if (!ima_policy_flag || !S_ISREG(inode->i_mode))
610+
return;
611+
609612
must_appraise = ima_must_appraise(mnt_userns, inode, MAY_ACCESS,
610613
FILE_CHECK);
611614
if (!must_appraise)
@@ -636,6 +639,9 @@ void ima_post_path_mknod(struct user_namespace *mnt_userns,
636639
struct inode *inode = dentry->d_inode;
637640
int must_appraise;
638641

642+
if (!ima_policy_flag || !S_ISREG(inode->i_mode))
643+
return;
644+
639645
must_appraise = ima_must_appraise(mnt_userns, inode, MAY_ACCESS,
640646
FILE_CHECK);
641647
if (!must_appraise)
@@ -780,6 +786,7 @@ int ima_load_data(enum kernel_load_data_id id, bool contents)
780786
pr_err("impossible to appraise a module without a file descriptor. sig_enforce kernel parameter might help\n");
781787
return -EACCES; /* INTEGRITY_UNKNOWN */
782788
}
789+
break;
783790
default:
784791
break;
785792
}

0 commit comments

Comments
 (0)