libbinder: Duplicate channel handle in RpcServerTrusty

The tipc library calls close() on the channel handle
when the connection is shut down. RpcServerTrusty wraps
the channel handle in a unique_fd for its own use.
This second copy of the handle needs to be a duplicate
from dup() to prevent a double call to close() on the
same handle.

Bug: 259517277
Test: trusty_stats_test
Change-Id: Ibbab75873ccf43e6d8315202794534e9f89a65c3
diff --git a/libs/binder/trusty/RpcServerTrusty.cpp b/libs/binder/trusty/RpcServerTrusty.cpp
index 18ce316..109da75 100644
--- a/libs/binder/trusty/RpcServerTrusty.cpp
+++ b/libs/binder/trusty/RpcServerTrusty.cpp
@@ -117,7 +117,15 @@
         *ctx_p = channelContext;
     };
 
-    base::unique_fd clientFd(chan);
+    // We need to duplicate the channel handle here because the tipc library
+    // owns the original handle and closes is automatically on channel cleanup.
+    // We use dup() because Trusty does not have fcntl().
+    // NOLINTNEXTLINE(android-cloexec-dup)
+    handle_t chanDup = dup(chan);
+    if (chanDup < 0) {
+        return chanDup;
+    }
+    base::unique_fd clientFd(chanDup);
     android::RpcTransportFd transportFd(std::move(clientFd));
 
     std::array<uint8_t, RpcServer::kRpcAddressSize> addr;