linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Verma, Vishal L" <vishal.l.verma@intel.com>
To: "kjlu@umn.edu" <kjlu@umn.edu>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>,
	"pakki001@umn.edu" <pakki001@umn.edu>,
	"zwisler@kernel.org" <zwisler@kernel.org>
Subject: Re: [PATCH] nvdimm: btt_devs: fix a NULL pointer dereference and a memory leak
Date: Fri, 22 Mar 2019 22:56:40 +0000	[thread overview]
Message-ID: <4377c210798b000d60ebdc5150e015737d05565b.camel@intel.com> (raw)
In-Reply-To: <eea1b50fe8c76d45fef0aaca1878c30fa8f2cbde.camel@intel.com>


On Fri, 2019-03-22 at 22:49 +0000, Verma, Vishal L wrote:
> On Tue, 2019-03-12 at 03:15 -0500, Kangjie Lu wrote:
> > In case kmemdup fails, the fix releases resources and returns to
> > avoid the NULL pointer dereference.
> > Also, the error paths in the following code should release
> > resources to avoid memory leaks.
> > 
> > Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> > ---
> >  drivers/nvdimm/btt_devs.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> 
> Looks good,
> Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

Looking again, there is another kmemdup() call in __nd_btt_probe which
is lacking error checking.
And referring to your other related patch to namespace_devs, that has
/several/ instances of the same thing.

Instead of fixing just a couple of these, it might be worthwhile to send
a wider cleanup patch to catch all of these, at least within
drivers/nvdimm/ for starters, instead of a select few.

> 
> > diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
> > index 795ad4ff35ca..565ea0b6f765 100644
> > --- a/drivers/nvdimm/btt_devs.c
> > +++ b/drivers/nvdimm/btt_devs.c
> > @@ -196,8 +196,13 @@ static struct device *__nd_btt_create(struct
> > nd_region *nd_region,
> >  	}
> >  
> >  	nd_btt->lbasize = lbasize;
> > -	if (uuid)
> > +	if (uuid) {
> >  		uuid = kmemdup(uuid, 16, GFP_KERNEL);
> > +		if (!uuid) {
> > +			kfree(nd_btt);
> > +			return NULL;
> > +		}
> > +	}
> >  	nd_btt->uuid = uuid;
> >  	dev = &nd_btt->dev;
> >  	dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
> > @@ -209,6 +214,7 @@ static struct device *__nd_btt_create(struct
> > nd_region *nd_region,
> >  		dev_dbg(&ndns->dev, "failed, already claimed by %s\n",
> >  				dev_name(ndns->claim));
> >  		put_device(dev);
> > +		kfree(uuid);
> >  		return NULL;
> >  	}
> >  	return dev;
> 
> _______________________________________________
> Linux-nvdimm mailing list
> Linux-nvdimm@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm


  reply	other threads:[~2019-03-22 22:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-12  8:15 [PATCH] nvdimm: btt_devs: fix a NULL pointer dereference and a memory leak Kangjie Lu
2019-03-22 22:49 ` Verma, Vishal L
2019-03-22 22:56   ` Verma, Vishal L [this message]
2019-03-22 23:31     ` Verma, Vishal L
2019-03-22 22:55 ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4377c210798b000d60ebdc5150e015737d05565b.camel@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=pakki001@umn.edu \
    --cc=zwisler@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).