Skip to content

bugfix: heap-use-after-free in tcp_finalize after receiveuntil iterator GC. - #2525

Merged
zhuizhuhaomeng merged 1 commit into
openresty:masterfrom
u5surf:issue-2517
Sep 16, 2026
Merged

zhuizhuhaomeng merged 1 commit into
openresty:masterfrom
u5surf:issue-2517

Conversation

@u5surf

@u5surf u5surf commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Fixes a heap-use-after-free after a receiveuntil() read error followed by iterator GC. See #2517 for details and the ASan report.

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

…or GC.

finalize_read_part() only cleared cp->upstream and left
u->input_filter_ctx pointing to the compiled pattern, which the Lua GC
could free before the socket was finalized. Clear both sides.

See openresty#2517.
u5surf added a commit to u5surf/lua-nginx-module that referenced this pull request Sep 15, 2026
nginx is built with NGX_BUILD_ASAN=1 and LuaJIT with LUAJIT_USE_SYSMALLOC,
without which ASan cannot see use-after-free on Lua objects, since
LuaJIT's own allocator never returns that memory to the C allocator.

Includes t/066-socket-receiveuntil.t TEST 27 from openresty#2525, which is the
regression test for openresty#2517. This branch does not carry the fix, so the
ASan job is expected to fail here: it is what verifies that the job
actually detects the defect.
u5surf added a commit to u5surf/lua-nginx-module that referenced this pull request Sep 15, 2026
nginx is built with NGX_BUILD_ASAN=1 and LuaJIT with LUAJIT_USE_SYSMALLOC,
without which ASan cannot see use-after-free on Lua objects, since
LuaJIT's own allocator never returns that memory to the C allocator.

Includes t/066-socket-receiveuntil.t TEST 27 from openresty#2525, which is the
regression test for openresty#2517. This branch does not carry the fix, so the
ASan job is expected to fail here: it is what verifies that the job
actually detects the defect.
u5surf added a commit to u5surf/lua-nginx-module that referenced this pull request Sep 15, 2026
…or GC.

The fix from openresty#2525, applied here so the ASan job can be seen going green
on the same branch where it caught the defect.

Also drops t/065-tcp-socket-timeout.t and t/131-duplex-req-socket.t from
the ASan run: both preload mockeagain themselves, which ASan's library
order check rejects.
@zhuizhuhaomeng
zhuizhuhaomeng merged commit 20acb75 into openresty:master Sep 16, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants