Thread View: muc.lists.freebsd.bugs
2 messages
2 total messages
Started by bugzilla-noreply
Fri, 27 Nov 2026 08:50
[Bug 301180] kexec_load(2): replacing or unloading a staged image panics ("vm_object_unwire: length is not a multiple of PAGE_SI...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 08:50
Date: Fri, 27 Nov 2026 08:50
143 lines
6838 bytes
6838 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301180
Bug ID: 301180
Summary: kexec_load(2): replacing or unloading a staged image
panics ("vm_object_unwire: length is not a multiple of
PAGE_SIZE")
Product: Base System
Version: 16.0-CURRENT
Hardware: arm64
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: dmilith@me.com
Affects: sys/kern/kern_kexec.c, kern_kexec_load() (machine-independent;
unchanged in main up to
f129398f6454, 2026-11-26)
Seen on: FreeBSD 16.0-CURRENT main-n291235-611046b15dbb (arm64 GENERIC,
snapshot 20261117).
amd64 should be affected the same way (not tested).
How to reproduce
----------------
Stage an image with kexec_load(2), then call kexec_load(2) again in the same
boot: with another
image, or with nseg = 0 to unload it. Either way:
panic: vm_object_unwire: length is not a multiple of PAGE_SIZE
cpuid = 1
KDB: stack backtrace:
db_trace_self() at db_trace_self
db_trace_self_wrapper() at db_trace_self_wrapper+0x44
vpanic() at vpanic+0x1c8
panic() at panic+0x48
vm_object_unwire() at vm_object_unwire+0x2c8
kern_kexec_load() at kern_kexec_load+0x6b8
do_el0_sync() at do_el0_sync+0x608
handle_el0_sync() at handle_el0_sync+0x6c
--- exception, esr 0x56000000
Cause
-----
if (kexec_obj != NULL) {
vm_object_unwire(kexec_obj, 0, kexec_obj->size, 0);
KASSERT(stage_addr != 0, ("Mapped kexec_obj without address"));
vm_map_remove(kernel_map, stage_addr, stage_addr + kexec_obj->size);
}
1. kexec_obj->size is in pages, but vm_object_unwire() takes a length in bytes
and asserts that
it is page-aligned. With INVARIANTS this panics. Without INVARIANTS, only
the first
size/PAGE_SIZE pages would be unwired, and the rest of the old image stays
wired.
2. stage_addr is never assigned. Under INVARIANTS the KASSERT is the next
panic. Without it,
vm_map_remove(kernel_map, 0, <page count>) does not remove the old mapping,
and the old image
(its kernel_map entry, object and pages) leaks. At this point staged_image
still describes
the old image (it is cleared just after), so map_addr and map_size are the
right values.
3. The error path at "out:" makes the same pages-vs-bytes mistake for
new_segments. It also uses
kexec_obj->size for the new mapping's end: that is the old object, which is
NULL when nothing
was staged before.
Fix
---
Patch attached (2-kern_kexec.c.diff). It is not compile-tested:
- the old image: ptoa(kexec_obj->size) for vm_object_unwire();
staged_image.map_addr and
map_size for vm_map_remove(); the unused stage_addr is removed;
- the error path: ptoa(new_segments->size) for both calls.
Patch:
--- a/sys/kern/kern_kexec.c
+++ b/sys/kern/kern_kexec.c
@@ -90,7 +90,6 @@
*/
static struct kexec_image staged_image;
-static vm_offset_t stage_addr;
static vm_object_t kexec_obj;
static eventhandler_tag kexec_reboot_handler;
@@ -300,9 +299,12 @@
goto out;
}
if (kexec_obj != NULL) {
- vm_object_unwire(kexec_obj, 0, kexec_obj->size, 0);
- KASSERT(stage_addr != 0, ("Mapped kexec_obj without address"));
- vm_map_remove(kernel_map, stage_addr, stage_addr +
kexec_obj->size);
+ /* The object's size is in pages; vm_object_unwire() takes
bytes. */
+ vm_object_unwire(kexec_obj, 0, ptoa(kexec_obj->size), 0);
+ KASSERT(staged_image.map_addr != 0,
+ ("Mapped kexec_obj without address"));
+ vm_map_remove(kernel_map, staged_image.map_addr,
+ staged_image.map_addr + staged_image.map_size);
}
kexec_obj = new_segments;
bzero(&staged_image, sizeof(staged_image));
@@ -322,9 +324,10 @@
out:
/* Clean up the mess if we've gotten far. */
if (err != 0 && new_segments != NULL) {
- vm_object_unwire(new_segments, 0, new_segments->size, 0);
+ vm_object_unwire(new_segments, 0, ptoa(new_segments->size), 0);
if (segment_va != 0)
- vm_map_remove(kernel_map, segment_va, segment_va +
kexec_obj->size);
+ vm_map_remove(kernel_map, segment_va,
+ segment_va + ptoa(new_segments->size));
else
vm_object_deallocate(new_segments);
}
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301180] kexec_load(2): replacing or unloading a staged image panics ("vm_object_unwire: length is not a multiple of PAGE_SI...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 09:02
Date: Fri, 27 Nov 2026 09:02
16 lines
2557 bytes
2557 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301180
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |crash
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads