Skip to contentSkip to conversation

dax: Fix stack overflow when mounting fsdax pmem device

PATCH In review Adrian Huang 3 participants 3 messages Sep 17, 2020 – Sep 18, 2020

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

PATCH v3 1/1 dax: Fix stack overflow when mounting fsdax pmem device

From: Adrian Huang <[email protected]>

When mounting fsdax pmem device, commit 6180bb446ab6 ("dax: fix detection of dax support for non-persistent memory block devices") introduces the stack overflow [1][2]. Here is the call path for mounting ext4 file system:
ext4_fill_super
bdev_dax_supported
__bdev_dax_supported
dax_supported
generic_fsdax_supported
__generic_fsdax_supported
bdev_dax_supported

The call path leads to the infinite calling loop, so we cannot call bdev_dax_supported() in __generic_fsdax_supported(). The sanity checking of the variable 'dax_dev' is moved prior to the two bdev_dax_pgoff() checks [3][4].

[1] https://lore.kernel.org/linux-nvdimm/[email protected]/
[2] https://lore.kernel.org/linux-nvdimm/alpine.LRH.2.02.2009141131220.30651@file01.intranet.prod.int.rdu2.redhat.com/
[3] https://lore.kernel.org/linux-nvdimm/CA+RJvhxBHriCuJhm-D8NvJRe3h2MLM+ZMFgjeJjrRPerMRLvdg@mail.gmail.com/
[4] https://lore.kernel.org/linux-nvdimm/[email protected]/

Fixes 6180bb446ab6 ("dax: fix detection of dax support for non-persistent memory block devices")
Cc Coly Li <[email protected]>
Cc Ira Weiny <[email protected]>
Cc John Pittman <[email protected]>

---
Changelog:
v3:
1. Add Reviewed-by from Jan
2. Add Reported-by
3. Replace lists.01.org with lore.kernel
v2:
Remove the checking for the returned value '-EOPNOTSUPP' of dax_direct_access(). Jan has prepared a patch to address the issue in dm.

---
 drivers/dax/super.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dax/super.c +6 -6
index e5767c83ea23..11d0541e6f8f 100644
@@ -85,6 +85,12 @@ bool __generic_fsdax_supported(struct dax_device *dax_dev,
 		return false;
 	}
 
+	if (!dax_dev) {
+		pr_debug("%s: error: dax unsupported by block device\n",
+				bdevname(bdev, buf));
+		return false;
+	}
+
 	err = bdev_dax_pgoff(bdev, start, PAGE_SIZE, &pgoff);
 	if (err) {
 		pr_info("%s: error: unaligned partition for dax\n",
@@ -100,12 +106,6 @@ bool __generic_fsdax_supported(struct dax_device *dax_dev,
 		return false;
 	}
 
-	if (!dax_dev || !bdev_dax_supported(bdev, blocksize)) {
-		pr_debug("%s: error: dax unsupported by block device\n",
-				bdevname(bdev, buf));
-		return false;
-	}
-
 	id = dax_read_lock();
 	len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn);
 	len2 = dax_direct_access(dax_dev, pgoff_end, 1, &end_kaddr, &end_pfn);
Signature · 4 lines
2.17.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw
Quoted 20 lines · Adrian Huang

From: Adrian Huang <[email protected]>

When mounting fsdax pmem device, commit 6180bb446ab6 ("dax: fix detection of dax support for non-persistent memory block devices") introduces the stack overflow [1][2]. Here is the call path for mounting ext4 file system:
ext4_fill_super
bdev_dax_supported
__bdev_dax_supported
dax_supported
generic_fsdax_supported
__generic_fsdax_supported
bdev_dax_supported

The call path leads to the infinite calling loop, so we cannot call bdev_dax_supported() in __generic_fsdax_supported(). The sanity checking of the variable 'dax_dev' is moved prior to the two bdev_dax_pgoff() checks [3][4].

Quoted 4 lines

[1] https://lore.kernel.org/linux-nvdimm/[email protected]/
[2] https://lore.kernel.org/linux-nvdimm/alpine.LRH.2.02.2009141131220.30651@file01.intranet.prod.int.rdu2.redhat.com/
[3] https://lore.kernel.org/linux-nvdimm/CA+RJvhxBHriCuJhm-D8NvJRe3h2MLM+ZMFgjeJjrRPerMRLvdg@mail.gmail.com/
[4] https://lore.kernel.org/linux-nvdimm/[email protected]/

Thanks for these fixups.

Applied.
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

Tested-by on v3 1/1
#2 lore raw
In reply to Adrian Huang

ccing fs list

Quoted 24 lines · Adrian Huang

From: Adrian Huang <[email protected]>

When mounting fsdax pmem device, commit 6180bb446ab6 ("dax: fix detection of dax support for non-persistent memory block devices") introduces the stack overflow [1][2]. Here is the call path for mounting ext4 file system:
ext4_fill_super
bdev_dax_supported
__bdev_dax_supported
dax_supported
generic_fsdax_supported
__generic_fsdax_supported
bdev_dax_supported

The call path leads to the infinite calling loop, so we cannot call bdev_dax_supported() in __generic_fsdax_supported(). The sanity checking of the variable 'dax_dev' is moved prior to the two bdev_dax_pgoff() checks [3][4].

[1] https://lore.kernel.org/linux-nvdimm/[email protected]/
[2] https://lore.kernel.org/linux-nvdimm/alpine.LRH.2.02.2009141131220.30651@file01.intranet.prod.int.rdu2.redhat.com/
[3] https://lore.kernel.org/linux-nvdimm/CA+RJvhxBHriCuJhm-D8NvJRe3h2MLM+ZMFgjeJjrRPerMRLvdg@mail.gmail.com/
[4] https://lore.kernel.org/linux-nvdimm/[email protected]/

Quoted 8 lines
Fixes 6180bb446ab6 ("dax: fix detection of dax support for non-persistent memory block devices")
Cc Coly Li <[email protected]>
Cc Ira Weiny <[email protected]>
Cc John Pittman <[email protected]>

Although I see that this is fix is already applied but ccing fsdevel and ext4 since I ended up debugging and coming to the same conclusion as this patch is fixing the recursion loop.
If not already applied then feel free to add:

Quoted 35 lines

---
Changelog:
v3:
1. Add Reviewed-by from Jan
2. Add Reported-by
3. Replace lists.01.org with lore.kernel
v2:
Remove the checking for the returned value '-EOPNOTSUPP' of dax_direct_access(). Jan has prepared a patch to address the issue in dm.

---
  drivers/dax/super.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dax/super.c +6 -0
index e5767c83ea23..11d0541e6f8f 100644
@@ -85,6 +85,12 @@ bool __generic_fsdax_supported(struct dax_device *dax_dev,
  		return false;
  	}
 
+	if (!dax_dev) {
+		pr_debug("%s: error: dax unsupported by block device\n",
+				bdevname(bdev, buf));
+		return false;
+	}
+
  	err = bdev_dax_pgoff(bdev, start, PAGE_SIZE, &pgoff);
  	if (err) {
  		pr_info("%s: error: unaligned partition for dax\n",
@@ -100,12 +106,6 @@ bool __generic_fsdax_supported(struct dax_device *dax_dev,
  		return false;
  	}

drivers/dax/super.c bool __generic_fsdax_supported(struct dax_device *dax_dev, · line 111

Quoted 10 lines
drivers/dax/super.c +0 -6
 
-	if (!dax_dev || !bdev_dax_supported(bdev, blocksize)) {
-		pr_debug("%s: error: dax unsupported by block device\n",
-				bdevname(bdev, buf));
-		return false;
-	}
-
  	id = dax_read_lock();
  	len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn);
  	len2 = dax_direct_access(dax_dev, pgoff_end, 1, &end_kaddr, &end_pfn);

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]