All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Mukesh Ojha <mojha@codeaurora.org>
Cc: linux-nvdimm <linux-nvdimm@lists.01.org>,
	Kangjie Lu <kjlu@umn.edu>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Aditya Pakki <pakki001@umn.edu>
Subject: Re: [PATCH v4] nvdimm: btt_devs: fix a NULL pointer dereference
Date: Tue, 26 Mar 2019 11:31:51 -0700	[thread overview]
Message-ID: <CAPcyv4jMrU4n1fOv31TOZ-8Re4-7mwG_C_d6WzxZbjnu91UVeQ@mail.gmail.com> (raw)
In-Reply-To: <5fa84f18-7253-2543-57e4-6a9e2b2da716@codeaurora.org>

On Tue, Mar 26, 2019 at 3:23 AM Mukesh Ojha <mojha@codeaurora.org> wrote:
>
>
> On 3/26/2019 3:25 AM, Aditya Pakki wrote:
> > In case kmemdup fails, the fix releases resources and returns to
> > avoid the NULL pointer dereference.
> >
> > Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> >
> > ---
> > v3: Move kfree(nd_btt) to goto block.
> > v2: Replace incorrect kfree with ida_simple_remove, suggested by
> > Johannes Thumshirn
> > v1: Free nd_btt->id in case of failure and avoid double free, suggested
> > by Dan Williams
> > ---
> >   drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
> >   1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
> > index b72a303176c7..9486acc08402 100644
> > --- a/drivers/nvdimm/btt_devs.c
> > +++ b/drivers/nvdimm/btt_devs.c
> > @@ -198,14 +198,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
> >               return NULL;
> >
> >       nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
> > -     if (nd_btt->id < 0) {
> > -             kfree(nd_btt);
> > -             return NULL;
> > -     }
> > +     if (nd_btt->id < 0)
> > +             goto out_nd_btt;
> >
> >       nd_btt->lbasize = lbasize;
> > -     if (uuid)
> > +     if (uuid) {
> >               uuid = kmemdup(uuid, 16, GFP_KERNEL);
> > +             if (!uuid)
> > +                     goto out_put_id;
> > +     }
> >       nd_btt->uuid = uuid;
> >       dev = &nd_btt->dev;
> >       dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
> > @@ -220,6 +221,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
> >               return NULL;
> >       }
> >       return dev;
> > +
> > +out_put_id:
> > +     ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
> > +
> > +out_nd_btt:
> > +     kfree(nd_btt);
> > +     return NULL;
> >   }
> >
> >   struct device *nd_btt_create(struct nd_region *nd_region)
>
>
> you have to take care of this below if block(true) as well as you are
> touching the function.
>   if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) {

No, once the device is successfully initialized then put_device()
takes care of the rest.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

WARNING: multiple messages have this Message-ID (diff)
From: Dan Williams <dan.j.williams@intel.com>
To: Mukesh Ojha <mojha@codeaurora.org>
Cc: Aditya Pakki <pakki001@umn.edu>, Kangjie Lu <kjlu@umn.edu>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Keith Busch <keith.busch@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	linux-nvdimm <linux-nvdimm@lists.01.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4] nvdimm: btt_devs: fix a NULL pointer dereference
Date: Tue, 26 Mar 2019 11:31:51 -0700	[thread overview]
Message-ID: <CAPcyv4jMrU4n1fOv31TOZ-8Re4-7mwG_C_d6WzxZbjnu91UVeQ@mail.gmail.com> (raw)
In-Reply-To: <5fa84f18-7253-2543-57e4-6a9e2b2da716@codeaurora.org>

On Tue, Mar 26, 2019 at 3:23 AM Mukesh Ojha <mojha@codeaurora.org> wrote:
>
>
> On 3/26/2019 3:25 AM, Aditya Pakki wrote:
> > In case kmemdup fails, the fix releases resources and returns to
> > avoid the NULL pointer dereference.
> >
> > Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> >
> > ---
> > v3: Move kfree(nd_btt) to goto block.
> > v2: Replace incorrect kfree with ida_simple_remove, suggested by
> > Johannes Thumshirn
> > v1: Free nd_btt->id in case of failure and avoid double free, suggested
> > by Dan Williams
> > ---
> >   drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
> >   1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
> > index b72a303176c7..9486acc08402 100644
> > --- a/drivers/nvdimm/btt_devs.c
> > +++ b/drivers/nvdimm/btt_devs.c
> > @@ -198,14 +198,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
> >               return NULL;
> >
> >       nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
> > -     if (nd_btt->id < 0) {
> > -             kfree(nd_btt);
> > -             return NULL;
> > -     }
> > +     if (nd_btt->id < 0)
> > +             goto out_nd_btt;
> >
> >       nd_btt->lbasize = lbasize;
> > -     if (uuid)
> > +     if (uuid) {
> >               uuid = kmemdup(uuid, 16, GFP_KERNEL);
> > +             if (!uuid)
> > +                     goto out_put_id;
> > +     }
> >       nd_btt->uuid = uuid;
> >       dev = &nd_btt->dev;
> >       dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
> > @@ -220,6 +221,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
> >               return NULL;
> >       }
> >       return dev;
> > +
> > +out_put_id:
> > +     ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
> > +
> > +out_nd_btt:
> > +     kfree(nd_btt);
> > +     return NULL;
> >   }
> >
> >   struct device *nd_btt_create(struct nd_region *nd_region)
>
>
> you have to take care of this below if block(true) as well as you are
> touching the function.
>   if (ndns && !__nd_attach_ndns(&nd_btt->dev, ndns, &nd_btt->ndns)) {

No, once the device is successfully initialized then put_device()
takes care of the rest.

  reply	other threads:[~2019-03-26 18:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 21:55 [PATCH v4] nvdimm: btt_devs: fix a NULL pointer dereference Aditya Pakki
2019-03-25 21:55 ` Aditya Pakki
2019-03-26 10:23 ` Mukesh Ojha
2019-03-26 18:31   ` Dan Williams [this message]
2019-03-26 18:31     ` 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=CAPcyv4jMrU4n1fOv31TOZ-8Re4-7mwG_C_d6WzxZbjnu91UVeQ@mail.gmail.com \
    --to=dan.j.williams@intel.com \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=mojha@codeaurora.org \
    --cc=pakki001@umn.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.