This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: guard the wcslen interceptor code with SANITIZER_INTERCEPT_WCSLEN
ClosedPublic

Authored by thurston on May 18 2023, 2:30 PM.

Details

Summary

This patch adds the #if SANITIZER_INTERCEPT_ guard for wcslen, similarly to how all the other
functions are guarded. It was the only missing SANITIZER_INTERCEPT_ guard [1].

This missing guard was discovered while investigating the stage2/hwasan check failure of https://reviews.llvm.org/D150708 ("hwasan: lay groundwork for importing subset of sanitizer_common interceptors [NFC]"), that was seen in https://lab.llvm.org/buildbot/#/builders/236/builds/4069. llvm_build_hwasan/unittests/ADT/./ADTTests had crashed with a backtrace of:
#0 0x0000000000000000 in ?? ()
#1 0x0000aaaaab20e058 in constexpr_wcslen () at /home/thurston/scratch_dir/libcxx_build_hwasan/include/c++/v1/cwchar:195
#2 length () at /home/thurston/scratch_dir/libcxx_build_hwasan/include/c++/v1/
string/char_traits.h:311
#3 basic_string<0> () at /home/thurston/scratch_dir/libcxx_build_hwasan/include/c++/v1/string:904
#4 0x0000aaaaab20d800 in TestBody () at /home/thurston/scratch_dir/llvm-project/llvm/unittests/ADT/HashingTest.cpp:125
...
A disassembly of the binary showed that wcslen interception was present (since it was not guarded by SANITIZER_INTERCEPT_WCSLEN); howver, since INIT_WCSLEN was not called, REAL(wcslen) was null, resulting in the null pointer dereference.

[1] I checked this using "egrep '^#[ ]*define[ ]+(INIT_.*)' sanitizer_common_interceptors.inc | tr -s ' ' | sed -r 's/^# /#/' | cut -d ' ' -f 2 | sort | uniq -c | grep -v '^[ ]*2[ ]'"
The other matches are {INIT_PTHREAD_SETNAME_NP, INIT_QSORT, INIT_SHA2_INTECEPTORS(LEN), INIT_TLS_GET_ADDR, INIT_WAIT4}, which all have good reasons for not having exactly two cases.

Diff Detail

Event Timeline

thurston created this revision.May 18 2023, 2:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 2:30 PM
Herald added a subscriber: Enna1. · View Herald Transcript
thurston requested review of this revision.May 18 2023, 2:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 2:30 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
thurston edited the summary of this revision. (Show Details)May 18 2023, 2:38 PM
thurston added a reviewer: vitalybuka.
thurston added a subscriber: pcc.
thurston retitled this revision from sanitizer_common: guard the wcslen interceptor code with SANITIZER_INTERCEPTOR_WCSLEN to sanitizer_common: guard the wcslen interceptor code with SANITIZER_INTERCEPT_WCSLEN.May 18 2023, 2:45 PM
thurston edited the summary of this revision. (Show Details)
vitalybuka accepted this revision.May 18 2023, 9:06 PM
This revision is now accepted and ready to land.May 18 2023, 9:06 PM
This revision was landed with ongoing or failed builds.May 18 2023, 11:44 PM
This revision was automatically updated to reflect the committed changes.