Skip to content

Commit 39e5993

Browse files
tyhicksmimizohar
authored andcommitted
ima: Shallow copy the args_p member of ima_rule_entry.lsm elements
The args_p member is a simple string that is allocated by ima_rule_init(). Shallow copy it like other non-LSM references in ima_rule_entry structs. There are no longer any necessary error path cleanups to do in ima_lsm_copy_rule(). Signed-off-by: Tyler Hicks <[email protected]> Signed-off-by: Tyler Hicks <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 5f3e926 commit 39e5993

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

security/integrity/ima/ima_policy.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,23 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
300300
continue;
301301

302302
nentry->lsm[i].type = entry->lsm[i].type;
303-
nentry->lsm[i].args_p = kstrdup(entry->lsm[i].args_p,
304-
GFP_KERNEL);
305-
if (!nentry->lsm[i].args_p)
306-
goto out_err;
303+
nentry->lsm[i].args_p = entry->lsm[i].args_p;
304+
/*
305+
* Remove the reference from entry so that the associated
306+
* memory will not be freed during a later call to
307+
* ima_lsm_free_rule(entry).
308+
*/
309+
entry->lsm[i].args_p = NULL;
307310

308311
security_filter_rule_init(nentry->lsm[i].type,
309312
Audit_equal,
310313
nentry->lsm[i].args_p,
311314
&nentry->lsm[i].rule);
312315
if (!nentry->lsm[i].rule)
313316
pr_warn("rule for LSM \'%s\' is undefined\n",
314-
(char *)entry->lsm[i].args_p);
317+
(char *)nentry->lsm[i].args_p);
315318
}
316319
return nentry;
317-
318-
out_err:
319-
ima_lsm_free_rule(nentry);
320-
kfree(nentry);
321-
return NULL;
322320
}
323321

324322
static int ima_lsm_update_rule(struct ima_rule_entry *entry)

0 commit comments

Comments
 (0)