Skip to content

Commit 5808611

Browse files
nramasmimizohar
authored andcommitted
IMA: Add KEY_CHECK func to measure keys
Measure keys loaded onto any keyring. This patch defines a new IMA policy func namely KEY_CHECK to measure keys. Updated ima_match_rules() to check for KEY_CHECK and ima_parse_rule() to handle KEY_CHECK. Signed-off-by: Lakshmi Ramasubramanian <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent c5563ba commit 5808611

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Documentation/ABI/testing/ima_policy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Description:
2929
base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK]
3030
[FIRMWARE_CHECK]
3131
[KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK]
32-
[KEXEC_CMDLINE]
32+
[KEXEC_CMDLINE] [KEY_CHECK]
3333
mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND]
3434
[[^]MAY_EXEC]
3535
fsmagic:= hex value
@@ -113,3 +113,7 @@ Description:
113113
Example of appraise rule allowing modsig appended signatures:
114114

115115
appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig
116+
117+
Example of measure rule using KEY_CHECK to measure all keys:
118+
119+
measure func=KEY_CHECK

security/integrity/ima/ima.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static inline unsigned long ima_hash_key(u8 *digest)
193193
hook(KEXEC_INITRAMFS_CHECK) \
194194
hook(POLICY_CHECK) \
195195
hook(KEXEC_CMDLINE) \
196+
hook(KEY_CHECK) \
196197
hook(MAX_CHECK)
197198
#define __ima_hook_enumify(ENUM) ENUM,
198199

security/integrity/ima/ima_policy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode,
373373
{
374374
int i;
375375

376-
if (func == KEXEC_CMDLINE) {
376+
if ((func == KEXEC_CMDLINE) || (func == KEY_CHECK)) {
377377
if ((rule->flags & IMA_FUNC) && (rule->func == func))
378378
return true;
379379
return false;
@@ -997,6 +997,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
997997
entry->func = POLICY_CHECK;
998998
else if (strcmp(args[0].from, "KEXEC_CMDLINE") == 0)
999999
entry->func = KEXEC_CMDLINE;
1000+
else if (strcmp(args[0].from, "KEY_CHECK") == 0)
1001+
entry->func = KEY_CHECK;
10001002
else
10011003
result = -EINVAL;
10021004
if (!result)

0 commit comments

Comments
 (0)