Skip to contentSkip to conversation

libnvdimm, namespace: potential NULL deref on allocation error

PATCH Applied Dan Carpenter 2 participants 2 messages Oct 12, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnvdimm, namespace: potential NULL deref on allocation error

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

Fixes 1b40e09a1232 ('libnvdimm: blk labels and namespace instantiation')
drivers/nvdimm/namespace_devs.c +8 -6
index 3509cff..abe5c6b 100644
@@ -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;
 }
 
Applied
#1 lore raw
Quoted 5 lines · Dan Carpenter

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

Fixes 1b40e09a1232 ('libnvdimm: blk labels and namespace instantiation')

Thanks, applied.