[compiler-rt] [compiler-rt] intercept the BSD timingsafe api (PR #79192)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 11:04:36 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: David CARLIER (devnexen)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/79192.diff


2 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc (+26-1) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h (+1) 


``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 1b56bebac64e68..9008837f87cabf 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -446,7 +446,7 @@ INTERCEPTOR(char*, textdomain, const char *domainname) {
 #define INIT_TEXTDOMAIN
 #endif
 
-#if SANITIZER_INTERCEPT_STRCMP || SANITIZER_INTERCEPT_MEMCMP
+#if SANITIZER_INTERCEPT_STRCMP || SANITIZER_INTERCEPT_MEMCMP || SANITIZER_INTERCEPT_TIMINGSAFE
 static inline int CharCmpX(unsigned char c1, unsigned char c2) {
   return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1;
 }
@@ -864,6 +864,30 @@ INTERCEPTOR(int, bcmp, const void *a1, const void *a2, uptr size) {
 #define INIT_BCMP
 #endif
 
+#if SANITIZER_INTERCEPT_TIMINGSAFE
+INTERCEPTOR(int, timingsafe_memcmp, const void *a1, const void *a2, uptr size) {
+  if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
+    return internal_memcmp(a1, a2, size);
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, memcmp, a1, a2, size);
+  return MemcmpInterceptorCommon(ctx, REAL(memcmp), a1, a2, size);
+}
+
+INTERCEPTOR(int, timingsafe_bcmp, const void *a1, const void *a2, uptr size) {
+  if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
+    return internal_memcmp(a1, a2, size);
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, bcmp, a1, a2, size);
+  return MemcmpInterceptorCommon(ctx, REAL(bcmp), a1, a2, size);
+}
+
+#define INIT_TIMINGSAFE                            \
+  COMMON_INTERCEPT_FUNCTION(timingsafe_memcmp);    \
+  COMMON_INTERCEPT_FUNCTION(timingsafe_bcmp)
+#else
+#define INIT_TIMINGSAFE
+#endif
+
 #if SANITIZER_INTERCEPT_MEMCHR
 INTERCEPTOR(void*, memchr, const void *s, int c, SIZE_T n) {
   if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
@@ -10302,6 +10326,7 @@ static void InitializeCommonInterceptors() {
   INIT_MEMCHR;
   INIT_MEMCMP;
   INIT_BCMP;
+  INIT_TIMINGSAFE;
   INIT_MEMRCHR;
   INIT_MEMMEM;
   INIT_READ;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 0ce4e9351bc1da..919c8d173b393d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -599,6 +599,7 @@
 #define SANITIZER_INTERCEPT_HEXDUMP SI_FREEBSD
 #define SANITIZER_INTERCEPT_ARGP_PARSE SI_GLIBC
 #define SANITIZER_INTERCEPT_CPUSET_GETAFFINITY SI_FREEBSD
+#define SANITIZER_INTERCEPT_TIMINGSAFE (SI_FREEBSD || SI_NETBSD)
 
 // This macro gives a way for downstream users to override the above
 // interceptor macros irrespective of the platform they are on. They have

``````````

</details>


https://github.com/llvm/llvm-project/pull/79192


More information about the llvm-commits mailing list