[PATCH] D33325: [asan] Avoid possible deadlock in child process after fork

Maxim Ostapenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 10:46:20 PDT 2017


m.ostapenko created this revision.
m.ostapenko added a project: Sanitizers.
Herald added a subscriber: kubamracek.

This patch addresses https://github.com/google/sanitizers/issues/774
When we fork a multi-threaded process it's possible to deadlock if some thread acquired StackDepot internal lock just before fork. In this case the lock will never be released in child process causing deadlock on following memory alloc/dealloc routine.


Repository:
  rL LLVM

https://reviews.llvm.org/D33325

Files:
  lib/asan/asan_interceptors.cc


Index: lib/asan/asan_interceptors.cc
===================================================================
--- lib/asan/asan_interceptors.cc
+++ lib/asan/asan_interceptors.cc
@@ -22,6 +22,7 @@
 #include "asan_stats.h"
 #include "asan_suppressions.h"
 #include "lsan/lsan_common.h"
+#include "sanitizer_common/sanitizer_stackdepot.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
 #if SANITIZER_POSIX
@@ -711,11 +712,21 @@
 #endif  // ASAN_INTERCEPT___CXA_ATEXIT
 
 #if ASAN_INTERCEPT_FORK
+static void BeforeFork() {
+  StackDepotLockAll();
+}
+
+static void AfterFork() {
+  StackDepotUnlockAll();
+}
+
 INTERCEPTOR(int, fork, void) {
   ENSURE_ASAN_INITED();
+  BeforeFork();
   if (common_flags()->coverage) CovBeforeFork();
   int pid = REAL(fork)();
   if (common_flags()->coverage) CovAfterFork(pid);
+  AfterFork();
   return pid;
 }
 #endif  // ASAN_INTERCEPT_FORK


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33325.99461.patch
Type: text/x-patch
Size: 873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170518/fc277217/attachment.bin>


More information about the llvm-commits mailing list