Skip to content

[sanitizer_common] Intercept timespec_get except for hwasan #117080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler-rt/lib/hwasan/hwasan_platform_interceptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
#undef SANITIZER_INTERCEPT_TIME
#define SANITIZER_INTERCEPT_TIME 0

#undef SANITIZER_INTERCEPT_TIMESPEC_GET
#define SANITIZER_INTERCEPT_TIMESPEC_GET 0

#undef SANITIZER_INTERCEPT_GLOB
#define SANITIZER_INTERCEPT_GLOB 0

Expand Down
20 changes: 20 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,25 @@ INTERCEPTOR(int, setitimer, int which, const void *new_value, void *old_value) {
#define INIT_GETITIMER
#endif

#if SANITIZER_INTERCEPT_TIMESPEC_GET
INTERCEPTOR(int, timespec_get, struct __sanitizer_timespec *ts, int base) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, timespec_get, ts, base);
// We don't yet know if ts is addressable, so we use our own scratch buffer
struct __sanitizer_timespec ts_local;
int res = REAL(timespec_get)(&ts_local, base);
if (res) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ts,
sizeof(struct __sanitizer_timespec));
internal_memcpy(ts, &ts_local, sizeof(struct __sanitizer_timespec));
}
return res;
}
# define INIT_TIMESPEC_GET COMMON_INTERCEPT_FUNCTION(timespec_get);
#else
# define INIT_TIMESPEC_GET
#endif

#if SANITIZER_INTERCEPT_GLOB
static void unpoison_glob_t(void *ctx, __sanitizer_glob_t *pglob) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pglob, sizeof(*pglob));
Expand Down Expand Up @@ -10324,6 +10343,7 @@ static void InitializeCommonInterceptors() {
INIT_TIMER_CREATE;
INIT_GETITIMER;
INIT_TIME;
INIT_TIMESPEC_GET;
INIT_GLOB;
INIT_GLOB64;
INIT___B64_TO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
#define SANITIZER_INTERCEPT_TIMER_CREATE SI_GLIBC
#define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
#define SANITIZER_INTERCEPT_TIME SI_POSIX
#define SANITIZER_INTERCEPT_TIMESPEC_GET SI_LINUX
#define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
#define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
#define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID
Expand Down
Loading