Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 2b68a6816f173200ec2e6e6c87b034e8431e7d6d
https://github.com/WebKit/WebKit/commit/2b68a6816f173200ec2e6e6c87b034e8431e7d6d
Author: Dan Glastonbury <[email protected]>
Date: 2026-07-02 (Thu, 02 Jul 2026)
Changed paths:
A LayoutTests/webxr/xr-isSessionSupported-detached-iframe-crash-expected.txt
A LayoutTests/webxr/xr-isSessionSupported-detached-iframe-crash.html
M Source/WebCore/Modules/webxr/WebXRSystem.cpp
Log Message:
-----------
[WebXR] Use-after-free of WebXRSystem in callbacks re-posted from
ensureImmersiveXRDeviceIsSelected
rdar://175674581
Reviewed by Mike Wyrzykowski.
WebXRSystem::ensureImmersiveXRDeviceIsSelected sends an async
EnumerateImmersiveXRDevices IPC whose reply lambda holds protectedThis = Ref
{ *this }, but inside that lambda a makeScopeExit re-posts the caller's callback
via callOnMainThread(). The reply lambda is then destroyed and protectedThis
drops. The callbacks supplied by isSessionSupported, obtainCurrentDevice and
requestSession capture only raw |this|, so the queued main-thread task holds no
ownership of the WebXRSystem. If iframe removal + GC tears down
NavigatorWebXR::m_xr between the protectedThis drop and the pending
callOnMainThread task, the task reads freed memory.
Separately, the RequestPermissionOnSessionFeatures reply lambda in
requestSession writes m_pendingImmersiveSession through raw |this| in its
!weakThis branch.
Fix by capturing protectedThis = protect(*this) in the isSessionSupported,
obtainCurrentDevice and requestSession callbacks so they keep the WebXRSystem
alive across the callOnMainThread re-post, and by splitting the !weakThis
early-return in the inner requestSession permission reply so it does not touch
members after the object is gone.
Test: webxr/xr-isSessionSupported-detached-iframe-crash.html
* LayoutTests/webxr/xr-isSessionSupported-detached-iframe-crash-expected.txt:
Added.
* LayoutTests/webxr/xr-isSessionSupported-detached-iframe-crash.html: Added.
* Source/WebCore/Modules/webxr/WebXRSystem.cpp:
(WebCore::WebXRSystem::obtainCurrentDevice):
(WebCore::WebXRSystem::isSessionSupported):
(WebCore::WebXRSystem::requestSession):
Originally-landed-as: 305413.841@safari-7624-branch (0e75e33398b8).
rdar://180429045
Canonical link: https://commits.webkit.org/316451@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications