diff mbox

[v2] libnvdimm: fix NULL ptr access in nvdimm_flush when region is disabled

Message ID 152339515127.30466.8052576975908716815.stgit@djiang5-desk3.ch.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dave Jiang April 10, 2018, 9:19 p.m. UTC
When a region is disabled, there is no driver attached. Therefore
dev->driverdata is NULL. An attempt to write to regionN/deep_flush via sysfs
would cause a NULL pointer dereference. Bail when dev->driver is NULL to
protect this scenario.

Fix: ab630891ce0eb(libnvdimm, region: sysfs trigger for nvdimm_flush())

Signed-off-by: Dave Jiang <dave.jiang@intel.com>

v2: Move to deep_flush_store. (Dan)

 drivers/nvdimm/region_devs.c |    5 +++++
 1 file changed, 5 insertions(+)
diff mbox


diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index a612be6f019d..65cc2a5b48b8 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -290,6 +290,11 @@  static ssize_t deep_flush_store(struct device *dev, struct device_attribute *att
 		return rc;
 	if (!flush)
 		return -EINVAL;
+	/* protect against disabled region */
+	if (!nd_region->dev.driver)
+		return -ENXIO;
 	return len;