Skip to contentSkip to conversation

kho: expose incoming sub-blob metadata instead of contents

PATCH In review Long Wei 4 participants 15 messages Nov 17 – Nov 19

Subsystems (5)
lore
Share & tools
lore

Long Wei

author
#0 lore raw

cover kho: expose incoming sub-blob metadata instead of contents

Incoming sub-blob pages under kho/in/sub_fdts are owned by their consumers and have independent lifetimes. Consumers restore and free them at their own initcall level, which is always earlier than kho_init() (fs_initcall) where the debugfs view is built. LUO, for example, frees its state in early_initcall, so in/sub_fdts/LUO ends up pointing at a page that has already been returned to the page allocator. Reading the file then triggers a KASAN use-after-free in _copy_to_user(), with the backing page already marked page_type: f0(buddy).

KHO does not own these pages, so it cannot safely expose their contents at any point. Instead of trying to track which blobs are still alive, replace the raw blob nodes with a read-only in/blobs file that reports the name, physical address and size of every sub-blob referenced by the incoming FDT. The FDT itself is reserved by KHO and remains available as in/fdt.

The first patch does the change, the second updates the documentation.

Long Wei (2):
kho: expose incoming sub-blob metadata instead of contents
docs: kho: describe the in/blobs debugfs file

 Documentation/admin-guide/mm/kho.rst       |  6 +--
 kernel/liveupdate/kexec_handover_debugfs.c | 83 +++++++++++++++---------------
 2 files changed, 45 insertions(+), 44 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 kho: expose incoming sub-blob metadata instead of contents

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 raw blob nodes and replace them with a read-only in/blobs metadata file that lists the name, physical address and size of every incoming sub-blob. The FDT itself is reserved by KHO and is still exposed as in/fdt.

Fixes 062dd306d99c ("kho: fix kho_in_debugfs_init() to handle non-FDT blobs")
---
 kernel/liveupdate/kexec_handover_debugfs.c | 83 +++++++++++-----------
 1 file changed, 42 insertions(+), 41 deletions(-)
kernel/liveupdate/kexec_handover_debugfs.c +42 -41
index 7d74477da0b7..3624d4bf44b2 100644
@@ -95,67 +95,68 @@ static int bootmem_len_show(struct seq_file *m, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(bootmem_len);
 
-__init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)
+static int kho_in_blobs_show(struct seq_file *m, void *v)
 {
-	struct dentry *dir, *sub_fdt_dir;
-	int err, child;
-
-	INIT_LIST_HEAD(&dbg->fdt_list);
-
-	dir = debugfs_create_dir("in", debugfs_root);
-	if (IS_ERR(dir)) {
-		err = PTR_ERR(dir);
-		goto err_out;
-	}
+	const void *fdt = m->private;
+	int child, len;
 
-	sub_fdt_dir = debugfs_create_dir("sub_fdts", dir);
-	if (IS_ERR(sub_fdt_dir)) {
-		err = PTR_ERR(sub_fdt_dir);
-		goto err_rmdir;
+	if (fdt_check_header(fdt)) {
+		seq_puts(m, "invalid incoming FDT\n");
+		return 0;
 	}
 
-	err = __kho_debugfs_blob_add(&dbg->fdt_list, dir, "fdt", fdt,
-				     fdt_totalsize(fdt));
-	if (err)
-		goto err_rmdir;
-
+	seq_puts(m, "# name pa size\n");
 	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);
+		if (!blob_phys || len != sizeof(*blob_phys))
 			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);
+		if (!blob_size || len != sizeof(*blob_size))
 			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;
