From: Wandun <chenwandun1@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 4/8] of: reserved_mem: save /memreserve/ entries into the reserved_mem array
Date: Fri, 22 May 2026 15:19:31 +0800 [thread overview]
Message-ID: <cc70c1af-2276-4d73-bd55-612995ec6cae@gmail.com> (raw)
In-Reply-To: <20260520103734.2CDFA1F000E9@smtp.kernel.org>
On 5/20/26 18:37, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Out-of-bounds write to the statically allocated `reserved_mem_array` due to inflated `total_reserved_mem_cnt` without guaranteed array reallocation.
> --
>
> commit cac834a48f61205ebaa2a6eaf1bc2f735c0a6c46
> Author: Wandun Chen <chenwandun1@gmail.com>
>
> of: reserved_mem: save /memreserve/ entries into the reserved_mem array
>
> This commit saves /memreserve/ entries into the reserved_mem array so they
> can be excluded from kdump vmcores. Overlapping entries are marked as dumpable
> to ensure useful crash analysis data is retained.
>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index 82f7327c59ea9..d2bcaf149fe81 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
> [ ... ]
>> @@ -516,7 +517,9 @@ void __init early_init_fdt_scan_reserved_mem(void)
>> if (!size)
>> break;
>> memblock_reserve(base, size);
>> + nr_memreserve++;
>> }
>> + fdt_reserved_mem_account_memreserve(nr_memreserve);
>> }
> [ ... ]
>> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
>> index 313cbc57aa453..6dfe9e03c535d 100644
>> --- a/drivers/of/of_reserved_mem.c
>> +++ b/drivers/of/of_reserved_mem.c
> [ ... ]
>> @@ -241,6 +241,43 @@ static void __init __rmem_check_for_overlap(void)
>> }
>> }
>>
>> +static void __init fdt_reserved_mem_add_memreserve(phys_addr_t base,
>> + phys_addr_t size)
>> +{
>> + struct reserved_mem *rmem;
>> + bool dumpable = false;
>> + int i;
>> +
>> + if (reserved_mem_count == total_reserved_mem_cnt) {
>> + pr_err("not enough space for memreserve regions.\n");
>> + return;
>> + }
> [Severity: High]
> Could this lead to an out-of-bounds write to the statically allocated
> reserved_mem_array during early boot?
>
> fdt_reserved_mem_account_memreserve() increments total_reserved_mem_cnt
> by the number of /memreserve/ entries. However, if the device tree lacks
> a /reserved-memory node, fdt_scan_reserved_mem_late() returns early and
> alloc_reserved_mem_array() is bypassed.
Yes, there is indeed an out-of-bounds issue if the device tree lacks a
/reserved-memory node.
At the same time, it will also cause inaccurate counting for
total_reserved_mem_cnt.
Will fix both in v3.
>
> If this happens, the reserved_mem pointer continues to point to the
> statically allocated array with a fixed capacity of MAX_RESERVED_REGIONS.
>
> Since the check above compares against the inflated total_reserved_mem_cnt, it
> appears we could write past the end of the static array if the device tree
> contains 64 or more /memreserve/ entries?
>
>> +
>> + for (i = 0; i < reserved_mem_count; i++) {
>> + rmem = &reserved_mem[i];
>> +
>> + if (!rmem->dumpable)
>> + continue;
>> +
>> + if (base < rmem->base + rmem->size && rmem->base < base + size) {
>> + dumpable = true;
>> + break;
>> + }
>> + }
>> +
>> + rmem = &reserved_mem[reserved_mem_count];
>> + rmem->base = base;
>> + rmem->size = size;
>> + rmem->dumpable = dumpable;
>> +
>> + reserved_mem_count++;
>> +}
> [ ... ]
>
next prev parent reply other threads:[~2026-05-22 7:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 9:18 [PATCH v2 0/8] kdump: reduce vmcore size and capture time Wandun Chen
2026-05-20 9:18 ` [PATCH v2 1/8] of: reserved_mem: handle NULL name in of_reserved_mem_lookup() Wandun Chen
2026-05-20 9:18 ` [PATCH v2 2/8] kexec/crash: provide crash_exclude_mem_range() stub when CONFIG_CRASH_DUMP=n Wandun Chen
2026-05-20 9:18 ` [PATCH v2 3/8] of: reserved_mem: add dumpable flag to opt-in vmcore Wandun Chen
2026-05-20 9:53 ` Marek Szyprowski
2026-05-20 9:18 ` [PATCH v2 4/8] of: reserved_mem: save /memreserve/ entries into the reserved_mem array Wandun Chen
2026-05-20 10:37 ` sashiko-bot
2026-05-22 7:19 ` Wandun [this message]
2026-05-20 9:18 ` [PATCH v2 5/8] of: reserved_mem: add kdump helpers to exclude non-dumpable regions Wandun Chen
2026-05-20 11:03 ` sashiko-bot
2026-05-22 7:22 ` Wandun
2026-05-20 9:18 ` [PATCH v2 6/8] arm64: kdump: exclude non-dumpable reserved memory regions from vmcore Wandun Chen
2026-05-20 12:02 ` sashiko-bot
2026-05-22 8:04 ` Wandun
2026-05-20 9:18 ` [PATCH v2 7/8] riscv: " Wandun Chen
2026-05-20 12:34 ` sashiko-bot
2026-05-20 9:18 ` [PATCH v2 8/8] loongarch: " Wandun Chen
2026-05-20 13:10 ` sashiko-bot
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=cc70c1af-2276-4d73-bd55-612995ec6cae@gmail.com \
--to=chenwandun1@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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