From: Roman Arutyunyan Date: Thu, 29 Oct 2026 17:37:05 +0000 (+0400) Subject: HTTP/2: account for queued frames when validating WINDOW_UPDATE X-Git-Tag: release-1.31.9~9 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=e27f5fa84fe6e98505e70bc543b748747dad0a3b;p=nginx.git HTTP/2: account for queued frames when validating WINDOW_UPDATE When a stream is terminated, its unsent payload length is refunded back to the connection flow control. Previously, this could increase the flow control beyond NGX_HTTP_V2_MAX_WINDOW, if it was increased by the client after the stream frames were queued and before the stream was terminated. This eventually resulted in broken buffer size control in ngx_http_v2_send_chain() followed by memory corruption and a possible segmentation fault. The fix is to account for the queued frames when validating a client WINDOW_UPDATE. From the client's point of view, the queued frames still belong to the flow control window. Reported by Xint.io. --- diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c index c308bdfcb..807dd59c1 100644 --- a/src/http/v2/ngx_http_v2.c +++ b/src/http/v2/ngx_http_v2.c @@ -2561,13 +2561,13 @@ ngx_http_v2_state_window_update(ngx_http_v2_connection_t *h2c, u_char *pos, return ngx_http_v2_state_complete(h2c, pos, end); } - if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) { + if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window - h2c->send_queued) { ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, "client violated connection flow control: " "received WINDOW_UPDATE frame " "with window increment %uz " "not allowed for window %uz", - window, h2c->send_window); + window, h2c->send_window + h2c->send_queued); return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR); } diff --git a/src/http/v2/ngx_http_v2.h b/src/http/v2/ngx_http_v2.h index eb3cd008e..b2eaa5787 100644 --- a/src/http/v2/ngx_http_v2.h +++ b/src/http/v2/ngx_http_v2.h @@ -135,6 +135,7 @@ struct ngx_http_v2_connection_s { ngx_uint_t refused_streams; size_t send_window; + size_t send_queued; size_t recv_window; size_t init_window; diff --git a/src/http/v2/ngx_http_v2_filter_module.c b/src/http/v2/ngx_http_v2_filter_module.c index 61e637137..e91eb5824 100644 --- a/src/http/v2/ngx_http_v2_filter_module.c +++ b/src/http/v2/ngx_http_v2_filter_module.c @@ -1242,6 +1242,7 @@ ngx_http_v2_send_chain(ngx_connection_t *fc, ngx_chain_t *in, off_t limit) ngx_http_v2_queue_frame(fn, frame); h2c->send_window -= frame_size; + h2c->send_queued += frame_size; stream->send_window -= frame_size; stream->queued++; @@ -1634,6 +1635,7 @@ done: stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE; h2c->payload_bytes += frame->length; + h2c->send_queued -= frame->length; ngx_http_v2_handle_frame(stream, frame); @@ -1770,6 +1772,7 @@ ngx_http_v2_filter_cleanup(void *data) } h2c->send_window += window; + h2c->send_queued -= window; }