Skip to content

Keep the daemon's resource-cache shadow inside its own mount namespace - #1103

Open
McTr0 wants to merge 1 commit into
JingMatrix:masterfrom
McTr0:fix/daemon-shadow-escape
Open

McTr0 wants to merge 1 commit into
JingMatrix:masterfrom
McTr0:fix/daemon-shadow-escape

Conversation

@McTr0

@McTr0 McTr0 commented Nov 22, 2026

Copy link
Copy Markdown

Standalone half of the investigation behind #1101 (see also the boot-loop escalation comment there and discussion #1042); the scope-spelling half is in #1103.

What breaks

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 (service.sh unshares first, deliberately). That is only safe while the isolation actually holds, and in the wild it does not reliably hold:

  • HyperOS 2.0 ships toybox 0.8.11 whose unshare takes no --propagation flag (the 3080-era service.sh used it), so the daemon script never ran under isolation there;
  • plain unshare -m is not guaranteed either — we measured intermittent EPERM from the same root SELinux domain seconds apart on the device, and the old code's || echo fell through to starting the daemon regardless, leaving the shadow in a shared namespace;
  • HEAD's form at least starts the daemon, but when the namespace cannot be created the bind mount still lands in the global namespace.

A shadow leaked into the global namespace hides the idmap files behind the framework-res overlay redirects from every process launched afterwards. A freshly booting system_server then reads the un-overlaid config_servicesExtensionPackage value: on the GMS build we reproduced on, the base value is android.ext.services (verified in framework-res), the only ExtServices on the image is com.google.android.ext.services (APEX, redirect carried by the enabled com.google.android.overlay.modules.ext.services.cn overlay), so PackageManagerService.getRequiredServicesExtensionPackageLPr throws on every cycle — the system_server boot loop reported in #1101. umount /data/resource-cache is what ended the loop on that device; the leaked tmpfs from the earlier build was still present in the global namespace then.

The change

service.sh degrades gracefully instead: when a private mount namespace cannot be established, the daemon starts unshadowed (an early idmap2 write at most) instead of leaking a shadow — or, in the pre-HEAD form, not starting at all. The daemon script mounts its shadow only when service.sh confirms the namespace around it is private (VECTOR_SHADOW_OK), so a leaked shadow cannot happen by construction.

Verification (HyperOS 2.0 / Android 15, beryl, KernelSU + Zygisk Next)

Built from this branch (debug) and deployed over the previously disabled module:

  • ksud services: vectord starts, the shadow lands in the daemon's own mount namespace, and init's namespace stays clean (grep resource-cache /proc/1/mountinfo = 0) across the whole boot and a following ksud soft-reboot.
  • Boot completes with no PMS exception and no crash loop, where the pre-fix build boot-looped.
  • The device's data and settings were untouched throughout.

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 JingMatrix#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 JingMatrix#1101.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant