Skip to content

Commit 7e88686

Browse files
committed
[sanitizer_common] Intercept timespec_get except for hwasan
Intercept timespec_get for all sanitizers except for hwasan
1 parent 53a6a11 commit 7e88686

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

compiler-rt/lib/hwasan/hwasan_platform_interceptors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@
209209
#undef SANITIZER_INTERCEPT_TIME
210210
#define SANITIZER_INTERCEPT_TIME 0
211211

212+
#undef SANITIZER_INTERCEPT_TIMESPEC_GET
213+
#define SANITIZER_INTERCEPT_TIMESPEC_GET 0
214+
212215
#undef SANITIZER_INTERCEPT_GLOB
213216
#define SANITIZER_INTERCEPT_GLOB 0
214217

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,24 @@ INTERCEPTOR(int, setitimer, int which, const void *new_value, void *old_value) {
23892389
#define INIT_GETITIMER
23902390
#endif
23912391

2392+
#if SANITIZER_INTERCEPT_TIMESPEC_GET
2393+
INTERCEPTOR(int, timespec_get, struct __sanitizer_timespec *ts, int base) {
2394+
void *ctx;
2395+
COMMON_INTERCEPTOR_ENTER(ctx, timespec_get, ts, base);
2396+
// FIXME: under ASan the call below may write to freed memory and corrupt
2397+
// its metadata. See
2398+
// https://github.com/google/sanitizers/issues/321.
2399+
int res = REAL(timespec_get)(ts, base);
2400+
if (res) {
2401+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ts, sizeof(struct __sanitizer_timespec));
2402+
}
2403+
return res;
2404+
}
2405+
#define INIT_TIMESPEC_GET COMMON_INTERCEPT_FUNCTION(timespec_get);
2406+
#else
2407+
#define INIT_TIMESPEC_GET
2408+
#endif
2409+
23922410
#if SANITIZER_INTERCEPT_GLOB
23932411
static void unpoison_glob_t(void *ctx, __sanitizer_glob_t *pglob) {
23942412
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pglob, sizeof(*pglob));
@@ -10324,6 +10342,7 @@ static void InitializeCommonInterceptors() {
1032410342
INIT_TIMER_CREATE;
1032510343
INIT_GETITIMER;
1032610344
INIT_TIME;
10345+
INIT_TIMESPEC_GET;
1032710346
INIT_GLOB;
1032810347
INIT_GLOB64;
1032910348
INIT___B64_TO;

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
210210
#define SANITIZER_INTERCEPT_PREAD64 (SI_GLIBC || SI_SOLARIS32)
211211
#define SANITIZER_INTERCEPT_PWRITE64 (SI_GLIBC || SI_SOLARIS32)
212212

213-
#define SANITIZER_INTERCEPT_LSEEK64 (SI_GLIBC || SI_SOLARIS32)
214-
215213
#define SANITIZER_INTERCEPT_READV SI_POSIX
216214
#define SANITIZER_INTERCEPT_WRITEV SI_POSIX
217215

@@ -263,6 +261,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
263261
#define SANITIZER_INTERCEPT_TIMER_CREATE SI_GLIBC
264262
#define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
265263
#define SANITIZER_INTERCEPT_TIME SI_POSIX
264+
#define SANITIZER_INTERCEPT_TIMESPEC_GET SI_LINUX
266265
#define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
267266
#define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
268267
#define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID

0 commit comments

Comments
 (0)