-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## Five functions wrote the check. The sixth is the bug.\n\n`t_stream.c` declares its stack-vs-heap threshold at line 24:\n\n```c\n/* For stream commands that require multiple IDs\n * when the number of IDs is less than 'STREAMID_STATIC_VECTOR_LEN',\n * avoid malloc allocation.*/\n#define STREAMID_STATIC_VECTOR_LEN 8\n```\n\nThe constant exists because Redis stream commands take a caller-supplied array of IDs whose count is unbounded by the protocol, and the codebase prefers not to call `malloc` in the common small case. Six places in this file use the idiom. The canonical example is `xdelexCommand`, at line 4020 of the 8.2.0 vulnerable build, also added by PR #14130:\n\n```c\nstreamID static_ids[STREAMID_STATIC_VECTOR_LEN];\nstreamID *ids = static_ids;\nif (args.numids > STREAMID_STATIC_VECTOR_LEN)\n ids = zmalloc(sizeof(streamID)*args.numids);\nfor (int j = 0; j < args.numids; j++) {\n if (streamParseStrictIDOrReply(c,c->argv[j+args.startidx],&ids[j],0,NULL) != C_OK)\n goto cleanup;\n}\n```\n\nSix lines of idiom. Declare a static array of eight `streamID` slots. Point `ids` at it. If the caller's count exceeds eight, swap `ids` to a heap allocation sized to fit. Then write through `ids`.\n\nThe same idiom appears at line 2307 inside `xreadCommand`, at line 3140 inside `xackCommand`, at line 3564 inside `xclaimCommand`, at line 3940 inside `xdelCommand`, and at line 4020 inside `xdelexCommand`. Five times. Each one carries the `if (count > STREAMID_STATIC_VECTOR_LEN) ids = zmalloc(...)` line that the header comment told the developer to write.\n\nHere is the same idiom at line 3206, inside `xackdelCommand`:\n\n```c\nstreamID static_ids[STREAMID_STATIC_VECTOR_LEN];\nstreamID *ids = static_ids;\nfor (int j = 0; j < args.numids; j++) {\n if (streamParseStrictIDOrReply(c,c->argv[j+args.startidx],&ids[j],0,NULL) != C_OK)\n goto cleanup;\n}\n```\n\nTwo lines are missing. The `if`. The `zmalloc`. The eight-slot stack buffer now absorbs `args.numids` writes, where `args.numids` is the caller-supplied count from the RESP-level command `XACKDEL key group IDS id [id ...]`.\n\n## Each ID is a sixteen-byte write the caller controls\n\n`streamID` is two `uint64_t` fields, `ms` and `seq`, sixteen bytes total. The wire format is the ASCII `-` Redis users type at the CLI, parsed by `streamParseStrictIDOrReply` into the binary struct. Neither field is range-validated. Both are caller-controlled bytes after the parse.\n\n`streamID static_ids[STREAMID_STATIC_VECTOR_LEN]` is 128 bytes on the stack. The compiler places the array inside `xackdelCommand`'s stack frame, beside whatever else the function spills. JFrog's exploitation analysis, reproduced here in [PoC form](https://github.com/GartonChan/redis-cve-2025-62507) against the published 8.2.0 binaries on x86-64 and ARM64, identifies where the saved return address lands relative to the array. Slot 53, specifically the `seq` half of the 53rd `streamID`, overlaps the saved `rip`.\n\nThe attacker authenticates, calls `XACKDEL` on a stream they have permission to write to, and sends enough IDs to reach the saved return address. The 53rd ID's `seq` becomes the return target. The next IDs become a ROP chain. The x86-64 chain in the PoC is six gadgets and a payload: `pop rdi; ret` to set the page address, `pop rsi; ret` to set the length, `pop rdx; ret` to set the permissions, `mprotect` to make the stack RWX, `call rsp` to enter shellcode that the same overflow wrote into adjacent stream IDs. The ARM64 chain is forty slots because AArch64 takes more gadget plumbing to populate `x0` through `x3` for the `mprotect` call.\n\nThe CVSS vector is `PR:L`. The realistic attacker is any application user that has permission to acknowledge stream messages, which is the population of every Redis-streams-as-work-queue consumer. Redis 8.2's ACL system defaults deny-everything; a tightly-configured cluster grants `XACKDEL` only where it is needed. `XACKDEL` is the canonical acknowledge-and-delete operation. Every consumer of a Redis stream tends to hold the permission.\n\n## The patch is the idiom\n\nThe patch commit is `5f83972188f6e5b1d6f1940218c650a9cbdf7741`, \"Fix XACKDEL stack overflow when IDs exceed STREAMID_STATIC_VECTOR_LEN (CVE-2025-62507)\". The diff to `src/t_stream.c` is two lines:\n\n```diff\n streamID static_ids[STREAMID_STATIC_VECTOR_LEN];\n streamID *ids = static_ids;\n+ if (args.numids > STREAMID_STATIC_VECTOR_LEN)\n+ ids = zmalloc(sizeof(streamID)*args.numids);\n for (int j = 0; j < args.numids; j++) {\n```\n\nThe two lines that appear inside `xreadCommand`. Inside `xackCommand`. Inside `xclaimCommand`. Inside `xdelCommand`. Inside `xdelexCommand`, the sibling function landed in PR #14130 by the same author in the same commit.\n\nThe fix did not require any analysis Redis maintainers had not already performed. The fix was the idiom.\n\n## This is Parallel Implementation Gap, in one file\n\nThe shape we name [Parallel Implementation Gap](https://nefariousplan.com/patterns/parallel-implementation-gap) is a capability implemented by parallel modules where the canonical modules import a security check from a shared template and the divergent module does not. The pattern's [Drupal exhibit](https://nefariousplan.com/posts/drupal-cve-2026-9082-the-comment-said-values) describes it: the base `Sql/Condition` is safe because it abstains from building IN-clauses out of array values, and the PostgreSQL override is unsafe because it has to. CVE-2026-9082 names the override.\n\nCVE-2025-62507 is the same shape, this time inside one file. Six `static_ids` declarations in `t_stream.c`. Five with the heap-realloc check. One without. The canonical idiom is in the file five times over. The divergent function is the canonical idiom with two lines absent.\n\nPR #14130 is an unusually clean exhibit because the divergence is internal to a single PR. The author touched two new functions. They typed the idiom correctly once, in `xdelexCommand`. They typed it incorrectly once, in `xackdelCommand`. The code review of the PR had the correctly-typed sibling in front of it, in the same file, and did not flag the divergence. Three months passed between merge and the CVE.\n\nThe vendor advisory credits Google Big Sleep, Google's LLM-based vulnerability research agent. A system that searches for boilerplate variations across a codebase is the kind of system that finds a function missing two lines that appear in five neighboring functions. The bug is the kind a structural comparator catches on its first pass. Redis's repetition of the same six-line idiom across `t_stream.c` is what made the bug findable; the absence of a `STREAMID_VEC_INIT(static_ids, count)` macro that hides the heap-realloc inside an expansion the developer cannot omit is what made the bug write-able in the first place.\n\n## The bug ships with the idiom\n\nFive of six is what humans hit when the language gives them five chances. The defense against stack overflow in stream-ID parsing exists in `t_stream.c` as a six-line ritual the developer has to remember. Every new stream command added to Redis 8.x will have to remember it. When the next author of a new stream command forgets the two lines, the patch will be two lines, and the boilerplate the patch adds will already exist in the file.\n\nPoC: [GartonChan/redis-cve-2025-62507](https://github.com/GartonChan/redis-cve-2025-62507)","closing_line":"The same PR added the bug and the fix. They live in different functions in the same file.","hook_md":"PR #14130 landed two new Redis stream commands in a single commit. `xackdelCommand` at line 3184 of `src/t_stream.c`. `xdelexCommand` at line 4000 of the same file. Both declare `streamID static_ids[STREAMID_STATIC_VECTOR_LEN]` on the stack. Both accept a caller-supplied count of stream IDs. `xdelexCommand`, before writing into the buffer, checks whether the count exceeds the static size and reallocates to the heap if it does. `xackdelCommand` does not.\n\nThe fix that lands in the CVE patch is two lines. Those two lines already exist, eight hundred lines down, in the function the same author added in the same commit.","post_id":539,"slug":"redis-cve-2025-62507-patch-already-existed","title":"CVE-2025-62507: The XACKDEL Patch Already Existed In Five Other Redis Stream Commands","type":"initial","unreadable_sentence":"The same PR added the bug and the fix. They live in different functions in the same file."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCapxV+AAKCRDeZjl4jgkQ JtjgAP4/2gmYNK7gmmvWbmXaakdx3pKV1LJy1WyfTpQYie3X3QD/bV6/X0FkdFpr gmej7mT5hw1rU/OPaMSzOKc6ou3VfAY= =itS/ -----END PGP SIGNATURE-----