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

Commit 406b9c97 authored by Andrei Homescu's avatar Andrei Homescu Committed by Dmitriy Filchenko
Browse files

Trusty Binder: split large messages in RpcTransportTipcAndroid

tipc_send returns -EMSGSIZE when attempting to send messages
larger than a little under a page. Fragment them manually
in the transport since the receiver reassembles them.

Bug: 415302667
Test: atest -c binderRpcToTrustyTest
Flag: EXEMPT bugfix
Change-Id: Ida0eb029eedb8b38603b7a4179d3641e34e70776
parent c4dc4b74
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public:
            const std::vector<std::variant<unique_fd, borrowed_fd>>* ancillaryFds) override {
        bool sentFds = false;
        auto writeFn = [&](iovec* iovs, size_t niovs) -> ssize_t {
            // Collect the ancillary FDs.
            trusty_shm shms[kMaxTipcHandles] = {{0}};
            ssize_t shm_count = 0;

@@ -100,9 +101,33 @@ public:
                }
            }

            auto ret = TEMP_FAILURE_RETRY(tipc_send(mSocket.fd.get(), iovs, niovs,
            // Trusty currently has a message size limit, which will go away once we
            // switch to vsock. The message is reassembled on the receiving side.
            static const size_t maxMsgSize = VIRTIO_VSOCK_MSG_SIZE_LIMIT;
            size_t niovsMsg;
            size_t currSize = 0;
            size_t cutSize = 0;
            for (niovsMsg = 0; niovsMsg < niovs; niovsMsg++) {
                if (__builtin_add_overflow(currSize, iovs[niovsMsg].iov_len, &currSize)) {
                    ALOGE("%s: iov_len add_overflow", __FUNCTION__);
                    return NO_MEMORY;
                }
                if (currSize >= maxMsgSize) {
                    // Truncate the last iov but restore it at the end
                    // so the caller can continue where we left off.
                    cutSize = currSize - maxMsgSize;
                    iovs[niovsMsg].iov_len -= cutSize;
                    niovsMsg++;
                    break;
                }
            }

            auto ret = TEMP_FAILURE_RETRY(tipc_send(mSocket.fd.get(), iovs, niovsMsg,
                                                    (shm_count == 0) ? nullptr : shms, shm_count));
            sentFds |= ret >= 0;
            if (niovsMsg > 0) {
                iovs[niovsMsg - 1].iov_len += cutSize;
            }
            return ret;
        };

+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ RpcServerTrusty::RpcServerTrusty(std::unique_ptr<RpcTransportCtx> ctx, std::stri
        mPortAcl(std::move(portAcl)) {
    mTipcPort.name = mPortName.c_str();
    mTipcPort.msg_max_size = msgMaxSize;
    mTipcPort.msg_queue_len = 6; // Three each way
    mTipcPort.msg_queue_len = 16;
    mTipcPort.priv = this;

    if (mPortAcl) {