From 8cf8a0d424584d8d3e7e29c3ea7864617498f16b Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 23 Jan 2019 21:59:54 +0100 Subject: Validate base mapping before using it Prevent infinite looping when we access a stale base map. This could happen when we encounter bogus mmap lists as happens in https://github.com/KDAB/hotspot/issues/164 Verify that the base map actually corresponds to the expected elf map and only use that then. Otherwise don't use the base map and continue with the original mapping, hoping for the best. While this fixes the stack overflow of the initial bug report, it doesn't solve the fundamental issue of dealing with broken data... We'll have to figure that one out separately. Fixes: https://github.com/KDAB/hotspot/issues/164 Change-Id: Iaebddbfbc891784a7fcc05df47aba761b75cc587 Reviewed-by: Milian Wolff --- app/perfsymboltable.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/perfsymboltable.cpp b/app/perfsymboltable.cpp index 27d0d58..ddb67f9 100644 --- a/app/perfsymboltable.cpp +++ b/app/perfsymboltable.cpp @@ -500,8 +500,12 @@ Dwfl_Module *PerfSymbolTable::module(quint64 addr, const PerfElfMap::ElfInfo &el if (!m_dwfl) return nullptr; - if (elf.pgoff && elf.hasBaseAddr()) - return module(addr, m_elfs.findElf(elf.baseAddr)); + if (elf.pgoff && elf.hasBaseAddr()) { + const auto base = m_elfs.findElf(elf.baseAddr); + if (base.addr == elf.baseAddr && !base.pgoff && elf.originalPath == base.originalPath) + return module(addr, base); + qWarning() << "stale base mapping referenced:" << elf << base << dec << m_pid << hex << addr; + } Dwfl_Module *mod = dwfl_addrmodule(m_dwfl, addr); -- cgit v1.2.3