aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetko Manolov <petkan@mip-labs.com>2015-12-02 10:47:55 -0500
committerMimi Zohar <zohar@linux.vnet.ibm.com>2015-12-15 10:01:43 -0500
commit41c89b64d7184a780f12f2cccdabe65cb2408893 (patch)
tree2f4b10b186e186bd70be5fea18c8423334ab831d
parent38d859f991f3a05b352a06f82af0baa1acf33e02 (diff)
IMA: create machine owner and blacklist keyrings
This option creates IMA MOK and blacklist keyrings. IMA MOK is an intermediate keyring that sits between .system and .ima keyrings, effectively forming a simple CA hierarchy. To successfully import a key into .ima_mok it must be signed by a key which CA is in .system keyring. On turn any key that needs to go in .ima keyring must be signed by CA in either .system or .ima_mok keyrings. IMA MOK is empty at kernel boot. IMA blacklist keyring contains all revoked IMA keys. It is consulted before any other keyring. If the search is successful the requested operation is rejected and error is returned to the caller. Signed-off-by: Petko Manolov <petkan@mip-labs.com> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
-rw-r--r--crypto/asymmetric_keys/x509_public_key.c2
-rw-r--r--include/keys/system_keyring.h24
-rw-r--r--security/integrity/digsig_asymmetric.c14
-rw-r--r--security/integrity/ima/Kconfig18
-rw-r--r--security/integrity/ima/Makefile1
-rw-r--r--security/integrity/ima/ima_mok.c54
6 files changed, 113 insertions, 0 deletions
diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c
index 2a44b3752471..9e9e5a6a9ed6 100644
--- a/crypto/asymmetric_keys/x509_public_key.c
+++ b/crypto/asymmetric_keys/x509_public_key.c
@@ -321,6 +321,8 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
321 goto error_free_cert; 321 goto error_free_cert;
322 } else if (!prep->trusted) { 322 } else if (!prep->trusted) {
323 ret = x509_validate_trust(cert, get_system_trusted_keyring()); 323 ret = x509_validate_trust(cert, get_system_trusted_keyring());
324 if (ret)
325 ret = x509_validate_trust(cert, get_ima_mok_keyring());
324 if (!ret) 326 if (!ret)
325 prep->trusted = 1; 327 prep->trusted = 1;
326 } 328 }
diff --git a/include/keys/system_keyring.h b/include/keys/system_keyring.h
index b20cd885c1fd..39fd38cfa8c9 100644
--- a/include/keys/system_keyring.h
+++ b/include/keys/system_keyring.h
@@ -35,4 +35,28 @@ extern int system_verify_data(const void *data, unsigned long len,
35 enum key_being_used_for usage); 35 enum key_being_used_for usage);
36#endif 36#endif
37 37
38#ifdef CONFIG_IMA_MOK_KEYRING
39extern struct key *ima_mok_keyring;
40extern struct key *ima_blacklist_keyring;
41
42static inline struct key *get_ima_mok_keyring(void)
43{
44 return ima_mok_keyring;
45}
46static inline struct key *get_ima_blacklist_keyring(void)
47{
48 return ima_blacklist_keyring;
49}
50#else
51static inline struct key *get_ima_mok_keyring(void)
52{
53 return NULL;
54}
55static inline struct key *get_ima_blacklist_keyring(void)
56{
57 return NULL;
58}
59#endif /* CONFIG_IMA_MOK_KEYRING */
60
61
38#endif /* _KEYS_SYSTEM_KEYRING_H */ 62#endif /* _KEYS_SYSTEM_KEYRING_H */
diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c
index 4fec1816a2b3..5ade2a7517a6 100644
--- a/security/integrity/digsig_asymmetric.c
+++ b/security/integrity/digsig_asymmetric.c
@@ -17,6 +17,7 @@
17#include <linux/key-type.h> 17#include <linux/key-type.h>
18#include <crypto/public_key.h> 18#include <crypto/public_key.h>
19#include <keys/asymmetric-type.h> 19#include <keys/asymmetric-type.h>
20#include <keys/system_keyring.h>
20 21
21#include "integrity.h" 22#include "integrity.h"
22 23
@@ -32,9 +33,22 @@ static struct key *request_asymmetric_key(struct key *keyring, uint32_t keyid)
32 33
33 pr_debug("key search: \"%s\"\n", name); 34 pr_debug("key search: \"%s\"\n", name);
34 35
36 key = get_ima_blacklist_keyring();
37 if (key) {
38 key_ref_t kref;
39
40 kref = keyring_search(make_key_ref(key, 1),
41 &key_type_asymmetric, name);
42 if (!IS_ERR(kref)) {
43 pr_err("Key '%s' is in ima_blacklist_keyring\n", name);
44 return ERR_PTR(-EKEYREJECTED);
45 }
46 }
47
35 if (keyring) { 48 if (keyring) {
36 /* search in specific keyring */ 49 /* search in specific keyring */
37 key_ref_t kref; 50 key_ref_t kref;
51
38 kref = keyring_search(make_key_ref(keyring, 1), 52 kref = keyring_search(make_key_ref(keyring, 1),
39 &key_type_asymmetric, name); 53 &key_type_asymmetric, name);
40 if (IS_ERR(kref)) 54 if (IS_ERR(kref))
diff --git a/security/integrity/ima/Kconfig b/security/integrity/ima/Kconfig
index e74d66cbfe87..8d5e6e0e0937 100644
--- a/security/integrity/ima/Kconfig
+++ b/security/integrity/ima/Kconfig
@@ -145,6 +145,24 @@ config IMA_TRUSTED_KEYRING
145 145
146 This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING 146 This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING
147 147
148config IMA_MOK_KEYRING
149 bool "Create IMA machine owner keys (MOK) and blacklist keyrings"
150 depends on SYSTEM_TRUSTED_KEYRING
151 depends on IMA_TRUSTED_KEYRING
152 default n
153 help
154 This option creates IMA MOK and blacklist keyrings. IMA MOK is an
155 intermediate keyring that sits between .system and .ima keyrings,
156 effectively forming a simple CA hierarchy. To successfully import a
157 key into .ima_mok it must be signed by a key which CA is in .system
158 keyring. On turn any key that needs to go in .ima keyring must be
159 signed by CA in either .system or .ima_mok keyrings. IMA MOK is empty
160 at kernel boot.
161
162 IMA blacklist keyring contains all revoked IMA keys. It is consulted
163 before any other keyring. If the search is successful the requested
164 operation is rejected and error is returned to the caller.
165
148config IMA_LOAD_X509 166config IMA_LOAD_X509
149 bool "Load X509 certificate onto the '.ima' trusted keyring" 167 bool "Load X509 certificate onto the '.ima' trusted keyring"
150 depends on IMA_TRUSTED_KEYRING 168 depends on IMA_TRUSTED_KEYRING
diff --git a/security/integrity/ima/Makefile b/security/integrity/ima/Makefile
index d79263d2fdbf..a8539f9e060f 100644
--- a/security/integrity/ima/Makefile
+++ b/security/integrity/ima/Makefile
@@ -8,3 +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
diff --git a/security/integrity/ima/ima_mok.c b/security/integrity/ima/ima_mok.c
new file mode 100644
index 000000000000..18e37f57f512
--- /dev/null
+++ b/security/integrity/ima/ima_mok.c
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2015 Juniper Networks, Inc.
3 *
4 * Author:
5 * Petko Manolov <petko.manolov@konsulko.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2 of the
10 * License.
11 *
12 */
13
14#include <linux/export.h>
15#include <linux/kernel.h>
16#include <linux/sched.h>
17#include <linux/cred.h>
18#include <linux/err.h>
19#include <linux/module.h>
20#include <keys/asymmetric-type.h>
21
22
23struct key *ima_mok_keyring;
24struct key *ima_blacklist_keyring;
25
26/*
27 * Allocate the IMA MOK and blacklist keyrings
28 */
29__init int ima_mok_init(void)
30{
31 pr_notice("Allocating IMA MOK and blacklist keyrings.\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, NULL);
39
40 ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
41 KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
42 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
43 KEY_USR_VIEW | KEY_USR_READ |
44 KEY_USR_WRITE | KEY_USR_SEARCH,
45 KEY_ALLOC_NOT_IN_QUOTA, NULL);
46
47 if (IS_ERR(ima_mok_keyring) || IS_ERR(ima_blacklist_keyring))
48 panic("Can't allocate IMA MOK or blacklist keyrings.");
49 set_bit(KEY_FLAG_TRUSTED_ONLY, &ima_mok_keyring->flags);
50 set_bit(KEY_FLAG_TRUSTED_ONLY, &ima_blacklist_keyring->flags);
51 return 0;
52}
53
54module_init(ima_mok_init);