Re: [PATCH v2 1/2] kho: do not expose incoming sub-blob contents in debugfs
From: Mike Rapoport
Date: Thu Nov 19 2026 - 03:27:07 EST
Hi,
> 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.
>
> Fixes: c609c144b0e8 ("kexec: add KHO parsing support")
> Signed-off-by: Long Wei <longwei27@xxxxxxxxxx>
The change is fine, but the Fixes: tag should name the commit that
made the use-after-free reachable.
c609c144b0e8 ("kexec: add KHO parsing support") added in/sub_fdts, but
only memblock consumed an incoming sub-tree back then, and it never
freed it. Preserved pages that nobody restores stay reserved, so the
debugfs blobs pointed at valid memory. The same was true for test_kho
and for LUO while it kept luo_global.fdt_in.
The page is first freed early in boot by d376e4b55c9a0 ("liveupdate:
centralize state management into struct luo_ser"). That commit added
kho_restore_free(luo_ser) to luo_early_startup(), and it is the path
in the changelog and the KASAN report. It went into v7.2-rc1.
Pasha asked for c609c144b0e8 in v1 because in/sub_fdts never owned
those pages. That is a fair point about the design, but with that tag
stable will try to backport the patch to every tree since v6.16. There
is no bug in those trees, and the code there lives in
kernel/kexec_handover.c, so the patch won't apply. I'd use
Fixes: d376e4b55c9a0 ("liveupdate: centralize state management into struct luo_ser")
and say in the changelog that in/sub_fdts has exposed memory KHO does not
own since c609c144b0e8.
--
Sincerely yours,
Mike.