All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] nvdimm: btt_devs: fix a NULL pointer dereference
@ 2019-03-23 21:41 ` Aditya Pakki
  0 siblings, 0 replies; 3+ messages in thread
From: Aditya Pakki @ 2019-03-23 21:41 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>

---
v1: Free nd_btt->id in case of failure and avoid double free, suggested
by Dan Williams
---
 drivers/nvdimm/btt_devs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index b72a303176c7..119a4ead2e46 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -204,8 +204,14 @@ 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->id);
+			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);
-- 
2.17.1

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

* [PATCH v2] nvdimm: btt_devs: fix a NULL pointer dereference
@ 2019-03-23 21:41 ` Aditya Pakki
  0 siblings, 0 replies; 3+ messages in thread
From: Aditya Pakki @ 2019-03-23 21:41 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Vishal Verma, Dan Williams, Dave Jiang, Keith Busch,
	Ira Weiny, linux-nvdimm, linux-kernel

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

Signed-off-by: Aditya Pakki <pakki001@umn.edu>

---
v1: Free nd_btt->id in case of failure and avoid double free, suggested
by Dan Williams
---
 drivers/nvdimm/btt_devs.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index b72a303176c7..119a4ead2e46 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -204,8 +204,14 @@ 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->id);
+			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);
-- 
2.17.1


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

* Re: [PATCH v2] nvdimm: btt_devs: fix a NULL pointer dereference
  2019-03-23 21:41 ` Aditya Pakki
  (?)
@ 2019-03-25  8:56 ` Johannes Thumshirn
  -1 siblings, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2019-03-25  8:56 UTC (permalink / raw)
  To: Aditya Pakki; +Cc: linux-nvdimm, kjlu, linux-kernel

On 23/03/2019 22:41, 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>
> 
> ---
> v1: Free nd_btt->id in case of failure and avoid double free, suggested
> by Dan Williams
> ---
>  drivers/nvdimm/btt_devs.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
> index b72a303176c7..119a4ead2e46 100644
> --- a/drivers/nvdimm/btt_devs.c
> +++ b/drivers/nvdimm/btt_devs.c
> @@ -204,8 +204,14 @@ 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->id);
> +			kfree(nd_btt);
> +			return NULL;
> +		}
> +	}

nd_btt->id is an ida and thus must be freed using:
ida_simple_remove(&nd_region->btt_ida, nd_btt->id);

that being I'd prefer a 'out_put_id' label at the end of the function
and to the cleanups there.

Something like this:

	if (uuid) {
		uuid = kmemdup(uuid, 16, GFP_KERNEL);
		if (!uuid)
			goto out_put_id;

	[...]

	return dev;

out_put_id:
	ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
	kfree(nd_btt);
	return NULL;
}


-- 
Johannes Thumshirn                            SUSE Labs Filesystems
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-23 21:41 [PATCH v2] nvdimm: btt_devs: fix a NULL pointer dereference Aditya Pakki
2019-03-23 21:41 ` Aditya Pakki
2019-03-25  8:56 ` Johannes Thumshirn

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.