Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

cfw: Fit iOS 27 dyld cache in the 26.x kernel shared region (maxSlide=0)

zqxwcea38fd3201fbd
diff --git a/research/0_binary_patch_comparison.md b/research/0_binary_patch_comparison.md
index 667ae852..d0de5261 100644
--- a/research/0_binary_patch_comparison.md
+++ b/research/0_binary_patch_comparison.md
@@ -175,6 +175,7 @@ do NOT execute these).
| 7 | cstring byte 5 mangle `'h' → 'X'` (`"kern.hv_vmm_present"` → `"kern.Xv_vmm_present"`) + per-page slot-hash re-attestation, BLACKLIST semantics — **EXP only** | DSC dylibs | Companion to EXP kernel rename (`KernelEXPPatcher.patchHvVmmRename`). The mangle is applied to every DSC dylib EXCEPT those in `DONT_PATCH_INSTALL_NAMES` (sign-in / device-likeness consumers, ~15 entries). Patched dylibs query `kern.Xv_vmm_present` and get the truthful 1 (graphics / accel passthrough). Blacklisted dylibs keep the original cstring, hit ENOENT on the renamed kernel, cache 0, lie about VM presence. On `codeSigningMonitor == 2` hardware the byte-mangle alone causes `CODESIGNING/Invalid Page` SIGKILL because TXM enforces per-page hashes; the re-attestation pass recomputes the SHA-256 slot in the chunk's `CS_CodeDirectory` for every modified 16 KiB page. See `scripts/patchers/cfw_dsc_codesign.py` and `cfw_patch_hv_vmm_dsc.py`. | - | - | - |
| 8 | (removed — was: standalone-binary mangle in 6 rootfs Mach-Os via SSH) | n/a | Removed in the blacklist-flip redesign. With the EXP kernel rename in place, the 6 rootfs binaries (MobileActivationMigrator, CheckerBoard, StoreKitUISceneService, storekitd, appstored, CorePrescriptionService) get the desired "cache 0 / not in a VM" behavior for free: they keep their original cstring, hit ENOENT on the renamed kernel sysctl, defensive `cbnz w0, skip` leaves the cached byte at BSS-zero. No SSH-time standalone patch needed. | - | - | - |
| 9 | `mov w3,#<size>` -> `mov w3,#0x560` in `_kern_SwapEnd` — **26.0/26.0.1 and 18.x** | DSC `IOMobileFramebuffer` | Fixes host VZ GUI black-screen with the available PCC vphone600 userclient: userland sends a smaller external-method-5 SwapEnd state than the 26.1-era 0x560 the userclient expects, so SwapEnd returns `kIOReturnBadArgument` and the host display stays black (guest still renders — the Apple logo is visible over VNC, just not in the vphone-cli view). Source sizes observed: 26.0/26.0.1 = 0x548, 18.6.2 = 0x514. The patcher is semantic (anchors on `mov w1,#5` -> `mov w3,#imm` -> `mov x4,#0`/`mov x5,#0` -> `bl` inside `_kern_SwapEnd`) and idempotent — rewrites the size to 0x560 regardless of source and re-attests the modified DSC page. Install gate fires when `ProductVersion` starts with `26.0` or `18.`. Validated after host install on `17,3_26.0_23A341`, `17,3_26.0.1_23A355`, and `17,3_18.6.2_22G100` (Apple logo now renders in the vphone-cli view); 26.1 remains unmodified. | Y | Y | Y |
+| 10 | Zero `maxSlide` in `dyld_cache_header` (`@0xF0`) — **iOS 27.0 / any userland whose cache overflows the 6 GiB region** | DSC `dyld_shared_cache_arm64e` header | Fixes pid-1 `launchd` panic at boot on the vphone600 26.x kernel. The kernel reserves `SHARED_REGION_SIZE_ARM64 = 0x180000000` (6 GiB) and, at map time, needs room for the cache's mapped span **plus** the header `maxSlide` (ASLR range). iOS 27.0's cache (span `0x17c830000` ≈ 5.95 GiB) + `maxSlide 0x20000000` = `0x19c830000` > 6 GiB, so `_shared_region_map_and_slide` returns `ENOMEM`, dyld cannot map `libSystem.B.dylib`, and `launchd` panics (`initproc failed to start`). Zeroing `maxSlide` (LE u64) in the main chunk maps the cache at slide 0 (fits with ~58 MiB spare). Self-gating (`patch-dsc-maxslide`): no-op unless span + maxSlide > `0x180000000`, so 26.x / 18.x are untouched. **No** page re-attestation (header metadata, not a `cs_validate`'d code page — confirmed empirically). Validated on `17,3_27.0_24A5380h` + cloudOS 26.4 (`c0ecdb4b…`): `dyld cache mapped system-wide`, launchd reaches first unlock, vphoned connects as iOS 27.0.0, 0 panics. See `scripts/patchers/cfw_patch_dsc_maxslide.py`. | Y | Y | Y |
### Installed Components
@@ -656,6 +657,7 @@ cache rebuild.
| BaseBin hook deployment (`*.dylib` -> `/mnt1/cores`) | - | - | Y (JB-3) | Y (JB-3) |
| First-boot JB finalization (`vphone_jb_setup.sh`) | - | - | Y (post-boot) | Y (post-boot) |
| IOMobileFramebuffer SwapEnd payload-size patch (`26.0 and 26.0.1` only) | Y | Y | Y (inherited from base run) | Y (inherited from base run) |
+| dyld cache `maxSlide` zero (`patch-dsc-maxslide`; only when cache overflows the 6 GiB region, e.g. iOS 27.0) | Y | Y | Y (inherited from base run) | Y (inherited from base run) |
| DSC pre-patch (`kern.hv_vmm_present` byte-5 mangle + slot reattest) | - | - | - | Y (pre-step, before base CFW) |
| DSC camera patches (12 patches across CMCapture / CoreMediaIO / AVFCapture / libMobileGestalt) | - | - | - | Y (pre-step, same cryptex mount as hv_vmm) |
| `watchdogd` surgical 2-insn patch + slot reattest | - | - | - | Y (EXP-JB-3.5) |
diff --git a/scripts/cfw_install.sh b/scripts/cfw_install.sh
index 8f2384c7..343dffe6 100755
--- a/scripts/cfw_install.sh
+++ b/scripts/cfw_install.sh
@@ -298,6 +298,19 @@ if [[ "$IOS_VERSION" == 26.0* || "$IOS_VERSION" == 18.* ]]; then
"$PYTHON3" "$SCRIPT_DIR/patchers/cfw.py" patch-iomfb-swapend "$DSC_DIR"
fi
+# Newer userlands ship a dyld shared cache that nearly fills the vphone600 26.x
+# kernel's fixed 6 GiB shared region. The kernel reserves the cache's mapped span
+# PLUS the cache-header maxSlide (512 MiB); when that overflows 0x180000000 (iOS
+# 27.0: ~5.95 GiB span + 512 MiB), _shared_region_map_and_slide returns ENOMEM,
+# dyld cannot map libSystem, and launchd (pid 1) panics at boot. Zero maxSlide so
+# the cache maps at slide 0 within the region. Self-gating: no-op for older
+# userlands (26.x/18.x) that already fit with full slide.
+DSC_DIR="$MNT1/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld"
+if [[ -d "$DSC_DIR" ]]; then
+ echo " [*] Checking dyld cache maxSlide vs kernel shared region..."
+ "$PYTHON3" "$SCRIPT_DIR/patchers/cfw.py" patch-dsc-maxslide "$DSC_DIR"
+fi
+
# ═══════════ 2/7 PATCH SEPUTIL ════════════════════════════════
echo ""
echo "[2/7] Patching seputil..."
diff --git a/scripts/patchers/cfw.py b/scripts/patchers/cfw.py
index 174c79e1..5b413a95 100755
--- a/scripts/patchers/cfw.py
+++ b/scripts/patchers/cfw.py
@@ -34,6 +34,13 @@ Commands:
payload size from 0x548 to 0x560 for the PCC vphone600 userclient,
then re-attest the modified DSC page hash.
+ patch-dsc-maxslide <chunks_dir> [--dry-run]
+ Zero the dyld_cache_header maxSlide when the userland cache would overflow
+ the vphone600 26.x kernel's 6 GiB shared region (cache span + maxSlide >
+ 0x180000000, e.g. iOS 27.0). Lets the cache map at slide 0 so launchd's dyld
+ can map libSystem. Self-gating (no-op if it already fits); no re-attest needed
+ (header field, not a cs_validate'd code page).
+
patch-camera-dsc <chunks_dir> <dsc_header> [--dry-run] [--force]
Apply the 10-patch set to the DSC chunks that makes Camera.app
launch-survivable on a vphone VM: synthesises a single
@@ -83,6 +90,7 @@ if __name__ == "__main__":
from patchers.cfw_patch_jetsam import patch_launchd_jetsam
from patchers.cfw_patch_hv_vmm_dsc import patch_hv_vmm_in_dsc
from patchers.cfw_patch_iomfb_swapend import patch_iomfb_swapend
+ from patchers.cfw_patch_dsc_maxslide import patch_dsc_maxslide
from patchers.cfw_patch_camera_dsc import apply_all_camera_patches
from patchers.cfw_patch_watchdogd import patch_watchdogd
from patchers.cfw_daemons import parse_cryptex_paths, inject_daemons, patch_dropbear_plist
@@ -93,6 +101,7 @@ else:
from .cfw_patch_jetsam import patch_launchd_jetsam
from .cfw_patch_hv_vmm_dsc import patch_hv_vmm_in_dsc
from .cfw_patch_iomfb_swapend import patch_iomfb_swapend
+ from .cfw_patch_dsc_maxslide import patch_dsc_maxslide
from .cfw_patch_camera_dsc import apply_all_camera_patches
from .cfw_patch_watchdogd import patch_watchdogd
from .cfw_daemons import parse_cryptex_paths, inject_daemons, patch_dropbear_plist
@@ -161,6 +170,14 @@ def main():
sys.exit(1)
sys.exit(0)
+ elif cmd == "patch-dsc-maxslide":
+ if len(sys.argv) < 3:
+ print("Usage: patch_cfw.py patch-dsc-maxslide <chunks_dir> [--dry-run]")
+ sys.exit(1)
+ dry_run = "--dry-run" in sys.argv[3:]
+ patch_dsc_maxslide(sys.argv[2], dry_run=dry_run)
+ sys.exit(0)
+
elif cmd == "patch-camera-dsc":
if len(sys.argv) < 4:
print("Usage: patch_cfw.py patch-camera-dsc <chunks_dir> <dsc_header> [--dry-run] [--force]")
@@ -222,7 +239,7 @@ def main():
print(f"Unknown command: {cmd}")
print("Commands: cryptex-paths, patch-seputil, patch-launchd-cache-loader, patch-camera-dsc,")
print(" patch-mobileactivationd, patch-launchd-jetsam,")
- print(" patch-hv-vmm-dsc, patch-iomfb-swapend, patch-watchdogd,")
+ print(" patch-hv-vmm-dsc, patch-iomfb-swapend, patch-dsc-maxslide, patch-watchdogd,")
print(" inject-daemons, patch-dropbear-plist, inject-dylib")
sys.exit(1)
diff --git a/scripts/patchers/cfw_patch_dsc_maxslide.py b/scripts/patchers/cfw_patch_dsc_maxslide.py
new file mode 100644
index 00000000..d55bf3ef
--- /dev/null
+++ b/scripts/patchers/cfw_patch_dsc_maxslide.py
@@ -0,0 +1,114 @@
+"""Clamp the dyld shared cache maxSlide so a large userland cache fits the
+PCC vphone600 26.x kernel's fixed 6 GiB shared region.
+
+The vphone600 26.x kernel reserves SHARED_REGION_SIZE_ARM64 = 0x180000000 (6 GiB)
+at SHARED_REGION_BASE_ARM64 = 0x180000000 (verified by disassembling the arm64 case
+of the kernel's shared_region_create). At map time the kernel needs room for the
+cache's mapped span PLUS the cache-header maxSlide (the ASLR range). A newer userland
+whose cache nearly fills the region overflows it:
+
+ iOS 27.0 (24A5380h): span 0x17c830000 (~5.95 GiB) + maxSlide 0x20000000 (512 MiB)
+ = 0x19c830000 (~6.46 GiB) > 0x180000000 (6 GiB)
+
+-> _shared_region_map_and_slide returns ENOMEM -> dyld cannot map libSystem ->
+launchd (pid 1) panics ("initproc failed to start -- Library not loaded:
+/usr/lib/libSystem.B.dylib"). Older userlands (e.g. 26.x/18.x) fit with full slide
+and are unaffected.
+
+Fix: zero maxSlide in the cache header so the cache maps at slide 0 and fits (iOS 27.0
+leaves ~58 MiB spare). Only the main chunk `dyld_shared_cache_arm64e` carries the
+dyld_cache_header. maxSlide is a plain metadata field the kernel reads during map
+setup, NOT a cs_validate'd dylib code page — so, unlike cfw_patch_iomfb_swapend, NO
+page re-attestation is required (confirmed empirically: a live-poked cache with
+maxSlide=0 booted with "dyld cache mapped system-wide", 0 panics).
+
+Self-gating: no-op unless span + maxSlide overflows the region.
+
+dyld_cache_header offsets (little-endian u64, stable across recent iOS):
+ sharedRegionStart @0xE0, sharedRegionSize @0xE8, maxSlide @0xF0
+"""
+
+import os
+import struct
+
+MAIN_CHUNK = "dyld_shared_cache_arm64e"
+
+OFF_SHARED_REGION_START = 0xE0
+OFF_SHARED_REGION_SIZE = 0xE8
+OFF_MAX_SLIDE = 0xF0
+
+# SHARED_REGION_SIZE_ARM64 baked into the PCC vphone600 26.x kernel. The cache's
+# span + maxSlide must fit within this or the shared_region map ENOMEMs.
+KERNEL_SHARED_REGION_SIZE = 0x180000000
+
+
+def patch_dsc_maxslide(chunks_dir, *, kernel_region_size=KERNEL_SHARED_REGION_SIZE, dry_run=False):
+ main = os.path.join(chunks_dir, MAIN_CHUNK)
+ if not os.path.isfile(main):
+ raise FileNotFoundError(f"main DSC chunk not found: {main}")
+
+ with open(main, "r+b") as f:
+ hdr = f.read(0x100)
+ if hdr[:7] != b"dyld_v1":
+ raise RuntimeError(f"{main}: not a dyld shared cache (magic={hdr[:16]!r})")
+ srstart = struct.unpack_from("<Q", hdr, OFF_SHARED_REGION_START)[0]
+ srsize = struct.unpack_from("<Q", hdr, OFF_SHARED_REGION_SIZE)[0]
+ maxslide = struct.unpack_from("<Q", hdr, OFF_MAX_SLIDE)[0]
+ print(f" [.] {MAIN_CHUNK}: start=0x{srstart:X} size=0x{srsize:X} maxSlide=0x{maxslide:X}")
+
+ if srsize + maxslide <= kernel_region_size:
+ print(f" [=] fits: span+maxSlide 0x{srsize + maxslide:X} <= "
+ f"region 0x{kernel_region_size:X}; no change")
+ return 0
+
+ # Overflow: set maxSlide to 0 so the cache maps at slide 0 within the region.
+ new_maxslide = 0
+ action = "would set" if dry_run else "set"
+ print(f" [+] overflow: span+maxSlide 0x{srsize + maxslide:X} > "
+ f"region 0x{kernel_region_size:X}; {action} maxSlide "
+ f"0x{maxslide:X} -> 0x{new_maxslide:X}")
+ if not dry_run:
+ f.seek(OFF_MAX_SLIDE)
+ f.write(struct.pack("<Q", new_maxslide))
+ f.flush()
+ os.fsync(f.fileno())
+ f.seek(OFF_MAX_SLIDE)
+ back = struct.unpack("<Q", f.read(8))[0]
+ if back != new_maxslide:
+ raise RuntimeError(f"maxSlide write verify failed: 0x{back:X}")
+
+ print(" [+] DSC maxSlide patch complete")
+ return 1
+
+
+def _self_test():
+ """Gate logic: a cache that overflows gets clamped; one that fits is untouched."""
+ import tempfile
+
+ def mkcache(size, maxslide, path):
+ hdr = bytearray(0x100)
+ hdr[0:16] = b"dyld_v1 arm64e\x00"
+ struct.pack_into("<Q", hdr, OFF_SHARED_REGION_START, 0x180000000)
+ struct.pack_into("<Q", hdr, OFF_SHARED_REGION_SIZE, size)
+ struct.pack_into("<Q", hdr, OFF_MAX_SLIDE, maxslide)
+ open(path, "wb").write(hdr)
+
+ with tempfile.TemporaryDirectory() as d:
+ c = os.path.join(d, MAIN_CHUNK)
+ # overflow (iOS 27.0-like): 0x17c830000 + 0x20000000 > 0x180000000 -> clamp
+ mkcache(0x17C830000, 0x20000000, c)
+ assert patch_dsc_maxslide(d) == 1
+ with open(c, "rb") as f:
+ f.seek(OFF_MAX_SLIDE)
+ assert struct.unpack("<Q", f.read(8))[0] == 0
+ # fits (26.4-like): 0x140904000 + 0x20000000 <= 0x180000000 -> untouched
+ mkcache(0x140904000, 0x20000000, c)
+ assert patch_dsc_maxslide(d) == 0
+ with open(c, "rb") as f:
+ f.seek(OFF_MAX_SLIDE)
+ assert struct.unpack("<Q", f.read(8))[0] == 0x20000000
+ print("self-test OK")
+
+
+if __name__ == "__main__":
+ _self_test()