nvdimm: btt_devs: fix a NULL pointer dereference and a memory leak
PATCH 1/1 nvdimm: btt_devs: fix a NULL pointer dereference and a memory leak
In case kmemdup fails, the fix releases resources and returns to avoid the NULL pointer dereference.
Also, the error paths in the following code should release resources to avoid memory leaks.
--- drivers/nvdimm/btt_devs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/nvdimm/btt_devs.c +7 -1
@@ -196,8 +196,13 @@ 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); +return NULL ; + } + } nd_btt->uuid = uuid; dev = &nd_btt->dev;dev_set_name (dev,"btt%d.%d" , nd_region->id, nd_btt->id);
@@ -209,6 +214,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,dev_dbg (&ndns->dev,"failed, already claimed by %s\n" ,dev_name (ndns->claim));put_device (dev); +kfree (uuid);return NULL ; }return dev;
Signature · 1 line
2.17.1
Quoted 10 lines · Kangjie Lu
In case kmemdup fails, the fix releases resources and returns to avoid the NULL pointer dereference.
Also, the error paths in the following code should release resources to avoid memory leaks.Signed-off-by Kangjie Lu <[email protected]>--- drivers/nvdimm/btt_devs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Looks good,
Quoted 28 lines
drivers/nvdimm/btt_devs.c +6
-1@@ -196,8 +196,13 @@ 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); +return NULL ; + } + } nd_btt->uuid = uuid; dev = &nd_btt->dev;drivers/nvdimm/btt_devs.c +1
-0dev_set_name (dev,"btt%d.%d" , nd_region->id, nd_btt->id);@@ -209,6 +214,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,dev_dbg (&ndns->dev,"failed, already claimed by %s\n" ,dev_name (ndns->claim));put_device (dev); +kfree (uuid);return NULL ; }
Quoted 1 line
return dev;
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerQuoted 6 lines · Vishal L
Quoted 5 lines · Kangjie Lu
In case kmemdup fails, the fix releases resources and returns to avoid the NULL pointer dereference.
Also, the error paths in the following code should release resources to avoid memory leaks.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Kangjie Lu <[email protected]>--- drivers/nvdimm/btt_devs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Looks good,
Reviewed-by Vishal Verma <[email protected]>
Looking again, there is another kmemdup() call in __nd_btt_probe which is lacking error checking.
And referring to your other related patch to namespace_devs, that has /several/ instances of the same thing.
Instead of fixing just a couple of these, it might be worthwhile to send a wider cleanup patch to catch all of these, at least within drivers/nvdimm/ for starters, instead of a select few.
Quoted 27 lines
Quoted 27 lines
drivers/nvdimm/btt_devs.c +6
-1@@ -196,8 +196,13 @@ 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); +return NULL ; + } + } nd_btt->uuid = uuid; dev = &nd_btt->dev;drivers/nvdimm/btt_devs.c +1
-0dev_set_name (dev,"btt%d.%d" , nd_region->id, nd_btt->id);@@ -209,6 +214,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,dev_dbg (&ndns->dev,"failed, already claimed by %s\n" ,dev_name (ndns->claim));put_device (dev); +kfree (uuid);
Quoted 8 lines
Quoted 3 lines
drivers/nvdimm/btt_devs.c +0
-0return NULL ; }return dev;
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerQuoted 16 lines · Vishal L
Quoted 6 lines · Vishal L
Quoted 5 lines · Kangjie Lu
In case kmemdup fails, the fix releases resources and returns to avoid the NULL pointer dereference.
Also, the error paths in the following code should release resources to avoid memory leaks.Quoted 8 lines
Quoted 5 lines
Signed-off-by Kangjie Lu <[email protected]>--- drivers/nvdimm/btt_devs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)Looks good,
Reviewed-by Vishal Verma <[email protected]>
Quoted 8 lines
Looking again, there is another
kmemdup()call in__nd_btt_probewhich is lacking error checking.
And referring to your other related patch tonamespace_devs, that has /several/ instances of the same thing.Instead of fixing just a couple of these, it might be worthwhile to send a wider cleanup patch to catch all of these, at least within
drivers/nvdimm/for starters, instead of a select few.
Hm, ignore this comment - these are the only two unchecked instances.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 16 lines · Kangjie Lu
In case kmemdup fails, the fix releases resources and returns to avoid the NULL pointer dereference.
Also, the error paths in the following code should release resources to avoid memory leaks.Signed-off-by Kangjie Lu <[email protected]>--- drivers/nvdimm/btt_devs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/nvdimm/btt_devs.c +0
-0
drivers/nvdimm/btt_devs.c static struct device *__nd_btt_create(struct nd_region *nd_region, · line 203
Quoted 9 lines
drivers/nvdimm/btt_devs.c +4
-1@@ -196,8 +196,13 @@ 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); +return NULL ;
What about nd_btt->id? That needs to be released as well.
drivers/nvdimm/btt_devs.c static struct device *__nd_btt_create(struct nd_region *nd_region, · line 217
Quoted 10 lines
drivers/nvdimm/btt_devs.c +3
-0+ } + } nd_btt->uuid = uuid; dev = &nd_btt->dev;dev_set_name (dev,"btt%d.%d" , nd_region->id, nd_btt->id);@@ -209,6 +214,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,dev_dbg (&ndns->dev,"failed, already claimed by %s\n" ,dev_name (ndns->claim));put_device (dev); +kfree (uuid);
This will be a double free because put_device() will arrange for nd_btt_release() to be called which does kfree(nd_btt->uuid);
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm