Skip to contentSkip to conversation

dax/fsdev: fix uninitialized kaddr in fsdev_dax_zero_page_range()

PATCH In review John Groves 3 participants 3 messages Apr 12 – Apr 13 1 message not in the archive

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

PATCH 1/1 dax/fsdev: fix uninitialized kaddr in fsdev_dax_zero_page_range()

In reply to a message not in the archive

From: John Groves <[email protected]>

__fsdev_dax_direct_access() returns -EFAULT without setting *kaddr when dax_pgoff_to_phys() returns -1 (pgoff out of range). The return value was ignored, leaving kaddr uninitialized before being passed to fsdev_write_dax().

Check the return value and propagate the error.

Thanks to Dan Carpenter and the smatch project for reporting this.

---
 drivers/dax/fsdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/dax/fsdev.c +4 -1
index 4499d9621f33..188b2526bee4 100644
@@ -80,9 +80,12 @@ static int fsdev_dax_zero_page_range(struct dax_device *dax_dev,
 			pgoff_t pgoff, size_t nr_pages)
 {
 	void *kaddr;
+	long rc;
 
 	WARN_ONCE(nr_pages > 1, "%s: nr_pages > 1\n", __func__);
-	__fsdev_dax_direct_access(dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, NULL);
+	rc = __fsdev_dax_direct_access(dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, NULL);
+	if (rc < 0)
+		return rc;
 	fsdev_write_dax(kaddr, ZERO_PAGE(0), 0, PAGE_SIZE);
 	return 0;
 }

base-commit: 2ae624d5a555d47a735fb3f4d850402859a4db77

Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#2 lore raw
Quoted 7 lines · On Sun, 12 Apr 2026 15:50:06 +0000 John Groves <[email protected]> wrote:

From: John Groves <[email protected]>

__fsdev_dax_direct_access() returns -EFAULT without setting *kaddr when dax_pgoff_to_phys() returns -1 (pgoff out of range). The return value was ignored, leaving kaddr uninitialized before being passed to fsdev_write_dax().

Quoted 5 lines

Check the return value and propagate the error.

Thanks to Dan Carpenter and the smatch project for reporting this.

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to John Groves
Quoted 7 lines · John Groves

From: John Groves <[email protected]>

__fsdev_dax_direct_access() returns -EFAULT without setting *kaddr when dax_pgoff_to_phys() returns -1 (pgoff out of range). The return value was ignored, leaving kaddr uninitialized before being passed to fsdev_write_dax().

Quoted 5 lines

Check the return value and propagate the error.

Thanks to Dan Carpenter and the smatch project for reporting this.

Quoted 24 lines
---
 drivers/dax/fsdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/dax/fsdev.c +4 -1
index 4499d9621f33..188b2526bee4 100644
@@ -80,9 +80,12 @@ static int fsdev_dax_zero_page_range(struct dax_device *dax_dev,
 			pgoff_t pgoff, size_t nr_pages)
 {
 	void *kaddr;
+	long rc;
 
 	WARN_ONCE(nr_pages > 1, "%s: nr_pages > 1\n", __func__);
-	__fsdev_dax_direct_access(dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, NULL);
+	rc = __fsdev_dax_direct_access(dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, NULL);
+	if (rc < 0)
+		return rc;
 	fsdev_write_dax(kaddr, ZERO_PAGE(0), 0, PAGE_SIZE);
 	return 0;
 }

base-commit: 2ae624d5a555d47a735fb3f4d850402859a4db77