BUG/MINOR: ssl: use a thread-safe sslconns increment
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 25 Oct 2023 13:38:04 +0000 (15:38 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 26 Oct 2023 13:25:07 +0000 (15:25 +0200)
commit350f8b0c0745c71b0d40fb16205580d7ffb7aa31
tree62b8618b4b5320bc70bb409318e0bf0182f7cc1a
parentfffd435bbd6f83f79bc5326d007365711ae0252d
BUG/MINOR: ssl: use a thread-safe sslconns increment

Each time a new SSL context is allocated, global.sslconns is
incremented. If global.maxsslconn is reached, the allocation is
cancelled.

This procedure was not entirely thread-safe due to the check and
increment operations conducted at different stage. This could lead to
global.maxsslconn slightly exceeded when several threads allocate SSL
context while sslconns is near the limit.

To fix this, use a CAS operation in a do/while loop. This code is
similar to the actconn/maxconn increment for connection.

A new function increment_sslconn() is defined for this operation. For
the moment, only SSL code is using it. However, it is expected that QUIC
will also use it to count QUIC connections as SSL ones.

This should be backported to all stable releases. Note that prior to the
2.6, sslconns was outside of global struct, so this commit should be
slightly adjusted.
include/haproxy/ssl_sock.h
src/ssl_sock.c