[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 04:18:33 PST 2018
devnexen updated this revision to Diff 179622.
devnexen edited the summary of this revision.
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/sanitizer_common/TestCases/Posix/arc4random.cc
Index: test/sanitizer_common/TestCases/Posix/arc4random.cc
===================================================================
--- /dev/null
+++ test/sanitizer_common/TestCases/Posix/arc4random.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_asan -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
+//
+// UNSUPPORTED: linux, darwin, solaris
+
+#include <stdlib.h>
+#include <time.h>
+#include <stdio.h>
+
+int main(void) {
+ printf("arc4random\n");
+ time_t now = ::time(nullptr);
+ char buf[10];
+ arc4random_addrandom((unsigned char *)&now, sizeof(now));
+
+ arc4random_buf(buf, sizeof(buf));
+ return 0;
+ // CHECK: arc4random
+}
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,33 @@
#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 && len)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, buf, len);
+ REAL(arc4random_buf)(buf, len);
+ if (buf && len)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, len);
+}
+
+INTERCEPTOR(void, arc4random_addrandom, u64 *dat, int datlen) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, arc4random_addrandom, dat, datlen);
+ if (dat && datlen)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, dat, datlen);
+ REAL(arc4random_addrandom)(dat, datlen);
+}
+
+#define INIT_ARC4RANDOM \
+ COMMON_INTERCEPT_FUNCTION(arc4random_buf); \
+ COMMON_INTERCEPT_FUNCTION(arc4random_addrandom);
+#else
+#define INIT_ARC4RANDOM
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map =
@@ -9365,6 +9392,7 @@
INIT_VIS;
INIT_CDB;
INIT_GETFSENT;
+ INIT_ARC4RANDOM;
INIT___PRINTF_CHK;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56125.179622.patch
Type: text/x-patch
Size: 2551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181228/1ec15943/attachment.bin>
More information about the llvm-commits
mailing list