[
// finalize_read_part did not detach the compiled pattern's back-pointer
// cp->upstream still referenced the socket to be freed
The fix detaches the back-pointer before teardown:
// fixed (commit 7581c68b, verbatim in the lab)
if (u->input_filter_ctx != NULL && u->input_filter_ctx != u) {
((ngx_stream_lua_socket_compiled_pattern_t *)
The socket's `input_filter_ctx` owned a compiled pattern whose `__gc` handler
dereferenced `upstream` back to the socket. Finalization freed the socket
without first clearing that link, so the Lua collector's later `__gc` call
operated on freed memory. The fix severs both directions of the reference
| `lua-vuln` | `cve-2026-136412:vuln` | dangling back-pointer |
| `lua-fixed` | `cve-2026-136412:fixed` | verbatim detach guard |
| `poc` | `cve-2026-136412-poc:local` | stdlib-only Python driver |
Both target images are compiled with AddressSanitizer. The C harness frees the
socket, then invokes the iterator's `__gc` handler, reproducing the exact
./run-lab.sh build # builds both sides (gcc 14, ASan)
./run-lab.sh up # cve136412lab network: lua-vuln / lua-fixed
* **check** — exit 1 when ASan reports the UAF, 0 when shutdown is clean;
* **exploit** — narrated chain: read error → iterator GC → `__gc` through freed
* **probe** — crash status and sanitizer report.
* **mitigation** — `7581c68b` / detach `cp->upstream`.
A standalone full-chain exploit ships at `exploit/exploit.py`:
python3 exploit/exploit.py --host=lua-vuln
# exit 1 on confirmed ASan UAF, 0 on a safe target
| | `lua-vuln` (pre-fix) | `lua-fixed` (`7581c68b`) |
| socket freed before iterator `__gc` | **ASan `heap-use-after-free`** | **`clean shutdown`** |
Captured runs: `evidence/check-*-run.txt`, `evidence/exploit-*-run.txt`,
`evidence/probe-*-run.txt`, `evidence/mitigation-*-run.txt`,
`evidence/exploit-standalone-run.txt`, `evidence/exploit-standalone-fixed-run.txt`,
`evidence/versions.txt`, `evidence/0day-sweep.txt`.
* Podman (or Docker); bounded containers on the isolated `cve136412lab`
* Real-world exploitation requires a stream-lua application using
`receiveuntil` on a socket that can be driven into a read error.
## 7. Additional findings (0-day sweep on the fixed line)
`finalize_read_part()` detaches the compiled pattern's `upstream` pointer and
clears `input_filter_ctx`, so a later `__gc` cannot touch a freed socket. Normal
`receiveuntil` iterators that are collected before socket close remain
run-lab.sh environment driver (build / up / sweep / down)
Makefile convenience targets
poc/poc.py the PoC (check / exploit / probe / mitigation)
exploit/exploit.py standalone full-chain exploit
lab/harness-*.c verbatim detach guard per side (ASan)
lab/service.py HTTP wrapper (POST /check), child-process isolation
evidence/ captured runs of every mode on both sides
TRACKING.md excluded (working record)
* CVE record —
* Fix commit —
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
