-
Notifications
You must be signed in to change notification settings - Fork 13.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
Open
jakeegan
wants to merge
19
commits into
llvm:main
Choose a base branch
from
jakeegan:asan_common3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1c2952c
[sanitizer_common] Implement interceptors for AIX
jakeegan 549b134
Define SANITIZER_AIX temporarily to build
jakeegan d3301a3
Revert "Define SANITIZER_AIX temporarily to build"
jakeegan 6ffa232
convert to preprocessor directives
jakeegan 4890013
Fix formatting
jakeegan dcde670
Add asan interceptor part
jakeegan c254027
Merge branch 'main' into asan_common3
jakeegan 878a567
Remove typo
jakeegan 7cc64a1
Fix undeclared identifier
jakeegan 4159aa9
Correct backslash mistake
jakeegan b0098db
Fix return
jakeegan b159f20
Fix formatting
jakeegan 67317ad
Move misplaced endif
jakeegan 16a2d81
Split code to different PRs
jakeegan 0935ed2
Use proper naming convention
jakeegan 30d1f12
Move return
jakeegan 38a520d
Remove accidental change
jakeegan 4c8cd38
Remove accidental change
jakeegan 8ce7b54
Fix build fail
jakeegan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ namespace __asan { | |
# define ASAN_READ_STRING(ctx, s, n) \ | ||
ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n)) | ||
|
||
# if ASAN_INTERCEPT_STRCAT || ASAN_INTERCEPT_STRCPY | ||
static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) { | ||
#if SANITIZER_INTERCEPT_STRNLEN | ||
if (REAL(strnlen)) { | ||
|
@@ -64,6 +65,7 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) { | |
#endif | ||
return internal_strnlen(s, maxlen); | ||
} | ||
# endif | ||
|
||
void SetThreadName(const char *name) { | ||
AsanThread *t = GetCurrentThread(); | ||
|
@@ -275,7 +277,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 int *)(thread); | ||
# else | ||
return result ? 0 : *(uptr *)(thread); | ||
# endif | ||
}); | ||
} | ||
if (result != 0) { | ||
|
@@ -432,12 +439,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 | ||
INTERCEPTOR(void, _longjmp, void *env, int val) { | ||
__asan_handle_no_return(); | ||
REAL(_longjmp)(env, val); | ||
|
@@ -508,6 +517,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); | ||
|
@@ -547,7 +557,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); | ||
|
@@ -569,6 +581,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) { | |
} | ||
return REAL(strcpy)(to, from); | ||
} | ||
# endif | ||
|
||
// Windows doesn't always define the strdup identifier, | ||
// and when it does it's a macro defined to either _strdup | ||
|
@@ -596,7 +609,13 @@ INTERCEPTOR(char*, strdup, const char *s) { | |
GET_STACK_TRACE_MALLOC; | ||
void *new_mem = asan_malloc(length + 1, &stack); | ||
if (new_mem) { | ||
# if SANITIZER_AIX | ||
// memcpy is a static function defined in libc.a on AIX. It can not be | ||
// intercepted, so REAL(memcpy) is null on AIX. Use internal_memcpy instead. | ||
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. Can you please extract 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. #if SANITIZER_INTERCEPT_MEMCPY rather than SANITIZER_AIX? |
||
internal_memcpy(new_mem, s, length + 1); | ||
# else | ||
REAL(memcpy)(new_mem, s, length + 1); | ||
# endif | ||
} | ||
return reinterpret_cast<char*>(new_mem); | ||
} | ||
|
@@ -614,12 +633,17 @@ INTERCEPTOR(char*, __strdup, const char *s) { | |
GET_STACK_TRACE_MALLOC; | ||
void *new_mem = asan_malloc(length + 1, &stack); | ||
if (new_mem) { | ||
# if SANITIZER_AIX | ||
internal_memcpy(new_mem, s, length + 1); | ||
# else | ||
REAL(memcpy)(new_mem, s, length + 1); | ||
# endif | ||
} | ||
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); | ||
|
@@ -632,6 +656,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) { | |
} | ||
return REAL(strncpy)(to, from, size); | ||
} | ||
# endif | ||
|
||
template <typename Fn> | ||
static ALWAYS_INLINE auto StrtolImpl(void *ctx, Fn real, const char *nptr, | ||
|
@@ -743,7 +768,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 | ||
|
||
# if ASAN_INTERCEPT___CXA_ATEXIT | ||
INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg, | ||
void *dso_handle) { | ||
if (SANITIZER_APPLE && UNLIKELY(!AsanInited())) | ||
|
@@ -804,10 +837,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); | ||
# if ASAN_INTERCEPT___STRDUP | ||
ASAN_INTERCEPT_FUNC(__strdup); | ||
|
@@ -827,7 +864,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); | ||
|
@@ -894,7 +933,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 | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's use
[[maybe_unused]]
instead of #if