From de631ae9d76afeb0bb71668148c59677990f27be Mon Sep 17 00:00:00 2001 From: McTr0 <1334853459@qq.com> Date: Sun, 22 Nov 2026 07:49:00 -0500 Subject: [PATCH] Keep the daemon's resource-cache shadow inside its own mount namespace The daemon shadows /data/resource-cache so its root app_process does not write the boot's framework idmaps into the cache every other process shares. The shadow is only safe while service.sh actually puts it in a private mount namespace: when that isolation is not available (toybox unshare lacking the flags, busybox and toybox disagreeing, or the SELinux domain refusing unshare outright), the bind mount used to land in the global namespace and hide the idmaps behind the framework-res overlay redirects from every process launched afterwards. A system_server booting behind a leaked shadow then reads the un-overlaid config_servicesExtensionPackage value. On GMS builds that names android.ext.services, which does not exist on the system image, and PMS init throws from getRequiredServicesExtensionPackageLPr every cycle - the system_server boot loop of #1101. service.sh now degrades gracefully instead: when a private namespace cannot be established the daemon starts unshadowed (an idmap2 write at most) rather than leaking a shadow or not starting at all, and the daemon script mounts its shadow only when service.sh confirms the namespace is private (VECTOR_SHADOW_OK). Fixes the boot-loop half of #1101. --- zygisk/module/daemon | 18 +++++++++++++----- zygisk/module/service.sh | 36 +++++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/zygisk/module/daemon b/zygisk/module/daemon index 79a70d799..a4b519177 100644 --- a/zygisk/module/daemon +++ b/zygisk/module/daemon @@ -30,11 +30,19 @@ fi # framework idmaps of this boot into the cache every other process shares. Bind an empty directory # rather than a tmpfs: a bind mount reuses the superblock of /data, so it claims none of the # kernel-global anonymous device minors, whose gaps are visible from any process on the device. -# Note that this script runs inside an isolated mount namespace (via unshare). -emptyDir="$dir/.resource-cache" -rm -rf "$emptyDir" -mkdir -p "$emptyDir" -mount -o bind "$emptyDir" /data/resource-cache +# +# Only while service.sh has put us in a private mount namespace (VECTOR_SHADOW_OK). In the global +# namespace this mount would hide the cache — and with it the idmaps behind the framework-res +# overlay redirects — from every process launched afterwards, and a system_server booting behind +# it dies in PMS init on GMS builds: config_servicesExtensionPackage resolves to a package name +# nothing on the system image answers to. Without a private namespace the daemon therefore runs +# unshadowed; that costs an idmap2 write at most, while a leaked shadow costs a boot. +if [ "$VECTOR_SHADOW_OK" = "1" ]; then + emptyDir="$dir/.resource-cache" + rm -rf "$emptyDir" + mkdir -p "$emptyDir" + mount -o bind "$emptyDir" /data/resource-cache +fi # Wait for Zygote socket using a polling loop if [ ! -S "/dev/socket/zygote" ]; then diff --git a/zygisk/module/service.sh b/zygisk/module/service.sh index cc00edf41..e1b13b03e 100644 --- a/zygisk/module/service.sh +++ b/zygisk/module/service.sh @@ -1,13 +1,31 @@ -# Extract the directory path and change directory +# Extract the directory path and change directory MODDIR="${0%/*}" cd "$MODDIR" || exit 1 +# The daemon shadows /data/resource-cache while it runs, so its own app_process does not write the +# boot's framework idmaps into the cache every other process shares. That shadow is only safe +# inside a mount namespace nothing else can see: in the global one it blanks the RRO idmap cache +# for every process launched afterwards, including a freshly booting system_server — whose +# framework-res overlay redirects then stop resolving, and PMS refuses to start when +# config_servicesExtensionPackage does not name a package on the system image. That is a full +# system_server boot loop on GMS builds. +# # A root manager runs this script with its own busybox, but a manual bootstrap has nothing in -# front of it except Android's utilities, so this is written for toybox's unshare: it makes a -# mount namespace with -m and takes no propagation flag. The namespace therefore marks its own -# root slave before handing over, which is what keeps the daemon's dex2oat bind-mounts out of -# the global one. -unshare -m /system/bin/sh -c ' - mount -o rslave none / || echo "vector: this mount namespace stays shared" >&2 - exec "$0" "$@" -' "$MODDIR/daemon" "$@" & +# front of it except Android's utilities, and the two disagree: toybox unshare takes no +# propagation flag, busybox unshare does; and whether unshare is permitted at all depends on the +# SELinux domain the script runs in. So every branch here degrades to starting the daemon +# unshadowed rather than to not starting it, and the daemon script mounts its shadow only when +# this script confirms the namespace around it is private (VECTOR_SHADOW_OK). +if unshare -m true 2>/dev/null; then + unshare -m /system/bin/sh -c ' + if mount -o rslave none /; then + VECTOR_SHADOW_OK=1 exec "$0" "$@" + else + echo "vector: mount namespace stays shared; daemon starts without the resource-cache shadow" >&2 + VECTOR_NO_SHADOW=1 exec "$0" "$@" + fi + ' "$MODDIR/daemon" "$@" & +else + echo "vector: no private mount namespace available; daemon starts without the resource-cache shadow" >&2 + VECTOR_NO_SHADOW=1 "$MODDIR/daemon" "$@" & +fi