]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
apparmor: fix memory leak on buffer on error exit path
authorColin Ian King <colin.king@canonical.com>
Tue, 27 Mar 2018 13:35:58 +0000 (14:35 +0100)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 12 Apr 2018 15:35:35 +0000 (10:35 -0500)
BugLink: http://bugs.launchpad.net/bugs/1763427
Currently on the error exit path the allocated buffer is not free'd
causing a memory leak. Fix this by kfree'ing it.

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

Fixes: 1180b4c757aa ("apparmor: fix dangling symlinks to policy rawdata after replacement")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 588558eb6d0e0b6edfa65a67e906c2ffeba63ff1
 git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor)
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
security/apparmor/apparmorfs.c

index a7017965b4434959bc9a2d442ca416128e9d2184..b7206af5b7b7b8f863d0ef97b9d5114f328bda52 100644 (file)
@@ -1500,8 +1500,10 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname)
        }
 
        error = snprintf(s, size, "raw_data/%s/%s", dirname, fname);
-       if (error >= size || error < 0)
+       if (error >= size || error < 0) {
+               kfree(buffer);
                return ERR_PTR(-ENAMETOOLONG);
+       }
 
        return buffer;
 }