[PATCH] D58850: [sanitizer] Intercept bzero.
Evgenii Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 15:01:37 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT355347: [sanitizer] Intercept bzero. (authored by eugenis, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D58850?vs=189018&id=189212#toc
Repository:
rCRT Compiler Runtime
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58850/new/
https://reviews.llvm.org/D58850
Files:
lib/sanitizer_common/sanitizer_common_interceptors.inc
lib/sanitizer_common/sanitizer_platform_interceptors.h
test/asan/TestCases/Linux/bzero.cc
test/msan/Linux/bzero.cc
Index: test/msan/Linux/bzero.cc
===================================================================
--- test/msan/Linux/bzero.cc
+++ test/msan/Linux/bzero.cc
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+
+// REQUIRES: !android
+
+#include <assert.h>
+#include <strings.h>
+#include <sanitizer/msan_interface.h>
+
+int main(int argc, char *argv[]) {
+ char buf[100];
+ assert(0 == __msan_test_shadow(buf, sizeof(buf)));
+ // *& to suppress bzero-to-memset optimization.
+ (*&bzero)(buf, 50);
+ assert(50 == __msan_test_shadow(buf, sizeof(buf)));
+ return 0;
+}
Index: test/asan/TestCases/Linux/bzero.cc
===================================================================
--- test/asan/TestCases/Linux/bzero.cc
+++ test/asan/TestCases/Linux/bzero.cc
@@ -0,0 +1,15 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: !android
+
+#include <assert.h>
+#include <strings.h>
+
+int main(int argc, char *argv[]) {
+ char buf[100];
+ // *& to suppress bzero-to-memset optimization.
+ (*&bzero)(buf, sizeof(buf) + 1);
+ // CHECK: AddressSanitizer: stack-buffer-overflow
+ // CHECK-NEXT: WRITE of size 101 at
+ return 0;
+}
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -5529,12 +5529,21 @@
void *ctx;
COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, 0, size);
}
-
#define INIT___BZERO COMMON_INTERCEPT_FUNCTION(__bzero);
#else
#define INIT___BZERO
#endif // SANITIZER_INTERCEPT___BZERO
+#if SANITIZER_INTERCEPT_BZERO
+INTERCEPTOR(void *, bzero, void *block, uptr size) {
+ void *ctx;
+ COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, 0, size);
+}
+#define INIT_BZERO COMMON_INTERCEPT_FUNCTION(bzero);
+#else
+#define INIT_BZERO
+#endif // SANITIZER_INTERCEPT_BZERO
+
#if SANITIZER_INTERCEPT_FTIME
INTERCEPTOR(int, ftime, __sanitizer_timeb *tp) {
void *ctx;
@@ -9693,6 +9702,7 @@
INIT_CAPGET;
INIT_AEABI_MEM;
INIT___BZERO;
+ INIT_BZERO;
INIT_FTIME;
INIT_XDR;
INIT_TSEARCH;
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -411,7 +411,8 @@
#else
#define SANITIZER_INTERCEPT_AEABI_MEM 0
#endif
-#define SANITIZER_INTERCEPT___BZERO SI_MAC
+#define SANITIZER_INTERCEPT___BZERO SI_MAC || SI_LINUX_NOT_ANDROID
+#define SANITIZER_INTERCEPT_BZERO SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_FTIME \
(!SI_FREEBSD && !SI_NETBSD && !SI_OPENBSD && SI_POSIX)
#define SANITIZER_INTERCEPT_XDR SI_LINUX_NOT_ANDROID || SI_SOLARIS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58850.189212.patch
Type: text/x-patch
Size: 2827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190304/a907471b/attachment.bin>
More information about the llvm-commits
mailing list