Repository navigation
fix(ext/web): address stream resource sink by resource id, not raw pointer - #37272
Open
bartlomieju wants to merge 1 commit into
Open
bartlomieju wants to merge 1 commit into
bartlomieju wants to merge 1 commit into
Conversation
…inter
The write side ("sink") of a ReadableStream resource was handed to JS as a
raw pointer to a heap box via a v8::External. Closing the sink freed that
box while the JS-held handle stayed valid, and the write ops re-derefed it
through a pointer check whose only guard was a process-constant marker word.
A reclaimed, forged box therefore gave untrusted JS a use-after-free write
primitive.
Give the sink its own resource (a clone of the channel) addressed by its
own ResourceId instead. All access goes through the resource table, so a
closed or bogus sink id just fails the lookup and the write becomes a no-op
on a closed channel; there is no raw pointer to forge and no unsafe deref.
The sink is a separate resource from the read side because the read side can
be taken out of the table by its consumer (e.g. a Deno.serve response body
with auto_close) while the producer keeps writing, so the sink holds its own
channel clone and its lifetime is independent of the read side's.
This branch has not been deployed
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.
The write side ("sink") of a ReadableStream resource was handed to JS as a
raw pointer to a heap-allocated box, wrapped in a v8::External. Closing the
sink freed that box, but the handle held by JS stayed valid, and the write
ops re-dereferenced it through a check whose only guard was a
process-constant marker word. A reclaimed and forged box therefore let
untrusted JS dereference an arbitrary pointer, i.e. a use-after-free.
This gives the sink its own resource, holding a clone of the channel, and
addresses it by its own resource id instead of a raw pointer. All access now
goes through the resource table, so a closed or bogus sink id simply fails
the lookup and the write becomes a no-op on a closed channel. There is no
pointer for JS to forge and no unsafe dereference left on this path.
The sink is intentionally a separate resource from the read side. The read
side can be taken out of the resource table by its consumer while the
producer is still writing (for example a Deno.serve response body with
auto_close), so the sink keeps its own channel clone and its lifetime stays
independent of the read side's.