Skip to content

fix(daemon): prevent circular binder recursion in SystemServerService - #1114

Open
ludicious-claw wants to merge 1 commit into
JingMatrix:masterfrom
ludicious-claw:fix-systemserver-binder-recursion
Open

ludicious-claw wants to merge 1 commit into
JingMatrix:masterfrom
ludicious-claw:fix-systemserver-binder-recursion

Conversation

@ludicious-claw

Copy link
Copy Markdown

Summary of Changes

This PR fixes a critical crash in vectord caused by infinite Binder transaction recursion and stack overflow (SIGSEGV (SEGV_ACCERR) in JavaBBinder::onTransact).

Root Cause Analysis

On Android 16 (BP2A) and newer OEM builds (reproduced on Vivo OriginOS, device PD2352), when SystemServerService is registered in ServiceManager, the IServiceCallback.onRegistration callback fires and notifies the daemon.

  1. Self-referential BinderProxy adoption:
    In SystemServerService.adoptOriginService(name, binder), the guard check was:

    if (binder === this) return

    However, the incoming binder passed by the Binder framework during registration callback is an instance of android.os.BinderProxy, not the local SystemServerService (Binder) instance. Therefore, binder === this evaluates to false, and originService was mistakenly set to a proxy targeting SystemServerService itself.

  2. Unconditional transaction forwarding:
    In SystemServerService.onTransact, incoming transactions were forwarded to originService before checking the transaction code:

    originService?.let {
        return it.transact(code, data, reply, flags)
    }

    When system_server (via Zygisk) invoked BRIDGE_TRANSACTION_CODE, the transaction was intercepted and forwarded to originService (which pointed right back to SystemServerService), creating a recursive loop on the same Binder thread until the stack overflowed the guard page (~500 recursive calls).

Fix

  1. Identity check via Descriptor:
    • Defined DESCRIPTOR = "org.matrix.vector.daemon.ipc.SystemServerService" and implemented getInterfaceDescriptor().
    • Updated adoptOriginService to reject adoption if binder === this or binder.interfaceDescriptor == DESCRIPTOR.
  2. Local transaction precedence:
    • Moved originService?.transact(...) forwarding from the top of onTransact into the else branch of when (code).
    • Internal Vector transactions (BRIDGE_TRANSACTION_CODE, DEX_TRANSACTION_CODE, OBFUSCATION_MAP_TRANSACTION_CODE) are strictly processed locally and never forwarded.

Verification

  • Code formatted with :daemon:ktfmtFormat.
  • Successfully built release artifacts via ./gradlew :daemon:assembleRelease.

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