tdb: runtime check for robust mutexes may hang in threaded programs
authorRalph Boehme <slow@samba.org>
Tue, 14 Mar 2017 13:24:18 +0000 (14:24 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 27 Apr 2017 12:52:16 +0000 (14:52 +0200)
commit19b193ebc974efdebdf347143938b5d053e67051
treeb2b9fc61ea6759e95455889f3ef9a019eafcc61b
parent5701880655c8a82b6d533c7c2e131cc803e7570b
tdb: runtime check for robust mutexes may hang in threaded programs

The current runtime check for robust mutexes in
tdb_runtime_check_for_robust_mutexes() is not thread-safe.

When called in a multi-threaded program where any another thread doesn't
have SIGCHLD blocked, we may end up hung in sigsuspend() waiting for a
SIGCHLD of a child procecss and the signal was delivered to another
thread.

Revert to the previous behaviour of waiting for the child instead of
waiting for the SIGCHLD signal.

Ensure the pid we wait for is not reset to -1 in a toctou race with the
signal handler.

Check whether waitpid() returns ECHILD which can happen if the signal
handler is run by more then one thread in parallel (yes, this can
happen) or if tdb_robust_mutex_wait_for_child() and the signal handler
are racing.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12593

Pair-programmed-with: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/tdb/common/mutex.c