Skip to contentSkip to conversation

dm-writecache: fix a crash if we attempt to use non-dax device

PATCH New Mikulas Patocka 1 participant 1 message Sep 30 Device mapper

lore
Share & tools
lore

Mikulas Patocka

author maintainer
#0 lore raw

PATCH 3/5 dm-writecache: fix a crash if we attempt to use non-dax device

If we specify a non-DAX device as a cache device in the 'P' mode, dm-writecache crashes on NULL pointer dereference inside dax_synchronous.

Note that this is not a security bug because only root can trigger it.

Fixes a46624580376 ("dm writecache: reject asynchronous pmem devices")
Assisted-by Claude:claude-opus-5
---
 drivers/md/dm-writecache.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/md/dm-writecache.c +5 -0
Index: linux-2.6/drivers/md/dm-writecache.c
===================================================================
@@ -2502,6 +2502,11 @@ invalid_optional:
 	}
 
 	if (WC_MODE_PMEM(wc)) {
+		if (!wc->ssd_dev->dax_dev) {
+			r = -EOPNOTSUPP;
+			ti->error = "Cache device is not a DAX device";
+			goto bad;
+		}
 		if (!dax_synchronous(wc->ssd_dev->dax_dev)) {
 			r = -EOPNOTSUPP;
 			ti->error = "Asynchronous persistent memory not supported as pmem cache";