]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/audit-fix-a-memory-leak-bug.patch
ba33da72e7176702c2fc005ab637d95bca0d47f2
[thirdparty/kernel/stable-queue.git] / queue-4.4 / audit-fix-a-memory-leak-bug.patch
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
5
6 [ Upstream commit 70c4cf17e445264453bc5323db3e50aa0ac9e81f ]
7
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.
18
19 To fix this issue, only allocate the tree when the type is AUDIT_ADD_RULE
20 or AUDIT_DEL_RULE.
21
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>
26 ---
27 kernel/auditfilter.c | 12 +++++++-----
28 1 file changed, 7 insertions(+), 5 deletions(-)
29
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,
35 int err = 0;
36 struct audit_entry *entry;
37
38 - entry = audit_data_to_entry(data, datasz);
39 - if (IS_ERR(entry))
40 - return PTR_ERR(entry);
41 -
42 switch (type) {
43 case AUDIT_ADD_RULE:
44 + entry = audit_data_to_entry(data, datasz);
45 + if (IS_ERR(entry))
46 + return PTR_ERR(entry);
47 err = audit_add_rule(entry);
48 audit_log_rule_change("add_rule", &entry->rule, !err);
49 break;
50 case AUDIT_DEL_RULE:
51 + entry = audit_data_to_entry(data, datasz);
52 + if (IS_ERR(entry))
53 + return PTR_ERR(entry);
54 err = audit_del_rule(entry);
55 audit_log_rule_change("remove_rule", &entry->rule, !err);
56 break;
57 default:
58 - err = -EINVAL;
59 WARN_ON(1);
60 + return -EINVAL;
61 }
62
63 if (err || type == AUDIT_DEL_RULE) {
64 --
65 2.20.1
66