Skip to content

Commit 41c89b6

Browse files
Petko ManolovMimi Zohar
authored andcommitted
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>
1 parent 38d859f commit 41c89b6

6 files changed

Lines changed: 113 additions & 0 deletions

File tree

‎crypto/asymmetric_keys/x509_public_key.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
321321
goto error_free_cert;
322322
} else if (!prep->trusted) {
323323
ret = x509_validate_trust(cert, get_system_trusted_keyring());
324+
if (ret)
325+
ret = x509_validate_trust(cert, get_ima_mok_keyring());
324326
if (!ret)
325327
prep->trusted = 1;
326328
}

‎include/keys/system_keyring.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,28 @@ extern int system_verify_data(const void *data, unsigned long len,
3535
enum key_being_used_for usage);
3636
#endif
3737

38+
#ifdef CONFIG_IMA_MOK_KEYRING
39+
extern struct key *ima_mok_keyring;
40+
extern struct key *ima_blacklist_keyring;
41+
42+
static inline struct key *get_ima_mok_keyring(void)
43+
{
44+
return ima_mok_keyring;
45+
}
46+
static inline struct key *get_ima_blacklist_keyring(void)
47+
{
48+
return ima_blacklist_keyring;
49+
}
50+
#else
51+
static inline struct key *get_ima_mok_keyring(void)
52+
{
53+
return NULL;
54+
}
55+
static inline struct key *get_ima_blacklist_keyring(void)
56+
{
57+
return NULL;
58+
}
59+
#endif /* CONFIG_IMA_MOK_KEYRING */
60+
61+
3862
#endif /* _KEYS_SYSTEM_KEYRING_H */

‎security/integrity/digsig_asymmetric.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/key-type.h>
1818
#include <crypto/public_key.h>
1919
#include <keys/asymmetric-type.h>
20+
#include <keys/system_keyring.h>
2021

2122
#include "integrity.h"
2223

@@ -32,9 +33,22 @@ static struct key *request_asymmetric_key(struct key *keyring, uint32_t keyid)
3233

3334
pr_debug("key search: \"%s\"\n", name);
3435

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+
3548
if (keyring) {
3649
/* search in specific keyring */
3750
key_ref_t kref;
51+
3852
kref = keyring_search(make_key_ref(keyring, 1),
3953
&key_type_asymmetric, name);
4054
if (IS_ERR(kref))

‎security/integrity/ima/Kconfig‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ config IMA_TRUSTED_KEYRING
145145

146146
This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING
147147

148+
config 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+
148166
config IMA_LOAD_X509
149167
bool "Load X509 certificate onto the '.ima' trusted keyring"
150168
depends on IMA_TRUSTED_KEYRING

‎security/integrity/ima/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ obj-$(CONFIG_IMA) += ima.o
88
ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \
99
ima_policy.o ima_template.o ima_template_lib.o
1010
ima-$(CONFIG_IMA_APPRAISE) += ima_appraise.o
11+
obj-$(CONFIG_IMA_MOK_KEYRING) += ima_mok.o

‎security/integrity/ima/ima_mok.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
23+
struct key *ima_mok_keyring;
24+
struct 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+
54+
module_init(ima_mok_init);

0 commit comments

Comments
 (0)