Comment #2 on issue 44 by
gli...@google.com: Feature request: detect fork()
without exec()
http://code.google.com/p/thread-sanitizer/issues/detail?id=44
I need TSan to help me quickly and correctly identify the situation when
the program acquires a lock in one thread, then calls fork() in another
thread and then tries to acquire the same lock in that thread in the child
process.
In the case the lock belongs to TSan runtime (e.g. if this is the reporting
lock):
1) TSan has to make sure this lock isn't acquired anymore. I'm guessing
that most of this can be done by disabling race detection after fork() if
there were multiple threads prior to fork(). However there may be
single-threaded errors (e.g. UAF) which we won't be able to report then.
Perhaps a better solution is to make sure all the relevant locks are
released before calling fork()
In the case the lock belongs to the client program:
2) TSan can report any attempt to acquire a lock taken by a dead thread.
This way we'll catch only those deadlocks that actually happen and won't
report any false positives.
3) If fork() has been called in the presence of other threads, TSan can
report any attempt to call an async signal unsafe function (even if it's
not leading to actual errors). Even less conservative approach is to report
thread creation after fork() if there were threads before (may lead to
false positives, although doing so is still UB)
malloc() calls deserve special handling, because they may cause acquiring
the same locks by the TSan runtime and the user code.
We can either force fork() to be synchronized with malloc() calls in other
threads (e.g. take the malloc lock before forking), or detect races between
unsynchronized fork() and malloc() calls.