Skip to content

Commit 7d2ce23

Browse files
author
Mimi Zohar
committed
ima: define '.ima' as a builtin 'trusted' keyring
Require all keys added to the IMA keyring be signed by an existing trusted key on the system trusted keyring. Changelog v6: - remove ifdef CONFIG_IMA_TRUSTED_KEYRING in C code - Dmitry - update Kconfig dependency and help - select KEYS_DEBUG_PROC_KEYS - Dmitry Changelog v5: - Move integrity_init_keyring() to init_ima() - Dmitry - reset keyring[id] on failure - Dmitry Changelog v1: - don't link IMA trusted keyring to user keyring Changelog: - define stub integrity_init_keyring() function (reported-by Fengguang Wu) - differentiate between regular and trusted keyring names. - replace printk with pr_info (D. Kasatkin) - only make the IMA keyring a trusted keyring (reported-by D. Kastatkin) - define stub integrity_init_keyring() definition based on CONFIG_INTEGRITY_SIGNATURE, not CONFIG_INTEGRITY_ASYMMETRIC_KEYS. (reported-by Jim Davis) Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com> Acked-by: David Howells <dhowells@redhat.com>
1 parent 32c4741 commit 7d2ce23

5 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎security/integrity/digsig.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1414

1515
#include <linux/err.h>
16+
#include <linux/sched.h>
1617
#include <linux/rbtree.h>
18+
#include <linux/cred.h>
1719
#include <linux/key-type.h>
1820
#include <linux/digsig.h>
1921

@@ -24,7 +26,11 @@ static struct key *keyring[INTEGRITY_KEYRING_MAX];
2426
static const char *keyring_name[INTEGRITY_KEYRING_MAX] = {
2527
"_evm",
2628
"_module",
29+
#ifndef CONFIG_IMA_TRUSTED_KEYRING
2730
"_ima",
31+
#else
32+
".ima",
33+
#endif
2834
};
2935

3036
int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
@@ -56,3 +62,25 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
5662

5763
return -EOPNOTSUPP;
5864
}
65+
66+
int integrity_init_keyring(const unsigned int id)
67+
{
68+
const struct cred *cred = current_cred();
69+
int err = 0;
70+
71+
keyring[id] = keyring_alloc(keyring_name[id], KUIDT_INIT(0),
72+
KGIDT_INIT(0), cred,
73+
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
74+
KEY_USR_VIEW | KEY_USR_READ |
75+
KEY_USR_WRITE | KEY_USR_SEARCH),
76+
KEY_ALLOC_NOT_IN_QUOTA, NULL);
77+
if (!IS_ERR(keyring[id]))
78+
set_bit(KEY_FLAG_TRUSTED_ONLY, &keyring[id]->flags);
79+
else {
80+
err = PTR_ERR(keyring[id]);
81+
pr_info("Can't allocate %s keyring (%d)\n",
82+
keyring_name[id], err);
83+
keyring[id] = NULL;
84+
}
85+
return err;
86+
}

‎security/integrity/ima/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,13 @@ config IMA_APPRAISE
123123
For more information on integrity appraisal refer to:
124124
<http://linux-ima.sourceforge.net>
125125
If unsure, say N.
126+
127+
config IMA_TRUSTED_KEYRING
128+
bool "Require all keys on the .ima keyring be signed"
129+
depends on IMA_APPRAISE && SYSTEM_TRUSTED_KEYRING
130+
depends on INTEGRITY_ASYMMETRIC_KEYS
131+
select KEYS_DEBUG_PROC_KEYS
132+
default y
133+
help
134+
This option requires that all keys added to the .ima
135+
keyring be signed by a key on the system trusted keyring.

‎security/integrity/ima/ima.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,16 @@ static inline int security_filter_rule_match(u32 secid, u32 field, u32 op,
249249
return -EINVAL;
250250
}
251251
#endif /* CONFIG_IMA_LSM_RULES */
252+
253+
#ifdef CONFIG_IMA_TRUSTED_KEYRING
254+
static inline int ima_init_keyring(const unsigned int id)
255+
{
256+
return integrity_init_keyring(id);
257+
}
258+
#else
259+
static inline int ima_init_keyring(const unsigned int id)
260+
{
261+
return 0;
262+
}
263+
#endif /* CONFIG_IMA_TRUSTED_KEYRING */
252264
#endif

‎security/integrity/ima/ima_main.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,14 @@ static int __init init_ima(void)
325325

326326
hash_setup(CONFIG_IMA_DEFAULT_HASH);
327327
error = ima_init();
328-
if (!error)
329-
ima_initialized = 1;
328+
if (error)
329+
goto out;
330+
331+
error = ima_init_keyring(INTEGRITY_KEYRING_IMA);
332+
if (error)
333+
goto out;
334+
ima_initialized = 1;
335+
out:
330336
return error;
331337
}
332338

‎security/integrity/integrity.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct integrity_iint_cache *integrity_iint_find(struct inode *inode);
124124
int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
125125
const char *digest, int digestlen);
126126

127+
int integrity_init_keyring(const unsigned int id);
127128
#else
128129

129130
static inline int integrity_digsig_verify(const unsigned int id,
@@ -133,6 +134,10 @@ static inline int integrity_digsig_verify(const unsigned int id,
133134
return -EOPNOTSUPP;
134135
}
135136

137+
static inline int integrity_init_keyring(const unsigned int id)
138+
{
139+
return 0;
140+
}
136141
#endif /* CONFIG_INTEGRITY_SIGNATURE */
137142

138143
#ifdef CONFIG_INTEGRITY_ASYMMETRIC_KEYS

0 commit comments

Comments
 (0)