[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAPcyv4jEgTsG5eR0siz71qytcEa7crhm4TpfFzUASoJM3bupiA@mail.gmail.com>
Date: Mon, 25 Mar 2019 14:42:58 -0700
From: Dan Williams <dan.j.williams@...el.com>
To: Aditya Pakki <pakki001@....edu>
Cc: 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 v3] nvdimm: btt_devs: fix a NULL pointer dereference
On Mon, Mar 25, 2019 at 2:36 PM Aditya Pakki <pakki001@....edu> wrote:
>
> In case kmemdup fails, the fix releases resources and returns to
> avoid the NULL pointer dereference.
>
> Signed-off-by: Aditya Pakki <pakki001@....edu>
>
> ---
> 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 | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
> index b72a303176c7..f73fb5fdc93f 100644
> --- a/drivers/nvdimm/btt_devs.c
> +++ b/drivers/nvdimm/btt_devs.c
> @@ -204,8 +204,11 @@ 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)
> + 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 +223,11 @@ 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);
> + kfree(nd_btt);
There's still 2 calls to "kfree(nd_btt)" when only one is needed.
Please route them both to the same call.
Powered by blists - more mailing lists