1 From 9ef43ada1a0f14c29b9940e3407bf53aae420394 Mon Sep 17 00:00:00 2001
2 From: Wenwen Wang <wang6495@umn.edu>
3 Date: Fri, 19 Apr 2019 20:49:29 -0500
4 Subject: audit: fix a memory leak bug
6 [ Upstream commit 70c4cf17e445264453bc5323db3e50aa0ac9e81f ]
8 In audit_rule_change(), audit_data_to_entry() is firstly invoked to
9 translate the payload data to the kernel's rule representation. In
10 audit_data_to_entry(), depending on the audit field type, an audit tree may
11 be created in audit_make_tree(), which eventually invokes kmalloc() to
12 allocate the tree. Since this tree is a temporary tree, it will be then
13 freed in the following execution, e.g., audit_add_rule() if the message
14 type is AUDIT_ADD_RULE or audit_del_rule() if the message type is
15 AUDIT_DEL_RULE. However, if the message type is neither AUDIT_ADD_RULE nor
16 AUDIT_DEL_RULE, i.e., the default case of the switch statement, this
17 temporary tree is not freed.
19 To fix this issue, only allocate the tree when the type is AUDIT_ADD_RULE
22 Signed-off-by: Wenwen Wang <wang6495@umn.edu>
23 Reviewed-by: Richard Guy Briggs <rgb@redhat.com>
24 Signed-off-by: Paul Moore <paul@paul-moore.com>
25 Signed-off-by: Sasha Levin <sashal@kernel.org>
27 kernel/auditfilter.c | 12 +++++++-----
28 1 file changed, 7 insertions(+), 5 deletions(-)
30 diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
31 index b57f929f1b468..cf7aa656b308b 100644
32 --- a/kernel/auditfilter.c
33 +++ b/kernel/auditfilter.c
34 @@ -1095,22 +1095,24 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data,
36 struct audit_entry *entry;
38 - entry = audit_data_to_entry(data, datasz);
40 - return PTR_ERR(entry);
44 + entry = audit_data_to_entry(data, datasz);
46 + return PTR_ERR(entry);
47 err = audit_add_rule(entry);
48 audit_log_rule_change("add_rule", &entry->rule, !err);
51 + entry = audit_data_to_entry(data, datasz);
53 + return PTR_ERR(entry);
54 err = audit_del_rule(entry);
55 audit_log_rule_change("remove_rule", &entry->rule, !err);
63 if (err || type == AUDIT_DEL_RULE) {