BUG/MEDIUM: quic: fix actconn on quic_conn alloc failure
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 6 Nov 2023 16:45:14 +0000 (17:45 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 7 Nov 2023 12:50:07 +0000 (13:50 +0100)
commita7ba679fe7b6511133441b3250e53a03ace7ed92
treea1d51716de81c3dc7790f667b9dac980afeb9080
parent62812b2a1d0d7b73b4a64cf3d0fe8256d0d5f5c1
BUG/MEDIUM: quic: fix actconn on quic_conn alloc failure

Since the following commit, quic_conn instances are accounted into
global actconn and compared against maxconn.

  commit 7735cf3854eb155a50a5ea747406f2a25657e25c
  MEDIUM: quic: count quic_conn instance for maxconn

Increment is always done prior to real allocation to guarantee minimal
resource consumption. Special care is taken to ensure there will always
be one decrement operation for each increment. To help this, decrement
is centralized in quic_conn_release().

This behaves incorrectly in case of an intermediary allocation failure
inside qc_new_conn(). In this case, quic_conn_release() will decrement
actconn. Then, a NULL qc is returned in quic_rx_pkt_retrieve_conn()
which will also decrement the counter on its own error code path.

To properly fix this, actconn incrementation has been moved directly
inside qc_new_conn(). It is thus easier to cover every cases :
* if alloc failure before or on pool_head_quic_conn, actconn is
  decremented manually at the end of qc_new_conn()
* after this step, actconn will be decremented by quic_conn_release()
  either on intermediary alloc failure or on proper connection release

This bug happens on memory allocation failure so it should be rare.
However, its impact is not negligeable as if actconn counter is wrapped
it will block any future connection allocation for both QUIC and TCP.

One small downside of this change is that a CID is now always allocated
before quic_conn even if maxconn will be reached. However, this is
considered as of minor importance compared to a more robust code.

This must be backported up to 2.6.
src/quic_conn.c
src/quic_rx.c