mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mtd: phram: reject non-RAM ranges for module parameters
@ 2026-10-21 11:53 Rahul Kumar
  0 siblings, 0 replies; only message in thread
From: Rahul Kumar @ 2026-10-21 11:53 UTC (permalink / raw)
  To: linux-mtd
  Cc: Joern Engel, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Vincent Whitchurch, linux-kernel,
	syzbot+eaaabe90f486cb6f31b2, syzbot+061cb4ee001379dbbfaf,
	Rahul Kumar

Writing a bogus address such as "p0,0x8000000000000000,0x1000" to
/sys/module/phram/parameters/phram reaches ioremap() and triggers
WARNING in __ioremap_caller on x86. On arm64 a non-RAM address can
map and later Oops in memcpy when FTL scans the device.

For module-parameter devices, require the range to be System RAM
before mapping. Also default that path to memremap(), matching DT
without "no-map".

Fixes: 9401911f2d9f ("mtd: phram: Allow cached mappings")
Reported-by: syzbot+eaaabe90f486cb6f31b2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=eaaabe90f486cb6f31b2
Reported-by: syzbot+061cb4ee001379dbbfaf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=061cb4ee001379dbbfaf
Signed-off-by: Rahul Kumar <rk0006818@gmail.com>
---
 drivers/mtd/devices/phram.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index b42cadcd76b1..9747e7e58e6f 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -19,6 +19,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/io.h>
+#include <linux/ioport.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
@@ -126,10 +127,16 @@ static int register_device(struct platform_device *pdev, const char *name,
 			   phys_addr_t start, size_t len, uint32_t erasesize)
 {
 	struct device_node *np = pdev ? pdev->dev.of_node : NULL;
-	bool cached = np ? !of_property_read_bool(np, "no-map") : false;
+	bool cached = np ? !of_property_read_bool(np, "no-map") : true;
 	struct phram_mtd_list *new;
 	int ret = -ENOMEM;
 
+	if (!np && region_intersects(start, len, IORESOURCE_SYSTEM_RAM,
+				     IORES_DESC_NONE) != REGION_INTERSECTS) {
+		pr_err("start/len is not System RAM\n");
+		return -EINVAL;
+	}
+
 	new = kzalloc_obj(*new);
 	if (!new)
 		goto out0;
@@ -138,7 +145,7 @@ static int register_device(struct platform_device *pdev, const char *name,
 
 	ret = phram_map(new, start, len);
 	if (ret) {
-		pr_err("ioremap failed\n");
+		pr_err("failed to map memory\n");
 		goto out1;
 	}
 
-- 
2.52.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-21 11:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 11:53 [PATCH] mtd: phram: reject non-RAM ranges for module parameters Rahul Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®