Skip to content

Commit 70a7526

Browse files
tyhicksgregkh
authored andcommitted
ima: Have the LSM free its audit rule
[ Upstream commit 9ff8a61 ] Ask the LSM to free its audit rule rather than directly calling kfree(). Both AppArmor and SELinux do additional work in their audit_rule_free() hooks. Fix memory leaks by allowing the LSMs to perform necessary work. Fixes: b169424 ("ima: use the lsm policy update notifier") Signed-off-by: Tyler Hicks <tyhicks@linux.microsoft.com> Cc: Janne Karhunen <janne.karhunen@gmail.com> Cc: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6e1ab3b commit 70a7526

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎security/integrity/ima/ima.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static inline void ima_free_modsig(struct modsig *modsig)
400400
#ifdef CONFIG_IMA_LSM_RULES
401401

402402
#define security_filter_rule_init security_audit_rule_init
403+
#define security_filter_rule_free security_audit_rule_free
403404
#define security_filter_rule_match security_audit_rule_match
404405

405406
#else
@@ -410,6 +411,10 @@ static inline int security_filter_rule_init(u32 field, u32 op, char *rulestr,
410411
return -EINVAL;
411412
}
412413

414+
static inline void security_filter_rule_free(void *lsmrule)
415+
{
416+
}
417+
413418
static inline int security_filter_rule_match(u32 secid, u32 field, u32 op,
414419
void *lsmrule)
415420
{

‎security/integrity/ima/ima_policy.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static void ima_lsm_free_rule(struct ima_rule_entry *entry)
258258
int i;
259259

260260
for (i = 0; i < MAX_LSM_RULES; i++) {
261-
kfree(entry->lsm[i].rule);
261+
security_filter_rule_free(entry->lsm[i].rule);
262262
kfree(entry->lsm[i].args_p);
263263
}
264264
kfree(entry);

0 commit comments

Comments
 (0)