Skip to content

fix(ext/web): address stream resource sink by resource id, not raw pointer - #37272

Open
bartlomieju wants to merge 1 commit into
mainfrom
fix/stream-resource-sink-uaf
Open

bartlomieju wants to merge 1 commit into
mainfrom
fix/stream-resource-sink-uaf

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

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.

…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

No deployments
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.

1 participant