libnvdimm, dax: Fix a missing check in nd_dax_probe()
PATCH 1/1 libnvdimm, dax: Fix a missing check in nd_dax_probe()
From: Yingjie Wang <[email protected]>
In nd_dax_probe(), nd_dax_alloc() may fail and return NULL. Check for NULL before attempting to
use nd_dax to avoid a NULL pointer dereference.
Fixes c5ed9268643c ("libnvdimm, dax: autodetect support")
Signed-off-by Yingjie Wang <[email protected]>
--- drivers/nvdimm/dax_devs.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvdimm/dax_devs.c +2 -0
@@ -106,6 +106,8 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)nvdimm_bus_lock (&ndns->dev); nd_dax =nd_dax_alloc (nd_region); +if (!nd_dax) +return -ENOMEM ; nd_pfn = &nd_dax->nd_pfn; dax_dev =nd_pfn_devinit (nd_pfn, ndns);nvdimm_bus_unlock (&ndns->dev);
Signature · 4 lines
2.7.4 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Quoted 18 lines · On Fri, Apr 9, 2021 at 5:33 PM <[email protected]> wrote:
From: Yingjie Wang <[email protected]>
In
nd_dax_probe(),nd_dax_alloc()may fail and return NULL. Check for NULL before attempting to
usend_daxto avoid a NULL pointer dereference.Fixes c5ed9268643c ("libnvdimm, dax: autodetect support")Signed-off-by Yingjie Wang <[email protected]>--- drivers/nvdimm/dax_devs.c | 2 ++ 1 file changed, 2 insertions(+)drivers/nvdimm/dax_devs.c +0
-0
drivers/nvdimm/dax_devs.c int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) · line 107
Quoted 2 lines
drivers/nvdimm/dax_devs.c +0
-0@@ -106,6 +106,8 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)nvdimm_bus_lock (&ndns->dev);
hmmm...
drivers/nvdimm/dax_devs.c int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) · line 110
Quoted 3 lines
drivers/nvdimm/dax_devs.c +2
-0nd_dax =nd_dax_alloc (nd_region); +if (!nd_dax) +return -ENOMEM ;
Can you spot the bug this introduces? See the hint above.
Quoted 6 lines
drivers/nvdimm/dax_devs.c +0
-1nd_pfn = &nd_dax->nd_pfn; dax_dev =nd_pfn_devinit (nd_pfn, ndns);nvdimm_bus_unlock (&ndns->dev); --2.7.4