-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[asan] Implement interception on AIX #131870
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
base: main
Are you sure you want to change the base?
Changes from all commits
1c2952c
549b134
d3301a3
6ffa232
4890013
dcde670
c254027
878a567
7cc64a1
4159aa9
b0098db
b159f20
67317ad
16a2d81
0935ed2
30d1f12
38a520d
4c8cd38
8ce7b54
fb70384
b024cac
b57eee8
c3ff763
ab72dfa
72b85c9
93a5093
ad0b183
1b40995
b7d52db
cab7b84
18a60b9
0048e02
54f6a42
cb545f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -56,8 +56,18 @@ namespace __asan { | |||||
| # define ASAN_READ_STRING(ctx, s, n) \ | ||||||
| ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n)) | ||||||
|
|
||||||
| static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) { | ||||||
| #if SANITIZER_INTERCEPT_STRNLEN | ||||||
| static inline void internal_or_real_memcpy(void* new_mem, const char* s, | ||||||
| uptr length) { | ||||||
| # if SANITIZER_INTERCEPT_MEMCPY | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the logical reason to use
|
||||||
| REAL(memcpy)(new_mem, s, length + 1); | ||||||
| # else | ||||||
| internal_memcpy(new_mem, s, length + 1); | ||||||
| # endif | ||||||
| } | ||||||
|
|
||||||
| [[maybe_unused]] static inline uptr MaybeRealStrnlen(const char* s, | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for the addition of |
||||||
| uptr maxlen) { | ||||||
| # if SANITIZER_INTERCEPT_STRNLEN | ||||||
| if (static_cast<bool>(REAL(strnlen))) | ||||||
| return REAL(strnlen)(s, maxlen); | ||||||
| # endif | ||||||
|
|
@@ -282,7 +292,12 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr, | |||||
| # endif | ||||||
| asanThreadArgRetval().Create(detached, {start_routine, arg}, [&]() -> uptr { | ||||||
| result = REAL(pthread_create)(thread, attr, asan_thread_start, t); | ||||||
| // AIX pthread_t is unsigned int. | ||||||
| # if SANITIZER_AIX | ||||||
| return result ? 0 : *(unsigned*)(thread); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Match style with similar line below.
Suggested change
|
||||||
| # else | ||||||
| return result ? 0 : *(uptr *)(thread); | ||||||
| # endif | ||||||
| }); | ||||||
| } | ||||||
| if (result != 0) { | ||||||
|
|
@@ -439,12 +454,14 @@ INTERCEPTOR(int, swapcontext, struct ucontext_t *oucp, | |||||
| #define siglongjmp __siglongjmp14 | ||||||
| #endif | ||||||
|
|
||||||
| # if ASAN_INTERCEPT_LONGJMP | ||||||
| INTERCEPTOR(void, longjmp, void *env, int val) { | ||||||
| __asan_handle_no_return(); | ||||||
| REAL(longjmp)(env, val); | ||||||
| } | ||||||
| # endif | ||||||
|
|
||||||
| #if ASAN_INTERCEPT__LONGJMP | ||||||
| # if ASAN_INTERCEPT__LONGJMP | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a formatting change that should have happened on a separate PR? |
||||||
| INTERCEPTOR(void, _longjmp, void *env, int val) { | ||||||
| __asan_handle_no_return(); | ||||||
| REAL(_longjmp)(env, val); | ||||||
|
|
@@ -515,6 +532,7 @@ DEFINE_REAL(char*, index, const char *string, int c) | |||||
|
|
||||||
| // For both strcat() and strncat() we need to check the validity of |to| | ||||||
| // argument irrespective of the |from| length. | ||||||
| # if ASAN_INTERCEPT_STRCAT | ||||||
| INTERCEPTOR(char *, strcat, char *to, const char *from) { | ||||||
| void *ctx; | ||||||
| ASAN_INTERCEPTOR_ENTER(ctx, strcat); | ||||||
|
|
@@ -554,7 +572,9 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) { | |||||
| } | ||||||
| return REAL(strncat)(to, from, size); | ||||||
| } | ||||||
| # endif | ||||||
|
|
||||||
| # if ASAN_INTERCEPT_STRCPY | ||||||
| INTERCEPTOR(char *, strcpy, char *to, const char *from) { | ||||||
| void *ctx; | ||||||
| ASAN_INTERCEPTOR_ENTER(ctx, strcpy); | ||||||
|
|
@@ -576,6 +596,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) { | |||||
| } | ||||||
| return REAL(strcpy)(to, from); | ||||||
| } | ||||||
| # endif | ||||||
|
|
||||||
| INTERCEPTOR(wchar_t*, wcscpy, wchar_t* to, const wchar_t* from) { | ||||||
| void* ctx; | ||||||
|
|
@@ -617,7 +638,7 @@ INTERCEPTOR(char*, strdup, const char *s) { | |||||
| GET_STACK_TRACE_MALLOC; | ||||||
| void *new_mem = asan_malloc(length + 1, &stack); | ||||||
| if (new_mem) { | ||||||
| REAL(memcpy)(new_mem, s, length + 1); | ||||||
| internal_or_real_memcpy(new_mem, s, length + 1); | ||||||
| } | ||||||
| return reinterpret_cast<char*>(new_mem); | ||||||
| } | ||||||
|
|
@@ -635,12 +656,13 @@ INTERCEPTOR(char*, __strdup, const char *s) { | |||||
| GET_STACK_TRACE_MALLOC; | ||||||
| void *new_mem = asan_malloc(length + 1, &stack); | ||||||
| if (new_mem) { | ||||||
| REAL(memcpy)(new_mem, s, length + 1); | ||||||
| internal_or_real_memcpy(new_mem, s, length + 1); | ||||||
| } | ||||||
| return reinterpret_cast<char*>(new_mem); | ||||||
| } | ||||||
| #endif // ASAN_INTERCEPT___STRDUP | ||||||
|
|
||||||
| # if ASAN_INTERCEPT_STRCPY | ||||||
| INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) { | ||||||
| void *ctx; | ||||||
| ASAN_INTERCEPTOR_ENTER(ctx, strncpy); | ||||||
|
|
@@ -653,6 +675,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) { | |||||
| } | ||||||
| return REAL(strncpy)(to, from, size); | ||||||
| } | ||||||
| # endif | ||||||
|
|
||||||
| INTERCEPTOR(wchar_t*, wcsncpy, wchar_t* to, const wchar_t* from, uptr size) { | ||||||
| void* ctx; | ||||||
|
|
@@ -778,7 +801,15 @@ static void AtCxaAtexit(void *unused) { | |||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| #if ASAN_INTERCEPT___CXA_ATEXIT | ||||||
| # if ASAN_INTERCEPT_EXIT | ||||||
| INTERCEPTOR(void, exit, int status) { | ||||||
| AsanInitFromRtl(); | ||||||
| StopInitOrderChecking(); | ||||||
| REAL(exit)(status); | ||||||
| } | ||||||
| # endif | ||||||
|
Comment on lines
+804
to
+810
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe split adding new interceptors out to a separate PR and focus this PR on compatibility changes to existing sanitizer code. |
||||||
|
|
||||||
| # if ASAN_INTERCEPT___CXA_ATEXIT | ||||||
| INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg, | ||||||
| void *dso_handle) { | ||||||
| if (SANITIZER_APPLE && UNLIKELY(!AsanInited())) | ||||||
|
|
@@ -839,10 +870,14 @@ void InitializeAsanInterceptors() { | |||||
| InitializeSignalInterceptors(); | ||||||
|
|
||||||
| // Intercept str* functions. | ||||||
| # if ASAN_INTERCEPT_STRCAT | ||||||
| ASAN_INTERCEPT_FUNC(strcat); | ||||||
| ASAN_INTERCEPT_FUNC(strcpy); | ||||||
| ASAN_INTERCEPT_FUNC(strncat); | ||||||
| # endif | ||||||
| # if ASAN_INTERCEPT_STRCPY | ||||||
| ASAN_INTERCEPT_FUNC(strcpy); | ||||||
| ASAN_INTERCEPT_FUNC(strncpy); | ||||||
| # endif | ||||||
| ASAN_INTERCEPT_FUNC(strdup); | ||||||
|
|
||||||
| // Intercept wcs* functions. | ||||||
|
|
@@ -867,7 +902,9 @@ void InitializeAsanInterceptors() { | |||||
| # endif | ||||||
|
|
||||||
| // Intercept jump-related functions. | ||||||
| # if ASAN_INTERCEPT_LONGJMP | ||||||
| ASAN_INTERCEPT_FUNC(longjmp); | ||||||
| # endif | ||||||
|
|
||||||
| # if ASAN_INTERCEPT_SWAPCONTEXT | ||||||
| ASAN_INTERCEPT_FUNC(swapcontext); | ||||||
|
|
@@ -934,7 +971,11 @@ void InitializeAsanInterceptors() { | |||||
| ASAN_INTERCEPT_FUNC(atexit); | ||||||
| #endif | ||||||
|
|
||||||
| #if ASAN_INTERCEPT_PTHREAD_ATFORK | ||||||
| # if ASAN_INTERCEPT_EXIT | ||||||
| ASAN_INTERCEPT_FUNC(exit); | ||||||
| # endif | ||||||
|
|
||||||
| # if ASAN_INTERCEPT_PTHREAD_ATFORK | ||||||
| ASAN_INTERCEPT_FUNC(pthread_atfork); | ||||||
| #endif | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,10 +31,22 @@ void InitializePlatformInterceptors(); | |||||||||
| // really defined to replace libc functions. | ||||||||||
| #if !SANITIZER_FUCHSIA | ||||||||||
|
|
||||||||||
| // AIX currently can't retrieve the address of longjmp | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add TODO comment to investigate using Also, for all "AIX currently can't retrieve the address of [ ... ]" comments, the correct phrasing is "Sanitizer on AIX is currently unable to retrieve the address of the real [ ... ] (or an alternative thereto)". |
||||||||||
| # if !SANITIZER_AIX | ||||||||||
| # define ASAN_INTERCEPT_LONGJMP 1 | ||||||||||
| # else | ||||||||||
| # define ASAN_INTERCEPT_LONGJMP 0 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| // Use macro to describe if specific function should be | ||||||||||
| // intercepted on a given platform. | ||||||||||
| # if !SANITIZER_WINDOWS | ||||||||||
| # define ASAN_INTERCEPT__LONGJMP 1 | ||||||||||
| // AIX currently can't retrieve the address of _longjmp | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add TODO comment re: |
||||||||||
| # if !SANITIZER_AIX | ||||||||||
| # define ASAN_INTERCEPT__LONGJMP 1 | ||||||||||
| # else | ||||||||||
| # define ASAN_INTERCEPT__LONGJMP 0 | ||||||||||
| # endif | ||||||||||
| # define ASAN_INTERCEPT_INDEX 1 | ||||||||||
| # define ASAN_INTERCEPT_PTHREAD_CREATE 1 | ||||||||||
| # else | ||||||||||
|
|
@@ -56,7 +68,8 @@ void InitializePlatformInterceptors(); | |||||||||
| # define ASAN_INTERCEPT_SWAPCONTEXT 0 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| # if !SANITIZER_WINDOWS | ||||||||||
| // AIX currently can't retrieve the address of siglongjmp | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add TODO comment re: |
||||||||||
| # if !SANITIZER_WINDOWS && !SANITIZER_AIX | ||||||||||
| # define ASAN_INTERCEPT_SIGLONGJMP 1 | ||||||||||
| # else | ||||||||||
| # define ASAN_INTERCEPT_SIGLONGJMP 0 | ||||||||||
|
|
@@ -84,12 +97,19 @@ void InitializePlatformInterceptors(); | |||||||||
| # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| # if !SANITIZER_WINDOWS | ||||||||||
| // AIX currently can't retrieve the address of __cxa_atexit | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| # if !SANITIZER_WINDOWS && !SANITIZER_AIX | ||||||||||
| # define ASAN_INTERCEPT___CXA_ATEXIT 1 | ||||||||||
| # else | ||||||||||
| # define ASAN_INTERCEPT___CXA_ATEXIT 0 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| # if SANITIZER_AIX | ||||||||||
| # define ASAN_INTERCEPT_EXIT 1 | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is special about AIX that we need it for AIX and not other platforms? What happens on AIX if we don't have this? |
||||||||||
| # else | ||||||||||
| # define ASAN_INTERCEPT_EXIT 0 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| # if SANITIZER_NETBSD | ||||||||||
| # define ASAN_INTERCEPT_ATEXIT 1 | ||||||||||
| # else | ||||||||||
|
|
@@ -110,6 +130,15 @@ void InitializePlatformInterceptors(); | |||||||||
| # define ASAN_INTERCEPT_TRYJOIN 0 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| // AIX currently can't retrieve the address of strcat or strcpy | ||||||||||
| # if SANITIZER_AIX | ||||||||||
| # define ASAN_INTERCEPT_STRCAT 0 | ||||||||||
| # define ASAN_INTERCEPT_STRCPY 0 | ||||||||||
| # else | ||||||||||
| # define ASAN_INTERCEPT_STRCAT 1 | ||||||||||
| # define ASAN_INTERCEPT_STRCPY 1 | ||||||||||
| # endif | ||||||||||
|
|
||||||||||
| # if SANITIZER_LINUX && \ | ||||||||||
| (defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \ | ||||||||||
| defined(__x86_64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment as written is misleading: it implies that being unable to retrieve an address for the real
memcpyas a member of a shared library (which, afaik, is not something that we plan to change) necessarily means that we have to useinternal_memcpy(i.e., there are no other options).Perhaps change this comment to reflect any future plans to use
___memcpyon AIX? Better yet: Update this PR to make use of___memcpy(which is what thememcpywrapper that AIXlibcprovides for static linking forwards to).