From: sashiko-bot@kernel.org
To: "Suseendran Bhaskaran" <suseendranb@google.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Dan Williams" <djbw@kernel.org>,
"David Hildenbrand" <david@kernel.org>
Cc: "Alexander Graf" <graf@amazon.com>,
"Alison Schofield" <alison.schofield@intel.com>,
"Andy Lutomirski" <luto@kernel.org>,
"Borislav Petkov" <bp@alien8.de>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Changyuan Lyu" <changyuanl@google.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Dave Jiang" <dave.jiang@intel.com>,
"David Rientjes" <rientjes@google.com>,
"Frank van der Linden" <fvdl@google.com>,
"H. Peter Anvin" <hpa@zytor.com>,
"Ingo Molnar" <mingo@redhat.com>, "Ira Weiny" <iweiny@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Liam R. Howlett" <liam@infradead.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Michal Hocko" <mhocko@suse.com>,
"Oscar Salvador" <osalvador@suse.de>,
"Pasha Tatashin" <pasha.tatashin@soleen.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Thomas Gleixner" <tglx@kernel.org>,
"Vishal Verma" <vishal.l.verma@intel.com>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Will Deacon" <will@kernel.org>,
kexec@lists.infradead.org, linux-cxl@vger.kernel.org,
linux-mm@kvack.org, nvdimm@lists.linux.dev, x86@kernel.org
Subject: Re: [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec
Date: Thu, 03 Dec 2026 00:27:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-246848@kernel.org> (raw)
In-Reply-To: <20261202001946.1226273-12-suseendranb@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mm/extmem: use-after-free in debugfs after kho_restore_free()
- [Low] mm/extmem: preserved folio leak on header error in
extmem_kho_revive()
--
commit 9f04f9db25ca8f17e991389629e8f29959226fb9
Author: Suseendran Bhaskaran <suseendranb@google.com>
mm/extmem: preserve carved regions across KHO kexec
This commit preserves boot-carved extmem physical memory regions and their
alignments across a Kexec HandOver (KHO) kexec using an "extmem" KHO
subtree descriptor table.
> diff --git a/mm/extmem_kho.c b/mm/extmem_kho.c
> new file mode 100644
> index 0000000000000..53d83fd8b84c5
> --- /dev/null
> +++ b/mm/extmem_kho.c
> @@ -0,0 +1,188 @@
[ ... ]
> +int __init extmem_kho_revive(void)
> +{
> + const struct kho_extmem_ser *ser;
> + phys_addr_t ser_phys;
> + size_t blob_size;
> + unsigned int i;
> + int err;
> +
> + err = kho_retrieve_subtree(EXTMEM_KHO_ENTRY_NAME, &ser_phys,
> + &blob_size);
> + if (err == -ENOENT)
> + return -ENOENT;
> + if (err) {
> + pr_warn_once("failed to retrieve KHO subtree: %pe\n",
> + ERR_PTR(err));
> + return err;
> + }
> +
> + if (!ser_phys || !PAGE_ALIGNED(ser_phys) || blob_size < sizeof(*ser) ||
> + blob_size > struct_size(ser, regions, EXTMEM_MAX_REGIONS) ||
> + !extmem_kho_is_ram(ser_phys, PAGE_SIZE)) {
> + err = -EINVAL;
> + goto err_warn;
> + }
> +
> + ser = phys_to_virt(ser_phys);
> + if (ser->version != KHO_EXTMEM_VERSION || !ser->nr_regions ||
> + blob_size != struct_size(ser, regions, ser->nr_regions)) {
> + err = -EINVAL;
> + goto err_warn;
> + }
> +
> + extmem_kho_in_ser_phys = ser_phys;
[Severity: Low]
Does this leak the preserved folio at ser_phys if the header validation
fails (for example, on a KHO_EXTMEM_VERSION mismatch)? Jumping to
err_warn before setting extmem_kho_in_ser_phys leaves it zero, so
extmem_kho_init() never reclaims the folio that kho_mem_retrieve()
reserves.
[ ... ]
> +static int __init extmem_kho_init(void)
> +{
> + struct kho_extmem_ser *ser;
> + unsigned int i;
> + size_t size;
> + int err;
> +
> + if (extmem_kho_in_ser_phys && is_kho_boot())
> + kho_restore_free(phys_to_virt(extmem_kho_in_ser_phys));
[Severity: Medium]
Does freeing extmem_kho_in_ser_phys here cause a use-after-free when
/sys/kernel/debug/kho/in/sub_fdts/extmem is read?
kho_init() runs earlier at fs_initcall and registers a debugfs blob for
every incoming KHO subnode pointing directly to phys_to_virt(*blob_phys):
kernel/liveupdate/kexec_handover_debugfs.c:kho_in_debugfs_init() {
...
blob = phys_to_virt(*blob_phys);
err = __kho_debugfs_blob_add(&dbg->fdt_list, sub_fdt_dir, name,
blob, *blob_size);
...
}
When extmem_kho_init() runs at late_initcall and calls kho_restore_free(),
the folio is returned to the page allocator while the debugfs entry keeps
the dangling pointer for the lifetime of the kernel.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202001946.1226273-1-suseendranb@google.com?part=11
next prev parent reply other threads:[~2026-12-03 0:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 0:19 [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 01/11] mm/cma: clamp multi-range search to 4G and honor memblock flags Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 02/11] mm/memblock: factor out multi-range contiguous reservation helper from CMA Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 03/11] x86/mm: add early direct-map unmap helpers for boot carveouts Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 04/11] arm64/mm: support unmapping boot carveouts from the linear map Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 05/11] mm/extmem: add architecture-neutral external memory subsystem Suseendran Bhaskaran
2026-12-03 0:27 ` sashiko-bot
2026-12-02 0:19 ` [RFC PATCH 06/11] dax/hmem: bind extmem platform devices with per-region alignment Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 07/11] nvdimm/ramdax: manage bus and DIMM allocations with devres Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 08/11] nvdimm/ramdax: harden probe checks and select NUMA_KEEP_MEMINFO Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 09/11] nvdimm/ramdax: support binding extmem platform devices Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 10/11] x86/kaslr: avoid placing kernel in carvable high memory when extmem= is set Suseendran Bhaskaran
2026-12-02 0:19 ` [RFC PATCH 11/11] mm/extmem: preserve carved regions across KHO kexec Suseendran Bhaskaran
2026-12-03 0:27 ` sashiko-bot [this message]
2026-12-02 14:45 ` [RFC PATCH 00/11] mm: NUMA-aware boot memory carving (extmem) Mike Rapoport
2026-12-02 15:10 ` David Hildenbrand (Arm)
2026-12-03 0:24 ` Suseendran Bhaskaran
2026-12-03 0:28 ` sashiko-bot
2026-12-03 0:34 ` Dave Hansen
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=sashiko-outbox-246848@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alison.schofield@intel.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=changyuanl@google.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=dave.jiang@intel.com \
--cc=david@kernel.org \
--cc=djbw@kernel.org \
--cc=fvdl@google.com \
--cc=graf@amazon.com \
--cc=hpa@zytor.com \
--cc=iweiny@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=liam@infradead.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=nvdimm@lists.linux.dev \
--cc=osalvador@suse.de \
--cc=pasha.tatashin@soleen.com \
--cc=peterz@infradead.org \
--cc=pratyush@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=skhan@linuxfoundation.org \
--cc=suseendranb@google.com \
--cc=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=vishal.l.verma@intel.com \
--cc=will@kernel.org \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.