lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.00.1204212258130.25551@swampdragon.chaosbits.net>
Date:	Sat, 21 Apr 2012 23:00:57 +0200 (CEST)
From:	Jesper Juhl <jj@...osbits.net>
To:	linux-kernel@...r.kernel.org
cc:	cluster-devel@...hat.com, Steven Whitehouse <swhiteho@...hat.com>
Subject: [PATCH] GFS2: Fix mem leak in gfs2_get_acl()

If gfs2_xattr_acl_get() returns 0 - which, as far as I can tell, it
may do independently of having allocated memory for its third argument
('data' in this case) - then we may leak the memory allocated to data.

This patch initializes 'data' to NULL so that it will be safe to call
kfree() on it even if we do not allocate anything and also makes sure
that we kfree(data) in the 'len == 0' case.

Signed-off-by: Jesper Juhl <jj@...osbits.net>
---
 fs/gfs2/acl.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

 Note: I have tested that this change compiles. It has seen no other 
       testing than that.

diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index 230eb0f..d254d98 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -43,7 +43,7 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
 	struct gfs2_inode *ip = GFS2_I(inode);
 	struct posix_acl *acl;
 	const char *name;
-	char *data;
+	char *data = NULL;
 	int len;
 
 	if (!ip->i_eattr)
@@ -60,8 +60,10 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
 	len = gfs2_xattr_acl_get(ip, name, &data);
 	if (len < 0)
 		return ERR_PTR(len);
-	if (len == 0)
+	if (len == 0) {
+		kfree(data);
 		return NULL;
+	}
 
 	acl = posix_acl_from_xattr(data, len);
 	kfree(data);
-- 
1.7.10


-- 
Jesper Juhl <jj@...osbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