kho: do not expose incoming sub-blob contents in debugfs
Subsystems (5)
PATCH v3 1/1 kho: do not expose incoming sub-blob contents in debugfs
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()
---
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(-)
Documentation/admin-guide/mm/kho.rst +0 -4
@@ -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.
kernel/liveupdate/kexec_handover_debugfs.c +2 -45
71 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 14 lines
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. beforekho_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", ...)
Quoted 7 lines
debugfs therefore ends up pointing at a page that was already handed back [ ... ]
addedkho_restore_free()Fixes d376e4b55c9a0 ("liveupdate: centralize state management into struct luo_ser")Acked-by Pasha Tatashin <[email protected]>Signed-off-by Long Wei <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 59 lines · Long Wei
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. beforekho_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/27436Call 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 commitd376e4b55c9a0("liveupdate: centralize state management into structluo_ser") which addedkho_restore_free()
Quoted 3 lines
Fixes d376e4b55c9a0 ("liveupdate: centralize state management into struct luo_ser")Acked-by Pasha Tatashin <[email protected]>Signed-off-by Long Wei <[email protected]>
[...]
Signature · 2 lines
Regards, Pratyush Yadav
From: Mike Rapoport (Microsoft) <[email protected]>
Quoted 10 lines · Long Wei
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. beforekho_init()(fs_initcall) builds the debugfs view:
early_initcall:luo_early_startup()-> kho_retrieve_subtree("LUO") -> kho_restore_free(luo_ser) /* page is freed */[...]
Applied to liveupdate-7.5 branch of liveupdate/linux.git tree, thanks!
[1/1] kho: do not expose incoming sub-blob contents in debugfs
commit: bfc4b321d12e344627c1ee4977d6a0a084746d7e
tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: liveupdate-7.5
--
Sincerely yours,
Mike.