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

Commit 42466c06 authored by Peter Collingbourne's avatar Peter Collingbourne Committed by Automerger Merge Worker
Browse files

Merge changes from topics "I1e5610d1353b4f5b718c1259825421c0c07d7c24",...

Merge changes from topics "I1e5610d1353b4f5b718c1259825421c0c07d7c24", "I52da338347ff6b7503cf5ac80763c540695dc061", "I94e4b7124b7735b92fd83a49c80ebded3483cd4e" am: 4058c5cf am: 867184e6 am: a3c22a61 am: 1cfa3ddd

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1367537

Change-Id: I374f789da1c17738b276ad4446cf18f262151fed
parents 12a2f481 1cfa3ddd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -253,7 +253,6 @@ cc_test {
        "libcutils",
        "libdebuggerd_client",
        "liblog",
        "libminijail",
        "libnativehelper",
        "libunwindstack",
    ],
@@ -261,6 +260,7 @@ cc_test {
    static_libs: [
        "libdebuggerd",
        "libgmock",
        "libminijail",
    ],

    header_libs: [
+50 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <sys/capability.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
@@ -556,6 +557,55 @@ TEST_F(CrasherTest, mte_multiple_causes) {
#endif
}

#if defined(__aarch64__) && defined(ANDROID_EXPERIMENTAL_MTE)
static uintptr_t CreateTagMapping() {
  uintptr_t mapping =
      reinterpret_cast<uintptr_t>(mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE | PROT_MTE,
                                       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
  if (reinterpret_cast<void*>(mapping) == MAP_FAILED) {
    return 0;
  }
  __asm__ __volatile__(".arch_extension mte; stg %0, [%0]"
                       :
                       : "r"(mapping + (1ULL << 56))
                       : "memory");
  return mapping;
}
#endif

TEST_F(CrasherTest, mte_tag_dump) {
#if defined(__aarch64__) && defined(ANDROID_EXPERIMENTAL_MTE)
  if (!mte_supported()) {
    GTEST_SKIP() << "Requires MTE";
  }

  int intercept_result;
  unique_fd output_fd;
  StartProcess([&]() {
    SetTagCheckingLevelSync();
    Trap(reinterpret_cast<void *>(CreateTagMapping()));
  });

  StartIntercept(&output_fd);
  FinishCrasher();
  AssertDeath(SIGTRAP);
  FinishIntercept(&intercept_result);

  ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";

  std::string result;
  ConsumeFd(std::move(output_fd), &result);

  ASSERT_MATCH(result, R"(memory near x0:
.*
.*
    01.............0 0000000000000000 0000000000000000  ................
    00.............0)");
#else
  GTEST_SKIP() << "Requires aarch64 + ANDROID_EXPERIMENTAL_MTE";
#endif
}

TEST_F(CrasherTest, LD_PRELOAD) {
  int intercept_result;
  unique_fd output_fd;
+129 −258

File changed.

Preview size limit exceeded, changes collapsed.

+23 −14
Original line number Diff line number Diff line
@@ -129,28 +129,23 @@ void _VLOG(log_t* log, enum logtype ltype, const char* fmt, va_list ap) {
#define MEMORY_BYTES_PER_LINE 16

void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const std::string& label) {
  // Align the address to sizeof(long) and start 32 bytes before the address.
  addr &= ~(sizeof(long) - 1);
  // Align the address to the number of bytes per line to avoid confusing memory tag output if
  // memory is tagged and we start from a misaligned address. Start 32 bytes before the address.
  addr &= ~(MEMORY_BYTES_PER_LINE - 1);
  if (addr >= 4128) {
    addr -= 32;
  }

  // We don't want the address tag to interfere with the bounds check below or appear in the
  // addresses in the memory dump.
  // We don't want the address tag to appear in the addresses in the memory dump.
  addr = untag_address(addr);

  // Don't bother if the address looks too low, or looks too high.
  if (addr < 4096 ||
#if defined(__LP64__)
      addr > 0x4000000000000000UL - MEMORY_BYTES_TO_DUMP) {
#else
      addr > 0xffff0000 - MEMORY_BYTES_TO_DUMP) {
#endif
  // Don't bother if the address would overflow, taking tag bits into account. Note that
  // untag_address truncates to 32 bits on 32-bit platforms as a side effect of returning a
  // uintptr_t, so this also checks for 32-bit overflow.
  if (untag_address(addr + MEMORY_BYTES_TO_DUMP - 1) < addr) {
    return;
  }

  _LOG(log, logtype::MEMORY, "\n%s:\n", label.c_str());

  // Dump 256 bytes
  uintptr_t data[MEMORY_BYTES_TO_DUMP/sizeof(uintptr_t)];
  memset(data, 0, MEMORY_BYTES_TO_DUMP);
@@ -191,6 +186,15 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s
    }
  }

  // If we were unable to read anything, it probably means that the register doesn't contain a
  // valid pointer. In that case, skip the output for this register entirely rather than emitting 16
  // lines of dashes.
  if (bytes == 0) {
    return;
  }

  _LOG(log, logtype::MEMORY, "\n%s:\n", label.c_str());

  // Dump the code around memory as:
  //  addr             contents                           ascii
  //  0000000000008d34 ef000000e8bd0090 e1b00000512fff1e  ............../Q
@@ -201,8 +205,13 @@ void dump_memory(log_t* log, unwindstack::Memory* memory, uint64_t addr, const s
  size_t current = 0;
  size_t total_bytes = start + bytes;
  for (size_t line = 0; line < MEMORY_BYTES_TO_DUMP / MEMORY_BYTES_PER_LINE; line++) {
    uint64_t tagged_addr = addr;
    long tag = memory->ReadTag(addr);
    if (tag >= 0) {
      tagged_addr |= static_cast<uint64_t>(tag) << 56;
    }
    std::string logline;
    android::base::StringAppendF(&logline, "    %" PRIPTR, addr);
    android::base::StringAppendF(&logline, "    %" PRIPTR, tagged_addr);

    addr += MEMORY_BYTES_PER_LINE;
    std::string ascii;