Skip to content

Commit 7121834

Browse files
tyhicksmimizohar
authored andcommitted
ima: Fail rule parsing when buffer hook functions have an invalid action
Buffer based hook functions, such as KEXEC_CMDLINE and KEY_CHECK, can only measure. The process_buffer_measurement() function quietly ignores all actions except measure so make this behavior clear at the time of policy load. The parsing of the keyrings conditional had a check to ensure that it was only specified with measure actions but the check should be on the hook function and not the keyrings conditional since "appraise func=KEY_CHECK" is not a valid rule. Fixes: b093512 ("IMA: Define a new hook to measure the kexec boot command line arguments") Fixes: 5808611 ("IMA: Add KEY_CHECK func to measure keys") Signed-off-by: Tyler Hicks <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 2bdd737 commit 7121834

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

security/integrity/ima/ima_policy.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,43 @@ static void check_template_modsig(const struct ima_template_desc *template)
973973
#undef MSG
974974
}
975975

976+
static bool ima_validate_rule(struct ima_rule_entry *entry)
977+
{
978+
/* Ensure that the action is set */
979+
if (entry->action == UNKNOWN)
980+
return false;
981+
982+
/*
983+
* Ensure that the hook function is compatible with the other
984+
* components of the rule
985+
*/
986+
switch (entry->func) {
987+
case NONE:
988+
case FILE_CHECK:
989+
case MMAP_CHECK:
990+
case BPRM_CHECK:
991+
case CREDS_CHECK:
992+
case POST_SETATTR:
993+
case MODULE_CHECK:
994+
case FIRMWARE_CHECK:
995+
case KEXEC_KERNEL_CHECK:
996+
case KEXEC_INITRAMFS_CHECK:
997+
case POLICY_CHECK:
998+
/* Validation of these hook functions is in ima_parse_rule() */
999+
break;
1000+
case KEXEC_CMDLINE:
1001+
case KEY_CHECK:
1002+
if (entry->action & ~(MEASURE | DONT_MEASURE))
1003+
return false;
1004+
1005+
break;
1006+
default:
1007+
return false;
1008+
}
1009+
1010+
return true;
1011+
}
1012+
9761013
static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
9771014
{
9781015
struct audit_buffer *ab;
@@ -1150,7 +1187,6 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
11501187
keyrings_len = strlen(args[0].from) + 1;
11511188

11521189
if ((entry->keyrings) ||
1153-
(entry->action != MEASURE) ||
11541190
(entry->func != KEY_CHECK) ||
11551191
(keyrings_len < 2)) {
11561192
result = -EINVAL;
@@ -1356,7 +1392,7 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
13561392
break;
13571393
}
13581394
}
1359-
if (!result && (entry->action == UNKNOWN))
1395+
if (!result && !ima_validate_rule(entry))
13601396
result = -EINVAL;
13611397
else if (entry->action == APPRAISE)
13621398
temp_ima_appraise |= ima_appraise_flag(entry->func);

0 commit comments

Comments
 (0)