]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: quic: fix possible integer wrap around in cubic window calculation
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 31 Jan 2024 17:21:34 +0000 (18:21 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Wed, 7 Feb 2024 07:44:31 +0000 (08:44 +0100)
Avoid loss of precision when computing K cubic value.
Same issue when computing the congestion window value from cubic increase function
formula with possible integer varaiable wrap around.

Depends on this commit:

MINOR: quic: Code clarifications for QUIC CUBIC (RFC 9438)

Must be backported as far as 2.6.

src/quic_cc_cubic.c

index 81eda3396a4f1653f48eef961e7e4a800d585f88..38557e044f4080e1828944c22eae9cefc860c5da 100644 (file)
@@ -245,7 +245,7 @@ static inline void quic_cubic_update(struct quic_cc *cc, uint32_t acked)
                         * Note that K is stored in 1024th of a second.
                         */
                        c->K = cubic_root((c->last_w_max - path->cwnd) *
-                                         (CUBIC_ONE_SCALED - CUBIC_BETA_SCALED) / CUBIC_C_SCALED / path->mtu) << TIME_SCALE_FACTOR_SHIFT;
+                                         ((CUBIC_ONE_SCALED - CUBIC_BETA_SCALED) << TIME_SCALE_FACTOR_SHIFT) / (CUBIC_C_SCALED * path->mtu));
                        c->W_target = c->last_w_max;
                }
 
@@ -273,7 +273,11 @@ static inline void quic_cubic_update(struct quic_cc *cc, uint32_t acked)
        }
 
        /* Compute W_cubic_t at t time. */
-       W_cubic_t = path->mtu * ((CUBIC_C_SCALED * t * t * t) >> (CUBIC_SCALE_FACTOR_SHIFT + 3 * TIME_SCALE_FACTOR_SHIFT));
+       W_cubic_t = CUBIC_C_SCALED * path->mtu;
+       W_cubic_t = (W_cubic_t * t) >> TIME_SCALE_FACTOR_SHIFT;
+       W_cubic_t = (W_cubic_t * t) >> TIME_SCALE_FACTOR_SHIFT;
+       W_cubic_t = (W_cubic_t * t) >> TIME_SCALE_FACTOR_SHIFT;
+       W_cubic_t >>= CUBIC_SCALE_FACTOR_SHIFT;
        if (elapsed_time < c->K)
                target = c->W_target - W_cubic_t;
        else