Skip to content

webgpu: Fix potential UaF in GPUBuffer - #45484

Merged
jschwe merged 1 commit into
servo:mainfrom
jschwe:jschwender/webgpu_uaf
Jun 9, 2026
Merged

jschwe merged 1 commit into
servo:mainfrom
jschwe:jschwender/webgpu_uaf

Conversation

@jschwe

@jschwe jschwe commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

We can't destroy the buffer since it might still be used. Instead, we should send DropBuffer, so the buffer can be destroyed once nothing references it (as all the surrounding webgpu code seems to do).
Fixes a crash (racy) with spookyball on macos.

Testing: Unclear
Fixes: Part of #45474

We can't destroy the buffer since it might still be used.
Instead, we should send `DropBuffer`, so the buffer
can be destroyed once nothing references it.

Signed-off-by: Jonathan Schwender <[email protected]>
@jschwe
jschwe requested a review from sagudev as a code owner June 8, 2026 16:02
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 8, 2026
@sagudev

sagudev commented Jun 8, 2026

Copy link
Copy Markdown
Member

Can you do mach try webgpu on your personal fork (to not clog CI here) to se if there is any change in WebGPU CTS.

@jschwe jschwe mentioned this pull request Jun 8, 2026
2 of 7 tasks
@jschwe

jschwe commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@sagudev

sagudev commented Jun 8, 2026

Copy link
Copy Markdown
Member

@jdm

jdm commented Jun 8, 2026

Copy link
Copy Markdown
Member

Oh, this should make it easy to fix #44640.

@sagudev sagudev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am willing to approve this as we should not be touching any SM objects in finalizers (read drop) anyway. But this is also is not proper solution as we should still do the cleanup (so detaching the buffer) as FF is doing: https://searchfox.org/firefox-main/source/dom/webgpu/Buffer.cpp#146.

I thought maybe we could have trait LazyFinalize: Drop that would cause all such objects to be stored in some array and then dropped from outside. But the problem are subobjects (they might be dead) and realm might also be dead, so we might need to something else (prefinalizer hooks ideally -- are they equal to FinalizeRegistery?)

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jun 9, 2026
@jschwe
jschwe added this pull request to the merge queue Jun 9, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 9, 2026
Merged via the queue into servo:main with commit cd23c72 Jun 9, 2026
34 checks passed
@jschwe
jschwe deleted the jschwender/webgpu_uaf branch June 9, 2026 09:26
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 9, 2026
niyabits pushed a commit to niyabits/servo that referenced this pull request Jun 11, 2026
We can't destroy the buffer since it might still be used. Instead, we
should send `DropBuffer`, so the buffer can be destroyed once nothing
references it (as all the surrounding webgpu code seems to do).
Fixes a crash (racy) with spookyball on macos.

Testing: Unclear
Fixes: Part of servo#45474

Signed-off-by: Jonathan Schwender <[email protected]>
jschwe added a commit to jschwe/servo that referenced this pull request Jun 26, 2026
We can't destroy the buffer since it might still be used. Instead, we
should send `DropBuffer`, so the buffer can be destroyed once nothing
references it (as all the surrounding webgpu code seems to do).
Fixes a crash (racy) with spookyball on macos.

Testing: Unclear
Fixes: Part of servo#45474

Signed-off-by: Jonathan Schwender <[email protected]>
(cherry picked from commit cd23c72)
jschwe added a commit that referenced this pull request Jun 26, 2026
We can't destroy the buffer since it might still be used. Instead, we
should send `DropBuffer`, so the buffer can be destroyed once nothing
references it (as all the surrounding webgpu code seems to do).
Fixes a crash (racy) with spookyball on macos.

Testing: Unclear
Fixes: Part of #45474

Signed-off-by: Jonathan Schwender <[email protected]>
(cherry picked from commit cd23c72)
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.

4 participants