kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] libnvdimm, namespace: potential NULL deref on allocation error
@ 2016-10-12  6:34 Dan Carpenter
  2016-10-12 21:51 ` Dan Williams
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-10-12  6:34 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-nvdimm-y27Ovi1pjclAfugRpC6u6w,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

If the kcalloc() fails then "devs" can be NULL and we dereference it
checking "devs[i]".

Fixes: 1b40e09a1232 ('libnvdimm: blk labels and namespace instantiation')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 3509cff..abe5c6b 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2176,12 +2176,14 @@ static struct device **scan_labels(struct nd_region *nd_region)
 	return devs;
 
  err:
-	for (i = 0; devs[i]; i++)
-		if (is_nd_blk(&nd_region->dev))
-			namespace_blk_release(devs[i]);
-		else
-			namespace_pmem_release(devs[i]);
-	kfree(devs);
+	if (devs) {
+		for (i = 0; devs[i]; i++)
+			if (is_nd_blk(&nd_region->dev))
+				namespace_blk_release(devs[i]);
+			else
+				namespace_pmem_release(devs[i]);
+		kfree(devs);
+	}
 	return NULL;
 }
 

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

* Re: [patch] libnvdimm, namespace: potential NULL deref on allocation error
  2016-10-12  6:34 [patch] libnvdimm, namespace: potential NULL deref on allocation error Dan Carpenter
@ 2016-10-12 21:51 ` Dan Williams
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Williams @ 2016-10-12 21:51 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-nvdimm, kernel-janitors-u79uwXL29TY76Z2rM5mHXA

On Tue, Oct 11, 2016 at 11:34 PM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> If the kcalloc() fails then "devs" can be NULL and we dereference it
> checking "devs[i]".
>
> Fixes: 1b40e09a1232 ('libnvdimm: blk labels and namespace instantiation')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, applied.

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

end of thread, other threads:[~2016-10-12 21:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-12  6:34 [patch] libnvdimm, namespace: potential NULL deref on allocation error Dan Carpenter
2016-10-12 21:51 ` 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).