]> 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)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 11 Nov 2026 12:16:37 +0000 (16:16 +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 c308bdfcb27c8171cfadbb4f9511cb9d2a914e19..807dd59c10f33a43323be793e95e6a97bc975180 100644 (file)
@@ -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);
     }
index eb3cd008e980d7c468b5543ee68bb399eab92fb1..b2eaa5787f149b617549dc44acfc0faad65026a3 100644 (file)
@@ -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;
 
index 61e637137451c3572352edf55077bdb60c613220..e91eb582430635e8fd52b94e9d24404e1451fd13 100644 (file)
@@ -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;
 }