From: Matthew Malcomson Date: Wed, 25 Nov 2020 16:31:35 +0000 (+0000) Subject: libsanitizer: Hwasan reporting check for dladdr failing X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8eb12742e8ae5a16e05be627c701234dc7c13504;p=gcc.git 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 --- diff --git a/libsanitizer/hwasan/hwasan_report.cpp b/libsanitizer/hwasan/hwasan_report.cpp index 0be7deeaee1..894a149775f 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(ptr), &info); + if (dladdr(reinterpret_cast(ptr), &info) == 0) + return 0; auto *ehdr = reinterpret_cast(info.dli_fbase); auto *phdr_begin = reinterpret_cast( reinterpret_cast(ehdr) + ehdr->e_phoff);