Set of corrections for MSan/NetBSD
Summary: Changes: - Don't attempt to intercept GLIBC specific functions like __strtol_internal. This is required to stop intercepting it as we leak dlerror(3) for dlsym(3) that cannot manage to find a symbol. - Correct interception of fstatat(2). - Don't run a test for fgetgrent_r() that is missing on NetBSD. - Correct link_map location (offset) in Obj_Entry on x86_64 and i386. - Stop intercepting getpshared-like functions in pthread(3). This is feature is not enabled by default on NetBSD as it's unfinished. - Switch intercepting from UTMP to UTMPX functions. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, kcc Reviewed By: vitalybuka Subscribers: llvm-commits, srhines, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D41053 llvm-svn: 320663
This commit is contained in:
parent
30b013bac8
commit
6c18f027ff
|
@ -417,6 +417,16 @@ INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) { // NOLINT
|
||||||
INTERCEPTOR_STRTO_BODY(ret_type, func, nptr, endptr, base, loc); \
|
INTERCEPTOR_STRTO_BODY(ret_type, func, nptr, endptr, base, loc); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SANITIZER_NETBSD
|
||||||
|
#define INTERCEPTORS_STRTO(ret_type, func, char_type) \
|
||||||
|
INTERCEPTOR_STRTO(ret_type, func, char_type) \
|
||||||
|
INTERCEPTOR_STRTO_LOC(ret_type, func##_l, char_type)
|
||||||
|
|
||||||
|
#define INTERCEPTORS_STRTO_BASE(ret_type, func, char_type) \
|
||||||
|
INTERCEPTOR_STRTO_BASE(ret_type, func, char_type) \
|
||||||
|
INTERCEPTOR_STRTO_BASE_LOC(ret_type, func##_l, char_type)
|
||||||
|
|
||||||
|
#else
|
||||||
#define INTERCEPTORS_STRTO(ret_type, func, char_type) \
|
#define INTERCEPTORS_STRTO(ret_type, func, char_type) \
|
||||||
INTERCEPTOR_STRTO(ret_type, func, char_type) \
|
INTERCEPTOR_STRTO(ret_type, func, char_type) \
|
||||||
INTERCEPTOR_STRTO_LOC(ret_type, func##_l, char_type) \
|
INTERCEPTOR_STRTO_LOC(ret_type, func##_l, char_type) \
|
||||||
|
@ -428,6 +438,7 @@ INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) { // NOLINT
|
||||||
INTERCEPTOR_STRTO_BASE_LOC(ret_type, func##_l, char_type) \
|
INTERCEPTOR_STRTO_BASE_LOC(ret_type, func##_l, char_type) \
|
||||||
INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_l, char_type) \
|
INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_l, char_type) \
|
||||||
INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_internal, char_type)
|
INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_internal, char_type)
|
||||||
|
#endif
|
||||||
|
|
||||||
INTERCEPTORS_STRTO(double, strtod, char) // NOLINT
|
INTERCEPTORS_STRTO(double, strtod, char) // NOLINT
|
||||||
INTERCEPTORS_STRTO(float, strtof, char) // NOLINT
|
INTERCEPTORS_STRTO(float, strtof, char) // NOLINT
|
||||||
|
@ -446,11 +457,17 @@ INTERCEPTORS_STRTO_BASE(long long, wcstoll, wchar_t) // NOLINT
|
||||||
INTERCEPTORS_STRTO_BASE(unsigned long, wcstoul, wchar_t) // NOLINT
|
INTERCEPTORS_STRTO_BASE(unsigned long, wcstoul, wchar_t) // NOLINT
|
||||||
INTERCEPTORS_STRTO_BASE(unsigned long long, wcstoull, wchar_t) // NOLINT
|
INTERCEPTORS_STRTO_BASE(unsigned long long, wcstoull, wchar_t) // NOLINT
|
||||||
|
|
||||||
|
#if SANITIZER_NETBSD
|
||||||
|
#define INTERCEPT_STRTO(func) \
|
||||||
|
INTERCEPT_FUNCTION(func); \
|
||||||
|
INTERCEPT_FUNCTION(func##_l);
|
||||||
|
#else
|
||||||
#define INTERCEPT_STRTO(func) \
|
#define INTERCEPT_STRTO(func) \
|
||||||
INTERCEPT_FUNCTION(func); \
|
INTERCEPT_FUNCTION(func); \
|
||||||
INTERCEPT_FUNCTION(func##_l); \
|
INTERCEPT_FUNCTION(func##_l); \
|
||||||
INTERCEPT_FUNCTION(__##func##_l); \
|
INTERCEPT_FUNCTION(__##func##_l); \
|
||||||
INTERCEPT_FUNCTION(__##func##_internal);
|
INTERCEPT_FUNCTION(__##func##_internal);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// FIXME: support *wprintf in common format interceptors.
|
// FIXME: support *wprintf in common format interceptors.
|
||||||
|
@ -697,7 +714,7 @@ INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
|
||||||
#define MSAN_MAYBE_INTERCEPT___FXSTAT64
|
#define MSAN_MAYBE_INTERCEPT___FXSTAT64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SANITIZER_FREEBSD && !SANITIZER_NETBSD
|
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
|
||||||
INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
|
INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
|
||||||
ENSURE_MSAN_INITED();
|
ENSURE_MSAN_INITED();
|
||||||
int res = REAL(fstatat)(fd, pathname, buf, flags);
|
int res = REAL(fstatat)(fd, pathname, buf, flags);
|
||||||
|
|
|
@ -3654,8 +3654,8 @@ TEST(MemorySanitizer, getgrent_r) {
|
||||||
EXPECT_NOT_POISONED(grpres);
|
EXPECT_NOT_POISONED(grpres);
|
||||||
}
|
}
|
||||||
|
|
||||||
// There's no fgetgrent_r() on FreeBSD.
|
// There's no fgetgrent_r() on FreeBSD and NetBSD.
|
||||||
#if !defined(__FreeBSD__)
|
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
|
||||||
TEST(MemorySanitizer, fgetgrent_r) {
|
TEST(MemorySanitizer, fgetgrent_r) {
|
||||||
FILE *fp = fopen("/etc/group", "r");
|
FILE *fp = fopen("/etc/group", "r");
|
||||||
struct group grp;
|
struct group grp;
|
||||||
|
|
|
@ -272,7 +272,8 @@
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
|
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
|
||||||
(SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID)
|
(SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID)
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPSHARED SI_POSIX
|
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPSHARED \
|
||||||
|
(SI_POSIX && !SI_NETBSD)
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_POSIX
|
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_POSIX
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \
|
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \
|
||||||
(SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID)
|
(SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID)
|
||||||
|
@ -280,11 +281,14 @@
|
||||||
(SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID)
|
(SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID)
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED SI_POSIX
|
#define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED \
|
||||||
|
(SI_POSIX && !SI_NETBSD)
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETKIND_NP SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETKIND_NP SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETPSHARED SI_POSIX
|
#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETPSHARED \
|
||||||
|
(SI_POSIX && !SI_NETBSD)
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETCLOCK SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETCLOCK SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED \
|
||||||
|
(SI_LINUX_NOT_ANDROID && !SI_NETBSD)
|
||||||
#define SANITIZER_INTERCEPT_TMPNAM SI_POSIX
|
#define SANITIZER_INTERCEPT_TMPNAM SI_POSIX
|
||||||
#define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
|
#define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
|
||||||
|
@ -372,8 +376,10 @@
|
||||||
#define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
|
#define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
|
||||||
#define SANITIZER_INTERCEPT___LXSTAT64 SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT___LXSTAT64 SI_LINUX_NOT_ANDROID
|
||||||
|
|
||||||
#define SANITIZER_INTERCEPT_UTMP (SI_POSIX && !SI_MAC && !SI_FREEBSD)
|
#define SANITIZER_INTERCEPT_UTMP \
|
||||||
#define SANITIZER_INTERCEPT_UTMPX (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD)
|
(SI_POSIX && !SI_MAC && !SI_FREEBSD && !SI_NETBSD)
|
||||||
|
#define SANITIZER_INTERCEPT_UTMPX \
|
||||||
|
(SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
|
||||||
|
|
||||||
#define SANITIZER_INTERCEPT_GETLOADAVG \
|
#define SANITIZER_INTERCEPT_GETLOADAVG \
|
||||||
(SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
|
(SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD)
|
||||||
|
|
|
@ -25,10 +25,10 @@
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__)
|
||||||
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
|
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
|
||||||
_GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 608)
|
_GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 312)
|
||||||
#elif defined(__i386__)
|
#elif defined(__i386__)
|
||||||
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
|
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
|
||||||
_GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 324)
|
_GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 164)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace __sanitizer {
|
namespace __sanitizer {
|
||||||
|
|
Loading…
Reference in New Issue