]> git.kaiwu.me - nginx.git/commitdiff
HTTP/2: account for queued frames when validating WINDOW_UPDATE
authorRoman Arutyunyan <arut@nginx.com>
Thu, 29 Oct 2026 17:37:05 +0000 (21:37 +0400)
committerSergey Kandaurov <pluknet@nginx.com>
Wed, 11 Nov 2026 18:08:26 +0000 (22:08 +0400)
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.

src/http/v2/ngx_http_v2.c
src/http/v2/ngx_http_v2.h
src/http/v2/ngx_http_v2_filter_module.c

index e0e7ef379b72bc89202af647870043f8cad98b51..e5d93733f00d525c92d3c377666ee3735ff8d89b 100644 (file)
@@ -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);
     }
index beb77a5c1db9eed659fe8719a0fe93e68ca144ad..0c8066e6657696d4eae111c04c10e7c49e905703 100644 (file)
@@ -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;
 
index 6b73b1e6876915478df765bd65662ec640944fc3..fe235fbd898ab9c52ab47a89bdc56d7deffdb7c3 100644 (file)
@@ -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;
 }