Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4af92ac7 authored by Andrei Homescu's avatar Andrei Homescu
Browse files

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
parent ee436e4f
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -117,7 +117,15 @@ int RpcServerTrusty::handleConnect(const tipc_port* port, handle_t chan, const u
        *ctx_p = channelContext;
        *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));
    android::RpcTransportFd transportFd(std::move(clientFd));


    std::array<uint8_t, RpcServer::kRpcAddressSize> addr;
    std::array<uint8_t, RpcServer::kRpcAddressSize> addr;