# CVE-2026-123007: Critical NGINX HTTP/2 Integer Underflow Leads to RCE

HTTP/2 flow-control double-refund in nginx's send_window lets an unauthenticated client underflow the connection window and corrupt memory, achieving worker-context RCE.

- Payout: Research
- Severity: critical
- Program: Nginx
- Write-up by: Stephen Fewer
- Disclosed: 2026-11-18
- CVE: CVE-2026-123007
- Write-up quality: 9/10
- Original: https://www.rapid7.com/blog/post/ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed
- Library page: https://bugbountylibrary.com/r/blog%3Arapid7-com-blog-post-ve-cve-2026-123007-critical-nginx-http-2-integer-underflow-leads-to-rce-fixed
- Tags: area:cloud domain:infra impact:data-leak impact:rce kind:research platform:threat-intel sev:critical tech:linux tech:nginx technique:source-review vuln:dos vuln:info-disclosure vuln:memory-corruption vuln:rce

**Target:** nginx HTTP/2 module (ngx_http_v2) over TLS
**Root cause:** Request cleanup refunds queued DATA credit to h2c->send_window without checking the HTTP/2 MAX_WINDOW invariant, and a later WINDOW_UPDATE check subtracts from an over-MAX size_t, underflowing to a huge value that becomes a negative off_t response length.
**Steps:**
1. Slow reads to keep a DATA frame queued unstarted; raise connection credit to MAX and selected streams to just below MAX via `WINDOW_UPDATE`.
2. Send `SETTINGS` raising `SETTINGS_INITIAL_WINDOW_SIZE` so streams exceed MAX; nginx calls `ngx_http_v2_terminate_stream()` (RST_STREAM) but keeps the connection open.
3. Stream cleanup runs `ngx_http_v2_filter_cleanup()`, adding frame lengths back to `h2c->send_window` past MAX (e.g. 0x7FFFFFFF + 1393 = 0x80000570).
4. Send another connection `WINDOW_UPDATE`; check `window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window` underflows to 2^64-R, allowing increments.
5. Send ~2^32-2^33 max-size WINDOW_UPDATE frames (~52-104 GiB) to push send_window above 2^63.
6. Trigger a normal response; `limit = h2c->send_window` becomes negative off_t, `frame_size` huge, `ngx_http_v2_filter_get_shadow()` sets `chunk->last = chunk->pos + size` before pos.
7. `ngx_ssl_send_chain()` computes negative `size` and calls `ngx_memcpy(buf->last, in->buf->pos, size)` with 2^64-d byte count; glibc EVEX backward-copy wraps end address and returns after limited OOB accesses.
8. Use OOB read to leak heap/libc pointers, OOB write to overwrite a request-pool cleanup callback, redirect to `system()` resolved via leaked ELF metadata.
**How found:** Code review of HTTP/2 flow-control accounting: noticed h2c->send_window is size_t while stream->send_window is ssize_t, that cleanup refunds credit without MAX check, and that ngx_http_v2_adjust_windows() terminates only the stream (continue) instead of the connection on FLOW_CONTROL_ERROR, leaving an over-MAX counter usable.
**Exploitation:** Attacker needs direct HTTP/2 path (no terminating proxy), ~119 GiB traffic within nginx's 1-hour connection limit, idle server, and x86-64 CPU with AVX-512/avx512vl for the specific glibc EVEX memcpy. PoC leaks heap and glibc/nginx pointers from memory preceding the response body, forges request/response buffer objects to return parts of glibc's ELF image over HTTP/2, resolves system() despite ASLR, then redirects a request-pool cleanup callback to run an attacker command as the worker user.
**Escalation:** Chains flow-control accounting bug to integer underflow, to negative off_t length, to invalid ngx_buf_t metadata, to oversized memcpy OOB read/write, then uses info leak to defeat ASLR and callback overwrite for code execution.
**Insight:** When auditing protocol flow-control, check every path that returns reserved credit (cleanup, cancel, error) against the protocol maximum, and check whether error handlers that should kill the connection only kill the stream, leaving corrupted shared state reachable.

## Proof of concept (copied exactly from the original report)

**Unchecked credit restoration in filter cleanup**

```
for ( ;; ) {
 frame = *fn;
 if (frame == NULL) {
 break;
 }
 if (frame->stream == stream && !frame->blocked) { // <--- [5]
 *fn = frame->next;
 window += frame->length; // <--- [6]
 if (--stream->queued == 0) {
 break;
 }
 continue;
 }
 fn = &frame->next;
}
// ...
h2c->send_window += window; // <--- [7]
```

**Underflowing WINDOW_UPDATE check**

```
if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) { // <--- [9]
 // ...
 return ngx_http_v2_connection_error(h2c,
 NGX_HTTP_V2_FLOW_CTRL_ERROR);
}
h2c->send_window += window; // <--- [10]
```

**Negative length to memcpy in TLS chain**

```
size = in->buf->last - in->buf->pos; // <--- [16]
if (size > buf->end - buf->last) {
 size = buf->end - buf->last;
}
if (send + size > limit) {
 size = (ssize_t) (limit - send);
}
// ...
ngx_memcpy(buf->last, in->buf->pos, size); // <--- [17]
```

