linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] nvdimm: btt_devs: fix a NULL pointer dereference
@ 2019-03-25 21:36 Aditya Pakki
  2019-03-25 21:42 ` Dan Williams
  0 siblings, 1 reply; 2+ messages in thread
From: Aditya Pakki @ 2019-03-25 21:36 UTC (permalink / raw)
  To: pakki001-OJFnDUYgAso
  Cc: linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw, kjlu-OJFnDUYgAso,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.

Signed-off-by: Aditya Pakki <pakki001-OJFnDUYgAso@public.gmane.org>

---
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);
+	return NULL;
 }
 
 struct device *nd_btt_create(struct nd_region *nd_region)
-- 
2.17.1

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

* Re: [PATCH v3] nvdimm: btt_devs: fix a NULL pointer dereference
  2019-03-25 21:36 [PATCH v3] nvdimm: btt_devs: fix a NULL pointer dereference Aditya Pakki
@ 2019-03-25 21:42 ` Dan Williams
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Williams @ 2019-03-25 21:42 UTC (permalink / raw)
  To: Aditya Pakki; +Cc: linux-nvdimm, Kangjie Lu, Linux Kernel Mailing List

On Mon, Mar 25, 2019 at 2:36 PM Aditya Pakki <pakki001@umn.edu> 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>
>
> ---
> 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.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2019-03-25 21:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-25 21:36 [PATCH v3] nvdimm: btt_devs: fix a NULL pointer dereference Aditya Pakki
2019-03-25 21:42 ` Dan Williams

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).