-		}
+		seq_printf(m, "%s 0x%016llx %llu\n", name,
+			   (u64)*blob_phys, (u64)*blob_size);
 	}
 
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(kho_in_blobs);
+
+/*
+ * Show the metadata of the sub-blobs referenced by the incoming FDT.  Each
+ * line contains the name, physical address and size of a sub-blob.  The raw
+ * contents of the sub-blobs are not exposed.
+ */
+__init void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt)
+{
+	struct dentry *dir;
+	int err;
+
+	INIT_LIST_HEAD(&dbg->fdt_list);
+
+	dir = debugfs_create_dir("in", debugfs_root);
+	if (IS_ERR(dir)) {
+		err = PTR_ERR(dir);
+		goto err_out;
+	}
+
+	err = __kho_debugfs_blob_add(&dbg->fdt_list, dir, "fdt", fdt,
+				     fdt_totalsize(fdt));
+	if (err)
+		goto err_rmdir;
+
+	debugfs_create_file("blobs", 0400, dir, (void *)fdt,
+			    &kho_in_blobs_fops);
+
 	dbg->dir = dir;
-	dbg->sub_fdt_dir = sub_fdt_dir;
+	dbg->sub_fdt_dir = NULL;
 
 	return;
 err_rmdir:
Signature · 1 line
2.43.0
#2 lore raw
Sashiko 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. 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", ...)
Quoted 7 lines

debugfs therefore ends up pointing at a page that was already handed back [ ... ]
size of every incoming sub-blob. The FDT itself is reserved by KHO and is still exposed as in/fdt.

Fixes 062dd306d99c ("kho: fix kho_in_debugfs_init() to handle non-FDT blobs")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw
In reply to Long Wei
Quoted 46 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. 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.

Quoted 5 lines

KHO does not own these pages, so it cannot safely expose their contents at all. Drop the in/sub_fdts raw blob nodes and replace them with a read-only in/blobs metadata file that lists the name, physical address and size of every incoming sub-blob. The FDT itself is reserved by KHO and is still exposed as in/fdt.

I suggest we simply remove in/sub_fdts without adding in/blobs. All of the metadata you are proposing to expose via in/blobs is already present in in/fdt (and can be parsed from userspace if needed), so I do not think it warrants adding another kernel debugfs interface. Keeping this to just removing in/sub_fdts (and updating the doc) also keeps the fix minimal for -rc.

Quoted 2 lines
Fixes 062dd306d99c ("kho: fix kho_in_debugfs_init() to handle non-FDT blobs")

This UAF has been there since in/sub_fdts was first added, so I think this should be: Fixes: c609c144b0e8 ("kexec: add KHO parsing support")

Signature · 1 line
Pasha
author
#4 lore raw

PATCH 2/2 docs: kho: describe the in/blobs debugfs file

In reply to Long Wei

The incoming sub-blob raw nodes under kho/in/sub_fdts no longer exist:
the sub-blob pages are owned by their consumers and may already be freed by the time the debugfs view is created, so exposing them was unsafe. Document the in/blobs metadata file that replaces them.

---
 Documentation/admin-guide/mm/kho.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/admin-guide/mm/kho.rst +3 -3
index 902d171a780a..602c8ce90e9a 100644
@@ -118,6 +118,6 @@ stabilized.
     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.
+``/sys/kernel/debug/kho/in/blobs``
+    Metadata for the sub-blobs referenced by the incoming FDT. Each line
+    contains the name, physical address and size of a sub-blob.

--
2.43.0

#5 lore raw

Re: [PATCH 2/2] docs: kho: describe the in/blobs debugfs file

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

The incoming sub-blob raw nodes under kho/in/sub_fdts no longer exist:
the sub-blob pages are owned by their consumers and may already be freed by the time the debugfs view is created, so exposing them was unsafe. Document the in/blobs metadata file that replaces them.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#6 lore raw

v2 cover kho: drop the incoming sub-blob debugfs view

In reply to Long Wei

kho/in/sub_fdts exposes the raw contents of the sub-blobs described by the incoming KHO FDT. KHO does not own those pages: they belong to the producers' consumers and have independent lifetimes. LUO, for example, restores and frees its state in early_initcall, before kho_init() (fs_initcall) creates the debugfs view, so the blobs point at pages that are already back in the buddy allocator. Reading them triggers a KASAN use-after-free in _copy_to_user().

The same information is already available to user space from in/fdt, which KHO does own and which stays reserved. Drop the directory rather than adding another interface to describe it, keeping the -rc fix small.

Patch 1 removes the interface, patch 2 drops its documentation.

Changes in v2:
- Drop the in/blobs metadata file entirely
- Just remove in/sub_fdts to fix the UAF, no replacement interface
- Update Fixes tag to c609c144b0e8 (the commit that first added sub_fdts)
- Remove the now-unused #include <linux/io.h>

Long Wei (2):
kho: do not expose incoming sub-blob contents in debugfs
docs: kho: drop kho/in/sub_fdts description

 Documentation/admin-guide/mm/kho.rst       |  4 --
 kernel/liveupdate/kexec_handover_debugfs.c | 47 +---------------------
 2 files changed, 2 insertions(+), 49 deletions(-)
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v2 1/2 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.

Fixes c609c144b0e8 ("kexec: add KHO parsing support")
---
 kernel/liveupdate/kexec_handover_debugfs.c | 47 +---------------------
 1 file changed, 2 insertions(+), 45 deletions(-)
kernel/liveupdate/kexec_handover_debugfs.c +2 -45
index 7d74477da0b7..3a91c47ad7a6 100644
@@ -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:
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v2 1/2] kho: do not expose incoming sub-blob contents in debugfs

