summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorNayna Jain <nayna@linux.ibm.com>2018-12-08 15:26:59 -0500
committerMimi Zohar <zohar@linux.ibm.com>2018-12-12 22:02:28 -0500
commit9dc92c45177ab70e20ae94baa2f2e558da63a9c7 (patch)
tree6620a5636e038d1cfb08d985e6effe541307d82e /security
parenta802ed0dd9c2607cc219574e881062d43ea3b7e0 (diff)
integrity: Define a trusted platform keyring
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image. It is further possible that the kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust, the kernel needs an additional keyring to store platform keys. This patch creates the new keyring called ".platform" to isolate keys provided by platform from keys by kernel. These keys are used to facilitate signature verification during kexec. Since the scope of this keyring is only the platform/firmware keys, it cannot be updated from userspace. This keyring can be enabled by setting CONFIG_INTEGRITY_PLATFORM_KEYRING. Signed-off-by: Nayna Jain <nayna@linux.ibm.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Acked-by: Serge Hallyn <serge@hallyn.com> Reviewed-by: James Morris <james.morris@microsoft.com> Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
Diffstat (limited to 'security')
-rw-r--r--security/integrity/Kconfig11
-rw-r--r--security/integrity/Makefile1
-rw-r--r--security/integrity/digsig.c47
-rw-r--r--security/integrity/integrity.h3
-rw-r--r--security/integrity/platform_certs/platform_keyring.c35
5 files changed, 81 insertions, 16 deletions
diff --git a/security/integrity/Kconfig b/security/integrity/Kconfig
index da9565891738..4b4d2aeef539 100644
--- a/security/integrity/Kconfig
+++ b/security/integrity/Kconfig
@@ -51,6 +51,17 @@ config INTEGRITY_TRUSTED_KEYRING
51 .evm keyrings be signed by a key on the system trusted 51 .evm keyrings be signed by a key on the system trusted
52 keyring. 52 keyring.
53 53
54config INTEGRITY_PLATFORM_KEYRING
55 bool "Provide keyring for platform/firmware trusted keys"
56 depends on INTEGRITY_ASYMMETRIC_KEYS
57 depends on SYSTEM_BLACKLIST_KEYRING
58 depends on EFI
59 help
60 Provide a separate, distinct keyring for platform trusted keys, which
61 the kernel automatically populates during initialization from values
62 provided by the platform for verifying the kexec'ed kerned image
63 and, possibly, the initramfs signature.
64
54config INTEGRITY_AUDIT 65config INTEGRITY_AUDIT
55 bool "Enables integrity auditing support " 66 bool "Enables integrity auditing support "
56 depends on AUDIT 67 depends on AUDIT
diff --git a/security/integrity/Makefile b/security/integrity/Makefile
index 04d6e462b079..046ffc1bb42d 100644
--- a/security/integrity/Makefile
+++ b/security/integrity/Makefile
@@ -9,6 +9,7 @@ integrity-y := iint.o
9integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o 9integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o
10integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o 10integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o
11integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o 11integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o
12integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o
12 13
13subdir-$(CONFIG_IMA) += ima 14subdir-$(CONFIG_IMA) += ima
14obj-$(CONFIG_IMA) += ima/ 15obj-$(CONFIG_IMA) += ima/
diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c
index 5eacba858e4b..4a22730e0cc6 100644
--- a/security/integrity/digsig.c
+++ b/security/integrity/digsig.c
@@ -35,6 +35,7 @@ static const char * const keyring_name[INTEGRITY_KEYRING_MAX] = {
35 ".ima", 35 ".ima",
36#endif 36#endif
37 "_module", 37 "_module",
38 ".platform",
38}; 39};
39 40
40#ifdef CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY 41#ifdef CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY
@@ -73,26 +74,14 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
73 return -EOPNOTSUPP; 74 return -EOPNOTSUPP;
74} 75}
75 76
76int __init integrity_init_keyring(const unsigned int id) 77static int __integrity_init_keyring(const unsigned int id, key_perm_t perm,
78 struct key_restriction *restriction)
77{ 79{
78 const struct cred *cred = current_cred(); 80 const struct cred *cred = current_cred();
79 struct key_restriction *restriction;
80 int err = 0; 81 int err = 0;
81 82
82 if (!IS_ENABLED(CONFIG_INTEGRITY_TRUSTED_KEYRING))
83 return 0;
84
85 restriction = kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
86 if (!restriction)
87 return -ENOMEM;
88
89 restriction->check = restrict_link_to_ima;
90
91 keyring[id] = keyring_alloc(keyring_name[id], KUIDT_INIT(0), 83 keyring[id] = keyring_alloc(keyring_name[id], KUIDT_INIT(0),
92 KGIDT_INIT(0), cred, 84 KGIDT_INIT(0), cred, perm,
93 ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
94 KEY_USR_VIEW | KEY_USR_READ |
95 KEY_USR_WRITE | KEY_USR_SEARCH),
96 KEY_ALLOC_NOT_IN_QUOTA, 85 KEY_ALLOC_NOT_IN_QUOTA,
97 restriction, NULL); 86 restriction, NULL);
98 if (IS_ERR(keyring[id])) { 87 if (IS_ERR(keyring[id])) {
@@ -101,9 +90,37 @@ int __init integrity_init_keyring(const unsigned int id)
101 keyring_name[id], err); 90 keyring_name[id], err);
102 keyring[id] = NULL; 91 keyring[id] = NULL;
103 } 92 }
93
104 return err; 94 return err;
105} 95}
106 96
97int __init integrity_init_keyring(const unsigned int id)
98{
99 struct key_restriction *restriction;
100 key_perm_t perm;
101
102 perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW
103 | KEY_USR_READ | KEY_USR_SEARCH;
104
105 if (id == INTEGRITY_KEYRING_PLATFORM) {
106 restriction = NULL;
107 goto out;
108 }
109
110 if (!IS_ENABLED(CONFIG_INTEGRITY_TRUSTED_KEYRING))
111 return 0;
112
113 restriction = kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
114 if (!restriction)
115 return -ENOMEM;
116
117 restriction->check = restrict_link_to_ima;
118 perm |= KEY_USR_WRITE;
119
120out:
121 return __integrity_init_keyring(id, perm, restriction);
122}
123
107int __init integrity_load_x509(const unsigned int id, const char *path) 124int __init integrity_load_x509(const unsigned int id, const char *path)
108{ 125{
109 key_ref_t key; 126 key_ref_t key;
diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
index e60473b13a8d..c2332a44799e 100644
--- a/security/integrity/integrity.h
+++ b/security/integrity/integrity.h
@@ -142,7 +142,8 @@ int integrity_kernel_read(struct file *file, loff_t offset,
142#define INTEGRITY_KEYRING_EVM 0 142#define INTEGRITY_KEYRING_EVM 0
143#define INTEGRITY_KEYRING_IMA 1 143#define INTEGRITY_KEYRING_IMA 1
144#define INTEGRITY_KEYRING_MODULE 2 144#define INTEGRITY_KEYRING_MODULE 2
145#define INTEGRITY_KEYRING_MAX 3 145#define INTEGRITY_KEYRING_PLATFORM 3
146#define INTEGRITY_KEYRING_MAX 4
146 147
147extern struct dentry *integrity_dir; 148extern struct dentry *integrity_dir;
148 149
diff --git a/security/integrity/platform_certs/platform_keyring.c b/security/integrity/platform_certs/platform_keyring.c
new file mode 100644
index 000000000000..79f80af5b470
--- /dev/null
+++ b/security/integrity/platform_certs/platform_keyring.c
@@ -0,0 +1,35 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Platform keyring for firmware/platform keys
4 *
5 * Copyright IBM Corporation, 2018
6 * Author(s): Nayna Jain <nayna@linux.ibm.com>
7 */
8
9#include <linux/export.h>
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/cred.h>
13#include <linux/err.h>
14#include <linux/slab.h>
15#include "../integrity.h"
16
17/*
18 * Create the trusted keyrings.
19 */
20static __init int platform_keyring_init(void)
21{
22 int rc;
23
24 rc = integrity_init_keyring(INTEGRITY_KEYRING_PLATFORM);
25 if (rc)
26 return rc;
27
28 pr_notice("Platform Keyring initialized\n");
29 return 0;
30}
31
32/*
33 * Must be initialised before we try and load the keys into the keyring.
34 */
35device_initcall(platform_keyring_init);