summaryrefslogtreecommitdiff
path: root/libs/binder/RpcSession.cpp
diff options
context:
space:
mode:
author Inseob Kim <inseob@google.com> 2025-02-28 09:12:21 +0900
committer Inseob Kim <inseob@google.com> 2025-03-05 17:20:08 +0900
commit4d78e342e546ec36418366b75017675dd3c71312 (patch)
tree6979b4eb7c2bc14da239bd5c416636fa351542e9 /libs/binder/RpcSession.cpp
parent48f26a3c63d9d96f2dab906b81142aaa9ecd03c9 (diff)
Support deleting param for preconnected sessions
Although we can pass arbitrary pointers to setup preconnected clients, the lifetime isn't clear and it's very easy to make UAF bugs. To prevent UAF, an additional function can be passed to delete param when param is no longer required, effectively transferring the ownership of param to RPC session. Bug: 398890208 Test: atest MicrodroidTests Change-Id: I1a1c149a56876f56fba81b89cdc90ee372d2d7fe
Diffstat (limited to 'libs/binder/RpcSession.cpp')
-rw-r--r--libs/binder/RpcSession.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 16023ffa82..1f3a45a6df 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -188,7 +188,9 @@ status_t RpcSession::setupInetClient(const char* addr, unsigned int port) {
}
status_t RpcSession::setupPreconnectedClient(unique_fd fd, std::function<unique_fd()>&& request) {
- return setupClient([&](const std::vector<uint8_t>& sessionId, bool incoming) -> status_t {
+ return setupClient([&, fd = std::move(fd),
+ request = std::move(request)](const std::vector<uint8_t>& sessionId,
+ bool incoming) mutable -> status_t {
if (!fd.ok()) {
fd = request();
if (!fd.ok()) return BAD_VALUE;
@@ -476,8 +478,10 @@ sp<RpcServer> RpcSession::server() {
return server;
}
-status_t RpcSession::setupClient(const std::function<status_t(const std::vector<uint8_t>& sessionId,
- bool incoming)>& connectAndInit) {
+template <typename Fn,
+ typename /* = std::enable_if_t<std::is_invocable_r_v<
+ status_t, Fn, const std::vector<uint8_t>&, bool>> */>
+status_t RpcSession::setupClient(Fn&& connectAndInit) {
{
RpcMutexLockGuard _l(mMutex);
LOG_ALWAYS_FATAL_IF(mStartedSetup, "Must only setup session once");