Skip to content

Fix the two defects behind #1101: the resource-cache shadow escape and the system-framework scope spelling - #1102

Closed
McTr0 wants to merge 2 commits into
JingMatrix:masterfrom
McTr0:fix/1101-system-server-scope-and-shadow
Closed

McTr0 wants to merge 2 commits into
JingMatrix:masterfrom
McTr0:fix/1101-system-server-scope-and-shadow

Conversation

@McTr0

@McTr0 McTr0 commented Nov 22, 2026

Copy link
Copy Markdown

Closes #1101.

Follow-up from #1101 and its boot-loop escalation comment. Reproducing on the same device narrowed the report's two symptoms to two concrete defects, both fixed here and verified on the device the report was filed from.

1. The system_server boot loop: the daemon's /data/resource-cache shadow escaping its namespace

The daemon script shadows /data/resource-cache so its own 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. On the device from #1101 it does not reliably hold:

  • HyperOS 2.0 ships toybox 0.8.11 whose unshare takes no --propagation flag (the 3080 build's service.sh used it), and whether unshare is permitted at all depends on the SELinux domain the script runs in - we measured intermittent EPERM for plain unshare -m from the same root domain seconds apart.
  • HEAD's service.sh already switched to unshare -m + mount -o rslave none /, but when the namespace cannot be created the old code either started nothing (unshare failing silently killed the daemon start) or left the shadow in a shared namespace (the || echo fell through to exec anyway).

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 this GMS build the base value is android.ext.services (verified in framework-res), the only ExtServices on the system image is com.google.android.ext.services (APEX GoogleExtServicesCn, redirect carried by the enabled com.google.android.overlay.modules.ext.services.cn overlay), so PackageManagerService.getRequiredServicesExtensionPackageLPr throws on every cycle - exactly the boot loop in the follow-up comment. Breaking the shadow (umount) was what ended the loop.

service.sh now degrades gracefully: when a private mount namespace cannot be established, the daemon starts unshadowed (an early idmap2 write at most) instead of leaking a shadow or not starting at all; the daemon script mounts its shadow only when service.sh confirms the namespace is private (VECTOR_SHADOW_OK). A leaked shadow now cannot happen by construction.

2. The never-dispatched onSystemServerStarting: the system-framework scope spelling

The dispatch chain itself is fine on this ROM. What empties it is the scope storage:

  • The manager stores the System Framework scope as system (ScopeViewModel.SYSTEM_FRAMEWORK_PACKAGE).
  • The libxposed API, the modules asking for a scope through it, and the CLI all use android - and the rows were stored verbatim.
  • ModuleDatabase.systemServerModuleRows() - the one query that serves system_server (ConfigCache.getModulesForSystemServer via FrameworkService.getAllModules) - matched only app_pkg_name = 'system'.

A scope row stored as android (added via vector-cli scope add <module> android/0, or requested by a module through the libxposed scope API) therefore matched no reader at all: getModules() returned an empty list, nothing loaded into system_server, onSystemServerStarting dispatched over an empty set, and the modules log had no system_server entries - silently, on every clean cycle, because it was not a race. This also explains why the classloader-capture chain the original report traced looked suspicious but was never the culprit: on this device handleSystemServerProcess's post-hook sees a perfectly valid context classloader (confirmed with an instrumented build during verification).

Writes are now normalized at the storage boundary (setModuleScope, the libxposed scope-request approval, and getModuleScope's read-back), the system_server reader accepts both spellings (deduped - both rows can exist), removal clears both, and the cache expansion treats the alias the same. The unresolved-apkPath skip in getModulesForSystemServer also logs now instead of silently dropping the module.

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

Built from this branch (debug), installed over the previously disabled module, scope row left stored as android:

  • ksud services: vectord starts, the shadow lands in the daemon's own mount namespace, init's namespace stays clean (grep resource-cache /proc/1/mountinfo = 0) across the whole boot.
  • ksud soft-reboot: boot completes, no PMS exception, no crash loop.
  • Framework logs show the full chain that libxposed modules scoped to android are never dispatched onSystemServerStarting; on HyperOS 2.0 (Android 15) android-scoped modules cause a system_server boot loop #1101 reported missing:
    forkCommon: isSystem=true isLateInject=false niceName=system binder!=null=true
    Injected Vector framework into system_server.
    handleSystemServerProcess post-hook: contextCL=dalvik.system.PathClassLoader[...services.jar...] resultType=RuntimeInit$MethodAndArgsCaller
    loadModules: getModules returned 1 modules
    dispatchSystemServerStarting: activeModules=1
    I/GPS Setter: io.github.varma322.gpssetter: Hooking system server (SDK 35)
    I/GPS Setter: Hooked getLastLocation / addGnss*Listener
    
  • Provider-level spoofing works again: dumpsys location shows gps and fused last location at the module's configured coordinates (previously null throughout).
  • The device's data and settings were untouched throughout (no resets, component disables intact).

Happy to split into two PRs if you prefer, or rework either half.

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.
The manager stores the System Framework scope as `system`, but the libxposed
API, the modules asking for a scope through it, and the CLI all use `android`
for the same target - and the rows were stored verbatim. The one query that
serves system_server only matched `system`, so a module scoped through any
spelling but the manager's was silently absent from the module list: nothing
loaded into system_server, onSystemServerStarting dispatched over an empty
set, and the modules log showed no system_server entries at all. That is the
never-dispatched half of JingMatrix#1101, and it reproduced on clean boot cycles
because it was not a race.

Writes are normalized at the storage boundary (setModuleScope, the scope
request approval, and getModuleScope's read-back), the system_server reader
accepts both spellings (deduped, since both rows can exist), removal clears
both, and the cache expansion treats the alias the same way. The unresolved
apkPath skip in getModulesForSystemServer also stops being silent.

Verified on HyperOS 2.0 (Android 15, beryl): with a scope row stored as
`android`, system_server now loads the module and dispatches
onSystemServerStarting on the first soft reboot after this change.

Fixes the dispatch half of JingMatrix#1101.
@McTr0

McTr0 commented Nov 22, 2026

Copy link
Copy Markdown
Author

Splitting per single-purpose reviewability: #1103 keeps the daemon's resource-cache shadow inside its own mount namespace (the boot-loop half), #1104 makes the system-framework scope spelling a harmless legacy (the dispatch half, framed against #1061 and the guidance comment there). Both carry the same device verification this PR described; this one supersedes them in combined form.

@McTr0 McTr0 closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant