BUG/MEDIUM: server: fix race on servers_list during server deletion
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 23 Oct 2024 16:18:48 +0000 (18:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Oct 2024 14:40:35 +0000 (16:40 +0200)
commit38c874bad691fc74a300817d1e85f3a331d4a6b4
tree7e89d4ed2fe824e4089069909ccd5230ee826db1
parentadceb4a595d9dedbcdc1bbf92b38ccc95c2b66ab
BUG/MEDIUM: server: fix race on servers_list during server deletion

Each server is inserted in a global list named servers_list on
new_server(). This list is then only used to finalize servers
initialization after parsing.

On dynamic server creation, there is no issue as new_server() is under
thread isolation. However, when a server is deleted after its refcount
reached zero, srv_drop() removes it from servers_list without lock
protection. In the longterm, this can cause list corruption and crashes,
especially if multiple adjacent servers are removed in parallel.

To fix this, convert servers_list to a mt_list. This should not impact
performance as servers_list is not used during runtime outside of server
creation/deletion.

This should fix github issue #2733. Thanks to Chris Staite who first
found the issue here.

This must be backported up to 2.6.

(cherry picked from commit 7a02fcaf20dbc19db36052bbc7001bcea3912ab5)
Signed-off-by: Willy Tarreau <w@1wt.eu>
include/haproxy/server-t.h
include/haproxy/server.h
src/cfgparse.c
src/server.c