Skip to content

Commit 6f0911a

Browse files
author
Mimi Zohar
committed
ima: fix updating the ima_appraise flag
As IMA policy rules are added, a mask of the type of rule (eg. kernel modules, firmware, IMA policy) is updated. Unlike custom IMA policy rules, which replace the original builtin policy rules and update the mask, the builtin "secure_boot" policy rules were loaded, but did not update the mask. This patch refactors the code to load custom policies, defining a new function named ima_appraise_flag(). The new function is called either when loading the builtin "secure_boot" or custom policies. Fixes: 503ceae ("ima: define a set of appraisal rules requiring file signatures") Signed-off-by: Mimi Zohar <[email protected]>
1 parent fd90bc5 commit 6f0911a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

security/integrity/ima/ima_policy.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,17 @@ void ima_update_policy_flag(void)
440440
ima_policy_flag &= ~IMA_APPRAISE;
441441
}
442442

443+
static int ima_appraise_flag(enum ima_hooks func)
444+
{
445+
if (func == MODULE_CHECK)
446+
return IMA_APPRAISE_MODULES;
447+
else if (func == FIRMWARE_CHECK)
448+
return IMA_APPRAISE_FIRMWARE;
449+
else if (func == POLICY_CHECK)
450+
return IMA_APPRAISE_POLICY;
451+
return 0;
452+
}
453+
443454
/**
444455
* ima_init_policy - initialize the default measure rules.
445456
*
@@ -478,9 +489,11 @@ void __init ima_init_policy(void)
478489
* Insert the appraise rules requiring file signatures, prior to
479490
* any other appraise rules.
480491
*/
481-
for (i = 0; i < secure_boot_entries; i++)
482-
list_add_tail(&secure_boot_rules[i].list,
483-
&ima_default_rules);
492+
for (i = 0; i < secure_boot_entries; i++) {
493+
list_add_tail(&secure_boot_rules[i].list, &ima_default_rules);
494+
temp_ima_appraise |=
495+
ima_appraise_flag(secure_boot_rules[i].func);
496+
}
484497

485498
for (i = 0; i < appraise_entries; i++) {
486499
list_add_tail(&default_appraise_rules[i].list,
@@ -934,12 +947,9 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
934947
}
935948
if (!result && (entry->action == UNKNOWN))
936949
result = -EINVAL;
937-
else if (entry->func == MODULE_CHECK)
938-
temp_ima_appraise |= IMA_APPRAISE_MODULES;
939-
else if (entry->func == FIRMWARE_CHECK)
940-
temp_ima_appraise |= IMA_APPRAISE_FIRMWARE;
941-
else if (entry->func == POLICY_CHECK)
942-
temp_ima_appraise |= IMA_APPRAISE_POLICY;
950+
else if (entry->action == APPRAISE)
951+
temp_ima_appraise |= ima_appraise_flag(entry->func);
952+
943953
audit_log_format(ab, "res=%d", !result);
944954
audit_log_end(ab);
945955
return result;

0 commit comments

Comments
 (0)