Skip to content

Commit 56104cf

Browse files
committed
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>
1 parent d3bfe84 commit 56104cf

File tree

5 files changed

+34
-64
lines changed

5 files changed

+34
-64
lines changed

include/keys/system_keyring.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,19 @@ extern int restrict_link_by_builtin_and_secondary_trusted(
3333
#define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted
3434
#endif
3535

36-
#ifdef CONFIG_IMA_MOK_KEYRING
37-
extern struct key *ima_mok_keyring;
36+
#ifdef CONFIG_IMA_BLACKLIST_KEYRING
3837
extern struct key *ima_blacklist_keyring;
3938

40-
static inline struct key *get_ima_mok_keyring(void)
41-
{
42-
return ima_mok_keyring;
43-
}
4439
static inline struct key *get_ima_blacklist_keyring(void)
4540
{
4641
return ima_blacklist_keyring;
4742
}
4843
#else
49-
static inline struct key *get_ima_mok_keyring(void)
50-
{
51-
return NULL;
52-
}
5344
static inline struct key *get_ima_blacklist_keyring(void)
5445
{
5546
return NULL;
5647
}
57-
#endif /* CONFIG_IMA_MOK_KEYRING */
48+
#endif /* CONFIG_IMA_BLACKLIST_KEYRING */
5849

5950

6051
#endif /* _KEYS_SYSTEM_KEYRING_H */

security/integrity/digsig.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,10 @@ static bool init_keyring __initdata = true;
4242
static bool init_keyring __initdata;
4343
#endif
4444

45-
#ifdef CONFIG_SYSTEM_TRUSTED_KEYRING
46-
/*
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-
*/
52-
static 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-
}
45+
#ifdef CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY
46+
#define restrict_link_to_ima restrict_link_by_builtin_and_secondary_trusted
6547
#else
66-
/*
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
48+
#define restrict_link_to_ima restrict_link_by_builtin_trusted
7149
#endif
7250

7351
int 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)
11492
KEY_USR_VIEW | KEY_USR_READ |
11593
KEY_USR_WRITE | KEY_USR_SEARCH),
11694
KEY_ALLOC_NOT_IN_QUOTA,
117-
restrict_link_by_ima_mok, NULL);
95+
restrict_link_to_ima, NULL);
11896
if (IS_ERR(keyring[id])) {
11997
err = PTR_ERR(keyring[id]);
12098
pr_info("Can't allocate %s keyring (%d)\n",

security/integrity/ima/Kconfig

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,33 @@ config IMA_TRUSTED_KEYRING
155155

156156
This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING
157157

158-
config IMA_MOK_KEYRING
159-
bool "Create IMA machine owner keys (MOK) and blacklist keyrings"
158+
config IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY
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+
175+
config IMA_BLACKLIST_KEYRING
176+
bool "Create IMA machine owner blacklist keyrings (EXPERIMENTAL)"
160177
depends on SYSTEM_TRUSTED_KEYRING
161178
depends on IMA_TRUSTED_KEYRING
162179
default n
163180
help
164-
This option creates IMA MOK and blacklist keyrings. IMA MOK is an
165-
intermediate keyring that sits between .system and .ima keyrings,
166-
effectively forming a simple CA hierarchy. To successfully import a
167-
key into .ima_mok it must be signed by a key which CA is in .system
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.
181+
This option creates an IMA blacklist keyring, which contains all
182+
revoked IMA keys. It is consulted before any other keyring. If
183+
the search is successful the requested operation is rejected and
184+
an error is returned to the caller.
175185

176186
config IMA_LOAD_X509
177187
bool "Load X509 certificate onto the '.ima' trusted keyring"

security/integrity/ima/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +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
11+
obj-$(CONFIG_IMA_BLACKLIST_KEYRING) += ima_mok.o

security/integrity/ima/ima_mok.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@
2020
#include <keys/system_keyring.h>
2121

2222

23-
struct key *ima_mok_keyring;
2423
struct key *ima_blacklist_keyring;
2524

2625
/*
27-
* Allocate the IMA MOK and blacklist keyrings
26+
* Allocate the IMA blacklist keyring
2827
*/
2928
__init int ima_mok_init(void)
3029
{
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,
39-
restrict_link_by_builtin_trusted, NULL);
30+
pr_notice("Allocating IMA blacklist keyring.\n");
4031

4132
ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
4233
KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
@@ -46,8 +37,8 @@ __init int ima_mok_init(void)
4637
KEY_ALLOC_NOT_IN_QUOTA,
4738
restrict_link_by_builtin_trusted, NULL);
4839

49-
if (IS_ERR(ima_mok_keyring) || IS_ERR(ima_blacklist_keyring))
50-
panic("Can't allocate IMA MOK or blacklist keyrings.");
40+
if (IS_ERR(ima_blacklist_keyring))
41+
panic("Can't allocate IMA blacklist keyring.");
5142

5243
set_bit(KEY_FLAG_KEEP, &ima_blacklist_keyring->flags);
5344
return 0;

0 commit comments

Comments
 (0)