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

Commit 623d140c authored by Kalesh Singh's avatar Kalesh Singh
Browse files

trusty: Remove explicit page-alignment of mmap and dmabuf allocations



bionic hard codes the PAGE_SIZE macro as 4096. This is going away as
Android begins to support larger page sizes.

trusty uses PAGE_SIZE to round up the allocation size of the DMA
buffers and mmap sizes. This is not explicitly needed since the kernel
will always give you a page-aligned and page-sized multiple allocation
when allocating a dmabuf or mmap-ing.

Remove this PAGE_SIZE usage from TrustyApp, app_fuzzer, coverage,
line-coverage, modulewrapper.

Bug: 294914413
Test: Boot test on 16k device
Change-Id: Iad922e0a152cb80db2e59e696d7556602fd17d67
Signed-off-by: default avatarKalesh Singh <kaleshsingh@google.com>
parent c519d1dd
Loading
Loading
Loading
Loading
+1 −5
Original line number Original line Diff line number Diff line
@@ -43,10 +43,6 @@ static struct uuid apploader_uuid = {
        {0xb5, 0xe8, 0xa7, 0xe9, 0xef, 0x17, 0x3a, 0x97},
        {0xb5, 0xe8, 0xa7, 0xe9, 0xef, 0x17, 0x3a, 0x97},
};
};


static inline uintptr_t RoundPageUp(uintptr_t val) {
    return (val + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
}

static bool SendLoadMsg(int chan, int dma_buf, size_t dma_buf_size) {
static bool SendLoadMsg(int chan, int dma_buf, size_t dma_buf_size) {
    apploader_header hdr = {
    apploader_header hdr = {
            .cmd = APPLOADER_CMD_LOAD_APPLICATION,
            .cmd = APPLOADER_CMD_LOAD_APPLICATION,
@@ -107,7 +103,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
        android::trusty::fuzz::Abort();
        android::trusty::fuzz::Abort();
    }
    }


    uint64_t shm_len = size ? RoundPageUp(size) : PAGE_SIZE;
    uint64_t shm_len = size ? size : 4096;
    BufferAllocator alloc;
    BufferAllocator alloc;
    unique_fd dma_buf(alloc.Alloc(kDmabufSystemHeapName, shm_len));
    unique_fd dma_buf(alloc.Alloc(kDmabufSystemHeapName, shm_len));
    if (dma_buf < 0) {
    if (dma_buf < 0) {
+1 −5
Original line number Original line Diff line number Diff line
@@ -30,10 +30,6 @@ namespace confirmationui {


using ::android::base::unique_fd;
using ::android::base::unique_fd;


static inline uintptr_t RoundPageUp(uintptr_t val) {
    return (val + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
}

ssize_t TrustyApp::TrustyRpc(const uint8_t* obegin, const uint8_t* oend, uint8_t* ibegin,
ssize_t TrustyApp::TrustyRpc(const uint8_t* obegin, const uint8_t* oend, uint8_t* ibegin,
                             uint8_t* iend) {
                             uint8_t* iend) {
    uint32_t olen = oend - obegin;
    uint32_t olen = oend - obegin;
@@ -99,7 +95,7 @@ TrustyApp::TrustyApp(const std::string& path, const std::string& appname)
        return;
        return;
    }
    }


    uint32_t shm_len = RoundPageUp(CONFIRMATIONUI_MAX_MSG_SIZE);
    uint32_t shm_len = CONFIRMATIONUI_MAX_MSG_SIZE;
    BufferAllocator allocator;
    BufferAllocator allocator;
    unique_fd dma_buf(allocator.Alloc("system", shm_len));
    unique_fd dma_buf(allocator.Alloc("system", shm_len));
    if (dma_buf < 0) {
    if (dma_buf < 0) {
+1 −5
Original line number Original line Diff line number Diff line
@@ -43,10 +43,6 @@ using std::string;
using std::to_string;
using std::to_string;
using std::unique_ptr;
using std::unique_ptr;


static inline uintptr_t RoundPageUp(uintptr_t val) {
    return (val + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
}

CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid)
CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid)
    : tipc_dev_(std::move(tipc_dev)),
    : tipc_dev_(std::move(tipc_dev)),
      coverage_srv_fd_(-1),
      coverage_srv_fd_(-1),
@@ -136,7 +132,7 @@ Result<void> CoverageRecord::Open() {
        return Error() << "failed to open coverage client: " << ret.error();
        return Error() << "failed to open coverage client: " << ret.error();
    }
    }
    record_len_ = resp.open_args.record_len;
    record_len_ = resp.open_args.record_len;
    shm_len_ = RoundPageUp(record_len_);
    shm_len_ = record_len_;


    BufferAllocator allocator;
    BufferAllocator allocator;


+1 −5
Original line number Original line Diff line number Diff line
@@ -50,10 +50,6 @@ using ::android::base::ErrnoError;
using ::android::base::Error;
using ::android::base::Error;
using ::std::string;
using ::std::string;


static inline uintptr_t RoundPageUp(uintptr_t val) {
    return (val + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
}

CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid)
CoverageRecord::CoverageRecord(string tipc_dev, struct uuid* uuid)
    : tipc_dev_(std::move(tipc_dev)),
    : tipc_dev_(std::move(tipc_dev)),
      coverage_srv_fd_(-1),
      coverage_srv_fd_(-1),
@@ -129,7 +125,7 @@ Result<void> CoverageRecord::Open(int fd) {
        return Error() << "failed to open coverage client: " << ret.error();
        return Error() << "failed to open coverage client: " << ret.error();
    }
    }
    record_len_ = resp.open_args.record_len;
    record_len_ = resp.open_args.record_len;
    shm_len_ = RoundPageUp(record_len_);
    shm_len_ = record_len_;


    BufferAllocator allocator;
    BufferAllocator allocator;


+3 −8
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@
#include <sys/mman.h>
#include <sys/mman.h>
#include <trusty/tipc.h>
#include <trusty/tipc.h>
#include <unistd.h>
#include <unistd.h>
#include <algorithm>


#include "acvp_ipc.h"
#include "acvp_ipc.h"


@@ -42,9 +43,6 @@ using android::base::Result;
using android::base::unique_fd;
using android::base::unique_fd;
using android::base::WriteFully;
using android::base::WriteFully;


static inline size_t AlignUpToPage(size_t size) {
    return (size + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
}


namespace {
namespace {


@@ -104,15 +102,12 @@ Result<void> ModuleWrapper::SendMessage(bssl::Span<const bssl::Span<const uint8_
    struct acvp_req request;
    struct acvp_req request;
    request.num_args = args.size();
    request.num_args = args.size();


    size_t total_args_size = 0;
    int total_args_size = 0;
    for (auto arg : args) {
    for (auto arg : args) {
        total_args_size += arg.size();
        total_args_size += arg.size();
    }
    }


    shm_size_ = ACVP_MIN_SHARED_MEMORY;
    shm_size_ = std::max(ACVP_MIN_SHARED_MEMORY, total_args_size);
    if (total_args_size > shm_size_) {
        shm_size_ = AlignUpToPage(total_args_size);
    }
    request.buffer_size = shm_size_;
    request.buffer_size = shm_size_;


    struct iovec iov = {
    struct iovec iov = {