Skip to contentSkip to conversation

ocfs2: free memory allocated by inode_init_security

PATCH New Tiger Yang 3 participants 3 messages Jun 2, 2011 – Aug 22, 2011 OCFS2

lore
Share & tools
lore

Tiger Yang

author
#0 lore raw

PATCH 1/1 ocfs2: free memory allocated by inode_init_security

The LSM security_inode_init_security() hook allocates memory for xattr name and value, expecting the caller to release the memory afterwards.

---
 fs/ocfs2/xattr.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
fs/ocfs2/xattr.c +6 -3
index 81ecf9c..fcd77a0 100644
@@ -7185,12 +7185,11 @@ int ocfs2_init_security_and_acl(struct inode *dir,
 {
 	int ret = 0;
 	struct buffer_head *dir_bh = NULL;
-	struct ocfs2_security_xattr_info si = {
-		.enable = 1,
-	};
+	struct ocfs2_security_xattr_info si = {0, };
 
 	ret = ocfs2_init_security_get(inode, dir, qstr, &si);
 	if (!ret) {
+		si.enable = 1;
 		ret = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY,
 				      si.name, si.value, si.value_len,
 				      XATTR_CREATE);
@@ -7216,6 +7215,10 @@ int ocfs2_init_security_and_acl(struct inode *dir,
 	ocfs2_inode_unlock(dir, 0);
 	brelse(dir_bh);
 leave:
+	if (si.enable) {
+		kfree(si.name);
+		kfree(si.value);
+	}
 	return ret;
 }
 /*
Signature · 1 line
1.7.4.4
maintainer
#2 lore raw

PATCH 1/1 ocfs2: free memory allocated by inode_init_security

In reply to Tiger Yang

This patch is now in the fixes branch of ocfs2.git.

Joel

Quoted 43 lines · Tiger Yang

The LSM security_inode_init_security() hook allocates memory for xattr name and value, expecting the caller to release the memory afterwards.

---
 fs/ocfs2/xattr.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
fs/ocfs2/xattr.c +6 -3
index 81ecf9c..fcd77a0 100644
@@ -7185,12 +7185,11 @@ int ocfs2_init_security_and_acl(struct inode *dir,
 {
 	int ret = 0;
 	struct buffer_head *dir_bh = NULL;
-	struct ocfs2_security_xattr_info si = {
-		.enable = 1,
-	};
+	struct ocfs2_security_xattr_info si = {0, };
 
 	ret = ocfs2_init_security_get(inode, dir, qstr, &si);
 	if (!ret) {
+		si.enable = 1;
 		ret = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY,
 				      si.name, si.value, si.value_len,
 				      XATTR_CREATE);
@@ -7216,6 +7215,10 @@ int ocfs2_init_security_and_acl(struct inode *dir,
 	ocfs2_inode_unlock(dir, 0);
 	brelse(dir_bh);
 leave:
+	if (si.enable) {
+		kfree(si.name);
+		kfree(si.value);
+	}
 	return ret;
 }
 /*
Signature · 1 line
1.7.4.4
Signature · 6 lines
"Practice random acts of kindness and senseless acts of beauty."

 Oh, and don't forget where your towel is.

			http://www.jlbec.org/
			jlbec at evilplan.org