Skip to content

XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)

C

vm-install-fki-service: pass nokaslr so EFI stub keeps kernel outside carve-out

Heyang Zhoua432c00e44e1
diff --git a/docs/production.md b/docs/production.md
index c8f89f0..69b38cc 100644
--- a/docs/production.md
+++ b/docs/production.md
@@ -28,6 +28,7 @@ What the PoC did to get each step running, and what replaces it. Ordered by what
| `kc-amfi-platform.py` patches AMFI's expected platform version in the kernel collection | Build the collection from the same macOS build as the disk (one version source), no byte patching |
| `amfi_get_out_of_my_way=1`, `lp-sip0=0x802`, `kern.memorystatus_highwater_enabled=0` | Keep SIP/AMFI on; sign our plugin and kexts (ad-hoc trust cache of our own), only the unauthenticated-root bit stays |
| `/chosen` UUIDs passed by hand (`root_uuid=`, `preboot_uuid=`) | Read from the disk's APFS container at load (xnu.ko or a host tool), no manual parameters (step one done: `mk-macvm-disk.sh` writes them to `mac.conf`, `xnulinux-boot.sh` reads it) |
+| Fixed `carve_base=0x400000000` with `nokaslr` so Linux's arm64 EFI stub does not place the kernel image inside the carve-out before `mem=15G` takes effect | Have `fki` choose the carve-out dynamically at load from the actual memory map (avoiding the kernel image and reserved regions), then re-enable KASLR |
## 4. Scripts and tests
diff --git a/scripts/vm-install-fki-service.sh b/scripts/vm-install-fki-service.sh
index 29506ed..80e9334 100755
--- a/scripts/vm-install-fki-service.sh
+++ b/scripts/vm-install-fki-service.sh
@@ -8,7 +8,9 @@ set -euo pipefail
P=$(cd "$(dirname "$0")/.." && pwd)
CARVE_BASE=${CARVE_BASE:-0x400000000}; CARVE_MB=${CARVE_MB:-8156}
G=/etc/default/grub.d/99-xnulinux.cfg
-echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX mem=15G log_buf_len=128M"' | sudo tee $G >/dev/null
+# nokaslr: arm64's EFI stub randomises the Linux kernel's physical load address across all EFI memory before mem=15G
+# takes effect, which otherwise places the kernel image inside the 0x400000000 carve-out on ~1/3 of boots.
+echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX mem=15G nokaslr log_buf_len=128M"' | sudo tee $G >/dev/null
sudo update-grub >/dev/null 2>&1
sudo tee /etc/systemd/system/xnulinux-fki.service >/dev/null <<UNIT
[Unit]