linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] aoe: use after free in aoedev_by_aoeaddr()
@ 2012-12-07  6:19 Dan Carpenter
  2012-12-07 13:20 ` Ed Cashin
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-12-07  6:19 UTC (permalink / raw)
  To: Ed L. Cashin; +Cc: linux-kernel, kernel-janitors

We should return NULL on failure instead of returning a freed pointer.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index e66ccbf..98f2965 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -461,6 +461,7 @@ aoedev_by_aoeaddr(ulong maj, int min, int do_alloc)
 	d->targets = kcalloc(NTARGETS, sizeof(*d->targets), GFP_ATOMIC);
 	if (!d->targets) {
 		kfree(d);
+		d = NULL;
 		goto out;
 	}
 	d->ntargets = NTARGETS;

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

* Re: [patch] aoe: use after free in aoedev_by_aoeaddr()
  2012-12-07  6:19 [patch] aoe: use after free in aoedev_by_aoeaddr() Dan Carpenter
@ 2012-12-07 13:20 ` Ed Cashin
  2012-12-10  8:59   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Ed Cashin @ 2012-12-07 13:20 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

On Dec 7, 2012, at 1:19 AM, Dan Carpenter wrote:

> We should return NULL on failure instead of returning a freed pointer.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
> index e66ccbf..98f2965 100644
> --- a/drivers/block/aoe/aoedev.c
> +++ b/drivers/block/aoe/aoedev.c
> @@ -461,6 +461,7 @@ aoedev_by_aoeaddr(ulong maj, int min, int do_alloc)
> 	d->targets = kcalloc(NTARGETS, sizeof(*d->targets), GFP_ATOMIC);
> 	if (!d->targets) {
> 		kfree(d);
> +		d = NULL;
> 		goto out;
> 	}
> 	d->ntargets = NTARGETS;


That looks good, thanks.

If smatch found that, then I have to figure out what I'm doing wrong, because
I ran sparse and smatch on the latest patch series until they were clean.  :/

-- 
  Ed Cashin
  ecashin@coraid.com



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

* Re: [patch] aoe: use after free in aoedev_by_aoeaddr()
  2012-12-07 13:20 ` Ed Cashin
@ 2012-12-10  8:59   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2012-12-10  8:59 UTC (permalink / raw)
  To: Ed Cashin; +Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

On Fri, Dec 07, 2012 at 07:20:10AM -0600, Ed Cashin wrote:
> On Dec 7, 2012, at 1:19 AM, Dan Carpenter wrote:
> 
> > We should return NULL on failure instead of returning a freed pointer.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
> > index e66ccbf..98f2965 100644
> > --- a/drivers/block/aoe/aoedev.c
> > +++ b/drivers/block/aoe/aoedev.c
> > @@ -461,6 +461,7 @@ aoedev_by_aoeaddr(ulong maj, int min, int do_alloc)
> > 	d->targets = kcalloc(NTARGETS, sizeof(*d->targets), GFP_ATOMIC);
> > 	if (!d->targets) {
> > 		kfree(d);
> > +		d = NULL;
> > 		goto out;
> > 	}
> > 	d->ntargets = NTARGETS;
> 
> 
> That looks good, thanks.
> 
> If smatch found that, then I have to figure out what I'm doing wrong, because
> I ran sparse and smatch on the latest patch series until they were clean.  :/

It's one of the checks which is only enabled with the --spammy
option.

regards,
dan carpenter


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

end of thread, other threads:[~2012-12-10  8:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-07  6:19 [patch] aoe: use after free in aoedev_by_aoeaddr() Dan Carpenter
2012-12-07 13:20 ` Ed Cashin
2012-12-10  8:59   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).