From e50874621a86893eb5b267cca89203e9052093cd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 16 Jul 2020 19:27:03 +0200 Subject: UserspaceEmulator: Don't scan text segment for malloc leaks There will be no (true positive) malloc addresses in the text segment. --- DevTools/UserspaceEmulator/Emulator.cpp | 2 ++ DevTools/UserspaceEmulator/MallocTracer.cpp | 2 ++ DevTools/UserspaceEmulator/SoftMMU.h | 4 ++++ 3 files changed, 8 insertions(+) (limited to 'DevTools/UserspaceEmulator') diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index 875b78340b..23e2855515 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -108,6 +108,8 @@ bool Emulator::load_elf() m_elf->image().for_each_program_header([&](const ELF::Image::ProgramHeader& program_header) { if (program_header.type() == PT_LOAD) { auto region = make(program_header.vaddr().get(), program_header.size_in_memory()); + if (program_header.is_executable() && !program_header.is_writable()) + region->set_text(true); memcpy(region->data(), program_header.raw_data(), program_header.size_in_image()); mmu().add_region(move(region)); return; diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp index 36bad55a19..72c183d99a 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -163,6 +163,8 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const // Skip the stack if (region.is_stack()) return IterationDecision::Continue; + if (region.is_text()) + return IterationDecision::Continue; // Skip malloc blocks if (region.is_mmap() && static_cast(region).is_malloc_block()) return IterationDecision::Continue; diff --git a/DevTools/UserspaceEmulator/SoftMMU.h b/DevTools/UserspaceEmulator/SoftMMU.h index d73eff7165..7202b73ab1 100644 --- a/DevTools/UserspaceEmulator/SoftMMU.h +++ b/DevTools/UserspaceEmulator/SoftMMU.h @@ -63,6 +63,9 @@ public: bool is_stack() const { return m_stack; } void set_stack(bool b) { m_stack = b; } + bool is_text() const { return m_text; } + void set_text(bool b) { m_text = b; } + protected: Region(u32 base, u32 size) : m_base(base) @@ -75,6 +78,7 @@ public: u32 m_size { 0 }; bool m_stack { false }; + bool m_text { false }; }; u8 read8(X86::LogicalAddress); -- cgit v1.2.3