[v26.x backport] http2: avoid uaf while receiving and sending rst_stream - #65264
Open
mcollina wants to merge 2 commits into
Open
[v26.x backport] http2: avoid uaf while receiving and sending rst_stream#65264mcollina wants to merge 2 commits into
mcollina wants to merge 2 commits into
Conversation
Mark the session as receiving around nghttp2_session_mem_recv() and defer RST_STREAM handling while receive is in progress. This prevents closing a stream while nghttp2 still processes it and avoids heap-use-after-free in nghttp2_session_mem_recv2(). Fixes: nodejs#64113 Signed-off-by: Evgeniy Gorbanev <gorbanev.es@gmail.com> PR-URL: nodejs#64166 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
The http2 UAF backport (avoid uaf while receiving and sending rst_stream) added a guard in SendPendingData() that returns busy while added a guard in SendPendingData() that returns busy while mem_recv is processing incoming data. On v26.x this stalls a graceful close: the server's GOAWAY (submitted by server.close()) is not flushed because sends during receive are blocked, so the client never completes its graceful close and both sockets stay open. The upstream fix relies on the http2 JS close/destroy refactor (PR nodejs#63249), which is semver-major and cannot be backported to v26.x. Drop the send guard instead; the RST_STREAM/Destroy/Close deferrals that are the primary UAF protection remain intact. Fixes the hang in test-http2-many-writes-and-destroy.js. Signed-off-by: Matteo Collina <hello@matteocollina.com>
Collaborator
|
Review requested:
|
Contributor
|
116 tests failed on the FIPS jobs, that's expected and already fixed on the staging branch. Closing and reopening to fix that |
aduh95
approved these changes
Aug 13, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v26.x-staging #65264 +/- ##
=================================================
+ Coverage 90.19% 90.29% +0.09%
=================================================
Files 737 729 -8
Lines 240370 242763 +2393
Branches 45490 46920 +1430
=================================================
+ Hits 216797 219191 +2394
+ Misses 15107 15024 -83
- Partials 8466 8548 +82
🚀 New features to boost your workflow:
|
Collaborator
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.
Backport of #64166 to
v26.x-staging.Original PR: http2: avoid uaf while receiving and sending rst_stream
Fixes: #64113
Backport note
The upstream fix relies on the http2 JS close/destroy refactor from PR #63249 (
http2: error for incomplete reads on RST, auto-drain, deprecate aborted), which is semver-major and cannot be backported to a release branch. Onv26.x(which lacks that refactor) the C++ backport alone stallstest-http2-many-writes-and-destroy.js(graceful close never completes — the server's GOAWAY is not flushed because theSendPendingData()guard returns busy duringnghttp2_session_mem_recv()).So this backport includes a second commit that drops the send guard. The primary UAF protection (the RST_STREAM / Destroy / Close deferrals) remains intact, and the full http2 suite passes.