[PATCH] D58221: [msan] Don't delete MSanAtExitRecord
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 13 17:42:08 PST 2019
vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added subscribers: llvm-commits, Sanitizers, jdoerfert, jfb.
Herald added projects: Sanitizers, LLVM.
Pre 2.27 libc can run same atexit handler twice
We will keep MSanAtExitRecord and reset fun to mark it as executed.
Fix PR40162
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D58221
Files:
compiler-rt/lib/msan/msan_interceptors.cc
compiler-rt/test/msan/cxa_atexit_race.cc
Index: compiler-rt/test/msan/cxa_atexit_race.cc
===================================================================
--- /dev/null
+++ compiler-rt/test/msan/cxa_atexit_race.cc
@@ -0,0 +1,28 @@
+// RUN: %clang_msan %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+extern "C" int
+__cxa_atexit(void (*func)(void *), void *arg, void *d);
+
+void handler(void *) {
+}
+
+void *thread(void *) {
+ for (;;)
+ __cxa_atexit(&handler, 0, (void *)&handler);
+}
+
+int main(void) {
+ printf("TEST_MAIN\n");
+ pthread_t pt;
+ for (int i = 0; i < 2; ++i)
+ pthread_create(&pt, 0, &thread, 0);
+ sleep(1);
+ return 1;
+}
+// CHECK: TEST_MAIN
+// CHECK-NOT: MemorySanitizer
Index: compiler-rt/lib/msan/msan_interceptors.cc
===================================================================
--- compiler-rt/lib/msan/msan_interceptors.cc
+++ compiler-rt/lib/msan/msan_interceptors.cc
@@ -1118,8 +1118,12 @@
void MSanCxaAtExitWrapper(void *arg) {
UnpoisonParam(1);
MSanAtExitRecord *r = (MSanAtExitRecord *)arg;
+ // libc before 2.27 had race which caused occasional double handler execution
+ // https://sourceware.org/ml/libc-alpha/2017-08/msg01204.html
+ if (!r->func)
+ return;
r->func(r->arg);
- InternalFree(r);
+ r->func = nullptr;
}
static int setup_at_exit_wrapper(void(*f)(), void *arg, void *dso);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58221.186781.patch
Type: text/x-patch
Size: 1409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190214/102417dc/attachment.bin>
More information about the llvm-commits
mailing list