[sanitizers] Fix interception of GLibc regexec
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 8 Mar 2021 10:09:42 +0000 (10:09 +0000)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 8 Mar 2021 10:53:55 +0000 (10:53 +0000)
commitad294e572bc5c16f9dc420cc994322de6ca3fbfb
treebca0be2f41ba2720d0590b4b27db51b922bdc4d8
parent1f1b15508618c57357658cf0855f645a6618efb5
[sanitizers] Fix interception of GLibc regexec

Previously, on GLibc systems, the interceptor was calling __compat_regexec
(regexec@GLIBC_2.2.5) insead of the newer __regexec (regexec@GLIBC_2.3.4).
The __compat_regexec strips the REG_STARTEND flag but does not report an
error if other flags are present. This can result in infinite loops for
programs that use REG_STARTEND to find all matches inside a buffer (since
ignoring REG_STARTEND means that the search always starts from the first
character).

The underlying issue is that GLibc's dlsym(RTLD_NEXT, ...) appears to
always return the oldest versioned symbol instead of the default. This
means it does not match the behaviour of dlsym(RTLD_DEFAULT, ...) or the
behaviour documented in the manpage.

It appears a similar issue was encountered with realpath and worked around
in 77ef78a0a5dbaa364529bd05ed7a7bd9a71dd8d4.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=14932 and
https://sourceware.org/bugzilla/show_bug.cgi?id=1319.

Fixes https://github.com/google/sanitizers/issues/1371

Reviewed By: #sanitizers, vitalybuka, marxin

Differential Revision: https://reviews.llvm.org/D96348
compiler-rt/lib/asan/asan_interceptors.cpp
compiler-rt/lib/asan/asan_interceptors.h
compiler-rt/lib/memprof/memprof_interceptors.cpp
compiler-rt/lib/memprof/memprof_interceptors.h
compiler-rt/lib/msan/msan_interceptors.cpp
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
compiler-rt/test/sanitizer_common/TestCases/Posix/regex_startend.cpp [new file with mode: 0644]