Sashiko 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. 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", ...)
Quoted 7 lines

debugfs therefore ends up pointing at a page that was already handed back [ ... ]
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")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#9 lore raw

Re: [PATCH v2 1/2] kho: do not expose incoming sub-blob contents in debugfs

In reply to Long Wei

Hi,

Quoted 46 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. 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.

Quoted 6 lines

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")

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.

Signature · 2 lines
Sincerely yours,
Mike.
author
#10 lore raw

PATCH v2 2/2 docs: kho: drop kho/in/sub_fdts description

In reply to Long Wei

The incoming sub-blob debugfs directory is gone, so remove its description from the KHO admin guide.

---
 Documentation/admin-guide/mm/kho.rst | 4 ----
 1 file changed, 4 deletions(-)
Documentation/admin-guide/mm/kho.rst +0 -4
index 902d171a780a..4281da6be5fa 100644
@@ -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.
Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH v2 2/2] docs: kho: drop kho/in/sub_fdts description

Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

The incoming sub-blob debugfs directory is gone, so remove its description from the KHO admin guide.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer Acked-by on the v2 series
#12 lore raw

Re: [PATCH v2 0/2] kho: drop the incoming sub-blob debugfs view

In reply to Long Wei
Quoted 11 lines · Long Wei

kho: drop the incoming sub-blob debugfs view

kho/in/sub_fdts exposes the raw contents of the sub-blobs described by the incoming KHO FDT. KHO does not own those pages: they belong to the producers' consumers and have independent lifetimes. LUO, for example, restores and frees its state in early_initcall, before kho_init() (fs_initcall) creates the debugfs view, so the blobs point at pages that are already back in the buddy allocator. Reading them triggers a KASAN use-after-free in _copy_to_user().

[...]

Signature · 1 line
Pasha
maintainer
#13 lore raw

Re: [PATCH v2 0/2] kho: drop the incoming sub-blob debugfs view

In reply to Long Wei

Hi,

Please don't send vN+1 as a reply to vN.

Quoted 8 lines

kho/in/sub_fdts exposes the raw contents of the sub-blobs described by the incoming KHO FDT. KHO does not own those pages: they belong to the producers' consumers and have independent lifetimes. LUO, for example, restores and frees its state in early_initcall, before kho_init() (fs_initcall) creates the debugfs view, so the blobs point at pages that are already back in the buddy allocator. Reading them triggers a KASAN use-after-free in _copy_to_user().

Quoted 5 lines

The same information is already available to user space from in/fdt, which KHO does own and which stays reserved. Drop the directory rather than adding another interface to describe it, keeping the -rc fix small.

Patch 1 removes the interface, patch 2 drops its documentation.

Patch 2 is only four lines of documentation for the interface patch 1 removes. It could be folded into patch 1 so that a stable backport removes the documentation together with the code.

Signature · 2 lines
Sincerely yours,
Mike.
#14 lore raw

Re: [PATCH v2 0/2] kho: drop the incoming sub-blob debugfs view

Hi Mike,

Thanks for the detailed explanation! I now understand why c609c144b0e8 is not the right Fixes target — the pages weren't freed back then, so there was no UAF. The kho_restore_free() path in d376e4b55c9a0 is what actually made it reachable.

I will send v3 with the following changes:

- Fold patch 2 (documentation removal) into patch 1, so stable backports pick up both code and docs together
- Update Fixes tag to d376e4b55c9a0 ("liveupdate: centralize state management into struct luo_ser")

Best,
Long Wei

Quoted 22 lines · Mike Rapoport

Hi,

Please don't send vN+1 as a reply to vN.

Quoted 8 lines

kho/in/sub_fdts exposes the raw contents of the sub-blobs described by the incoming KHO FDT. KHO does not own those pages: they belong to the producers' consumers and have independent lifetimes. LUO, for example, restores and frees its state in early_initcall, before kho_init() (fs_initcall) creates the debugfs view, so the blobs point at pages that are already back in the buddy allocator. Reading them triggers a KASAN use-after-free in _copy_to_user().

Quoted 5 lines

The same information is already available to user space from in/fdt, which KHO does own and which stays reserved. Drop the directory rather than adding another interface to describe it, keeping the -rc fix small.

Patch 1 removes the interface, patch 2 drops its documentation.

Patch 2 is only four lines of documentation for the interface patch 1 removes. It could be folded into patch 1 so that a stable backport removes the documentation together with the code.