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

Commit 3efc231e authored by Elliott Hughes's avatar Elliott Hughes Committed by Automerger Merge Worker
Browse files

Merge "debuggerd: add the PAC keys to the tombstones." am: 94531996 am: 16ad439b am: 96ca2502

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

Change-Id: I629e70cac77831bf2a48526af3776e6d8247915c
parents 70b9ba1b 96ca2502
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -502,15 +502,24 @@ int main(int argc, char** argv) {
        continue;
      }

      struct iovec iov = {
      struct iovec tagged_addr_iov = {
          &info.tagged_addr_ctrl,
          sizeof(info.tagged_addr_ctrl),
      };
      if (ptrace(PTRACE_GETREGSET, thread, NT_ARM_TAGGED_ADDR_CTRL,
                 reinterpret_cast<void*>(&iov)) == -1) {
                 reinterpret_cast<void*>(&tagged_addr_iov)) == -1) {
        info.tagged_addr_ctrl = -1;
      }

      struct iovec pac_enabled_keys_iov = {
          &info.pac_enabled_keys,
          sizeof(info.pac_enabled_keys),
      };
      if (ptrace(PTRACE_GETREGSET, thread, NT_ARM_PAC_ENABLED_KEYS,
                 reinterpret_cast<void*>(&pac_enabled_keys_iov)) == -1) {
        info.pac_enabled_keys = -1;
      }

      if (thread == g_target_thread) {
        // Read the thread's registers along with the rest of the crash info out of the pipe.
        ReadCrashInfo(input_pipe, &siginfo, &info.registers, &process_info);
+14 −0
Original line number Diff line number Diff line
@@ -173,6 +173,14 @@ static void tombstoned_intercept(pid_t target_pid, unique_fd* intercept_fd, uniq
  *status = response.status;
}

static bool pac_supported() {
#if defined(__aarch64__)
  return getauxval(AT_HWCAP) & HWCAP_PACA;
#else
  return false;
#endif
}

class CrasherTest : public ::testing::Test {
 public:
  pid_t crasher_pid = -1;
@@ -357,6 +365,12 @@ TEST_F(CrasherTest, smoke) {
    ASSERT_MATCH(result, R"(tagged_addr_ctrl: 000000000007fff3)"
                         R"( \(PR_TAGGED_ADDR_ENABLE, PR_MTE_TCF_SYNC, mask 0xfffe\))");
  }

  if (pac_supported()) {
    // Test that the default PAC_ENABLED_KEYS value is set.
    ASSERT_MATCH(result, R"(pac_enabled_keys: 000000000000000f)"
                         R"( \(PR_PAC_APIAKEY, PR_PAC_APIBKEY, PR_PAC_APDAKEY, PR_PAC_APDBKEY\))");
  }
}

TEST_F(CrasherTest, tagged_fault_addr) {
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
struct ThreadInfo {
  std::unique_ptr<unwindstack::Regs> registers;
  long tagged_addr_ctrl = -1;
  long pac_enabled_keys = -1;

  pid_t uid;

+18 −21
Original line number Diff line number Diff line
/* system/debuggerd/utility.h
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
/*
 * Copyright 2008, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DEBUGGERD_UTILITY_H
#define _DEBUGGERD_UTILITY_H
#pragma once

#include <inttypes.h>
#include <signal.h>
@@ -93,6 +91,7 @@ void get_signal_sender(char* buf, size_t n, const siginfo_t*);
const char* get_signame(const siginfo_t*);
const char* get_sigcode(const siginfo_t*);
std::string describe_tagged_addr_ctrl(long ctrl);
std::string describe_pac_enabled_keys(long keys);

// Number of bytes per MTE granule.
constexpr size_t kTagGranuleSize = 16;
@@ -100,5 +99,3 @@ constexpr size_t kTagGranuleSize = 16;
// Number of rows and columns to display in an MTE tag dump.
constexpr size_t kNumTagColumns = 16;
constexpr size_t kNumTagRows = 16;

#endif // _DEBUGGERD_UTILITY_H
+9 −0
Original line number Diff line number Diff line
@@ -31,3 +31,12 @@ TEST(UtilityTest, describe_tagged_addr_ctrl) {
      describe_tagged_addr_ctrl(0xf0000000 | PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC |
                                PR_MTE_TCF_ASYNC | (0xfffe << PR_MTE_TAG_SHIFT)));
}

TEST(UtilityTest, describe_pac_enabled_keys) {
  EXPECT_EQ("", describe_pac_enabled_keys(0));
  EXPECT_EQ(" (PR_PAC_APIAKEY)", describe_pac_enabled_keys(PR_PAC_APIAKEY));
  EXPECT_EQ(" (PR_PAC_APIAKEY, PR_PAC_APDBKEY)",
            describe_pac_enabled_keys(PR_PAC_APIAKEY | PR_PAC_APDBKEY));
  EXPECT_EQ(" (PR_PAC_APIAKEY, PR_PAC_APDBKEY, unknown 0x1000)",
            describe_pac_enabled_keys(PR_PAC_APIAKEY | PR_PAC_APDBKEY | 0x1000));
}
Loading