Skip to content
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

Deadlock in glib between fork and exec #774

Closed
EricRahm opened this issue Mar 1, 2017 · 4 comments
Closed

Deadlock in glib between fork and exec #774

EricRahm opened this issue Mar 1, 2017 · 4 comments

Comments

@EricRahm
Copy link

EricRahm commented Mar 1, 2017

The Firefox project is seeing occasional deadlocks when running Firefox under ASAN on Linux. The root cause has been tracked down to glib allocating and freeing memory between fork and exec. The hypothesis is that when the process is forked an internal ASAN lock is held, the forked process then tries to acquire the lock when allocating or freeing and becomes deadlocked.

Example stack:

(gdb) info threads
Id Target Id Frame

  • 1 Thread 0x7f9062736700 (LWP 1728) "dconf worker" 0x000000000041eb1d in proc_yield ()
    at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_x86.h:23

(gdb) bt
#0 0x000000000041eb1d in LockSlow() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_atomic_clang_x86.h:23
#1 0x000000000041eb1d in LockSlow() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_mutex.h:53
#2 0x00000000004ca891 in Put() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h:32
#3 0x00000000004ca891 in Put() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_mutex.h:179
#4 0x00000000004ca891 in Put() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h:52
#5 0x00000000004ca891 in Put() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h:67
#6 0x00000000004ca891 in Put() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h:126
#7 0x00000000004ca16d in StackDepotPut() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc:112
#8 0x0000000000420dcc in QuarantineChunk() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_allocator.cc:488
#9 0x00000000004b2c00 in __interceptor_free() () at /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:41
#10 0x00007f909b8d781a in g_free (mem=mem@entry=0x60b0002d5ee0) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmem.c:189
#11 0x00007f909b917cdd in do_exec (search_path_from_envp=0, search_path=1, envp=0x0, argv=0x604000465550, file=) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gspawn.c:1799
#12 0x00007f909b917cdd in do_exec (child_err_report_fd=47, stdin_fd=, stdout_fd=, stderr_fd=51, working_directory=working_directory@entry=0x0, argv=argv@entry=0x604000465550, envp=0x0, close_descriptors=1, search_path=1, search_path_from_envp=0, stdout_to_null=0, stderr_to_null=0, child_inherits_stdin=0, file_and_argv_zero=0, child_setup=0x0, user_data=0x0)
at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gspawn.c:1229

We've worked around this behavior in glib a few times in our own malloc hooks by registering a pthread_atfork handler that acquires the offending lock prior to forking and releases it once forked.

@eugenis
Copy link
Contributor

eugenis commented Mar 1, 2017 via email

@chefmax
Copy link

chefmax commented May 31, 2017

Should be fixed for {A, M, L}San by https://reviews.llvm.org/rL304285.

@xonatius
Copy link

Looks like the fix was rolled back in https://reviews.llvm.org/rL304735 was there another fix after that?

@eugenis
Copy link
Contributor

eugenis commented Dec 23, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants