Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions zygisk/module/daemon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 27 additions & 9 deletions zygisk/module/service.sh
Original file line number Diff line number Diff line change
@@ -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