From: Rob Herring <robh@kernel.org>
To: Sang-Heon Jeon <ekffu200098@gmail.com>
Cc: saravanak@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH] of: reserved_mem: prevent OOB when too many dynamic regions are defined
Date: Wed, 3 Jun 2026 17:49:59 -0500 [thread overview]
Message-ID: <20260603224959.GA2317076-robh@kernel.org> (raw)
In-Reply-To: <20260603152709.941788-1-ekffu200098@gmail.com>
On Thu, Jun 04, 2026 at 12:27:09AM +0900, Sang-Heon Jeon wrote:
> On boot, fdt_scan_reserved_mem() saves each dynamically-placed
> /reserved-memory subnode into a local array of size
> MAX_RESERVED_REGIONS.
>
> If the device tree declares more than MAX_RESERVED_REGIONS
> dynamically-placed regions, fdt_scan_reserved_mem() writes past the
> end of the local array.
>
> Add a bounds check that logs an error and skips the excess regions,
> restoring the original behavior.
>
> Fixes: 8a6e02d0c00e ("of: reserved_mem: Restructure how the reserved memory regions are processed")
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
> ---
> QEMU-based test results
>
> - With 65(MAX_RESERVED_REGIONS + 1) dynamically-placed region DTB
>
> 1) AS-IS (before-fix)
> [ 0.000000] OF: reserved mem: 0x000000043ffff000..0x000000043fffffff (4 KiB) map non-reusable rgn00
> [ 0.000000] OF: reserved mem: 0x000000043fffe000..0x000000043fffefff (4 KiB) map non-reusable rgn01
>
> ...
>
> [ 0.000000] OF: reserved mem: 0x000000043ffc1000..0x000000043ffc1fff (4 KiB) map non-reusable rgn62
> [ 0.000000] OF: reserved mem: 0x000000043ffc0000..0x000000043ffc0fff (4 KiB) map non-reusable rgn63
> [ 0.000000] OF: reserved mem: not enough space for all defined regions.
> [ 0.000000] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: fdt_scan_reserved_mem+0x5f0/0x610
> [ 0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.1.0-rc1-00022-gcf5d7a55d3b6 #6 PREEMPT
> [ 0.000000] Hardware name: linux,dummy-virt (DT)
> [ 0.000000] Call trace:
> [ 0.000000] show_stack+0x18/0x24 (C)
> [ 0.000000] dump_stack_lvl+0x34/0x8c
> [ 0.000000] dump_stack+0x18/0x24
> [ 0.000000] vpanic+0x47c/0x4dc
> [ 0.000000] do_panic_on_target_cpu+0x0/0x1c
> [ 0.000000] __stack_chk_fail+0x20/0x24
> [ 0.000000] fdt_scan_reserved_mem+0x5f0/0x610
> [ 0.000000] early_init_fdt_scan_reserved_mem+0x50/0x124
> [ 0.000000] arm64_memblock_init+0x188/0x2b8
> [ 0.000000] setup_arch+0x24c/0x5f4
> [ 0.000000] start_kernel+0x70/0x848
> [ 0.000000] __primary_switched+0x88/0x90
> [ 0.000000] ---[ end Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: fdt_scan_reserved_mem+0x5f0/0x610 ]---
>
> 2) TO-BE (after-fix)
> [ 0.000000] OF: reserved mem: not enough space for all dynamic regions.
> [ 0.000000] OF: reserved mem: 0x000000043ffff000..0x000000043fffffff (4 KiB) map non-reusable rgn00
> [ 0.000000] OF: reserved mem: 0x000000043fffe000..0x000000043fffefff (4 KiB) map non-reusable rgn01
>
> ...
>
> [ 0.000000] OF: reserved mem: 0x000000043ffc1000..0x000000043ffc1fff (4 KiB) map non-reusable rgn62
> [ 0.000000] OF: reserved mem: 0x000000043ffc0000..0x000000043ffc0fff (4 KiB) map non-reusable rgn63
>
> ---
> Hello,
>
> I found a bug introduced by a previous patch, so I am sending this
> fix as quickly as possible after testing. Although we are at the end
> of the 7.1 -rc cycle, I do not want to rush this patch.
>
> Thank you as always for the thoughtful review.
>
> Best Regards,
> Sang-Heon Jeon
> ---
> drivers/of/of_reserved_mem.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index ce1d5530ec0f..4efd521adee0 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -346,6 +346,12 @@ int __init fdt_scan_reserved_mem(void)
> err = __reserved_mem_reserve_reg(child, uname);
> if (!err)
> count++;
> +
> + if (dynamic_nodes_cnt == MAX_RESERVED_REGIONS) {
> + pr_err("not enough space for all dynamic regions.\n");
It would be more useful to print the node name(s) that we skip.
Sashiko's analysis looks correct to me.
Rob
next prev parent reply other threads:[~2026-06-03 22:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 15:27 [PATCH] of: reserved_mem: prevent OOB when too many dynamic regions are defined Sang-Heon Jeon
2026-06-03 15:36 ` sashiko-bot
2026-06-03 22:49 ` Rob Herring [this message]
2026-06-04 11:28 ` Sang-Heon Jeon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260603224959.GA2317076-robh@kernel.org \
--to=robh@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ekffu200098@gmail.com \
--cc=saravanak@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox