Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 5/8] of: reserved_mem: add kdump helpers to exclude non-dumpable regions
Date: Wed, 20 May 2026 11:03:20 +0000	[thread overview]
Message-ID: <20260520110321.2A23C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260520091844.592753-6-chenwandun@lixiang.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free when accessing `reserved_mem` during kexec load on systems with `/memreserve/` but no `/reserved-memory` node.
--

commit f3d66a3fdb2eb02781d662efcbf6e92d5a51228e
Author: Wandun Chen <chenwandun1@gmail.com>

of: reserved_mem: add kdump helpers to exclude non-dumpable regions

This commit adds two helpers to exclude non-dumpable reserved memory
regions during kdump. These helpers calculate the number of excluded
ranges and perform the actual exclusion by iterating over the
reserved_mem array.

> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c

[ ... ]

> +/* Exclude non-dumpable reserved regions from @cmem. */
> +int of_reserved_mem_kdump_exclude(struct crash_mem *cmem)
> +{
> +	unsigned int i;
> +	int ret;
> +
> +	for (i = 0; i < reserved_mem_count; i++) {
> +		struct reserved_mem *r = &reserved_mem[i];

[Severity: High]
Can accessing reserved_mem here cause a use-after-free on systems that have
/memreserve/ entries but no /reserved-memory node?

The global pointer reserved_mem initially points to reserved_mem_array,
which is marked with __initdata. During early boot, if there is no
/reserved-memory node, fdt_scan_reserved_mem_late() returns early without
dynamically allocating a permanent array.

However, fdt_reserved_mem_save_memreserve_entries() unconditionally
populates /memreserve/ entries into this __initdata array and increments
reserved_mem_count.

After boot completes, the __initdata section is freed.

When a kexec image is later loaded, won't these helpers iterate over
reserved_mem_count and read fields like size, dumpable, and base from
the freed init memory?

> +
> +		if (!r->size || r->dumpable)
> +			continue;
> +		ret = crash_exclude_mem_range(cmem, r->base,
> +					      r->base + r->size - 1);
> +		if (ret)
> +			return ret;
> +	}
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260520091844.592753-1-chenwandun@lixiang.com?part=5

  reply	other threads:[~2026-05-20 11:03 UTC|newest]

Thread overview: 15+ 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-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 [this message]
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-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=20260520110321.2A23C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=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