BUG/MEDIUM: thread: Fix a deadlock if an isolated thread is marked as harmless
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 25 Mar 2021 13:11:36 +0000 (14:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 31 Mar 2021 07:47:58 +0000 (09:47 +0200)
commit1060ea3917646aad673a7fe53d48f3cba88f9726
tree63e2f650aca4c55e62622d73f4ed31a7f68604bb
parent699b67c499c809ce7d11dc447e9d07553c55258d
BUG/MEDIUM: thread: Fix a deadlock if an isolated thread is marked as harmless

If an isolated thread is marked as harmless, it will loop forever in
thread_harmless_till_end() waiting no threads are isolated anymore. It never
happens because the current thread is isolated. To fix the bug, we exclude
the current thread for the test. We now wait for all other threads to leave
the rendez-vous point.

This bug only seems to occurr if HAProxy is compiled with DEBUG_UAF, when
pool_gc() is called. pool_gc() isolates the current thread, while
pool_free_area() set the thread as harmless when munmap is called.

This patch must be backported as far as 2.0.

(cherry picked from commit a9a9e9aac93bae4d21d22e02fd436717a5a4a07a)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit fc583641657c6d385182f2ed0ef3b3a89c5fad24)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit d33d095f88be4575fe4e36f83e8d1df9e38d65a0)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/hathreads.c