-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The validator subtracts unsigned from a counter it trusts to stay below MAX\n\nThe relevant code is `ngx_http_v2_state_window_update` in `src/http/v2/ngx_http_v2.c`. The connection-wide branch takes a `window` increment off the wire and runs one check before applying it:\n\n```c\nif (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) {\n ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,\n \"client violated connection flow control: ...\");\n return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR);\n}\n\nh2c->send_window += window;\n```\n\n`NGX_HTTP_V2_MAX_WINDOW` is `0x7fffffff`. The field `h2c->send_window` is a `size_t`: unsigned 64-bit on every platform NGINX Plus ships to. The subtraction `NGX_HTTP_V2_MAX_WINDOW - h2c->send_window` is unsigned 64-bit arithmetic.\n\nThe check is correct exactly while `send_window <= NGX_HTTP_V2_MAX_WINDOW`. In that regime the subtraction returns the signed distance to the ceiling, and the comparison does what the HTTP/2 spec requires: reject any increment that would push the per-connection total above `0x7fffffff`. The regime the check depends on is an invariant on `send_window`. Nothing in this function enforces that invariant. The function reads it.\n\nWhen `send_window` is already above `0x7fffffff`, the subtraction underflows. `size_t` arithmetic wraps modulo 2^64, so the expression returns a number close to `2^64`. Every legal `window` on the wire is a 31-bit integer less than `0x80000000`. Every such `window` is less than `2^64 - 0x80000000`. The check passes for any input. The branch below runs. `h2c->send_window += window` adds it in.\n\n## Only the cleanup refund can cross the ceiling\n\n`h2c->send_window` is written in three places in NGINX's HTTP/2 implementation. Each site is correct on its own terms. The composed system has a hole exactly where no single site is responsible for the invariant.\n\nThe reservation site is `ngx_http_v2_send_chain` in `src/http/v2/ngx_http_v2_filter_module.c`. When NGINX commits bytes to a DATA frame and queues it for output, the function subtracts those bytes from `send_window`:\n\n```c\nh2c->send_window -= frame_size;\n\nstream->send_window -= frame_size;\nstream->queued++;\n```\n\nThe on-wire site is in the frame-send handler. Once a queued frame reaches the wire, the handler does nothing to `send_window`: those bytes were deducted at reservation and never need to be deducted again. The handler updates per-stream state and `payload_bytes` for logging.\n\nThe refund site is `ngx_http_v2_filter_cleanup`. When a stream dies before its queued frames reach the wire, cleanup walks the stream's reserved payload and adds it back to the connection counter:\n\n```c\nh2c->send_window += window;\n```\n\nEach site treats `send_window` as \"credit available for NGINX to spend on this connection.\" Each site honors that definition locally. The protocol semantics, from the client's side, are different. The client's view of the connection window reflects only what NGINX has already acknowledged shipping on the wire. Queued-but-not-sent bytes are, from the client's view, still owed. The client is free to raise the connection window at any moment up to `0x7fffffff` minus what NGINX has shipped.\n\nNow compose. A queued frame costs `frame_size` against `send_window`. Immediately after that reservation, the client sends a `WINDOW_UPDATE` that fills the gap exactly, and `send_window` returns to the ceiling. The frame has not reached the wire. The stream is reset by any means the protocol permits. Cleanup fires. `send_window += frame_size`. The counter is now `frame_size` above `NGX_HTTP_V2_MAX_WINDOW`.\n\nThe invariant that the validator reads was broken by the only path that never checks it.\n\n## Reaching the signed midpoint takes 2^33 WINDOW_UPDATEs and 52 GiB of them\n\nMaking `send_window` legally larger than `0x7fffffff` is a DoS primitive by itself; NGINX later casts the counter to a signed type in the output path and misreads it. The Rapid7 PoC walks from the unsigned wrap all the way to that cast.\n\nThe bootstrap stage drives the exact race described above. It opens two Range-response streams against zero stream credit so the DATA frames stay queued, grants per-stream credit so the DATA frames exist as queued-but-not-sent bytes, then sends the client-side event that trips the refund:\n\n```python\nevent = (window_update(0, reserved) + window_update(0, MAX_WINDOW)\n + window_update(target_streams[0], MAX_WINDOW - 1)\n + window_update(target_streams[1], MAX_WINDOW - 1)\n + settings_window(2) + window_update(0, MAX_WINDOW)\n + settings_window(65535)\n + range_request(release_stream, ...))\n```\n\nThe first `window_update(0, reserved)` refills the connection window to exactly cover the queued bytes. The second `window_update(0, MAX_WINDOW)` raises the connection window to the ceiling. The two per-stream updates push each target stream's window to `MAX_WINDOW - 1`. The `settings_window(2)` changes `SETTINGS_INITIAL_WINDOW_SIZE` to 2, which pushes each target stream's window to `MAX_WINDOW + 1`, illegal under HTTP/2 flow control. NGINX resets both streams with `NGX_HTTP_V2_FLOW_CTRL_ERROR`. Cleanup refunds each stream's queued `frame_size` into `send_window`, which is already at `MAX_WINDOW`. `send_window` is now above `MAX_WINDOW`. The next `window_update(0, MAX_WINDOW)` is accepted because the validator's subtraction has already underflowed.\n\nFrom there the primitive is monotonic. Every subsequent 13-byte `WINDOW_UPDATE` carrying `0x7fffffff` adds `0x7fffffff` to `send_window` and the unsigned-subtraction check keeps wrapping. The PoC sends exactly `2^33 + 1` such increments through 96 live stream owners, rotating the owner on each tranche boundary so no DATA is released and no owner waits for NGINX's send timeout:\n\n```text\n17:39:43 INFO replaying 8589934593 legal WINDOW_UPDATE frames across 96 owners\n...\n17:41:19 INFO wrapped flow-control distance reached; tailored increment=0x7fffc0d5\n```\n\n`8589934593` is `2^33 + 1`. Each `WINDOW_UPDATE` is 13 bytes on the wire. The replay sends 111.67 GiB of application plaintext just to walk the counter. NGINX's flood-protection budget would normally drop traffic that over-represents control frames relative to parsed payload, so the stage is preceded by a 15 GiB fixed carrier of maximum-size HEAD-request `HEADERS` payloads that pays NGINX's accounting cost for the WINDOW_UPDATE flood that follows.\n\nAt the end of the replay, `send_window` has crossed the 64-bit signed midpoint. It is a legal positive `size_t` whose top bit is set.\n\n## (off_t) send_window is the primitive\n\n`send_window` is read by two sinks. The validator reads it through the unsigned subtraction. The output path reads it through a signed cast, in the same function that reserves:\n\n```c\nif (limit == 0 || limit > (off_t) h2c->send_window) {\n limit = h2c->send_window;\n}\n```\n\n`off_t` is signed 64-bit on x86-64 Linux. Casting a `size_t` whose top bit is set to `off_t` produces a negative number. The comparison `limit > (off_t) h2c->send_window` holds for any non-negative `limit`, so the branch body runs. `limit = h2c->send_window` assigns the unsigned counter back. The implicit conversion to `limit`'s type is where the wrapped value re-enters the output filter as a very large positive integer. From there `limit` flows into the per-frame-size budget that controls how many bytes the output filter copies into the TLS record staging buffer. The Rapid7 profile targets a glibc EVEX/YMM `memcpy` path that walks that budget directly into the heap.\n\nThe PoC refines the wrap into something smaller than the full crash primitive. The `send_numeric_stage` routine computes a tailored final `WINDOW_UPDATE` increment so `send_window` lands at a specific distance past the signed midpoint, not at the top of its range:\n\n```python\ndef near_wrap(start, distance):\n target = (-distance) & MASK64\n for extra in range(8):\n count = (1 << 33) + extra\n current = (start + count * MAX_WINDOW) & MASK64\n tailored = (target - current) & MASK64\n if 1 <= tailored <= MAX_WINDOW:\n return count, tailored\n raise RuntimeError(\"could not construct legal near-wrap transition\")\n```\n\nThat tailored value turns the memcpy's walk from \"crash the worker\" into \"read a profiled region of the worker's heap.\" The exploit picks up the disclosure, recovers `h2c`'s address and libc's base through a chain of NGINX pool and chunk invariants, and reclaims the vacated slot with a forged `ngx_http_request_t` whose cleanup handler points at `system()` and whose attached data is the `--cmd` string. Nginx runs the cleanup. Nginx runs `system(\"touch /tmp/rapid7-nginx-h2-proof-01\")`.\n\nEverything after the signed-midpoint crossing is operational engineering. The primitive is the wrap. The wrap is the refund crossing a ceiling the validator's unsigned subtraction trusted would hold.\n\n## The patch does not add a bounds check. It adds a column.\n\nThe commit is `e27f5fa84fe6e98505e70bc543b748747dad0a3b`, by Roman Arutyunyan, dated 2026-10-29. It touches three files and changes six lines. It does not add a bounds check to the cleanup refund. It does not clamp `send_window` to `NGX_HTTP_V2_MAX_WINDOW`. It does not change the shape of the validator's arithmetic. It introduces a second counter:\n\n```diff\n size_t send_window;\n+ size_t send_queued;\n size_t recv_window;\n size_t init_window;\n```\n\n`send_queued` tracks exactly the bytes that are reserved against a queued-but-not-yet-sent DATA frame. The reservation site adds to it:\n\n```diff\n h2c->send_window -= frame_size;\n+ h2c->send_queued += frame_size;\n\n stream->send_window -= frame_size;\n stream->queued++;\n```\n\nThe on-wire site subtracts from it:\n\n```diff\n h2c->payload_bytes += frame->length;\n+ h2c->send_queued -= frame->length;\n```\n\nThe cleanup refund subtracts from it:\n\n```diff\n h2c->send_window += window;\n+ h2c->send_queued -= window;\n```\n\nAnd the validator's check is now:\n\n```diff\n- if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) {\n+ if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window - h2c->send_queued) {\n```\n\nThe validator's arithmetic shape is the same as before. What has changed is the input. The validator is now asking \"is the increment greater than the ceiling minus what NGINX has spent and what NGINX has committed to spend?\" The committed-to-spend column is `send_queued`. Before the patch, NGINX did not track it; `send_window` was treated as both \"unspent credit\" and \"unreserved credit\" at different sites, which are the same quantity only when the queue is empty.\n\nThe commit message names the structural error directly:\n\n> 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. [...] From the client's point of view, the queued frames still belong to the flow control window.\n\nThe server's view and the client's view of the flow-control window disagreed exactly during the queued-but-not-sent interval. The patch does not reconcile them with a check. It gives the server the second column it needed to see the same window the client was seeing.\n\nThis is [refund-breaks-the-invariant](/patterns/refund-breaks-the-invariant). A single state variable is written by a primary spend path and a secondary refund path. The primary path maintains an invariant that downstream validators compute against. The refund path writes without enforcing that invariant, because its local semantics are \"return reserved resource to the pool\" and the pool's ceiling is not visible to it. A separate accounting dimension, the committed-but-not-released column the patch introduces, is what makes the refund path's writes safe. Where that column is missing, the refund's write is the primitive.\n\n## The commit message is the disclosure\n\nThe commit landed on NGINX's public mainline on 2026-10-29 at 21:37 +0400. It is credited \"Reported by Xint.io.\" Its message contains a four-sentence prose description of the exact bug class, including the specific phrase \"memory corruption and a possible segmentation fault\" as the eventual consequence. Any defender watching NGINX's commit stream on a `grep -i \"flow control\\|HTTP/2.*WINDOW\"` filter saw the shape of the bug within minutes of the push.\n\nThe release tag for NGINX 1.31.9, `c2c4470`, is dated 2026-11-06, eight days later. Rapid7's advisory records their outreach to F5 on 2026-11-11, five days after the release. CVE-2026-123007 was assigned on 2026-11-16. F5's public advisory and Rapid7's full RCE repository published on 2026-11-18.\n\nThat calendar maps onto the catalog's [release-lag-disclosure](/patterns/release-lag-disclosure) shape. NGINX's commit log carried a legible security disclosure on 2026-10-29. The CVE record caught up to it on 2026-11-18, 20 days later. The release tag landed in the middle of that window. Vulnerability-management products that gate their urgency on CVE publication saw this bug on 2026-11-18. The commit log saw it on 2026-10-29 with a commit message that read, in English, like a vendor advisory in draft.\n\nThe 300-line exploit module Rapid7 shipped on disclosure day is not the kind of artifact built in a weekend. The commit-message disclosure is the enabling signal; what is distinctive here is how much of the chain already existed when Rapid7 made the Nov 11 outreach call: the profile-driven ASLR disclosure, the heap-layout grooming, the deferred-execution path, the EVEX/YMM memcpy profile. The 18-day gap between a public commit and a public CVE is the window. The exploit is what Rapid7 built inside it.\n\n## Audit your `size_t` counters for a missing second column\n\nThe Rapid7 exploit's full chain is operational craft. The primitive is one patched struct field. Every HTTP/2 or gRPC implementation that tracks flow-control credit in a single counter, that services queued-but-not-sent DATA frames, and that admits a stream-reset path that refunds reserved credit is a candidate for the same bug. The question to ask of such a codebase is not \"does the validator check the ceiling.\" It is \"does the refund path know about the ceiling the validator reads.\" Where that answer is maintained by the client's protocol compliance rather than by a second counter, the next WINDOW_UPDATE is the primitive.","closing_line":"The validator has been reading `send_window` since NGINX shipped HTTP/2 in 2015. For eleven years the number it was reading was the right one by accident.","hook_md":"NGINX's HTTP/2 connection-level send window is a `size_t` named `send_window`. Through version 1.31.8, the connection WINDOW_UPDATE validator checked every client grant with `window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window`. That subtraction is correct only while `send_window` is at or below `NGX_HTTP_V2_MAX_WINDOW`. Every path that wrote the counter maintained that invariant except one. When a stream was reset, the cleanup path refunded the credit that had been reserved for queued-but-not-yet-sent DATA frames. If the client had raised the window between queueing and reset, the refund crossed the ceiling. From that moment the validator was subtracting a larger unsigned value from a smaller one. It wrapped. The next WINDOW_UPDATE was accepted. Rapid7 walked that wrap into unauthenticated RCE against unmodified NGINX 1.31.8 in 190 seconds and 119 GiB of plaintext.","post_id":883,"slug":"nginx-cve-2026-123007-missing-ledger-column","title":"CVE-2026-123007: NGINX's HTTP/2 Validator Subtracted From a Counter That Could Legally Exceed Its Maximum. The Fix Is the Ledger Column That Would Have Kept It Legal.","type":"initial","unreadable_sentence":"The patch does not add a bounds check. It adds the ledger column the validator had been reading all along."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCawHfhQAKCRDeZjl4jgkQ JisYAP4ytwadjvYT9tfex84ZBkUq51yLZlE0+qfT0cenpULUNgEAyDYvmmkr88zw 2o7Xq0XUq5D0cOxW9ltZ5iYPL8nLSAM= =3BEx -----END PGP SIGNATURE-----