Article View: muc.lists.freebsd.bugs
Article #780[Bug 301180] kexec_load(2): replacing or unloading a staged image panics ("vm_object_unwire: length is not a multiple of PAGE_SI...
From: 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
Technical Details
Message-ID:
<bug-301180-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 301180] kexec_load(2): replacing or unloading a staged image
panics ("vm_object_unwire: length is not a multiple of PAGE_SIZE")
Date: Fri, 27 Nov 2026 08:50:26 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301180-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
logging-data="78399"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
t=1795769425;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding;
bh=/DEU3gSXQBiNpPhQZ64VCh3IvAbZ9ILskrjlJ1Ibu5o=;
b=ELr+zN0xXlg/aJ7Sb5aT5iFEPBI9ORU0ICVqnLhpZhubLPwe3rvtdCLYX6UrodDJ145Ox/
vD+Hsryh2WP7vxJmHylPfmbd5gl0FbzTVdthGoG2eFUhDPRYpGUD9bMg1/C9MReaGJGZRU
Pn95OvA3HZQKpcSNQZStSCbDRCf+kI6197WZ8ViSoTi2gKoxkTajRxEACMKDzSUZycHzgy
bdaHJ3hz5AnHs7iTNeSXJjNe4tVM3+V8FrPikLKKojDiVCQe0TpsrzODbviPASEIEu2VsC
snGCicTCG6VfzpJrUL4CcfpHiAP/q32Y3XM+qpl2QUL6eL7h8XCffD5/27OgnQ==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes