public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smackfs: check for allocation failures in smk_set_access()
@ 2008-12-22  4:16 Sergio Luis
  2008-12-23  5:03 ` Casey Schaufler
  0 siblings, 1 reply; 3+ messages in thread
From: Sergio Luis @ 2008-12-22  4:16 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: Ahmed S. Darwish, LSM, LKLM

 smackfs: check for allocation failures in smk_set_access() 

 While adding a new subject/object pair to smack_list, smk_set_access()
 didn't check the return of kzalloc(). 

 This patch changes smk_set_access() to return 0 or -ENOMEM, based on 
 kzalloc()'s return. It also updates its caller, smk_write_load(), to
 check for smk_set_access()'s return, given it is no longer a void 
 return function.

 Signed-off-by: Sergio Luis <sergio@larces.uece.br>
 To: Casey Schaufler <casey@schaufler-ca.com>
 Cc: Ahmed S. Darwish <darwish.07@gmail.com>
 Cc: LSM <linux-security-module@vger.kernel.org>
 Cc: LKLM <linux-kernel@vger.kernel.org>

 security/smack/smackfs.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index c21d8c8..44eb933 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -185,11 +185,15 @@ static int smk_open_load(struct inode *inode, struct file *file)
  * the subject/object pair and replaces the access that was
  * there. If the pair isn't found add it with the specified
  * access.
+ *
+ * Returns 0 if nothing goes wrong or -ENOMEM if it fails
+ * during the allocation of the new pair to add.
  */
-static void smk_set_access(struct smack_rule *srp)
+static int smk_set_access(struct smack_rule *srp)
 {
 	struct smk_list_entry *sp;
 	struct smk_list_entry *newp;
+	int ret = 0;
 
 	mutex_lock(&smack_list_lock);
 
@@ -202,14 +206,20 @@ static void smk_set_access(struct smack_rule *srp)
 
 	if (sp == NULL) {
 		newp = kzalloc(sizeof(struct smk_list_entry), GFP_KERNEL);
+		if (newp == NULL) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
 		newp->smk_rule = *srp;
 		newp->smk_next = smack_list;
 		smack_list = newp;
 	}
 
+out:
 	mutex_unlock(&smack_list_lock);
 
-	return;
+	return ret;
 }
 
 /**
@@ -309,8 +319,10 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 		goto out;
 	}
 
-	smk_set_access(&rule);
-	rc = count;
+	rc = smk_set_access(&rule);
+
+	if (!rc)
+		rc = count;
 
 out:
 	kfree(data);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] smackfs: check for allocation failures in smk_set_access()
  2008-12-22  4:16 [PATCH] smackfs: check for allocation failures in smk_set_access() Sergio Luis
@ 2008-12-23  5:03 ` Casey Schaufler
  2008-12-25  1:17   ` James Morris
  0 siblings, 1 reply; 3+ messages in thread
From: Casey Schaufler @ 2008-12-23  5:03 UTC (permalink / raw)
  To: Sergio Luis; +Cc: Ahmed S. Darwish, LSM, LKLM

Sergio Luis wrote:
>  smackfs: check for allocation failures in smk_set_access() 
>
>  While adding a new subject/object pair to smack_list, smk_set_access()
>  didn't check the return of kzalloc(). 
>
>  This patch changes smk_set_access() to return 0 or -ENOMEM, based on 
>  kzalloc()'s return. It also updates its caller, smk_write_load(), to
>  check for smk_set_access()'s return, given it is no longer a void 
>  return function.
>
>  Signed-off-by: Sergio Luis <sergio@larces.uece.br>
>  To: Casey Schaufler <casey@schaufler-ca.com>
>  Cc: Ahmed S. Darwish <darwish.07@gmail.com>
>  Cc: LSM <linux-security-module@vger.kernel.org>
>  Cc: LKLM <linux-kernel@vger.kernel.org>
>   

Acked-by: Casey Schaufler <casey@schaufler-ca.com>


>  security/smack/smackfs.c |   20 ++++++++++++++++----
>  1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
> index c21d8c8..44eb933 100644
> --- a/security/smack/smackfs.c
> +++ b/security/smack/smackfs.c
> @@ -185,11 +185,15 @@ static int smk_open_load(struct inode *inode, struct file *file)
>   * the subject/object pair and replaces the access that was
>   * there. If the pair isn't found add it with the specified
>   * access.
> + *
> + * Returns 0 if nothing goes wrong or -ENOMEM if it fails
> + * during the allocation of the new pair to add.
>   */
> -static void smk_set_access(struct smack_rule *srp)
> +static int smk_set_access(struct smack_rule *srp)
>  {
>  	struct smk_list_entry *sp;
>  	struct smk_list_entry *newp;
> +	int ret = 0;
>  
>  	mutex_lock(&smack_list_lock);
>  
> @@ -202,14 +206,20 @@ static void smk_set_access(struct smack_rule *srp)
>  
>  	if (sp == NULL) {
>  		newp = kzalloc(sizeof(struct smk_list_entry), GFP_KERNEL);
> +		if (newp == NULL) {
> +			ret = -ENOMEM;
> +			goto out;
> +		}
> +
>  		newp->smk_rule = *srp;
>  		newp->smk_next = smack_list;
>  		smack_list = newp;
>  	}
>  
> +out:
>  	mutex_unlock(&smack_list_lock);
>  
> -	return;
> +	return ret;
>  }
>  
>  /**
> @@ -309,8 +319,10 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
>  		goto out;
>  	}
>  
> -	smk_set_access(&rule);
> -	rc = count;
> +	rc = smk_set_access(&rule);
> +
> +	if (!rc)
> +		rc = count;
>  
>  out:
>  	kfree(data);
>
>
>   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] smackfs: check for allocation failures in smk_set_access()
  2008-12-23  5:03 ` Casey Schaufler
@ 2008-12-25  1:17   ` James Morris
  0 siblings, 0 replies; 3+ messages in thread
From: James Morris @ 2008-12-25  1:17 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: Sergio Luis, Ahmed S. Darwish, LSM, LKLM

On Mon, 22 Dec 2008, Casey Schaufler wrote:

> Sergio Luis wrote:
> >  smackfs: check for allocation failures in smk_set_access() 
> >  While adding a new subject/object pair to smack_list, smk_set_access()
> >  didn't check the return of kzalloc(). 
> >  This patch changes smk_set_access() to return 0 or -ENOMEM, based on
> > kzalloc()'s return. It also updates its caller, smk_write_load(), to
> >  check for smk_set_access()'s return, given it is no longer a void  return
> > function.
> > 
> >  Signed-off-by: Sergio Luis <sergio@larces.uece.br>
> >  To: Casey Schaufler <casey@schaufler-ca.com>
> >  Cc: Ahmed S. Darwish <darwish.07@gmail.com>
> >  Cc: LSM <linux-security-module@vger.kernel.org>
> >  Cc: LKLM <linux-kernel@vger.kernel.org>
> >   
> 
> Acked-by: Casey Schaufler <casey@schaufler-ca.com>
> 

Applied to:
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next

I'll push this to Linus after he pulls the main security update, or with 
it on re-send.

-- 
-- 
James Morris
<jmorris@namei.org>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-12-25  1:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-22  4:16 [PATCH] smackfs: check for allocation failures in smk_set_access() Sergio Luis
2008-12-23  5:03 ` Casey Schaufler
2008-12-25  1:17   ` James Morris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox