bugfix: heap-use-after-free in tcp_finalize after receiveuntil iterator GC. - #2525
Merged
Merged
Conversation
…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
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.