compiler-rt-netbsd: Add initial support for intercepting ioctl(3)
authorKamil Rytarowski <n54@gmx.com>
Wed, 10 Jan 2018 05:12:39 +0000 (06:12 +0100)
committerKamil Rytarowski <n54@gmx.com>
Wed, 10 Jan 2018 05:12:39 +0000 (06:12 +0100)
Sponsored by <The NetBSD Foundation>

compiler-rt-netbsd/distinfo
compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__common__interceptors.inc
compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc [new file with mode: 0644]
compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__platform__interceptors.h
compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__freebsd.cc [new file with mode: 0644]

index 135a7a36b7439ac5b4309fcff1c6e11de2200616..b34cc385369299b6b1dbc7c7a20dd0e0f03abb0c 100644 (file)
@@ -10,14 +10,16 @@ SHA1 (patch-lib_hwasan_hwasan__interceptors.cc) = 45fd48ae7bb21878432f925dea7af8
 SHA1 (patch-lib_msan_msan__interceptors.cc) = 92ed308e84b0845f15110e0167f265ed5cea2580
 SHA1 (patch-lib_msan_msan__linux.cc) = d75d7587071a9e7a3f6a08a3008af55319e62cab
 SHA1 (patch-lib_sanitizer__common_CMakeLists.txt) = fcbf2987ccab5258fe760aef6ef47bd97e0e0b2c
-SHA1 (patch-lib_sanitizer__common_sanitizer__common__interceptors.inc) = dd3cff382af879365cf78f2539f1789bbbfd3f17
+SHA1 (patch-lib_sanitizer__common_sanitizer__common__interceptors.inc) = b1b91d58b48c6709e653efd4ca0842ade3cde274
 SHA1 (patch-lib_sanitizer__common_sanitizer__common__interceptors__ioctl.inc) = 231f519a0564aa69d746a7f0bbee1b1aeed927a7
 SHA1 (patch-lib_sanitizer__common_sanitizer__internal__defs.h) = 126424635f89439e89371a57754232082e2290c6
+SHA1 (patch-lib_sanitizer__common_sanitizer__linux.cc) = 77b7e2d6b177166c4f83bbd550d0e5bacf9a4cc0
 SHA1 (patch-lib_sanitizer__common_sanitizer__netbsd__interceptors__ioctl.inc) = 0ed3a4a6467c73247e646e2f7ac8f5ea9e3f4da7
 SHA1 (patch-lib_sanitizer__common_sanitizer__netbsd__syscalls.inc) = 6d94bc705f62aeeda363f19a6f073738d3bae3b0
-SHA1 (patch-lib_sanitizer__common_sanitizer__platform__interceptors.h) = f4e69e0e3a27f763bd4064d34eec1aaa965b79b8
+SHA1 (patch-lib_sanitizer__common_sanitizer__platform__interceptors.h) = 6ad9d650ccd9cf4c7ea2afc22fa96bed4d10f249
 SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.cc) = ae99697d5331e6b05f26f74c48119f5cacd4c4e0
 SHA1 (patch-lib_sanitizer__common_sanitizer__platform__limits__netbsd.h) = 19490197ac6d275d777f5b79b96c25aa6d4e3d71
+SHA1 (patch-lib_sanitizer__common_sanitizer__procmaps__freebsd.cc) = c34f35173466e8fd6d65c550f303fdede9e47bec
 SHA1 (patch-lib_scudo_scudo__platform.h) = 6b07d34d5f1209c7f1bf21fdf0cda5cbe88b802f
 SHA1 (patch-lib_tsan_rtl_tsan__interceptors.cc) = 4fbaa64e3f8d28cdbab6783c296dfd31cecb45a5
 SHA1 (patch-test_asan_lit.cfg) = 121fb6db88a17b8b588a40ee022a9a219d84493f
