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 | dc9a1935d509bf97b15e43dfeab89c8eb3a1e4e2 (patch) | |
| tree | 2832d853a8b2dfa6f66f1c5d04d22df742b22d4d /libunwindstack/include | |
| parent | 461a213ae8a01581ff1fa9c589c9b412b5ce6425 (diff) | |
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 'libunwindstack/include')
| -rw-r--r-- | libunwindstack/include/unwindstack/DexFiles.h | 4 | ||||
| -rw-r--r-- | libunwindstack/include/unwindstack/Elf.h | 2 | ||||
| -rw-r--r-- | libunwindstack/include/unwindstack/Global.h | 9 | ||||
| -rw-r--r-- | libunwindstack/include/unwindstack/JitDebug.h | 16 | ||||
| -rw-r--r-- | libunwindstack/include/unwindstack/MapInfo.h | 2 |
5 files changed, 22 insertions, 11 deletions
diff --git a/libunwindstack/include/unwindstack/DexFiles.h b/libunwindstack/include/unwindstack/DexFiles.h index c2fde74efc..c202a334de 100644 --- a/libunwindstack/include/unwindstack/DexFiles.h +++ b/libunwindstack/include/unwindstack/DexFiles.h @@ -47,8 +47,6 @@ class DexFiles : public Global { void GetMethodInformation(Maps* maps, MapInfo* info, uint64_t dex_pc, std::string* method_name, uint64_t* method_offset); - void SetArch(ArchEnum arch); - private: void Init(Maps* maps); @@ -64,6 +62,8 @@ class DexFiles : public Global { bool ReadVariableData(uint64_t ptr_offset) override; + void ProcessArch() override; + std::mutex lock_; bool initialized_ = false; std::unordered_map<uint64_t, DexFile*> files_; diff --git a/libunwindstack/include/unwindstack/Elf.h b/libunwindstack/include/unwindstack/Elf.h index 24cabf2205..e5b0a89c9b 100644 --- a/libunwindstack/include/unwindstack/Elf.h +++ b/libunwindstack/include/unwindstack/Elf.h @@ -57,6 +57,8 @@ class Elf { void InitGnuDebugdata(); + void Invalidate(); + bool GetSoname(std::string* name); bool GetFunctionName(uint64_t addr, std::string* name, uint64_t* func_offset); diff --git a/libunwindstack/include/unwindstack/Global.h b/libunwindstack/include/unwindstack/Global.h index 70e3ddd455..a7e6c15baa 100644 --- a/libunwindstack/include/unwindstack/Global.h +++ b/libunwindstack/include/unwindstack/Global.h @@ -25,6 +25,7 @@ #include <unordered_map> #include <vector> +#include <unwindstack/Elf.h> #include <unwindstack/Memory.h> namespace unwindstack { @@ -39,12 +40,20 @@ class Global { Global(std::shared_ptr<Memory>& memory, std::vector<std::string>& search_libs); virtual ~Global() = default; + void SetArch(ArchEnum arch); + + ArchEnum arch() { return arch_; } + protected: uint64_t GetVariableOffset(MapInfo* info, const std::string& variable); void FindAndReadVariable(Maps* maps, const char* variable); virtual bool ReadVariableData(uint64_t offset) = 0; + virtual void ProcessArch() = 0; + + ArchEnum arch_ = ARCH_UNKNOWN; + std::shared_ptr<Memory> memory_; std::vector<std::string> search_libs_; }; diff --git a/libunwindstack/include/unwindstack/JitDebug.h b/libunwindstack/include/unwindstack/JitDebug.h index ccb473f7ef..f64b04f0a6 100644 --- a/libunwindstack/include/unwindstack/JitDebug.h +++ b/libunwindstack/include/unwindstack/JitDebug.h @@ -42,17 +42,9 @@ class JitDebug : public Global { Elf* GetElf(Maps* maps, uint64_t pc); - void SetArch(ArchEnum arch); - private: void Init(Maps* maps); - uint64_t entry_addr_ = 0; - bool initialized_ = false; - std::vector<Elf*> elf_list_; - - std::mutex lock_; - uint64_t (JitDebug::*read_descriptor_func_)(uint64_t) = nullptr; uint64_t (JitDebug::*read_entry_func_)(uint64_t*, uint64_t*) = nullptr; @@ -64,6 +56,14 @@ class JitDebug : public Global { uint64_t ReadEntry64(uint64_t* start, uint64_t* size); bool ReadVariableData(uint64_t ptr_offset) override; + + void ProcessArch() override; + + uint64_t entry_addr_ = 0; + bool initialized_ = false; + std::vector<Elf*> elf_list_; + + std::mutex lock_; }; } // namespace unwindstack diff --git a/libunwindstack/include/unwindstack/MapInfo.h b/libunwindstack/include/unwindstack/MapInfo.h index ff634f26e9..9c6b55211c 100644 --- a/libunwindstack/include/unwindstack/MapInfo.h +++ b/libunwindstack/include/unwindstack/MapInfo.h @@ -72,7 +72,7 @@ struct MapInfo { std::atomic_uint64_t load_bias; // This function guarantees it will never return nullptr. - Elf* GetElf(const std::shared_ptr<Memory>& process_memory); + Elf* GetElf(const std::shared_ptr<Memory>& process_memory, ArchEnum expected_arch); uint64_t GetLoadBias(const std::shared_ptr<Memory>& process_memory); |
