From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754046AbZHJMWH (ORCPT ); Mon, 10 Aug 2009 08:22:07 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753987AbZHJMWG (ORCPT ); Mon, 10 Aug 2009 08:22:06 -0400 Received: from msux-gh1-uea01.nsa.gov ([63.239.67.1]:55172 "EHLO msux-gh1-uea01.nsa.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753726AbZHJMWF (ORCPT ); Mon, 10 Aug 2009 08:22:05 -0400 Subject: Re: [PATCH] SELinux: re. BUG memory leakage at ./security/selinux/hooks.c From: Stephen Smalley To: James Morris Cc: iceberg , linux-kernel@vger.kernel.org, selinux@tycho.nsa.gov, Eric Paris In-Reply-To: References: <200908101257.43672.strakh@ispras.ru> Content-Type: text/plain Organization: National Security Agency Date: Mon, 10 Aug 2009 08:24:07 -0400 Message-Id: <1249907047.2422.31.camel@moss-pluto.epoch.ncsc.mil> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2009-08-10 at 22:17 +1000, James Morris wrote: > Please review. > > Author: James Morris > 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. > > Reported-by: iceberg > Signed-off-by: James Morris Acked-by: Stephen Smalley > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > index 15c2a08..1e8cfc4 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -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_dent > dput(dentry); > goto out_unlock; > } > - kfree(context); > len = rc; > context = kmalloc(len+1, GFP_NOFS); > if (!context) { > -- Stephen Smalley National Security Agency