index 09595d7b09954c2316592ee09904f250877fe64f..56f88b5331ad6e36f9f16f07a2240ff7f7afa991 100644 (file)
@@ -18,7 +18,7 @@ $NetBSD$
  INTERCEPTOR(int, ioctl, int d, unsigned long request, ...) {
    // We need a frame pointer, because we call into ioctl_common_[pre|post] which
    // can trigger a report and we need to be able to unwind through this
-@@ -6452,6 +6454,304 @@ INTERCEPTOR(wchar_t *, wcsncat, wchar_t 
+@@ -6452,6 +6454,341 @@ INTERCEPTOR(wchar_t *, wcsncat, wchar_t 
  #define INIT_WCSCAT
  #endif
  
@@ -319,16 +319,54 @@ $NetBSD$
 +#else
 +#define INIT_DEVNAME
 +#endif
++
++#if SANITIZER_INTERCEPT_SYSCTL
++INTERCEPTOR(int, sysctl, int *name, unsigned int namelen, void *oldp, uptr *oldlenp, void *newp, uptr newlen) {
++  void *ctx;
++  int res;
++  COMMON_INTERCEPTOR_ENTER(ctx, sysctl, name, namelen, oldp, oldlenp, newp, newlen);
++  if (name) {
++    COMMON_INTERCEPTOR_READ_RANGE(ctx, name, namelen * sizeof(*name));
++  }
++  if (newp) {
++    COMMON_INTERCEPTOR_READ_RANGE(ctx, newp, newlen);
++  }
++  res = REAL(sysctl)(name, namelen, oldp, oldlenp, newp, newlen);
++  if (!res)
++    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, oldp, *oldlenp);
++  return res;
++}
++
++INTERCEPTOR(int, sysctlbyname, char *sname, void *oldp, uptr *oldlenp, void *newp, uptr newlen) {
++  void *ctx;
++  int res;
++  COMMON_INTERCEPTOR_ENTER(ctx, sysctlbyname, sname, oldp, oldlenp, newp, newlen);
++  if (sname) {
++    COMMON_INTERCEPTOR_READ_RANGE(ctx, sname, REAL(strlen)(sname) + 1);
++  }
++  res = REAL(sysctlbyname)(sname, oldp, oldlenp, newp, newlen);
++  if (!res)
++    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, oldp, *oldlenp);
++  return res;
++}
++
++#define INIT_SYSCTL \
++  COMMON_INTERCEPT_FUNCTION(sysctl); \
++  COMMON_INTERCEPT_FUNCTION(sysctlbyname)
++#else
++#define INIT_SYSCTL
++#endif
 +
  static void InitializeCommonInterceptors() {
    static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
    interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
-@@ -6663,6 +6963,8 @@ static void InitializeCommonInterceptors
+@@ -6663,6 +7000,9 @@ static void InitializeCommonInterceptors
    INIT_GETLOADAVG;
    INIT_WCSLEN;
    INIT_WCSCAT;
 +  INIT_KVM;
 +  INIT_DEVNAME;
++  INIT_SYSCTL;
  
  #if SANITIZER_NETBSD
    COMMON_INTERCEPT_FUNCTION(__libc_mutex_lock);
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__linux.cc
new file mode 100644 (file)
index 0000000..cf8a729
--- /dev/null
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_linux.cc.orig       2018-01-10 05:12:01.286320517 +0000
++++ lib/sanitizer_common/sanitizer_linux.cc
+@@ -89,6 +89,7 @@ extern char **environ;  // provided by c
+ #if SANITIZER_NETBSD
+ #include <limits.h>  // For NAME_MAX
++#define sysctl _sysctl
+ #include <sys/sysctl.h>
+ extern char **environ;  // provided by crt1
+ #include <sys/exec.h>
+@@ -1898,4 +1899,3 @@ bool GetRandom(void *buffer, uptr length
+ #endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
+         // SANITIZER_SOLARIS
+-
index ed12047af246b00415414a66ecd8e6385c628b9b..0d0307f4e5abe609135944a4b3e3fdd25f3643e0 100644 (file)
@@ -2,11 +2,12 @@ $NetBSD$
 
 --- lib/sanitizer_common/sanitizer_platform_interceptors.h.orig        2018-01-08 15:33:13.000000000 +0000
 +++ lib/sanitizer_common/sanitizer_platform_interceptors.h
-@@ -432,4 +432,7 @@
+@@ -432,4 +432,8 @@
  #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA)
  #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID
  
 +#define SANITIZER_INTERCEPT_KVM SI_NETBSD
 +#define SANITIZER_INTERCEPT_DEVNAME SI_NETBSD
++#define SANITIZER_INTERCEPT_SYSCTL SI_NETBSD
 +
  #endif  // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
diff --git a/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__freebsd.cc b/compiler-rt-netbsd/patches/patch-lib_sanitizer__common_sanitizer__procmaps__freebsd.cc
new file mode 100644 (file)
index 0000000..02b61bd
--- /dev/null
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- lib/sanitizer_common/sanitizer_procmaps_freebsd.cc.orig    2018-01-10 05:12:07.886871696 +0000
++++ lib/sanitizer_common/sanitizer_procmaps_freebsd.cc
+@@ -19,6 +19,9 @@
+ #include "sanitizer_procmaps.h"
+ #include <unistd.h>
++#if SANITIZER_NETBSD
++#define sysctl _sysctl // Use an internal symbol to omit the interceptor
++#endif
+ #include <sys/sysctl.h>
+ #if SANITIZER_FREEBSD
+ #include <sys/user.h>