Skip to content

Commit 33d6d19

Browse files
committed
libbinder: allow fd transport in trusty by default
Changes the default protocol version of 0 for trusty servers and keeps them in line with the latest stable RPC_WIRE_PROTOCOL_VERSION (currently 1). It seems that hardcoding to version 0 happened before aosp/2534786 where RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL was the default. Version 1 allows parcels to contain FDs. This should be safe because rpc binder negotiates a protocol version using the min value of the client and server configurations. Older clients will be able to downgrade the protocol version (but not transact with fds in their parcels) and newer clients will see their protocol versions negotiated down to the server's version on connection. This change also adds supported file descriptor transport modes to servers by default. In trusty, tipc allows handles to be transmitted by default so this is in line with the current security posture. Bug: 377907450 Test: trusty/vendor/google/aosp/scripts/build.py \ --test "boot-test:com.android.trusty.binderRpcTest" \ qemu-generic-arm64-test-debug Test: trusty/vendor/google/aosp/scripts/build.py qemu-generic-arm64-test-debug \ --test="boot-test:com.android.trusty.rust.service_manager_tests.test Change-Id: I0efbd7781f0fd2bc81981b01ae1b1d0d149b12b6
1 parent 6ff1302 commit 33d6d19

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

libs/binder/trusty/include/binder/RpcServerTrusty.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ class RpcServerTrusty final : public virtual RefBase {
9494
static sp<RpcServer> makeRpcServer(std::unique_ptr<RpcTransportCtx> ctx) {
9595
auto rpcServer = sp<RpcServer>::make(std::move(ctx));
9696

97-
// TODO(b/266741352): follow-up to prevent needing this in the future
98-
// Trusty needs to be set to the latest stable version that is in prebuilts there.
99-
LOG_ALWAYS_FATAL_IF(!rpcServer->setProtocolVersion(0));
97+
// By default we use the latest stable version.
98+
LOG_ALWAYS_FATAL_IF(!rpcServer->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION));
10099

101100
return rpcServer;
102101
}

libs/binder/trusty/rust/binder_rpc_server_bindgen/cpp/ARpcServerTrusty.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ using android::RpcTransportCtxFactoryTipcTrusty;
2727
using android::sp;
2828
using android::wp;
2929

30+
// The default behavior in trusty is to allow handles to be passed with tipc IPC.
31+
// We add mode NONE so that servers do not reject connections from clients who do
32+
// not change their default transport mode.
33+
static const std::vector<RpcSession::FileDescriptorTransportMode> TRUSTY_SERVER_SUPPORTED_FD_MODES =
34+
{RpcSession::FileDescriptorTransportMode::TRUSTY,
35+
RpcSession::FileDescriptorTransportMode::NONE};
36+
3037
struct ARpcServerTrusty {
3138
sp<RpcServer> mRpcServer;
3239

@@ -53,6 +60,8 @@ ARpcServerTrusty* ARpcServerTrusty_newPerSession(AIBinder* (*cb)(const void*, si
5360
return nullptr;
5461
}
5562

63+
rpcServer->setSupportedFileDescriptorTransportModes(TRUSTY_SERVER_SUPPORTED_FD_MODES);
64+
5665
rpcServer->setPerSessionRootObject(
5766
[cb, cbArgSp](wp<RpcSession> /*session*/, const void* addrPtr, size_t len) {
5867
auto* aib = (*cb)(addrPtr, len, cbArgSp.get());

0 commit comments

Comments
 (0)