-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[win/asan] Don't intercept memset etc. in ntdll #120397
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
Changes from 1 commit
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 |
---|---|---|
|
@@ -1177,8 +1177,7 @@ static void **InterestingDLLsAvailable() { | |
"libc++.dll", // libc++ | ||
"libunwind.dll", // libunwind | ||
# endif | ||
// NTDLL should go last as it exports some functions that we should | ||
// override in the CRT [presumably only used internally]. | ||
// NTDLL must go last as it gets special treatment in OverrideFunction. | ||
"ntdll.dll", | ||
NULL | ||
}; | ||
|
@@ -1281,9 +1280,22 @@ uptr InternalGetProcAddress(void *module, const char *func_name) { | |
|
||
bool OverrideFunction( | ||
const char *func_name, uptr new_func, uptr *orig_old_func) { | ||
static const char *kNtDllIgnore[] = { | ||
"memcmp", "memcpy", "memmove", "memset" | ||
}; | ||
|
||
bool hooked = false; | ||
void **DLLs = InterestingDLLsAvailable(); | ||
for (size_t i = 0; DLLs[i]; ++i) { | ||
if (DLLs[i + 1] == nullptr) { | ||
// This is the last DLL, i.e. NTDLL. It exports some functions that | ||
// we only want to override in the CRT. | ||
for (const char *ignored : kNtDllIgnore) { | ||
if (strcmp(func_name, ignored) == 0) | ||
return hooked; | ||
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, let's just 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. It's a nested loop, I think returning is the most straight-forward. |
||
} | ||
} | ||
|
||
uptr func_addr = InternalGetProcAddress(DLLs[i], func_name); | ||
if (func_addr && | ||
OverrideFunction(func_addr, new_func, orig_old_func)) { | ||
|
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.
Is there some
internal_strcmp
function we should be calling instead in order to avoid libc re-entrancy, like hitting the ASan strcmp interceptor, for example?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.
Done.