CVE-2026-58985 AI-generated analysis
platform/frameworks/native, libbinder RPC (RpcServer / RpcSession / Trusty RpcServerTrusty)
Makes RpcServerTrusty create a ChannelContext for client-"incoming" (server-outgoing) RPC connections so TIPC disconnects on those channels are observed and handled, and makes RpcSession::addOutgoingConnection only register a connection after its init succeeds, with a graceful rejection on DEAD_OBJECT instead of a fatal abort.
Root cause
In libs/binder/trusty/RpcServerTrusty.cpp, handleConnectInternal only installed a ChannelContext via joinFn, which RpcServer::establishConnection invokes for server-incoming connections. For connections that the client flags as RPC_CONNECTION_OPTION_INCOMING (outgoing from the server's side), establishConnection called session->addOutgoingConnection(..., true) and returned without any callback, so *ctx_p stayed null. handleDisconnectInternal and handleChannelCleanup ignored a null ctx (the removed comment documents this). The RpcConnection pushed into mConnections.mOutgoing therefore had no disconnect handling after the peer closed the channel. The new test IncomingConnectionDos repeatedly opens and drops such connections using a valid session ID, and its comment says this is done "to trigger the leak". Additionally, addOutgoingConnection pushed the connection into mOutgoing before sendConnectionInit ran, and establishConnection treated any non-OK result as LOG_ALWAYS_FATAL.
How the fix works
- libs/binder/RpcSession.cpp:RpcSession::addOutgoingConnection: new optional out parameter sp<RpcConnection>* outConnection. The connection is now pushed into mConnections.mOutgoing (under mMutex) only after sendConnectionInit succeeds. On init failure the function returns the error without registering the connection and sets *outConnection to nullptr. On success it hands back the connection object and returns OK.
- libs/binder/RpcServer.cpp:RpcServer::establishConnection: gains a second callback, incomingSetupFn (defaulted to nullptr in RpcServer.h). In the `incoming` branch it now calls addOutgoingConnection(std::move(client), true, &connection). If the result is DEAD_OBJECT it logs and returns (connection rejected) instead of aborting. Other errors remain LOG_ALWAYS_FATAL with the status string. If incomingSetupFn is set, it is invoked with the session and a PreJoinSetupResult{connection, OK}.
- libs/binder/RpcServer.cpp:RpcServer::acceptConnection: the socket path is updated to pass an explicit nullptr incomingSetupFn.
- libs/binder/trusty/RpcServerTrusty.cpp:RpcServerTrusty::handleConnectInternal: moves the context creation into setupChannelContext(session, result, isIncoming). joinFn calls it with isIncoming=true and the new incomingSetupFn calls it with isIncoming=false. Both are passed to RpcServer::establishConnection, so outgoing connections now also get a ChannelContext holding the session and connection.
- libs/binder/trusty/include/binder/RpcServerTrusty.h: ChannelContext gains `bool isIncoming = true`.
- libs/binder/trusty/RpcServerTrusty.cpp:RpcServerTrusty::handleDisconnectInternal: the comment on the null-ctx early return is removed. Because outgoing connections now carry a ctx, the existing disconnect handling applies to them too. Per the commit message, that handling shuts down the RpcSession, as was already done for incoming connections.
- libs/binder/trusty/RpcServerTrusty.cpp:RpcServerTrusty::handleChannelCleanup: calls session->removeIncomingConnection(connection) only when channelContext->isIncoming. For outgoing connections it just deletes the ChannelContext.
- libs/binder/tests/binderRpcTest.cpp: adds the TIPC-only test BinderRpc.IncomingConnectionDos. It opens a session, fetches the session ID via RPC_SPECIAL_TRANSACT_GET_SESSION_ID, then opens 500 incoming connections with that ID, keeping 5 and closing the rest, and expects every tipc_connect to succeed.
Completeness
- Covers the Trusty TIPC server path: outgoing (client-flagged incoming) connections now have a ChannelContext, so handleDisconnectInternal sees them. Recovery is shutting down the session, not removing the single connection from mConnections.mOutgoing: handleChannelCleanup does not remove outgoing connections from the list, and the commit message says these connections are not managed dynamically.
- addOutgoingConnection no longer leaves a half-initialized connection in mOutgoing when sendConnectionInit fails. The material does not show which other callers of addOutgoingConnection are affected by this change.
- Only DEAD_OBJECT from addOutgoingConnection is handled gracefully in establishConnection. Any other non-OK status is still LOG_ALWAYS_FATAL.
- The socket-based server path (RpcServer::acceptConnection) passes nullptr for incomingSetupFn and is otherwise unchanged by this commit.
Behavior changes
- Trusty server: a TIPC disconnect on an outgoing connection now gets the same handling as on incoming connections (per the commit message, RpcSession shutdown) instead of being ignored.
- RpcServer::establishConnection: adding an outgoing connection to a dead session now logs 'Connection request to a dead session. Rejecting connection.' and drops the connection instead of aborting.
- RpcSession::addOutgoingConnection: on init failure the connection is not left in mConnections.mOutgoing and the init status is returned. On success it returns OK.
- New private signatures: establishConnection(..., joinFn, incomingSetupFn = nullptr) and addOutgoingConnection(transport, init, outConnection = nullptr). The removeIncomingConnection declaration moved within RpcSession.h.
Per major
- Android 14: Not affected per the bulletin. At android-security-14.0.0_r31, 6/8 lines of the patched region are present.
- Android 15: Not affected per the bulletin. At android-security-15.0.0_r19, 6/8 lines of the patched region are present.
- Android 16: Not affected per the bulletin (only 16-qpr2 is listed). At android-security-16.0.0_r10, 6/8 lines of the patched region are present.
- Android 17: Fixed by commit 96516983e021 in android-security-17.0.0_r3 (its message lists two Cherrypick-From references, 8017334ca67f and 7b08f25146ad). 7/8 lines of the patched region are present at that tag.
Unknowns
- The full body of RpcServerTrusty::handleDisconnectInternal is not shown. The claim that it shuts down the RpcSession comes from the commit message.
- What status sendConnectionInit returns when the peer closes during init, and therefore whether failures other than DEAD_OBJECT can still hit LOG_ALWAYS_FATAL in establishConnection.
- Which resource was exhausted by the pre-fix leak (RpcConnection objects, transport handles, or both).
- Why 16-qpr2 is listed as affected while the base 16 branch is not.
- Whether the two Cherrypick-From references are separate changes or one change cherry-picked twice.
- Where the Trusty-side half of the fix is built and shipped (Trusty tree versus device image).
- How the socket server path (RpcServer::acceptConnection) handles a peer closing a client-flagged incoming connection. The material does not show it.