]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
audit: fix a memory leak bug
authorWenwen Wang <wang6495@umn.edu>
Sat, 20 Apr 2019 01:49:29 +0000 (20:49 -0500)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1838700
[ Upstream commit 70c4cf17e445264453bc5323db3e50aa0ac9e81f ]

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 <wang6495@umn.edu>
Reviewed-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
kernel/auditfilter.c

index 4b29b85246b8a5b4029a181da394fabe5ef99351..fb80c84bfb19f44f4a7a38cca25f0d13e3e2893a 100644 (file)
@@ -1119,22 +1119,24 @@ int audit_rule_change(int type, int seq, void *data, size_t datasz)
        int err = 0;
        struct audit_entry *entry;
 
-       entry = audit_data_to_entry(data, datasz);
-       if (IS_ERR(entry))
-               return PTR_ERR(entry);
-
        switch (type) {
        case AUDIT_ADD_RULE:
+               entry = audit_data_to_entry(data, datasz);
+               if (IS_ERR(entry))
+                       return PTR_ERR(entry);
                err = audit_add_rule(entry);
                audit_log_rule_change("add_rule", &entry->rule, !err);
                break;
        case AUDIT_DEL_RULE:
+               entry = audit_data_to_entry(data, datasz);
+               if (IS_ERR(entry))
+                       return PTR_ERR(entry);
                err = audit_del_rule(entry);
                audit_log_rule_change("remove_rule", &entry->rule, !err);
                break;
        default:
-               err = -EINVAL;
                WARN_ON(1);
+               return -EINVAL;
        }
 
        if (err || type == AUDIT_DEL_RULE) {