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.30.7~8 X-Git-Url: https://git.kaiwu.me/http/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=b89c4100bf6762a45e4a6463eaf4b70368277c94;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 e0e7ef379..e5d93733f 100644 --- a/src/http/v2/ngx_http_v2.c +++ b/src/http/v2/ngx_http_v2.c @@ -2484,13 +2484,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 beb77a5c1..0c8066e66 100644 --- a/src/http/v2/ngx_http_v2.h +++ b/src/http/v2/ngx_http_v2.h @@ -137,6 +137,7 @@ struct ngx_http_v2_connection_s { ngx_uint_t priority_limit; 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 6b73b1e68..fe235fbd8 100644 --- a/src/http/v2/ngx_http_v2_filter_module.c +++ b/src/http/v2/ngx_http_v2_filter_module.c @@ -1224,6 +1224,7 @@ ngx_http_v2_send_chain(ngx_connection_t *fc, ngx_chain_t *in, off_t limit) ngx_http_v2_queue_frame(h2c, frame); h2c->send_window -= frame_size; + h2c->send_queued += frame_size; stream->send_window -= frame_size; stream->queued++; @@ -1619,6 +1620,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); @@ -1753,6 +1755,7 @@ ngx_http_v2_filter_cleanup(void *data) } h2c->send_window += window; + h2c->send_queued -= window; }