[PATCH] D56125: [Sanitizer] Intercept arc4random_buf on FreeBSD/NetBSD
David CARLIER via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 28 03:40:57 PST 2018
devnexen updated this revision to Diff 179618.
devnexen added a comment.
Fixing unit test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56125/new/
https://reviews.llvm.org/D56125
Files:
lib/sanitizer_common/sanitizer_common_interceptors.inc
lib/sanitizer_common/sanitizer_platform_interceptors.h
test/asan/TestCases/Posix/arc4random.cc
Index: test/asan/TestCases/Posix/arc4random.cc
===================================================================
--- /dev/null
+++ test/asan/TestCases/Posix/arc4random.cc
@@ -0,0 +1,24 @@
+// RUN: %clangxx_asan -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
+//
+// Darwin supports it, would need interception in its specific code before enabling it.
+// Linux does not support it but only via third party library.
+// Android supports it via bionic however it is known to have issue with older versions
+// of the implementations. Can be enabled by an Android committer later on if necessary
+// once there is more 'certainity'/been more tested.
+// UNSUPPORTED: linux, darwin, solaris
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void) {
+ printf("arc4random\n");
+ char buf[10];
+ char *p = &buf[0];
+
+ arc4random_buf(p, sizeof(buf));
+ p = &buf[1];
+ arc4random_buf(p, sizeof(buf));
+ return 0;
+ // CHECK: arc4random
+ // CHECK: {{AddressSanitizer: stack-buffer-overflow}}
+}
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -546,5 +546,6 @@
#define SANITIZER_INTERCEPT_CDB SI_NETBSD
#define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD)
+#define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD)
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9084,6 +9084,24 @@
#else
#define INIT_GETFSENT
#endif
+
+#if SANITIZER_INTERCEPT_ARC4RANDOM
+INTERCEPTOR(void, arc4random_buf, void *buf, SIZE_T len) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, arc4random_buf, buf, len);
+ if (buf)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, buf, len);
+ REAL(arc4random_buf)(buf, len);
+ if (buf)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, len);
+}
+
+#define INIT_ARC4RANDOM \
+ COMMON_INTERCEPT_FUNCTION(arc4random_buf);
+#else
+#define INIT_ARC4RANDOM
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map =
@@ -9365,6 +9383,7 @@
INIT_VIS;
INIT_CDB;
INIT_GETFSENT;
+ INIT_ARC4RANDOM;
INIT___PRINTF_CHK;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56125.179618.patch
Type: text/x-patch
Size: 2586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181228/762ce161/attachment.bin>
More information about the llvm-commits
mailing list