From: Long Wei <longwei27@huawei.com>
To: <rppt@kernel.org>, <pasha.tatashin@soleen.com>,
<pratyush@kernel.org>, <akpm@linux-foundation.org>
Cc: <graf@amazon.com>, <leitao@debian.org>, <corbet@lwn.net>,
<rdunlap@infradead.org>, <linux-mm@kvack.org>,
<kexec@lists.infradead.org>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <hewenliang4@huawei.com>,
Long Wei <longwei27@huawei.com>
Subject: [PATCH v3] kho: do not expose incoming sub-blob contents in debugfs
Date: Thu, 19 Nov 2026 17:59:37 +0800 [thread overview]
Message-ID: <20261119095937.826980-1-longwei27@huawei.com> (raw)
Incoming sub-blob pages are owned by their consumers and have independent
lifetimes. Some consumers, such as LUO, restore and free their state in
early_initcall, i.e. before kho_init() (fs_initcall) builds the debugfs
view:
early_initcall: luo_early_startup()
-> kho_retrieve_subtree("LUO")
-> kho_restore_free(luo_ser) /* page is freed */
fs_initcall: kho_init()
-> kho_in_debugfs_init()
-> phys_to_virt(luo_ser_phys)
-> debugfs_create_blob("LUO", ...)
debugfs therefore ends up pointing at a page that was already handed back
to the page allocator, and reading the file triggers a use-after-free:
# cat /sys/kernel/debug/kho/in/sub_fdts/LUO
==================================================================
BUG: KASAN: use-after-free in _copy_to_user+0x37/0x60
Read of size 32 at addr ffff88810309c000 by task cat/27436
Call Trace:
<TASK>
kasan_report+0xb9/0xf0
kasan_check_range+0x100/0x1b0
_copy_to_user+0x37/0x60
simple_read_from_buffer+0x77/0xd0
read_file_blob+0x75/0xa0
vfs_read+0x12d/0x520
ksys_read+0xc3/0x160
do_syscall_64+0x97/0x4b0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
</TASK>
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x1fd
pfn:0x10309c
flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
page_type: f0(buddy)
==================================================================
The page is already in the buddy allocator (page_type: f0(buddy),
refcount 0), which confirms it was freed before the debugfs view was
created.
KHO does not own these pages, so it cannot safely expose their contents at
all. Drop the in/sub_fdts directory. The incoming FDT is reserved by KHO
and remains exposed as in/fdt, where the same metadata is available.
The incoming sub-blob debugfs directory is gone, so remove its description
from the KHO admin guide as well.
Note that in/sub_fdts has exposed memory KHO does not own since
commit c609c144b0e8 ("kexec: add KHO parsing support"), but the
use-after-free only became reachable after commit d376e4b55c9a0
("liveupdate: centralize state management into struct luo_ser") which
added kho_restore_free()
Fixes: d376e4b55c9a0 ("liveupdate: centralize state management into struct luo_ser")
Acked-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Long Wei <longwei27@huawei.com>
---
Changes in v3:
- Fold documentation removal into this patch (per Mike Rapoport)
- Update Fixes tag to d376e4b55c9a0 (per Mike Rapoport)
Changes in v2:
- Drop the in/blobs metadata file entirely (per Pasha Tatashin)
- Remove unused sub_fdt_dir member and #include <linux/io.h>
Documentation/admin-guide/mm/kho.rst | 4 --
kernel/liveupdate/kexec_handover_debugfs.c | 47 +---------------------
2 files changed, 2 insertions(+), 49 deletions(-)
diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-guide/mm/kho.rst
index 902d171a780a..4281da6be5fa 100644
--- a/Documentation/admin-guide/mm/kho.rst
+++ b/Documentation/admin-guide/mm/kho.rst
@@ -117,7 +117,3 @@ stabilized.
kernel's state is in this file in the format of flattened
device tree. This file may disappear when all consumers of
it finished to interpret their metadata.
-
-``/sys/kernel/debug/kho/in/sub_fdts/``
- Similar to ``kho/out/sub_fdts/``, but contains sub blobs
- of KHO producers passed from the old kernel.
diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate/kexec_handover_debugfs.c
index 7d74477da0b7..3a91c47ad7a6 100644
--- a/kernel/liveupdate/kexec_handover_debugfs.c
+++ b/kernel/liveupdate/kexec_handover_debugfs.c
@@ -10,7 +10,6 @@
#define pr_fmt(fmt) "KHO: " fmt
#include <linux/init.h>
-#include <linux/io.h>
#include <linux/libfdt.h>
#include <linux/mm.h>
#include <linux/kho/abi/kexec_handover.h>
@@ -97,8 +96,8 @@ DEFINE_SHOW_ATTRIBUTE(bootmem_len);
__init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)
{
- struct dentry *dir, *sub_fdt_dir;
- int err, child;
+ struct dentry *dir;
+ int err;
INIT_LIST_HEAD(&dbg->fdt_list);
@@ -108,54 +107,12 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)
goto err_out;
}
- sub_fdt_dir = debugfs_create_dir("sub_fdts", dir);
- if (IS_ERR(sub_fdt_dir)) {
- err = PTR_ERR(sub_fdt_dir);
- goto err_rmdir;
- }
-
err = __kho_debugfs_blob_add(&dbg->fdt_list, dir, "fdt", fdt,
fdt_totalsize(fdt));
if (err)
goto err_rmdir;
- fdt_for_each_subnode(child, fdt, 0) {
- int len = 0;
- const char *name = fdt_get_name(fdt, child, NULL);
- const u64 *blob_phys;
- const u64 *blob_size;
- void *blob;
-
- blob_phys = fdt_getprop(fdt, child,
- KHO_SUB_TREE_PROP_NAME, &len);
- if (!blob_phys)
- continue;
- if (len != sizeof(*blob_phys)) {
- pr_warn("node %s prop %s has invalid length: %d\n",
- name, KHO_SUB_TREE_PROP_NAME, len);
- continue;
- }
-
- blob_size = fdt_getprop(fdt, child,
- KHO_SUB_TREE_SIZE_PROP_NAME, &len);
- if (!blob_size || len != sizeof(*blob_size)) {
- pr_warn("node %s missing or invalid %s property\n",
- name, KHO_SUB_TREE_SIZE_PROP_NAME);
- continue;
- }
-
- blob = phys_to_virt(*blob_phys);
- err = __kho_debugfs_blob_add(&dbg->fdt_list, sub_fdt_dir, name,
- blob, *blob_size);
- if (err) {
- pr_warn("failed to add blob %s to debugfs: %pe\n",
- name, ERR_PTR(err));
- continue;
- }
- }
-
dbg->dir = dir;
- dbg->sub_fdt_dir = sub_fdt_dir;
return;
err_rmdir:
--
2.43.0
next reply other threads:[~2026-11-19 10:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:59 Long Wei [this message]
2026-11-19 10:50 ` Pratyush Yadav
2026-11-19 11:17 ` Mike Rapoport
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=20261119095937.826980-1-longwei27@huawei.com \
--to=longwei27@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=graf@amazon.com \
--cc=hewenliang4@huawei.com \
--cc=kexec@lists.infradead.org \
--cc=leitao@debian.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rppt@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
all inboxes | Powered by JetHome®