diff options
author | Christopher Ferris <cferris@google.com> | 2018-10-23 17:42:41 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-10-29 18:08:09 -0700 |
commit | 4568f4bc0f116f097a13b1d931de93cf525ae204 (patch) | |
tree | 2832d853a8b2dfa6f66f1c5d04d22df742b22d4d /libbacktrace | |
parent | 2a8460721ca219ea2d9bc00e0412297afd12df47 (diff) | |
download | system_core-4568f4bc0f116f097a13b1d931de93cf525ae204.tar.gz system_core-4568f4bc0f116f097a13b1d931de93cf525ae204.tar.bz2 system_core-4568f4bc0f116f097a13b1d931de93cf525ae204.zip |
Verify that the elf matches the expected arch.
To avoid a case where a malicious app might try and trick the system to
create an elf and register object that mismatches, always verify that they
are the same arch.
Test: Ran unit tests.
Change-Id: I66978e9e02f8e4f396856912e7019528ead4838e
Diffstat (limited to 'libbacktrace')
-rw-r--r-- | libbacktrace/UnwindStack.cpp | 1 | ||||
-rw-r--r-- | libbacktrace/UnwindStackMap.cpp | 13 | ||||
-rw-r--r-- | libbacktrace/UnwindStackMap.h | 5 |
3 files changed, 18 insertions, 1 deletions
diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp index 4e7f761ff..fe28eba41 100644 --- a/libbacktrace/UnwindStack.cpp +++ b/libbacktrace/UnwindStack.cpp @@ -49,6 +49,7 @@ bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map, unwindstack::Unwinder unwinder(MAX_BACKTRACE_FRAMES + num_ignore_frames, stack_map->stack_maps(), regs, stack_map->process_memory()); unwinder.SetResolveNames(stack_map->ResolveNames()); + stack_map->SetArch(regs->Arch()); if (stack_map->GetJitDebug() != nullptr) { unwinder.SetJitDebug(stack_map->GetJitDebug(), regs->Arch()); } diff --git a/libbacktrace/UnwindStackMap.cpp b/libbacktrace/UnwindStackMap.cpp index 52dd44192..9d15af2db 100644 --- a/libbacktrace/UnwindStackMap.cpp +++ b/libbacktrace/UnwindStackMap.cpp @@ -25,6 +25,7 @@ #include <unwindstack/Elf.h> #include <unwindstack/MapInfo.h> #include <unwindstack/Maps.h> +#include <unwindstack/Regs.h> #include "UnwindStackMap.h" @@ -106,7 +107,17 @@ std::string UnwindStackMap::GetFunctionName(uint64_t pc, uint64_t* offset) { return ""; } - unwindstack::Elf* elf = map_info->GetElf(process_memory()); + if (arch_ == unwindstack::ARCH_UNKNOWN) { + if (pid_ == getpid()) { + arch_ = unwindstack::Regs::CurrentArch(); + } else { + // Create a remote regs, to figure out the architecture. + std::unique_ptr<unwindstack::Regs> regs(unwindstack::Regs::RemoteGet(pid_)); + arch_ = regs->Arch(); + } + } + + unwindstack::Elf* elf = map_info->GetElf(process_memory(), arch_); std::string name; uint64_t func_offset; diff --git a/libbacktrace/UnwindStackMap.h b/libbacktrace/UnwindStackMap.h index 039f4a289..e19b60565 100644 --- a/libbacktrace/UnwindStackMap.h +++ b/libbacktrace/UnwindStackMap.h @@ -30,6 +30,7 @@ #if !defined(NO_LIBDEXFILE_SUPPORT) #include <unwindstack/DexFiles.h> #endif +#include <unwindstack/Elf.h> #include <unwindstack/JitDebug.h> #include <unwindstack/Maps.h> @@ -58,6 +59,8 @@ class UnwindStackMap : public BacktraceMap { unwindstack::DexFiles* GetDexFiles() { return dex_files_.get(); } #endif + void SetArch(unwindstack::ArchEnum arch) { arch_ = arch; } + protected: uint64_t GetLoadBias(size_t index) override; @@ -67,6 +70,8 @@ class UnwindStackMap : public BacktraceMap { #if !defined(NO_LIBDEXFILE_SUPPORT) std::unique_ptr<unwindstack::DexFiles> dex_files_; #endif + + unwindstack::ArchEnum arch_ = unwindstack::ARCH_UNKNOWN; }; class UnwindStackOfflineMap : public UnwindStackMap { |