of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
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.
--- drivers/of/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/of/fdt.c +2 -1
@@ -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
Hi Yuntaoi,
Quoted 4 lines · Yuntao Wang
The len value is in bytes, while
dt_root_addr_cells + dt_root_size_cellsis 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
so code in v5.14 and older will be fixed by stable backports, too.
Quoted 1 line
Signed-off-by Yuntao Wang <[email protected]>
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
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.
---
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
@@ -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
Rob Herring
maintainerQuoted 5 lines · Yuntao Wang
The len value is in bytes, while
dt_root_addr_cells + dt_root_size_cellsis 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")Reviewed-by Geert Uytterhoeven <[email protected]>Signed-off-by Yuntao Wang <[email protected]>---
v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoevendrivers/of/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/of/fdt.c +2
-2@@ -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
Quoted 10 lines · Rob Herring
Quoted 5 lines · Yuntao Wang
The len value is in bytes, while
dt_root_addr_cells + dt_root_size_cellsis 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")Reviewed-by Geert Uytterhoeven <[email protected]>Signed-off-by Yuntao Wang <[email protected]>---
v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoevendrivers/of/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/of/fdt.c +2
-2@@ -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