[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 15:28:52 PDT 2026
https://github.com/androm3da created https://github.com/llvm/llvm-project/pull/189198
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.
>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] [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;
More information about the llvm-commits
mailing list