Make all sanitizers intercept bzero, bcopy, and bcmp. Despite these functions are deprecated, they are quite popular in legacy codes.
Diff Detail
Event Timeline
please add tests adjacent and similar to test/asan/TestCases/Linux/memmem_test.cc
lib/sanitizer_common/sanitizer_platform_interceptors.h | ||
---|---|---|
277 | I think these need to be SI_LINUX, not 1. |
lib/sanitizer_common/sanitizer_platform_interceptors.h | ||
---|---|---|
277 | Note that these functions are also available on FreeBSD and OSX. |
LGTM, and thanks a lot!
Please watch the bots as the patch is potentially risky for other platforms.
Do you have llvm commit access?
If not, I can land it.
Note that this started causing some memory corruptions when using ASan/TSan from SVN trunk on Darwin. There's nothing wrong with this patch, but it's a binary-compatibility issue. I'll try to see if there's a workaround, but maybe I'll have to disable SANITIZER_INTERCEPT_BZERO on Darwin. I'll keep you posted.
There's nothing wrong with this patch, but it's a binary-compatibility issue
What is the issue with ABI?
A system library requires that bzero doesn't touch some specific register. This is true for the current system implementation of bzero, but not when using the interceptor.
Should we change
#define SANITIZER_INTERCEPT_BZERO SI_LINUX || SI_FREEBSD || SI_MAC
to
#define SANITIZER_INTERCEPT_BZERO SI_LINUX || SI_FREEBSD
?
We think this change breaks lots of tests on our mac/asan bots (https://bugs.chromium.org/p/chromium/issues/detail?id=674435). So +1 to adding a setting for opting out of this. I'd argue that it should be off by default on Darwin until system libraries no longer make this assumption too, else asanified binaries on darwin will be broken by default.
(This currently blocks us from updating clang in chromium.)
Re-opening since the patch was reverted. Please commit again removing SI_MAC and adding a TODO with my name:
// TODO(kuba.brecka): Add SI_MAC when strncpy on Darwin supports bzero // interceptors. https://reviews.llvm.org/D27659. #define SANITIZER_INTERCEPT_BZERO SI_LINUX || SI_FREEBSD
No need to change the other #defines, the issue is only with the bzero interceptor.
dvyukov also says that using WRAP(memset) is a bad idea, even though we have such code in other places.
please see internal b/33656003 about what went wrong with this patch (other than the Mac failure).
Also I've noticed that bzer_test.cc does not actually test anything -- it passes w/o the patch.
Probably you explained it here: https://github.com/google/sanitizers/issues/750#issuecomment-266262859
bzero_test.cc is easy to fix (adding -std=c99). But I am not sure how to properly fix the problem of WRAP though. Does following approach work?
Proposal: a separate CL dedicated for WRAP() issue.
- extract the body of "INTERCEPTOR(void*, memcpy, void *dst, const void *src, uptr size) {"
to a macro.
- replace all WRAP(memcpy) by the macro.
- repeat for others functions WRAP(*).
Any suggestions?
Yes, this should work.
I would actually suggest that you do this only for the functions you change now.
If we need to fix the older interceptors, it's our yak to shave.
First, it creates yet another frame. and may cause confusing stack traces.
Second, it adds a call to memset to the tsan run-time, and we have a test that checks for absence of such calls.
I think these need to be SI_LINUX, not 1.
If we try to intercept a function that does not exist on other OSes things will fail there.