public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails
@ 2004-04-26 16:17 Petri T. Koistinen
  2004-04-26 16:45 ` J. Bruce Fields
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Petri T. Koistinen @ 2004-04-26 16:17 UTC (permalink / raw)
  To: David S. Miller; +Cc: linux-net, linux-kernel

Hi!

I browsed http://linuxbugs.coverity.com/ site and found this:

NULL_RETURNS error: Dereference of possibly NULL ptr "new" returned by "kmalloc".
/home/test/nightly-qa/test-packages/linux-2.6.4/net/sunrpc/svcauth_unix.c:53:unix_domain_find:
(also see line 54)
53            new = kmalloc(sizeof(*new), GFP_KERNEL);
NULL_RETURNS information here
(also see line 53)
54            cache_init(&new->h.h);

Is this correct fix? What happens when unix_domain_find return NULL?

Best regards,
Petri Koistinen

--- linux-2.5/net/sunrpc/svcauth_unix.c.orig	2004-04-26 18:58:04.000000000 +0300
+++ linux-2.5/net/sunrpc/svcauth_unix.c	2004-04-26 18:58:58.000000000 +0300
@@ -36,36 +36,38 @@ struct unix_domain {
 struct auth_domain *unix_domain_find(char *name)
 {
 	struct auth_domain *rv, ud;
 	struct unix_domain *new;

 	ud.name = name;

 	rv = auth_domain_lookup(&ud, 0);

  foundit:
 	if (rv && rv->flavour != RPC_AUTH_UNIX) {
 		auth_domain_put(rv);
 		return NULL;
 	}
 	if (rv)
 		return rv;

 	new = kmalloc(sizeof(*new), GFP_KERNEL);
+	if (new == NULL)
+		return NULL;
 	cache_init(&new->h.h);
 	atomic_inc(&new->h.h.refcnt);
 	new->h.name = strdup(name);
 	new->h.flavour = RPC_AUTH_UNIX;
 	new->addr_changes = 0;
 	new->h.h.expiry_time = NEVER;
 	new->h.h.flags = 0;

 	rv = auth_domain_lookup(&new->h, 2);
 	if (rv == &new->h) {
 		if (atomic_dec_and_test(&new->h.h.refcnt)) BUG();
 	} else {
 		auth_domain_put(&new->h);
 		goto foundit;
 	}

 	return rv;
 }

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

* Re: [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails
  2004-04-26 16:17 [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails Petri T. Koistinen
@ 2004-04-26 16:45 ` J. Bruce Fields
  2004-04-26 23:37 ` David S. Miller
  2004-04-26 23:38 ` David S. Miller
  2 siblings, 0 replies; 4+ messages in thread
From: J. Bruce Fields @ 2004-04-26 16:45 UTC (permalink / raw)
  To: Petri T. Koistinen; +Cc: David S. Miller, linux-net, linux-kernel

On Mon, Apr 26, 2004 at 07:17:19PM +0300, Petri T. Koistinen wrote:
> Is this correct fix? What happens when unix_domain_find return NULL?

I just noticed that the other day, and have been testing with the
identical fix; seems to work fine.  All the callers check for NULL
returns and appear to do the right thing.  --Bruce Fields

> --- linux-2.5/net/sunrpc/svcauth_unix.c.orig	2004-04-26 18:58:04.000000000 +0300
> +++ linux-2.5/net/sunrpc/svcauth_unix.c	2004-04-26 18:58:58.000000000 +0300
> @@ -36,36 +36,38 @@ struct unix_domain {
>  struct auth_domain *unix_domain_find(char *name)
>  {
>  	struct auth_domain *rv, ud;
>  	struct unix_domain *new;
> 
>  	ud.name = name;
> 
>  	rv = auth_domain_lookup(&ud, 0);
> 
>   foundit:
>  	if (rv && rv->flavour != RPC_AUTH_UNIX) {
>  		auth_domain_put(rv);
>  		return NULL;
>  	}
>  	if (rv)
>  		return rv;
> 
>  	new = kmalloc(sizeof(*new), GFP_KERNEL);
> +	if (new == NULL)
> +		return NULL;
>  	cache_init(&new->h.h);
>  	atomic_inc(&new->h.h.refcnt);
>  	new->h.name = strdup(name);
>  	new->h.flavour = RPC_AUTH_UNIX;
>  	new->addr_changes = 0;
>  	new->h.h.expiry_time = NEVER;
>  	new->h.h.flags = 0;
> 
>  	rv = auth_domain_lookup(&new->h, 2);
>  	if (rv == &new->h) {
>  		if (atomic_dec_and_test(&new->h.h.refcnt)) BUG();
>  	} else {
>  		auth_domain_put(&new->h);
>  		goto foundit;
>  	}
> 
>  	return rv;
>  }
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails
  2004-04-26 16:17 [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails Petri T. Koistinen
  2004-04-26 16:45 ` J. Bruce Fields
@ 2004-04-26 23:37 ` David S. Miller
  2004-04-26 23:38 ` David S. Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David S. Miller @ 2004-04-26 23:37 UTC (permalink / raw)
  To: Petri T. Koistinen; +Cc: linux-net, linux-kernel

On Mon, 26 Apr 2004 19:17:19 +0300 (EEST)
"Petri T. Koistinen" <petri.koistinen@iki.fi> wrote:

> I browsed http://linuxbugs.coverity.com/ site and found this:
> 
> NULL_RETURNS error: Dereference of possibly NULL ptr "new" returned by "kmalloc".
 ...
> Is this correct fix? What happens when unix_domain_find return NULL?

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

* Re: [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails
  2004-04-26 16:17 [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails Petri T. Koistinen
  2004-04-26 16:45 ` J. Bruce Fields
  2004-04-26 23:37 ` David S. Miller
@ 2004-04-26 23:38 ` David S. Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David S. Miller @ 2004-04-26 23:38 UTC (permalink / raw)
  To: Petri T. Koistinen; +Cc: linux-net, linux-kernel

On Mon, 26 Apr 2004 19:17:19 +0300 (EEST)
"Petri T. Koistinen" <petri.koistinen@iki.fi> wrote:

> I browsed http://linuxbugs.coverity.com/ site and found this:
 ...
> Is this correct fix? What happens when unix_domain_find return NULL?

I've put this into my tree and will pass on to Linus.

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

end of thread, other threads:[~2004-04-26 23:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-26 16:17 [PATCH] net/sunrpc/svcauth_unix.c: unix_domain_find: return NULL if kmalloc fails Petri T. Koistinen
2004-04-26 16:45 ` J. Bruce Fields
2004-04-26 23:37 ` David S. Miller
2004-04-26 23:38 ` David S. Miller

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