Skip to content

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

C

Hosted macOS reaches the desktop: no first-login MiniBuddy for the made user; no bindfs grafts

Heyang Zhou9f045aa28e70
diff --git a/tools/hosted/gui-user.py b/tools/hosted/gui-user.py
index c07b7e2..6abdc4d 100644
--- a/tools/hosted/gui-user.py
+++ b/tools/hosted/gui-user.py
@@ -70,9 +70,28 @@ seen = {k: True for k in ['DidSeeCloudSetup', 'DidSeePrivacy', 'DidSeeSiriSetup'
'DidSeeAppearanceSetup', 'DidSeeAccessibility', 'DidSeeActivationLock', 'DidSeeTermsOfAddress', 'DidSeeIntelligence',
'DidSeeApplePaySetup', 'DidSeeAvatarSetup', 'DidSeeiCloudLoginForStorageServices', 'DidSeeSyncSetup',
'DidSeeSyncSetup2', 'DidSeeTrueTonePrivacy', 'DidSeeWalletSetup', 'SkipFirstLoginOptimization']}
-seen.update({'LastSeenCloudProductVersion': '99.0', 'LastSeenBuddyBuildVersion': '99Z999',
- 'LastPreLoginTasksPerformedVersion': '99.0', 'LastPreLoginTasksPerformedBuild': '99Z999'})
+# Setup Assistant compares these with the running system: a version or build it has not seen yet (or none) starts
+# MiniBuddy at login (the upgrade panes), and loginwindow holds the Dock and Finder until it ends. They are the system's own,
+# from the System volume's SystemVersion.plist next to the template.
+sv = plistlib.load(open(os.path.join(os.path.dirname(template.rstrip('/')), 'CoreServices', 'SystemVersion.plist'), 'rb'))
+ver, build = sv['ProductVersion'], sv['ProductBuildVersion']
+seen.update({k: ver for k in ['LastSeenCloudProductVersion', 'LastSeenDiagnosticsProductVersion', 'LastSeenSiriProductVersion',
+ 'LastSeenGlassTintUpsellProductVersion', 'LastSeenIntelligenceProductVersion', 'LastSeenSyncProductVersion',
+ 'LastSeeniCloudStorageServicesProductVersion', 'LastSeenAgeRangeSelectionProductVersion',
+ 'LastPreLoginTasksPerformedVersion', 'PreviousSystemVersion', 'InitialSetupProductVersion',
+ 'LastLaunchedMiniBuddyForStorageServicesVersion']})
+seen.update({k: build for k in ['LastSeenBuddyBuildVersion', 'LastPreLoginTasksPerformedBuild', 'PreviousBuildVersion',
+ 'InitialSetupBuildVersion']})
+seen.update({'MiniBuddyLaunchReason': 0, 'MiniBuddyShouldLaunchToResumeSetup': False, 'LastPrivacyBundleVersion': '2',
+ 'selectedFDEEscrowType': 'DeclinedFDE', 'InitialAccountOnMac': False})
dump(home + '/Library/Preferences/com.apple.SetupAssistant.plist', seen, 0o644)
+# The template's loginwindow preferences ask for MiniBuddy at the user's first login (MiniBuddyLaunch), as for an account
+# made by Setup Assistant; this user has been set up already.
+lwp = home + '/Library/Preferences/com.apple.loginwindow.plist'
+if os.path.exists(lwp):
+ ulw = plistlib.load(open(lwp, 'rb'))
+ ulw.pop('MiniBuddyLaunch', None)
+ dump(lwp, ulw, 0o644)
subprocess.run(['chown', '-R', '%d:20' % uid, home], check=True)
os.chmod(home, 0o755)
print('gui-user: %s (%d), admin, automatic login, home from the template' % (name, uid))
diff --git a/xnu-patches/0001-linux64-stage-hook.patch b/xnu-patches/0001-linux64-stage-hook.patch
index 6842ed7..c27805f 100644
--- a/xnu-patches/0001-linux64-stage-hook.patch
+++ b/xnu-patches/0001-linux64-stage-hook.patch
@@ -267,7 +267,7 @@ index ec19ee7..6baf626 100644
}
}
diff --git a/bsd/kern/bsd_init.c b/bsd/kern/bsd_init.c
-index 5362b32..88414be 100644
+index 5362b32..6345650 100644
--- a/bsd/kern/bsd_init.c
+++ b/bsd/kern/bsd_init.c
@@ -585,7 +585,7 @@ bsd_init(void)
@@ -309,7 +309,7 @@ index 5362b32..88414be 100644
if (require_rootauth) {
/* enforce sealedness */
int autherr = VNOP_IOCTL(rootvnode, FSIOC_KERNEL_ROOTAUTH, NULL, 0, vfs_context_kernel());
-@@ -1177,6 +1193,42 @@ bsd_init(void)
+@@ -1177,6 +1193,25 @@ bsd_init(void)
}
#endif /* DEVFS */
@@ -319,8 +319,8 @@ index 5362b32..88414be 100644
+ * LINUX64 (xnulinux): a hosted APFS root from a Mac's own disk. On a Mac, dyld in launchd grafts the boot
+ * cryptexes (the OS cryptex holds the dyld shared cache) from the ignition blob AppleImage4 builds out of iBoot's
+ * boot object manifests; a hosted boot has no iBoot. The OS and App cryptexes' contents sit in the Preboot
-+ * volume's Cryptexes/OS and Cryptexes/App (scripts/mk-macvm-disk.sh), where dyld also looks: mount the Preboot
-+ * volume of the root's container at its usual place before launchd runs, as the Recovery volume is mounted.
++ * volume's Cryptexes/OS and Cryptexes/App (scripts/mk-macvm-disk.sh), where dyld finds the shared cache: mount
++ * the Preboot volume of the root's container at its usual place before launchd runs, as Recovery is mounted.
+ */
+ extern uintptr_t linux64_hook;
+ if (linux64_hook && rootvnode && strcmp(rootvnode->v_mount->mnt_vfsstat.f_fstypename, "apfs") == 0) {
@@ -328,23 +328,6 @@ index 5362b32..88414be 100644
+ int perr = kernel_mount("apfs", NULLVP, NULLVP, prebootpath, rootvnode->v_mount, 0, 0,
+ KERNEL_MOUNT_PREBOOTVOL, vfs_context_kernel());
+ printf("LINUX64: Preboot volume at %s: %d\n", prebootpath, perr);
-+ /*
-+ * The cryptexes' graft points on the system volume, where dyld looks for their libraries (e.g.
-+ * /usr/lib/libLaunchServicesSupport.dylib lives only in the OS cryptex) and /Applications/Safari.app points:
-+ * bound to the cryptexes' trees in Preboot, read-only, as the grafts would show them.
-+ */
-+ static const char *const grafts[][2] = {
-+ { "/System/Cryptexes/OS", "/System/Volumes/Preboot/Cryptexes/OS" },
-+ { "/System/Cryptexes/App", "/System/Volumes/Preboot/Cryptexes/App" },
-+ };
-+ for (int g = 0; perr == 0 && g < 2; g++) {
-+ char at[64], from[64];
-+ strlcpy(at, grafts[g][0], sizeof(at));
-+ strlcpy(from, grafts[g][1], sizeof(from));
-+ int berr = kernel_mount("bindfs", NULLVP, NULLVP, at, (void *)from, 0, MNT_RDONLY | MNT_DONTBROWSE,
-+ 0, vfs_context_kernel());
-+ printf("LINUX64: %s bound to %s: %d\n", at, from, berr);
-+ }
+ }
+ }
+#endif
@@ -806,34 +789,6 @@ index c08a74c..1e26f75 100644
353 AUE_GETAUID ALL { int getauid(au_id_t *auid); }
354 AUE_SETAUID ALL { int setauid(au_id_t *auid); }
355 AUE_NULL ALL { int nosys(void); } { old getaudit }
-diff --git a/bsd/miscfs/bindfs/bind_vfsops.c b/bsd/miscfs/bindfs/bind_vfsops.c
-index 4d50604..dc49a67 100644
---- a/bsd/miscfs/bindfs/bind_vfsops.c
-+++ b/bsd/miscfs/bindfs/bind_vfsops.c
-@@ -137,14 +137,21 @@ bindfs_mount(struct mount * mp, __unused vnode_t devvp, user_addr_t user_data, v
- }
-
- /* check entitlement */
-- if (!IOCurrentTaskHasEntitlement(BINDFS_ENTITLEMENT)) {
-+ /* LINUX64 (xnulinux): the kernel's own bind mounts (bsd_init, a hosted APFS boot) pass the path from kernel memory */
-+ boolean_t kernel_mount_path = vfs_iskernelmount(mp);
-+ if (!kernel_mount_path && !IOCurrentTaskHasEntitlement(BINDFS_ENTITLEMENT)) {
- return EPERM;
- }
-
- /*
- * Get argument
- */
-- error = copyinstr(user_data, data, MAXPATHLEN - 1, &count);
-+ if (kernel_mount_path) {
-+ count = strlcpy(data, (const char *)user_data, MAXPATHLEN - 1) + 1;
-+ error = 0;
-+ } else {
-+ error = copyinstr(user_data, data, MAXPATHLEN - 1, &count);
-+ }
- if (error) {
- BINDFSERROR("error copying data from user %d\n", error);
- goto error;
diff --git a/bsd/net/if_linux64.c b/bsd/net/if_linux64.c
new file mode 100644
index 0000000..29cf3df