summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2016-04-07 04:45:23 -0400
committerDavid Howells <dhowells@redhat.com>2016-04-11 17:49:15 -0400
commit56104cf2b8d20eed32c14eac8ac574c35377ab38 (patch)
tree7fc12f22e49f9b799c998245f226906db293255e /security
parentd3bfe84129f65e0af2450743ebdab33d161d01c9 (diff)
IMA: Use the the system trusted keyrings instead of .ima_mok
Add a config option (IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY) that, when enabled, allows keys to be added to the IMA keyrings by userspace - with the restriction that each must be signed by a key in the system trusted keyrings. EPERM will be returned if this option is disabled, ENOKEY will be returned if no authoritative key can be found and EKEYREJECTED will be returned if the signature doesn't match. Other errors such as ENOPKG may also be returned. If this new option is enabled, the builtin system keyring is searched, as is the secondary system keyring if that is also enabled. Intermediate keys between the builtin system keyring and the key being added can be added to the secondary keyring (which replaces .ima_mok) to form a trust chain - provided they are also validly signed by a key in one of the trusted keyrings. The .ima_mok keyring is then removed and the IMA blacklist keyring gets its own config option (IMA_BLACKLIST_KEYRING). Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security')
-rw-r--r--security/integrity/digsig.c30
-rw-r--r--security/integrity/ima/Kconfig36
-rw-r--r--security/integrity/ima/Makefile2
-rw-r--r--security/integrity/ima/ima_mok.c17
4 files changed, 32 insertions, 53 deletions
diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c
index 98ee4c752cf5..4304372b323f 100644
--- a/security/integrity/digsig.c
+++ b/security/integrity/digsig.c
@@ -42,32 +42,10 @@ static bool init_keyring __initdata = true;
42static bool init_keyring __initdata; 42static bool init_keyring __initdata;
43#endif 43#endif
44 44
45#ifdef CONFIG_SYSTEM_TRUSTED_KEYRING 45#ifdef CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY
46/* 46#define restrict_link_to_ima restrict_link_by_builtin_and_secondary_trusted
47 * Restrict the addition of keys into the IMA keyring.
48 *
49 * Any key that needs to go in .ima keyring must be signed by CA in
50 * either .system or .ima_mok keyrings.
51 */
52static int restrict_link_by_ima_mok(struct key *keyring,
53 const struct key_type *type,
54 const union key_payload *payload)
55{
56 int ret;
57
58 ret = restrict_link_by_builtin_trusted(keyring, type, payload);
59 if (ret != -ENOKEY)
60 return ret;
61
62 return restrict_link_by_signature(get_ima_mok_keyring(),
63 type, payload);
64}
65#else 47#else
66/* 48#define restrict_link_to_ima restrict_link_by_builtin_trusted
67 * If there's no system trusted keyring, then keys cannot be loaded into
68 * .ima_mok and added keys cannot be marked trusted.
69 */
70#define restrict_link_by_ima_mok restrict_link_reject
71#endif 49#endif
72 50
73int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, 51int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
@@ -114,7 +92,7 @@ int __init integrity_init_keyring(const unsigned int id)
114 KEY_USR_VIEW | KEY_USR_READ | 92 KEY_USR_VIEW | KEY_USR_READ |
115 KEY_USR_WRITE | KEY_USR_SEARCH), 93 KEY_USR_WRITE | KEY_USR_SEARCH),
116 KEY_ALLOC_NOT_IN_QUOTA, 94 KEY_ALLOC_NOT_IN_QUOTA,
117 restrict_link_by_ima_mok, NULL); 95 restrict_link_to_ima, NULL);
118 if (IS_ERR(keyring[id])) { 96 if (IS_ERR(keyring[id])) {
119 err = PTR_ERR(keyring[id]); 97 err = PTR_ERR(keyring[id]);
120 pr_info("Can't allocate %s keyring (%d)\n", 98 pr_info("Can't allocate %s keyring (%d)\n",
diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig
index e54a8a8dae94..5487827fa86c 100644
--- a/security/integrity/ima/Kconfig
+++ b/security/integrity/ima/Kconfig
@@ -155,23 +155,33 @@ config IMA_TRUSTED_KEYRING
155 155
156 This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING 156 This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING
157 157
158config IMA_MOK_KEYRING 158config IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY
159 bool "Create IMA machine owner keys (MOK) and blacklist keyrings" 159 bool "Permit keys validly signed by a built-in or secondary CA cert (EXPERIMENTAL)"
160 depends on SYSTEM_TRUSTED_KEYRING
161 depends on SECONDARY_TRUSTED_KEYRING
162 depends on INTEGRITY_ASYMMETRIC_KEYS
163 select INTEGRITY_TRUSTED_KEYRING
164 default n
165 help
166 Keys may be added to the IMA or IMA blacklist keyrings, if the
167 key is validly signed by a CA cert in the system built-in or
168 secondary trusted keyrings.
169
170 Intermediate keys between those the kernel has compiled in and the
171 IMA keys to be added may be added to the system secondary keyring,
172 provided they are validly signed by a key already resident in the
173 built-in or secondary trusted keyrings.
174
175config IMA_BLACKLIST_KEYRING
176 bool "Create IMA machine owner blacklist keyrings (EXPERIMENTAL)"
160 depends on SYSTEM_TRUSTED_KEYRING 177 depends on SYSTEM_TRUSTED_KEYRING
161 depends on IMA_TRUSTED_KEYRING 178 depends on IMA_TRUSTED_KEYRING
162 default n 179 default n
163 help 180 help
164 This option creates IMA MOK and blacklist keyrings. IMA MOK is an 181 This option creates an IMA blacklist keyring, which contains all
165 intermediate keyring that sits between .system and .ima keyrings, 182 revoked IMA keys. It is consulted before any other keyring. If
166 effectively forming a simple CA hierarchy. To successfully import a 183 the search is successful the requested operation is rejected and
167 key into .ima_mok it must be signed by a key which CA is in .system 184 an error is returned to the caller.
168 keyring. On turn any key that needs to go in .ima keyring must be
169 signed by CA in either .system or .ima_mok keyrings. IMA MOK is empty
170 at kernel boot.
171
172 IMA blacklist keyring contains all revoked IMA keys. It is consulted
173 before any other keyring. If the search is successful the requested
174 operation is rejected and error is returned to the caller.
175 185
176config IMA_LOAD_X509 186config IMA_LOAD_X509
177 bool "Load X509 certificate onto the '.ima' trusted keyring" 187 bool "Load X509 certificate onto the '.ima' trusted keyring"
diff --git a/security/integrity/ima/Makefile b/security/integrity/ima/Makefile
index a8539f9e060f..9aeaedad1e2b 100644
--- a/security/integrity/ima/Makefile
+++ b/security/integrity/ima/Makefile
@@ -8,4 +8,4 @@ obj-$(CONFIG_IMA) += ima.o
8ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \ 8ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \
9 ima_policy.o ima_template.o ima_template_lib.o 9 ima_policy.o ima_template.o ima_template_lib.o
10ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o 10ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o
11obj-$(CONFIG_IMA_MOK_KEYRING) += ima_mok.o 11obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o
diff --git a/security/integrity/ima/ima_mok.c b/security/integrity/ima/ima_mok.c
index 2988726d30d6..74a279957464 100644
--- a/security/integrity/ima/ima_mok.c
+++ b/security/integrity/ima/ima_mok.c
@@ -20,23 +20,14 @@
20#include <keys/system_keyring.h> 20#include <keys/system_keyring.h>
21 21
22 22
23struct key *ima_mok_keyring;
24struct key *ima_blacklist_keyring; 23struct key *ima_blacklist_keyring;
25 24
26/* 25/*
27 * Allocate the IMA MOK and blacklist keyrings 26 * Allocate the IMA blacklist keyring
28 */ 27 */
29__init int ima_mok_init(void) 28__init int ima_mok_init(void)
30{ 29{
31 pr_notice("Allocating IMA MOK and blacklist keyrings.\n"); 30 pr_notice("Allocating IMA blacklist keyring.\n");
32
33 ima_mok_keyring = keyring_alloc(".ima_mok",
34 KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
35 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
36 KEY_USR_VIEW | KEY_USR_READ |
37 KEY_USR_WRITE | KEY_USR_SEARCH,
38 KEY_ALLOC_NOT_IN_QUOTA,
39 restrict_link_by_builtin_trusted, NULL);
40 31
41 ima_blacklist_keyring = keyring_alloc(".ima_blacklist", 32 ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
42 KUIDT_INIT(0), KGIDT_INIT(0), current_cred(), 33 KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
@@ -46,8 +37,8 @@ __init int ima_mok_init(void)
46 KEY_ALLOC_NOT_IN_QUOTA, 37 KEY_ALLOC_NOT_IN_QUOTA,
47 restrict_link_by_builtin_trusted, NULL); 38 restrict_link_by_builtin_trusted, NULL);
48 39
49 if (IS_ERR(ima_mok_keyring) || IS_ERR(ima_blacklist_keyring)) 40 if (IS_ERR(ima_blacklist_keyring))
50 panic("Can't allocate IMA MOK or blacklist keyrings."); 41 panic("Can't allocate IMA blacklist keyring.");
51 42
52 set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags); 43 set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags);
53 return 0; 44 return 0;