lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 26 Mar 2019 11:31:51 -0700
From:   Dan Williams <dan.j.williams@...el.com>
To:     Mukesh Ojha <mojha@...eaurora.org>
Cc:     Aditya Pakki <pakki001@....edu>, Kangjie Lu <kjlu@....edu>,
        Vishal Verma <vishal.l.verma@...el.com>,
        Dave Jiang <dave.jiang@...el.com>,
        Keith Busch <keith.busch@...el.com>,
        Ira Weiny <ira.weiny@...el.com>,
        linux-nvdimm <linux-nvdimm@...ts.01.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4] nvdimm: btt_devs: fix a NULL pointer dereference

On Tue, Mar 26, 2019 at 3:23 AM Mukesh Ojha <mojha@...eaurora.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@....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.

Powered by blists - more mailing lists