[PATCH 10 of 10] Disabled repeated posts of write events without progress

Maxim Dounin mdounin at mdounin.ru
Tue Nov 24 00:27:13 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1795479910 -10800
#      Tue Nov 24 03:25:10 2026 +0300
# Node ID c77a4ec02febc04371a0e56083fecd8bf2aae531
# Parent  1da25011f59c171287369585748a1117a42d9322
Disabled repeated posts of write events without progress.

Previously, since 7947:51a260276425 in write filter and
7949:862f6130d357 in output chain, write events were posted for the next
event loop operation if there were unsent data and the connection was
still ready for writing.  However, with SSL the c->write->ready flag
might still be set when writing isn't possible, such as when SSL_write()
returns SSL_ERROR_WANT_READ (which might be the case during a handshake
when responding to early data, or during renegotiation with an upstream
server).  This could cause some excessive CPU usage until the timeout
expires (known as CVE-2026-132779, though security impact in freenginx
is questionable).

The fix is to post write events only if some progress was made,
similarly to how we rearm write timeouts (9358:4c872940b19b).

See also:
https://github.com/nginx/nginx/commit/2c84628229bdeedd16db5980af6e8fdf754cc80d
https://github.com/nginx/nginx/commit/a12a232e6472b39a53b5e31266846843e142950d

diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -658,7 +658,7 @@ ngx_chain_writer(void *data, ngx_chain_t
 {
     ngx_chain_writer_ctx_t *ctx = data;
 
-    off_t              size;
+    off_t              size, sent;
     ngx_chain_t       *cl, *ln, *chain;
     ngx_connection_t  *c;
 
@@ -775,6 +775,8 @@ ngx_chain_writer(void *data, ngx_chain_t
         return NGX_OK;
     }
 
+    sent = c->sent;
+
     chain = c->send_chain(c, ctx->out, ctx->limit);
 
     ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0,
@@ -784,7 +786,7 @@ ngx_chain_writer(void *data, ngx_chain_t
         return NGX_ERROR;
     }
 
-    if (chain && c->write->ready) {
+    if (chain && c->write->ready && c->sent != sent) {
         ngx_post_event(c->write, &ngx_posted_next_events);
     }
 
diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c
--- a/src/http/ngx_http_write_filter_module.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -336,7 +336,7 @@ ngx_http_write_filter(ngx_http_request_t
         }
     }
 
-    if (chain && c->write->ready && !c->write->delayed) {
+    if (chain && c->write->ready && !c->write->delayed && c->sent != sent) {
         ngx_post_event(c->write, &ngx_posted_next_events);
     }
 



More information about the nginx-devel mailing list