-
Notifications
You must be signed in to change notification settings - Fork 13.7k
release/19.x: [lsan] Fix free(NULL) interception during initialization #121100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@tmiasko @vitalybuka @vitalybuka What do you think about merging this PR to the release branch? |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: None (llvmbot) ChangesBackport 1797174 ae0ed3d d9ed8b0 Requested by: @nikic Full diff: https://github.com/llvm/llvm-project/pull/121100.diff 2 Files Affected:
diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index b569c337e97641..efbf2fdfb0ab3f 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -77,6 +77,8 @@ INTERCEPTOR(void*, malloc, uptr size) {
}
INTERCEPTOR(void, free, void *p) {
+ if (UNLIKELY(!p))
+ return;
if (DlsymAlloc::PointerIsMine(p))
return DlsymAlloc::Free(p);
ENSURE_LSAN_INITED;
diff --git a/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
new file mode 100644
index 00000000000000..7b5b9cf34a90f9
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
@@ -0,0 +1,60 @@
+// RUN: %clang -O0 %s -o %t && %run %t
+
+// FIXME: TSAN does not use DlsymAlloc.
+// UNSUPPORTED: tsan
+// FIXME: investigate why this fails on macos
+// UNSUPPORTED: darwin
+
+#include <stdlib.h>
+
+const char *test() __attribute__((disable_sanitizer_instrumentation)) {
+ void *volatile p = malloc(3);
+ p = realloc(p, 7);
+ free(p);
+
+ p = calloc(3, 7);
+ free(p);
+
+ free(NULL);
+
+ return "";
+}
+
+const char *__asan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__hwasan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__lsan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__memprof_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__msan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__nsan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__rtsan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__tsan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+const char *__ubsan_default_options()
+ __attribute__((disable_sanitizer_instrumentation)) {
+ return test();
+}
+
+int main(int argc, char **argv) { return 0; }
|
Almost all sanitizers already support the test. * Tsan does not use DlsymAlloc yet. * Lsan will support with llvm#106912. memprof,rtsan,nsan are not tested as part of sanitizer_common, but we should keep them here to show up when it happen. --------- Co-authored-by: Xiaofeng Tian <[email protected]> (cherry picked from commit 1797174)
Previously an attempt to free a null pointer during initialization would fail on ENSURE_LSAN_INITED assertion (since a null pointer is not owned by DlsymAlloc). (cherry picked from commit ae0ed3d)
…108439) With llvm#106912, the test now fails on macos, e.g. https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2058/. (cherry picked from commit d9ed8b0)
@nikic (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. |
Backport 1797174 ae0ed3d d9ed8b0
Requested by: @nikic