* [PATCH] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
@ 2025-11-02 14:17 Yuntao Wang
2025-11-03 14:51 ` Geert Uytterhoeven
0 siblings, 1 reply; 5+ messages in thread
From: Yuntao Wang @ 2025-11-02 14:17 UTC (permalink / raw)
To: linux-kernel, devicetree
Cc: Rob Herring, Saravana Kannan, Geert Uytterhoeven, 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.
Fixes: f7e7ce93aac1 ("of: fdt: Add generic support for handling elf core headers property")
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
drivers/of/fdt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0edd639898a6..f79461f5cffc 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
2025-11-02 14:17 [PATCH] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
@ 2025-11-03 14:51 ` Geert Uytterhoeven
2025-11-05 9:00 ` [PATCH v2] " Yuntao Wang
0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2025-11-03 14:51 UTC (permalink / raw)
To: Yuntao Wang
Cc: linux-kernel, devicetree, Rob Herring, Saravana Kannan,
Geert Uytterhoeven
Hi Yuntaoi,
On Sun, 2 Nov 2025 at 15:18, Yuntao Wang <yuntao.wang@linux.dev> wrote:
> 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!
> 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.
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
2025-11-03 14:51 ` Geert Uytterhoeven
@ 2025-11-05 9:00 ` Yuntao Wang
2025-11-11 16:56 ` Rob Herring
0 siblings, 1 reply; 5+ messages in thread
From: Yuntao Wang @ 2025-11-05 9:00 UTC (permalink / raw)
To: geert, robh, saravanak
Cc: devicetree, geert+renesas, linux-kernel, 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.
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 <geert+renesas@glider.be>
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
---
v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoeven
drivers/of/fdt.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0edd639898a6..f79461f5cffc 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
2025-11-05 9:00 ` [PATCH v2] " Yuntao Wang
@ 2025-11-11 16:56 ` Rob Herring
2025-11-12 14:58 ` Yuntao Wang
0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2025-11-11 16:56 UTC (permalink / raw)
To: Yuntao Wang; +Cc: geert, saravanak, devicetree, geert+renesas, linux-kernel
On Wed, Nov 5, 2025 at 3:02 AM Yuntao Wang <yuntao.wang@linux.dev> wrote:
>
> 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.
>
> 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 <geert+renesas@glider.be>
> Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
> ---
> v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoeven
>
> drivers/of/fdt.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 0edd639898a6..f79461f5cffc 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr()
2025-11-11 16:56 ` Rob Herring
@ 2025-11-12 14:58 ` Yuntao Wang
0 siblings, 0 replies; 5+ messages in thread
From: Yuntao Wang @ 2025-11-12 14:58 UTC (permalink / raw)
To: robh; +Cc: devicetree, geert+renesas, geert, linux-kernel, saravanak,
yuntao.wang
On Tue, 11 Nov 2025 10:56:51 -0600, Rob Herring <robh@kernel.org> wrote:
> On Wed, Nov 5, 2025 at 3:02 AM Yuntao Wang <yuntao.wang@linux.dev> wrote:
> >
> > 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/20251112143520.233870-11-yuntao.wang@linux.dev/t/
Thanks,
Yuntao
> > 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 <geert+renesas@glider.be>
> > Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
> > ---
> > v1 -> v2: Add a new Fixes tag as suggested by Geert Uytterhoeven
> >
> > drivers/of/fdt.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 0edd639898a6..f79461f5cffc 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-12 14:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-02 14:17 [PATCH] of: fdt: Fix the len check in early_init_dt_check_for_elfcorehdr() Yuntao Wang
2025-11-03 14:51 ` Geert Uytterhoeven
2025-11-05 9:00 ` [PATCH v2] " Yuntao Wang
2025-11-11 16:56 ` Rob Herring
2025-11-12 14:58 ` Yuntao Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).