diff options
author | Matthew Malcomson <matthew.malcomson@arm.com> | 2020-11-25 16:31:35 +0000 |
---|---|---|
committer | Matthew Malcomson <matthew.malcomson@arm.com> | 2020-11-25 16:35:31 +0000 |
commit | 8eb12742e8ae5a16e05be627c701234dc7c13504 (patch) | |
tree | 790322638eedb4a867dc18779c490330d982d0fd | |
parent | 1ee3d1ef105c5181fbf298b8ddb638f8e3cbaaca (diff) | |
download | gcc-8eb12742e8ae5a16e05be627c701234dc7c13504.zip gcc-8eb12742e8ae5a16e05be627c701234dc7c13504.tar.gz gcc-8eb12742e8ae5a16e05be627c701234dc7c13504.tar.bz2 |
libsanitizer: Hwasan reporting check for dladdr failing
In `GetGlobalSizeFromDescriptor` we use `dladdr` to get info on the the
current address. `dladdr` returns 0 if it failed.
During testing on Linux this returned 0 to indicate failure, and
populated the `info` structure with a NULL pointer which was
dereferenced later.
This patch checks for `dladdr` returning 0, and in that case returns 0
from `GetGlobalSizeFromDescriptor` to indicate failure of identifying
the address.
This occurs when `GetModuleNameAndOffsetForPC` succeeds for some address
not in a dynamically loaded library. One example is when the found
"module" is '[stack]' having come from parsing /proc/self/maps.
Cherry-pick from 83ac18205ec69a00ac2be3b603bc3a61293fbe89.
Differential Revision: https://reviews.llvm.org/D91344
-rw-r--r-- | libsanitizer/hwasan/hwasan_report.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/libsanitizer/hwasan/hwasan_report.cpp b/libsanitizer/hwasan/hwasan_report.cpp index 0be7dee..894a149 100644 --- a/libsanitizer/hwasan/hwasan_report.cpp +++ b/libsanitizer/hwasan/hwasan_report.cpp @@ -254,7 +254,8 @@ static bool TagsEqual(tag_t tag, tag_t *tag_ptr) { static uptr GetGlobalSizeFromDescriptor(uptr ptr) { // Find the ELF object that this global resides in. Dl_info info; - dladdr(reinterpret_cast<void *>(ptr), &info); + if (dladdr(reinterpret_cast<void *>(ptr), &info) == 0) + return 0; auto *ehdr = reinterpret_cast<const ElfW(Ehdr) *>(info.dli_fbase); auto *phdr_begin = reinterpret_cast<const ElfW(Phdr) *>( reinterpret_cast<const u8 *>(ehdr) + ehdr->e_phoff); |