BUG memory leakage at ./security/selinux/hooks.c
KERNEL_VERSION: 2.6.30.4
SUBJECT: in function inode_doinit_with_dentry memory is not released
on error path (if rc<0).
DESCRIBE:
In ./security/selinux/hooks.c in function inode_doinit_with_dentry:
1. If in the line 1278 we successfully allocate memory and assign it to context variablehen
2. if in the line 1284 getxattr returns -ERANGE and
3. if in the line 1288 getxattr returns rc<0
then we go to out_unlock without releasing memory pointed to by context variable.
1278 context = kmalloc(len, GFP_NOFS);
1279 if (!context) {
1280 rc = -ENOMEM; 1281 dput(dentry); 1282 goto out_unlock;
1283 }
1284 rc = inode->i_op->getxattr(dentry, XATTR_NAME_SELINUX,
1285 context, len);
1286 if (rc == -ERANGE) {
1287 /* Need a larger buffer. Query for the
right size. */
1288 rc = inode->i_op->getxattr(dentry,XATTR_NAME_SELINUX,
1289 NULL, 0);
1290 if (rc < 0) {
1291 dput(dentry);
1292 goto out_unlock;
1293 } 1294 kfree(context); 1295 len = rc; 1296 context = kmalloc(len, GFP_NOFS);
Thanks for the report. (Cc'd to the SELinux list).
Quoted 41 lines · iceberg
KERNEL_VERSION: 2.6.30.4
SUBJECT: in functioninode_doinit_with_dentrymemory is not released
on error path (if rc<0).
DESCRIBE:
In./security/selinux/hooks.cin functioninode_doinit_with_dentry:
1. If in the line 1278 we successfully allocate memory and assign it to context variablehen
2. if in the line 1284 getxattr returns-ERANGEand
3. if in the line 1288 getxattr returns rc<0
then we go toout_unlockwithout releasing memory pointed to by context variable.1278 context =
kmalloc(len, GFP_NOFS);
1279 if (!context) {1280 rc = -ENOMEM; 1281 dput(dentry); 1282 goto out_unlock;1283 }
1284 rc = inode->i_op->getxattr(dentry,XATTR_NAME_SELINUX,
1285 context, len);
1286 if (rc ==-ERANGE) {
1287 /* Need a larger buffer. Query for the
right size. */
1288 rc = inode->i_op->getxattr(dentry,XATTR_NAME_SELINUX,
1289 NULL, 0);
1290 if (rc < 0) {
1291 dput(dentry);
1292 gotoout_unlock;1293 } 1294 kfree(context); 1295 len = rc; 1296 context = kmalloc(len, GFP_NOFS);--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 7 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/1 SELinux: re. BUG memory leakage at ./security/selinux/hooks.c
Please review.
Author: James Morris <[email protected]> Date: Mon Aug 10 22:00:13 2009 +1000
SELinux: fix memory leakage in /security/selinux/hooks.c
Fix memory leakage in /security/selinux/hooks.c
The buffer always needs to be freed here; we either error out or allocate more memory.
security/selinux/hooks.c +2 -1
@@ -1285,6 +1285,8 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent rc = inode->i_op->getxattr (dentry,XATTR_NAME_SELINUX , context, len);if (rc == -ERANGE ) { +kfree (context); +/* Need a larger buffer. Query for the right size. */ rc = inode->i_op->getxattr (dentry,XATTR_NAME_SELINUX ,NULL ,0 );
@@ -1292,7 +1294,6 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dentdput (dentry); goto out_unlock; } -kfree (context); len = rc; context =kmalloc (len+1 ,GFP_NOFS );if (!context) {
Signature · 7 lines
James Morris <[email protected]> -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH] SELinux: re. BUG memory leakage at ./security/selinux/hooks.c
Quoted 7 lines · James Morris
Please review.
Author: James Morris <[email protected]> Date: Mon Aug 10 22:00:13 2009 +1000SELinux: fix memory leakage in /security/selinux/hooks.c
Quoted 7 lines
Fix memory leakage in /security/selinux/hooks.c
The buffer always needs to be freed here; we either error out or allocate more memory.
Reported-by iceberg <[email protected]>Signed-off-by James Morris <[email protected]>
Quoted 23 lines
security/selinux/hooks.c +2
-1@@ -1285,6 +1285,8 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent rc = inode->i_op->getxattr (dentry,XATTR_NAME_SELINUX , context, len);if (rc == -ERANGE ) { +kfree (context); +/* Need a larger buffer. Query for the right size. */ rc = inode->i_op->getxattr (dentry,XATTR_NAME_SELINUX ,NULL ,0 );@@ -1292,7 +1294,6 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dentdput (dentry); goto out_unlock; } -kfree (context); len = rc; context =kmalloc (len+1 ,GFP_NOFS );if (!context) {
Signature · 2 lines
Stephen Smalley National Security Agency