]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
apparmor: Fix memory leak of rule on error exit path
authorTyler Hicks <tyhicks@canonical.com>
Thu, 17 May 2018 19:53:45 +0000 (19:53 +0000)
committerJohn Johansen <john.johansen@canonical.com>
Thu, 7 Jun 2018 08:50:48 +0000 (01:50 -0700)
Currently on the error exit path the allocated rule is not free'd
causing a memory leak. Fix this by calling aa_audit_rule_free().

Detected by CoverityScan, CID#1468966 ("Resource leaks")

Fixes: cb740f574c7b ("apparmor: modify audit rule support to support profile stacks")
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/audit.c

index 575f3e9c8c80a5921b492b70566afc33fe37f324..eeaddfe0c0fb9c3999453451de1899db81a9ad84 100644 (file)
@@ -200,10 +200,12 @@ int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
        /* Currently rules are treated as coming from the root ns */
        rule->label = aa_label_parse(&root_ns->unconfined->label, rulestr,
                                     GFP_KERNEL, true, false);
-       if (IS_ERR(rule->label))
+       if (IS_ERR(rule->label)) {
+               aa_audit_rule_free(rule);
                return PTR_ERR(rule->label);
-       *vrule = rule;
+       }
 
+       *vrule = rule;
        return 0;
 }