[compiler-rt] [compiler-rt][msan] Guard shmat interceptor w SANITIZER_INTERCEPT_SHMCTL (PR #189198)
Brian Cain via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 28 20:17:25 PDT 2026
https://github.com/androm3da updated https://github.com/llvm/llvm-project/pull/189198
>From 3026ff34a0982b74078b4f9fba32a5e8050c6f0e Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Sat, 28 Mar 2026 14:02:50 -0700
Subject: [PATCH 1/2] [compiler-rt][msan] Guard shmat interceptor behind
SANITIZER_INTERCEPT_SHMCTL
The shmat interceptor calls REAL(shmctl), but shmctl is not
intercepted on all targets (e.g. 32-bit Linux with musl). Guard
shmat behind SANITIZER_INTERCEPT_SHMCTL and use a MSAN_MAYBE_INTERCEPT
pattern consistent with other conditional interceptors.
---
compiler-rt/lib/msan/msan_interceptors.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index bc28434d1d494..84f75a2c4bb65 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1672,6 +1672,7 @@ static int msan_dl_iterate_phdr_cb(__sanitizer_dl_phdr_info *info, SIZE_T size,
return cbdata->callback(info, size, cbdata->data);
}
+#if SANITIZER_INTERCEPT_SHMCTL
INTERCEPTOR(void *, shmat, int shmid, const void *shmaddr, int shmflg) {
ENSURE_MSAN_INITED();
void *p = REAL(shmat)(shmid, shmaddr, shmflg);
@@ -1684,6 +1685,10 @@ INTERCEPTOR(void *, shmat, int shmid, const void *shmaddr, int shmflg) {
}
return p;
}
+# define MSAN_MAYBE_INTERCEPT_SHMAT INTERCEPT_FUNCTION(shmat)
+#else
+# define MSAN_MAYBE_INTERCEPT_SHMAT
+#endif
INTERCEPTOR(int, dl_iterate_phdr, dl_iterate_phdr_cb callback, void *data) {
void *ctx;
@@ -1944,7 +1949,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(tzset);
INTERCEPT_FUNCTION(atexit);
INTERCEPT_FUNCTION(__cxa_atexit);
- INTERCEPT_FUNCTION(shmat);
+ MSAN_MAYBE_INTERCEPT_SHMAT;
MSAN_MAYBE_INTERCEPT_OPENPTY;
MSAN_MAYBE_INTERCEPT_FORKPTY;
>From 873b59302eff655e7701b74f6560b53bbc7ea775 Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Sat, 28 Mar 2026 20:16:43 -0700
Subject: [PATCH 2/2] fixup! [compiler-rt][msan] Guard shmat interceptor behind
SANITIZER_INTERCEPT_SHMCTL
Define SANITIZER_INTERCEPT_SHMAT in platform header
Add a dedicated SANITIZER_INTERCEPT_SHMAT macro derived from
SANITIZER_INTERCEPT_SHMCTL so the guard on shmat does not look
like a typo.
---
compiler-rt/lib/msan/msan_interceptors.cpp | 2 +-
.../lib/sanitizer_common/sanitizer_platform_interceptors.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index 84f75a2c4bb65..ce2eae02d4179 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -1672,7 +1672,7 @@ static int msan_dl_iterate_phdr_cb(__sanitizer_dl_phdr_info *info, SIZE_T size,
return cbdata->callback(info, size, cbdata->data);
}
-#if SANITIZER_INTERCEPT_SHMCTL
+#if SANITIZER_INTERCEPT_SHMAT
INTERCEPTOR(void *, shmat, int shmid, const void *shmaddr, int shmflg) {
ENSURE_MSAN_INITED();
void *p = REAL(shmat)(shmid, shmaddr, shmflg);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 1e5f1360321ff..9f6fc4e9b9bfa 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -393,6 +393,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
#define SANITIZER_INTERCEPT_SHMCTL \
(((SI_FREEBSD || SI_LINUX_NOT_ANDROID) && SANITIZER_WORDSIZE == 64) || \
SI_NETBSD || SI_SOLARIS)
+// shmat calls REAL(shmctl), so it requires shmctl interception.
+#define SANITIZER_INTERCEPT_SHMAT SANITIZER_INTERCEPT_SHMCTL
#define SANITIZER_INTERCEPT_RANDOM_R SI_GLIBC
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET SI_POSIX
#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \
More information about the llvm-commits
mailing list