Skip to contentSkip to conversation

of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()

PATCH Superseded Yuntao Wang 3 participants 5 messages Nov 2, 2025 – Nov 12, 2025 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

Fixes f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
---
 drivers/of/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/fdt.c +2 -1
index 0edd639898a6..f79461f5cffc 100644
@@ -812,6 +812,7 @@ static void __init early_init_dt_check_for_initrd(unsigned long node)
  */
 static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 {
+	int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
 	const __be32 *prop;
 	int len;
 
@@ -821,7 +822,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 	pr_debug("Looking for elfcorehdr property... ");
 
 	prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
-	if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
+	if (!prop || len < t_len)
 		return;
 
 	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Yuntaoi,

Quoted 4 lines · Yuntao Wang

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

Thanks for your patch!

Quoted 1 line
Fixes f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")

My commit consolidated existing code, so you may want to add

Fixes e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file")

so code in v5.14 and older will be fixed by stable backports, too.

Quoted 1 line

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw

PATCH v2 1/1 of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

Fixes f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
Fixes e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file")

---
v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoeven

 drivers/of/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/fdt.c +2 -1
index 0edd639898a6..f79461f5cffc 100644
@@ -812,6 +812,7 @@ static void __init early_init_dt_check_for_initrd(unsigned long node)
  */
 static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 {
+	int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
 	const __be32 *prop;
 	int len;
 
@@ -821,7 +822,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 	pr_debug("Looking for elfcorehdr property... ");
 
 	prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
-	if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
+	if (!prop || len < t_len)
 		return;
 
 	elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
Signature · 1 line
2.51.0
maintainer
#3 lore raw
Quoted 5 lines · Yuntao Wang

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

We have 3 copies of the same code. This one plus "linux,kho-fdt" and "linux,kho-scratch". Please consolidate them. The few places we have for this type of mismatch, the better.

Quoted 34 lines
Fixes f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
Fixes e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file")

---
v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoeven

 drivers/of/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/fdt.c +2 -2
index 0edd639898a6..f79461f5cffc 100644
@@ -812,6 +812,7 @@ static void __init early_init_dt_check_for_initrd(unsigned long node)
  */
 static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 {
+       int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
        const __be32 *prop;
        int len;
 
@@ -821,7 +822,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
        pr_debug("Looking for elfcorehdr property... ");
 
        prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
-       if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
+       if (!prop || len < t_len)
                return;
 
        elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
--

2.51.0

#4 lore raw
Quoted 10 lines · Rob Herring
Quoted 5 lines · Yuntao Wang

The len value is in bytes, while dt_root_addr_cells + dt_root_size_cells is in cells (4 bytes per cell).

Comparing them directly is incorrect. Convert units before comparison.

We have 3 copies of the same code. This one plus "linux,kho-fdt" and "linux,kho-scratch". Please consolidate them. The few places we have for this type of mismatch, the better.

Hi Rob,

The link to the new patch series:

https://lore.kernel.org/linux-devicetree/[email protected]/t/

Thanks,
Yuntao

Quoted 33 lines
Quoted 33 lines
Fixes f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
Fixes e62aaeac426ab1dd ("arm64: kdump: provide /proc/vmcore file")

---
v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoeven

 drivers/of/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/fdt.c +2 -2
index 0edd639898a6..f79461f5cffc 100644
@@ -812,6 +812,7 @@ static void __init early_init_dt_check_for_initrd(unsigned long node)
  */
 static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
 {
+       int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
        const __be32 *prop;
        int len;
 
@@ -821,7 +822,7 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
        pr_debug("Looking for elfcorehdr property... ");
 
        prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
-       if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
+       if (!prop || len < t_len)
                return;
 
        elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
--

2.51.0