Skip to content

Commit d57378d

Browse files
GUO Zihuamimizohar
GUO Zihua
authored andcommitted
ima: Simplify ima_lsm_copy_rule
Currently ima_lsm_copy_rule() set the arg_p field of the source rule to NULL, so that the source rule could be freed afterward. It does not make sense for this behavior to be inside a "copy" function. So move it outside and let the caller handle this field. ima_lsm_copy_rule() now produce a shallow copy of the original entry including args_p field. Meaning only the lsm.rule and the rule itself should be freed for the original rule. Thus, instead of calling ima_lsm_free_rule() which frees lsm.rule as well as args_p field, free the lsm.rule directly. Signed-off-by: GUO Zihua <[email protected]> Reviewed-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 11220db commit d57378d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

security/integrity/ima/ima_policy.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,6 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
398398

399399
nentry->lsm[i].type = entry->lsm[i].type;
400400
nentry->lsm[i].args_p = entry->lsm[i].args_p;
401-
/*
402-
* Remove the reference from entry so that the associated
403-
* memory will not be freed during a later call to
404-
* ima_lsm_free_rule(entry).
405-
*/
406-
entry->lsm[i].args_p = NULL;
407401

408402
ima_filter_rule_init(nentry->lsm[i].type, Audit_equal,
409403
nentry->lsm[i].args_p,
@@ -417,6 +411,7 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
417411

418412
static int ima_lsm_update_rule(struct ima_rule_entry *entry)
419413
{
414+
int i;
420415
struct ima_rule_entry *nentry;
421416

422417
nentry = ima_lsm_copy_rule(entry);
@@ -431,7 +426,8 @@ static int ima_lsm_update_rule(struct ima_rule_entry *entry)
431426
* references and the entry itself. All other memory references will now
432427
* be owned by nentry.
433428
*/
434-
ima_lsm_free_rule(entry);
429+
for (i = 0; i < MAX_LSM_RULES; i++)
430+
ima_filter_rule_free(entry->lsm[i].rule);
435431
kfree(entry);
436432

437433
return 0;

0 commit comments

Comments
 (0)