Skip to content

Commit

Permalink
ima: initialize the "template" field with the default template
Browse files Browse the repository at this point in the history
IMA policy rules are walked sequentially.  Depending on the ordering of
the policy rules, the "template" field might be defined in one rule, but
will be replaced by subsequent, applicable rules, even if the rule does
not explicitly define the "template" field.

This patch initializes the "template" once and only replaces the
"template", when explicitly defined.

Fixes: 19453ce ("IMA: support for per policy rule template formats")
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
  • Loading branch information
Mimi Zohar committed Aug 1, 2019
1 parent 609488b commit b36f281
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions security/integrity/ima/ima_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid,
struct ima_rule_entry *entry;
int action = 0, actmask = flags | (flags << 1);

if (template_desc)
*template_desc = ima_template_desc_current();

rcu_read_lock();
list_for_each_entry_rcu(entry, ima_rules, list) {

Expand All @@ -510,6 +513,7 @@ int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid,
action |= IMA_FAIL_UNVERIFIABLE_SIGS;
}


if (entry->action & IMA_DO_MASK)
actmask &= ~(entry->action | entry->action << 1);
else
Expand All @@ -520,8 +524,6 @@ int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid,

if (template_desc && entry->template)
*template_desc = entry->template;
else if (template_desc)
*template_desc = ima_template_desc_current();

if (!actmask)
break;
Expand Down

0 comments on commit b36f281

Please sign in to comment.