Skip to content

Commit 70c4cf1

Browse files
Wenwen Wangpcmoore
authored andcommitted
audit: fix a memory leak bug
In audit_rule_change(), audit_data_to_entry() is firstly invoked to translate the payload data to the kernel's rule representation. In audit_data_to_entry(), depending on the audit field type, an audit tree may be created in audit_make_tree(), which eventually invokes kmalloc() to allocate the tree. Since this tree is a temporary tree, it will be then freed in the following execution, e.g., audit_add_rule() if the message type is AUDIT_ADD_RULE or audit_del_rule() if the message type is AUDIT_DEL_RULE. However, if the message type is neither AUDIT_ADD_RULE nor AUDIT_DEL_RULE, i.e., the default case of the switch statement, this temporary tree is not freed. To fix this issue, only allocate the tree when the type is AUDIT_ADD_RULE or AUDIT_DEL_RULE. Signed-off-by: Wenwen Wang <[email protected]> Reviewed-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 7e8eda7 commit 70c4cf1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kernel/auditfilter.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,22 +1114,24 @@ int audit_rule_change(int type, int seq, void *data, size_t datasz)
11141114
int err = 0;
11151115
struct audit_entry *entry;
11161116

1117-
entry = audit_data_to_entry(data, datasz);
1118-
if (IS_ERR(entry))
1119-
return PTR_ERR(entry);
1120-
11211117
switch (type) {
11221118
case AUDIT_ADD_RULE:
1119+
entry = audit_data_to_entry(data, datasz);
1120+
if (IS_ERR(entry))
1121+
return PTR_ERR(entry);
11231122
err = audit_add_rule(entry);
11241123
audit_log_rule_change("add_rule", &entry->rule, !err);
11251124
break;
11261125
case AUDIT_DEL_RULE:
1126+
entry = audit_data_to_entry(data, datasz);
1127+
if (IS_ERR(entry))
1128+
return PTR_ERR(entry);
11271129
err = audit_del_rule(entry);
11281130
audit_log_rule_change("remove_rule", &entry->rule, !err);
11291131
break;
11301132
default:
1131-
err = -EINVAL;
11321133
WARN_ON(1);
1134+
return -EINVAL;
11331135
}
11341136

11351137
if (err || type == AUDIT_DEL_RULE) {

0 commit comments

Comments
 (0)