Use after free in Media Stream (CVE-2024-6775)
A use-after-free flaw in Chromium's media stream handling occurs when a raw pointer to a RenderFrameHost is passed to an asynchronous callback and later dereferenced after the frame has been freed. An attacker could potentially exploit this to cause a crash or possibly execute arbitrary code.
- Fix shipped in 32 days
Security Bug
Important: Please do not change the component of this bug manually.
Please READ THIS FAQ before filing a bug: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md
Please see the following link for instructions on filing security bugs: https://www.chromium.org/Home/chromium-security/reporting-security-bugs
Reports may be eligible for reward payments under the Chrome VRP: https://g.co/chrome/vrp
NOTE: Security bugs are normally made public once a fix has been widely deployed.
VULNERABILITY DETAILS
The GetPrimaryMainFrame[1] function will return RenderFrameHostImpl raw pointer. And it is passed as a callback parameter to GetRawDeviceIdsOpenedForFrame [0], which eventually results in UAF at [2].
void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened( blink::mojom::MediaStreamType type, base::OnceCallback<void(std::vectorstd::string)> callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); CHECK(type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE || type == blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE);
MediaStreamManager* media_stream_manager = BrowserMainLoop::GetInstance()->media_stream_manager(); if (!media_stream_manager) { std::move(callback).Run({}); return; }
GetIOThreadTaskRunner({})->PostTask( FROM_HERE, base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame, base::Unretained(media_stream_manager), GetPrimaryMainFrame(), type, //[0] base::BindPostTaskToCurrentDefault(std::move(callback)))); }
RenderFrameHostImpl* WebContentsImpl::GetPrimaryMainFrame() { return const_cast<RenderFrameHostImpl*>( //[1] std::as_const(*this).GetPrimaryMainFrame()); }
void MediaStreamManager::GetRawDeviceIdsOpenedForFrame( RenderFrameHost* render_frame_host, blink::mojom::MediaStreamType type, GetRawDeviceIdsOpenedForFrameCallback callback) const { DCHECK_CURRENTLY_ON(BrowserThread::IO); CHECK(render_frame_host); auto collect_all_render_frame_host_ids = base::BindOnce( [](RenderFrameHost* render_frame_host) { base::flat_set<GlobalRenderFrameHostId> all_render_frame_host_ids; render_frame_host->ForEachRenderFrameHost( //[2] UAF occur [&all_render_frame_host_ids](RenderFrameHost* render_frame_host) { all_render_frame_host_ids.insert( render_frame_host->GetGlobalId()); }); return all_render_frame_host_ids; }, render_frame_host);
GetUIThreadTaskRunner()->PostTaskAndReplyWithResult( FROM_HERE, std::move(collect_all_render_frame_host_ids), base::BindPostTaskToCurrentDefault( base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrameIds, base::Unretained(this), type, std::move(callback)))); }
VERSION Chrome Version: newest Operating System: Macos
REPRODUCTION CASE
1.Please make sure the microphone or camera permissions are enabled 2.out/Default/Chromium.app/Contents/MacOS/Chromium http://127.0.0.1:9000/poc.html about:blank 3.Need a little interaction, click the button.
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION Type of crash: [tab, browser, etc.] Crash State: [see link above: stack trace with symbols, registers, exception record] Client ID (if relevant): [see link above]
================================================================= ==21851==ERROR: AddressSanitizer: heap-use-after-free on address 0x622000354100 at pc 0x00010f635a40 bp 0x00016ee74fd0 sp 0x00016ee74fc8 READ of size 8 at 0x622000354100 thread T0 ==21851==WARNING: invalid path to external symbolizer! ==21851==WARNING: Failed to use and restart external symbolizer! #0 0x10f635a3c in base::internal::Invoker<base::internal::FunctorTraits<content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0&&, content::RenderFrameHost*&&>, base::internal::BindState<false, false, false, content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0, base::internal::UnretainedWrapper<content::RenderFrameHost, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>::RunOnce(base::internal::BindStateBase*)+0x254 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b05a3c) #1 0x10f647cb0 in void base::internal::ReturnAsParamAdapter<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>>(base::OnceCallback<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>, std::__Cr::unique_ptr<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>, std::__Cr::default_delete<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>>>)+0x160 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b17cb0) #2 0x10f6483e4 in base::internal::Invoker<base::internal::FunctorTraits<void (&&)(base::OnceCallback<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>, std::__Cr::unique_ptr<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>, std::__Cr::default_delete<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>>>), base::OnceCallback<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>&&, std::__Cr::unique_ptr<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>, std::__Cr::default_delete<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>>>&&>, base::internal::BindState<false, true, false, void ()(base::OnceCallback<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>, std::__Cr::unique_ptr<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>, std::__Cr::default_delete<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>>>), base::OnceCallback<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>, base::internal::UnretainedWrapper<std::__Cr::unique_ptr<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>, std::__Cr::default_delete<base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>>>>, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, void ()>::RunOnce(base::internal::BindStateBase*)+0x19c (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b183e4) #3 0x1037204a4 in base::internal::PostTaskAndReplyRelay::RunTaskAndPostReply(base::internal::PostTaskAndReplyRelay)+0x160 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x20c4a4) #4 0x103720854 in base::internal::Invoker<base::internal::FunctorTraits<void (&&)(base::internal::PostTaskAndReplyRelay), base::internal::PostTaskAndReplyRelay&&>, base::internal::BindState<false, true, false, void ()(base::internal::PostTaskAndReplyRelay), base::internal::PostTaskAndReplyRelay>, void ()>::RunOnce(base::internal::BindStateBase*)+0x110 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x20c854) #5 0x1036a1a94 in base::TaskAnnotator::RunTaskImpl(base::PendingTask&)+0x34c (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x18da94) #6 0x10370abbc in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow*)+0x7f8 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x1f6bbc) #7 0x10370a028 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()+0x138 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x1f6028) #8 0x1038540e4 in base::MessagePumpCFRunLoopBase::RunWork()+0x1c4 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x3400e4) #9 0x1038427f0 in base::apple::CallWithEHFrame(void () block_pointer)+0xc (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x32e7f0) #10 0x103852688 in base::MessagePumpCFRunLoopBase::RunWorkSource(void*)+0xec (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x33e688) #11 0x1918ba4d4 in CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION+0x18 (/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation:arm64+0x7e4d4) #12 0x90610001918ba468 (<unknown module>) #13 0x644d0001918ba1d8 (<unknown module>) #14 0xc1608001918b8dc4 (<unknown module>) #15 0x18508001918b8430 (<unknown module>) #16 0x753c80019c05c198 (<unknown module>) #17 0x655b00019c05be28 (<unknown module>) #18 0xe46400019c05bd2c (<unknown module>) #19 0x801f800195117d64 (<unknown module>) #20 0x6a2500019590d804 (<unknown module>) #21 0x810600011b4b0b24 (<unknown module>) #22 0x1038427f0 in base::apple::CallWithEHFrame(void () block_pointer)+0xc (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x32e7f0) #23 0x11b4b07e8 in -[BrowserCrApplication nextEventMatchingMask:untilDate:inMode:dequeue:]+0x1a4 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x2d807e8) #24 0x19510b098 in -[NSApplication run]+0x1d8 (/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit:arm64+0x2d098) #25 0x1e0e000103856000 (<unknown module>) #26 0x1038512a4 in base::MessagePumpCFRunLoopBase::Run(base::MessagePump::Delegate*)+0x28c (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x33d2a4) #27 0x10370c16c in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta)+0x3cc (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x1f816c) #28 0x1036354d0 in base::RunLoop::Run(base::Location const&)+0x438 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x1214d0) #29 0x10e8a3df0 in content::BrowserMainLoop::RunMainMessageLoop()+0x178 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0xd73df0) #30 0x10e8aa0f4 in content::BrowserMainRunnerImpl::Run()+0x30 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0xd7a0f4) #31 0x10e89c80c in content::BrowserMain(content::MainFunctionParams)+0x1f8 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0xd6c80c) #32 0x110c663b0 in content::RunBrowserProcessMain(content::MainFunctionParams, content::ContentMainDelegate*)+0x1ac (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x31363b0) #33 0x110c68fb0 in content::ContentMainRunnerImpl::RunBrowser(content::MainFunctionParams, bool)+0x8dc (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x3138fb0) #34 0x110c684ac in content::ContentMainRunnerImpl::Run()+0x490 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x31384ac) #35 0x110c6468c in content::RunContentProcess(content::ContentMainParams, content::ContentMainRunner*)+0x670 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x313468c) #36 0x110c64f44 in content::ContentMain(content::ContentMainParams)+0x190 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x3134f44) #37 0x11873aeac in ChromeMain+0x338 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0xaeac) #38 0x100f88b80 in main+0x1f8 (/Users/test/chromium/src/out/Default/Chromium.app/Contents/MacOS/Chromium:arm64+0x100000b80) #39 0x1914520dc (<unknown module>) #40 0xa85efffffffffffc (<unknown module>)
0x622000354100 is located 0 bytes inside of 5328-byte region [0x622000354100,0x6220003555d0) freed by thread T0 here: #0 0x101b48524 in __sanitizer_finish_switch_fiber+0xa24 (/Users/test/chromium/src/out/Default/Chromium.app/Contents/MacOS/libclang_rt.asan_osx_dynamic.dylib:arm64+0x60524) #1 0x10f8d3270 in content::RenderFrameHostManager::~RenderFrameHostManager()+0xa8 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1da3270) #2 0x10f564708 in content::FrameTreeNode::~FrameTreeNode()+0xd14 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1a34708) #3 0x10f5549d8 in content::FrameTree::~FrameTree()+0x54 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1a249d8) #4 0x10fe82830 in content::WebContentsImpl::~WebContentsImpl()+0x1508 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x2352830) #5 0x10fe84fe0 in content::WebContentsImpl::~WebContentsImpl()+0x8 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x2354fe0) #6 0x11fbbdd38 in tabs::TabModel::~TabModel()+0x1bc (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x748dd38) #7 0x11fbd40b8 in TabStripModel::SendDetachWebContentsNotifications(TabStripModel::DetachNotifications*)+0x5ac (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x74a40b8) #8 0x11fbddffc in TabStripModel::CloseTabs(base::span<content::WebContents* const, 18446744073709551615ul, content::WebContents* const*>, unsigned int)+0xb90 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x74adffc) #9 0x11fbdd188 in TabStripModel::CloseAllTabs()+0x368 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x74ad188) #10 0x120549f74 in BrowserView::OnWindowCloseRequested()+0x128 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7e19f74) #11 0x13a965048 in views::Widget::CloseWithReason(views::Widget::ClosedReason)+0x190 (/Users/test/chromium/src/out/Default/libui_views.dylib:arm64+0x3b1048) #12 0x11bdfde2c in BrowserCloseManager::CloseBrowsers()+0x220 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x36cde2c) #13 0x11bdfe32c in BrowserCloseManager::TryToCloseBrowsers()+0x228 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x36ce32c) #14 0x11bdfbc20 in chrome::CloseAllBrowsers()+0x104 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x36cbc20) #15 0x11b496b4c in -[AppController tryToTerminateApplication:]+0xf4 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x2d66b4c) #16 0x11b4b05e0 in -[BrowserCrApplication terminate:]+0x3c (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x2d805e0) #17 0x11c184ebc in (anonymous namespace)::ExitHandler::ExitWhenPossibleOnUIThread(int)+0x1d4 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x3a54ebc) #18 0x11c1851c4 in base::internal::Invoker<base::internal::FunctorTraits<void (&&)(int)>, base::internal::BindState<false, true, false, void ()(int)>, void (int)>::RunOnce(base::internal::BindStateBase*, int)+0xe0 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x3a551c4) #19 0x11ae1e588 in base::internal::Invoker<base::internal::FunctorTraits<base::OnceCallback<void (int)>&&, int&&>, base::internal::BindState<false, true, true, base::OnceCallback<void (int)>, int>, void ()>::RunOnce(base::internal::BindStateBase*)+0x188 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x26ee588) #20 0x1036a1a94 in base::TaskAnnotator::RunTaskImpl(base::PendingTask&)+0x34c (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x18da94) #21 0x10370abbc in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::LazyNow*)+0x7f8 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x1f6bbc) #22 0x10370a028 in base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork()+0x138 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x1f6028) #23 0x1038540e4 in base::MessagePumpCFRunLoopBase::RunWork()+0x1c4 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x3400e4) #24 0x1038427f0 in base::apple::CallWithEHFrame(void () block_pointer)+0xc (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x32e7f0) #25 0x103852688 in base::MessagePumpCFRunLoopBase::RunWorkSource(void*)+0xec (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x33e688) #26 0x1918ba4d4 in CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION+0x18 (/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation:arm64+0x7e4d4) #27 0x90610001918ba468 (<unknown module>) #28 0x644d0001918ba1d8 (<unknown module>) #29 0xc1608001918b8dc4 (<unknown module>)
previously allocated by thread T0 here: #0 0x101b4811c in __sanitizer_finish_switch_fiber+0x61c (/Users/test/chromium/src/out/Default/Chromium.app/Contents/MacOS/libclang_rt.asan_osx_dynamic.dylib:arm64+0x6011c) #1 0x10f7e37b4 in content::RenderFrameHostFactory::Create(content::SiteInstance*, scoped_refptrcontent::RenderViewHostImpl, content::RenderFrameHostDelegate*, content::FrameTree*, content::FrameTreeNode*, int, mojo::PendingAssociatedRemotecontent::mojom::Frame, base::TokenTypeblink::LocalFrameTokenTypeMarker const&, base::TokenTypeblink::DocumentTokenTypeMarker const&, base::UnguessableToken, bool, content::RenderFrameHostImpl::LifecycleStateImpl, scoped_refptrcontent::BrowsingContextState)+0x270 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1cb37b4) #2 0x10f8d5134 in content::RenderFrameHostManager::CreateRenderFrameHost(content::RenderFrameHostManager::CreateFrameCase, content::SiteInstanceImpl*, int, mojo::PendingAssociatedRemotecontent::mojom::Frame, base::TokenTypeblink::LocalFrameTokenTypeMarker const&, base::TokenTypeblink::DocumentTokenTypeMarker const&, base::UnguessableToken, bool, scoped_refptrcontent::BrowsingContextState)+0x830 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1da5134) #3 0x10f8d431c in content::RenderFrameHostManager::InitRoot(content::SiteInstanceImpl*, bool, blink::FramePolicy, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&, base::UnguessableToken const&)+0x648 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1da431c) #4 0x10f55bb7c in content::FrameTree::Init(content::SiteInstanceImpl*, bool, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&, content::RenderFrameHostImpl*, blink::FramePolicy const&, base::UnguessableToken const&)+0x128 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1a2bb7c) #5 0x10f40cbcc in content::PrerenderHost::PrerenderHost(content::PrerenderAttributes const&, content::WebContentsImpl&, base::WeakPtrcontent::PreloadingAttempt, std::__Cr::unique_ptr<content::DevToolsPrerenderAttempt, std::__Cr::default_deletecontent::DevToolsPrerenderAttempt>)+0x6e8 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x18dcbcc) #6 0x10f428424 in content::(anonymous namespace)::PrerenderHostBuilder::Build(content::PrerenderAttributes const&, content::WebContentsImpl&)+0x218 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x18f8424) #7 0x10f4257ec in content::PrerenderHostRegistry::CreateAndStartHost(content::PrerenderAttributes const&, content::PreloadingAttempt*)+0xb78 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x18f57ec) #8 0x10ff2c8e8 in content::WebContentsImpl::StartPrerendering(GURL const&, content::PreloadingTriggerType, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&, ui::PageTransition, content::PreloadingHoldbackStatus, content::PreloadingAttempt*, base::RepeatingCallback<bool (GURL const&)>, base::RepeatingCallback<void (content::NavigationHandle&)>)+0x344 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x23fc8e8) #9 0x11b9c44f4 in PrerenderManager::StartPrerenderDirectUrlInput(GURL const&, content::PreloadingAttempt&)+0x35c (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x32944f4) #10 0x11b9d26b4 in predictors::AutocompleteActionPredictor::StartPrerendering(GURL const&, content::WebContents&, gfx::Size const&)+0x300 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x32a26b4) #11 0x12062e614 in ChromeOmniboxClient::DoPrerender(AutocompleteMatch const&)+0x1a4 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7efe614) #12 0x12062e30c in ChromeOmniboxClient::OnTextChanged(AutocompleteMatch const&, bool, std::__Cr::basic_string<char16_t, std::__Cr::char_traits<char16_t>, std::__Cr::allocator<char16_t>> const&, AutocompleteResult const&, bool)+0x274 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7efe30c) #13 0x11f8a85c0 in OmniboxEditModel::OnChanged()+0x228 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x71785c0) #14 0x11f8b7ab0 in OmniboxEditModel::OnPopupDataChanged(std::__Cr::basic_string<char16_t, std::__Cr::char_traits<char16_t>, std::__Cr::allocator<char16_t>> const&, bool, std::__Cr::basic_string<char16_t, std::__Cr::char_traits<char16_t>, std::__Cr::allocator<char16_t>> const&, std::__Cr::basic_string<char16_t, std::__Cr::char_traits<char16_t>, std::__Cr::allocator<char16_t>> const&, std::__Cr::basic_string<char16_t, std::__Cr::char_traits<char16_t>, std::__Cr::allocator<char16_t>> const&, bool, std::__Cr::basic_string<char16_t, std::__Cr::char_traits<char16_t>, std::__Cr::allocator<char16_t>> const&, AutocompleteMatch const&)+0xc94 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7187ab0) #15 0x11f8b9c58 in OmniboxEditModel::OnCurrentMatchChanged()+0x3dc (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7189c58) #16 0x11f8a37b4 in OmniboxController::OnResultChanged(AutocompleteController*, bool)+0x208 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x71737b4) #17 0x11e74982c in AutocompleteController::NotifyChanged()+0x5f4 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x601982c) #18 0x11e74d3d8 in base::internal::Invoker<base::internal::FunctorTraits<void (AutocompleteController::&&)(), AutocompleteController>, base::internal::BindState<true, true, false, void (AutocompleteController::)(), base::internal::UnretainedWrapper<AutocompleteController, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, void ()>::RunOnce(base::internal::BindStateBase)+0x184 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x601d3d8) #19 0x11e78ba90 in AutocompleteProviderDebouncer::Run()+0x154 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x605ba90) #20 0x11e78bd88 in base::internal::Invoker<base::internal::FunctorTraits<void (AutocompleteProviderDebouncer::&&)(), AutocompleteProviderDebouncer>, base::internal::BindState<true, true, false, void (AutocompleteProviderDebouncer::)(), base::internal::UnretainedWrapper<AutocompleteProviderDebouncer, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, void ()>::RunOnce(base::internal::BindStateBase)+0x184 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x605bd88) #21 0x1037ad058 in base::OneShotTimer::RunUserTask()+0x1a0 (/Users/test/chromium/src/out/Default/libbase.dylib:arm64+0x299058) #22 0x11e73d4b0 in AutocompleteController::RequestNotifyChanged(bool, bool)+0x1ac (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x600d4b0) #23 0x11e73cad4 in AutocompleteController::UpdateResult(AutocompleteController::UpdateType)+0x674 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x600cad4) #24 0x11e73b924 in AutocompleteController::Start(AutocompleteInput const&)+0xbcc (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x600b924) #25 0x11f8a2814 in OmniboxController::StartAutocomplete(AutocompleteInput const&) const+0x168 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7172814) #26 0x11f8ab640 in OmniboxEditModel::StartAutocomplete(bool, bool)+0x85c (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x717b640) #27 0x11f8a9ed4 in OmniboxEditModel::UpdateInput(bool, bool)+0x1e0 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7179ed4) #28 0x11f8b87b8 in OmniboxEditModel::OnAfterPossibleChange(OmniboxView::StateChanges const&, bool)+0x6d8 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x71887b8) #29 0x1206e6e34 in OmniboxViewViews::OnAfterPossibleChange(bool)+0x180 (/Users/test/chromium/src/out/Default/libchrome_dll.dylib:arm64+0x7fb6e34)
SUMMARY: AddressSanitizer: heap-use-after-free (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b05a3c) in base::internal::Invoker<base::internal::FunctorTraits<content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0&&, content::RenderFrameHost*&&>, base::internal::BindState<false, false, false, content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0, base::internal::UnretainedWrapper<content::RenderFrameHost, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocatorcontent::GlobalRenderFrameHostId>> ()>::RunOnce(base::internal::BindStateBase*)+0x254 Shadow bytes around the buggy address: 0x622000353e80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x622000353f00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x622000353f80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x622000354000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x622000354080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa f7 fa =>0x622000354100:[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x622000354180: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x622000354200: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x622000354280: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x622000354300: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd 0x622000354380: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb
==21851==ADDITIONAL INFO
==21851==Note: Please include this section with the ASan report. Task trace: #0 0x10f622fe8 in content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const+0x2d8 (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1af2fe8) #1 0x10ff2dc10 in content::WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened(blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>)+0x22c (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x23fdc10)
CREDIT INFORMATION Externally reported security bugs may appear in Chrome release notes. If this bug is included, how would you like to be credited? Reporter credit: anonymous
I made a small change to the code to make it easier to trigger the vulnerability.
patch.diff @@ -11116,6 +11039,9 @@ void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpene return; }
- LOG(ERROR)<<"GetRawDeviceIdsOpenedForFrame----------";
- sleep(5);
- GetIOThreadTaskRunner({})->PostTask( FROM_HERE, base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame, @@ -11125,3 +11051,4 @@ void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpene
Fix
use WeakPtr or don't use pointer
commit introduce
https://chromium-review.googlesource.com/c/chromium/src/+/4976193
Context
This is a use-after-free (UAF) in Chrome's media capture code, tracked as CVE-2024-6775 and affecting the Media Stream component. The bug sits in the browser process, in the path that answers the question "which raw capture device IDs are currently open for this frame?". That path is reached through WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened, which forwards the request to the MediaStreamManager living on the IO thread.
The report was filed through the Chrome VRP and credited to an anonymous reporter. It is a high severity memory safety issue in the browser process, which is the process that holds the privileges worth attacking.
Setup
- Target: Chromium built from source, run from
out/Default. - Operating system: macOS.
- Version: the report says "newest" Chrome version; no specific build number is given.
- Precondition: microphone or camera permissions must already be enabled for the origin used in the proof of concept.
- The proof of concept is served locally at
http://[redacted]:9000/poc.htmland is opened alongsideabout:blank. - Some interaction is required: the user has to click a button on the page.
- The crash was observed under AddressSanitizer, so an ASan build is needed to reproduce the reported output.
Finding it
The reporter traced the call chain and noticed that a raw RenderFrameHostImpl* pointer is captured and then used later, after control has moved between threads. The pointer comes from GetPrimaryMainFrame, which returns a raw pointer obtained through a const_cast:
RenderFrameHostImpl* WebContentsImpl::GetPrimaryMainFrame() {
return const_cast<RenderFrameHostImpl*>( //[1]
std::as_const(*this).GetPrimaryMainFrame());
}
That pointer is passed as a bound argument into a task posted to the IO thread:
void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened(
blink::mojom::MediaStreamType type,
base::OnceCallback<void(std::vector<std::string>)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CHECK(type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE ||
type == blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE);
MediaStreamManager* media_stream_manager =
BrowserMainLoop::GetInstance()->media_stream_manager();
if (!media_stream_manager) {
std::move(callback).Run({});
return;
}
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame,
base::Unretained(media_stream_manager),
GetPrimaryMainFrame(), type, //[0]
base::BindPostTaskToCurrentDefault(std::move(callback))));
}
Nothing in this code keeps the frame host alive while the task is in flight. If the frame host is destroyed in the meantime, the pointer bound into the task dangles.
Exploitation
Step 1: enable capture permissions
Make sure the microphone or camera permissions are enabled, so the media capture path can be reached without a permission prompt blocking the flow.
Step 2: launch Chromium with the proof of concept
out/Default/Chromium.app/Contents/MacOS/Chromium http://[redacted]:9000/poc.html about:blank
This opens the local proof of concept page together with a blank tab.
Step 3: interact with the page
Click the button on the page. This is the only user interaction the report asks for. The click drives the code into GetMediaCaptureRawDeviceIdsOpened, which posts the task carrying the raw frame host pointer to the IO thread.
Step 4: let the frame host die before the task runs
The bound pointer is dereferenced later, on the UI thread, inside the callback that enumerates frame hosts:
void MediaStreamManager::GetRawDeviceIdsOpenedForFrame(
RenderFrameHost* render_frame_host,
blink::mojom::MediaStreamType type,
GetRawDeviceIdsOpenedForFrameCallback callback) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
CHECK(render_frame_host);
auto collect_all_render_frame_host_ids = base::BindOnce(
[](RenderFrameHost* render_frame_host) {
base::flat_set<GlobalRenderFrameHostId> all_render_frame_host_ids;
render_frame_host->ForEachRenderFrameHost( //[2] UAF occur
[&all_render_frame_host_ids](RenderFrameHost* render_frame_host) {
all_render_frame_host_ids.insert(
render_frame_host->GetGlobalId());
});
return all_render_frame_host_ids;
},
render_frame_host);
GetUIThreadTaskRunner()->PostTaskAndReplyWithResult(
FROM_HERE, std::move(collect_all_render_frame_host_ids),
base::BindPostTaskToCurrentDefault(
base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrameIds,
base::Unretained(this), type, std::move(callback))));
}
The ForEachRenderFrameHost call on the captured pointer is where the use-after-free happens. In the reported run, the frame host had already been freed because the browser was being closed: the free stack shows RenderFrameHostManager::~RenderFrameHostManager, FrameTreeNode::~FrameTreeNode, FrameTree::~FrameTree and WebContentsImpl::~WebContentsImpl, reached from TabStripModel::CloseAllTabs and BrowserView::OnWindowCloseRequested during application termination.
Step 5: observe the ASan report
The crash is a heap-use-after-free, a READ of size 8, in the invoker for the lambda inside GetRawDeviceIdsOpenedForFrame:
==21851==ERROR: AddressSanitizer: heap-use-after-free on address 0x622000354100 at pc 0x00010f635a40 bp 0x00016ee74fd0 sp 0x00016ee74fc8
READ of size 8 at 0x622000354100 thread T0
The summary line names the same location:
SUMMARY: AddressSanitizer: heap-use-after-free (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b05a3c) in base::internal::Invoker<base::internal::FunctorTraits<content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0&&, content::RenderFrameHost*&&>, base::internal::BindState<false, false, false, content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0, base::internal::UnretainedWrapper<content::RenderFrameHost, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocator<content::GlobalRenderFrameHostId>>> ()>::RunOnce(base::internal::BindStateBase*)+0x254
The freed region is 5328 bytes, and the allocation stack shows the frame host being created through RenderFrameHostFactory::Create and RenderFrameHostManager::CreateRenderFrameHost, reached from PrerenderHost::PrerenderHost and PrerenderHostRegistry::CreateAndStartHost, which in turn came from PrerenderManager::StartPrerenderDirectUrlInput and predictors::AutocompleteActionPredictor::StartPrerendering triggered by omnibox input.
Step 6: widen the race window
The reporter added a deliberate delay to make the bug easier to trigger, in a local patch:
@@ -11116,6 +11039,9 @@ void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpene
return;
}
+ LOG(ERROR)<<"GetRawDeviceIdsOpenedForFrame----------";
+ sleep(5);
+
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame,
@@ -11125,3 +11051,4 @@ void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpene
The five second sleep before posting the task makes the bug easier to trigger.
Root cause
GetPrimaryMainFrame hands out a raw RenderFrameHostImpl* with no ownership or lifetime guarantee. That pointer is bound into a task that crosses from the UI thread to the IO thread and back to the UI thread before it is dereferenced. Between the post and the dereference, the frame host can be destroyed, for example when the tab or browser is closed. The CHECK(render_frame_host) in GetRawDeviceIdsOpenedForFrame only proves the pointer is non-null, not that it still points at a live object, so it does not help. The base::Unretained wrappers used for the manager and the frame host likewise express no lifetime relationship. The reporter's suggested fix is to use a WeakPtr or to avoid holding the pointer at all.
The report also links the change that introduced the code: https://chromium-review.googlesource.com/c/chromium/src/+/4976193.
Impact
This is a browser-process use-after-free in the media capture path, triggered after a user click. A UAF in the browser process is the kind of primitive that can lead to memory corruption and potentially to code execution in the most privileged Chrome process, though the report itself only demonstrates a crash under ASan. The report does not describe a full exploit chain, and the practical exploitability beyond the crash is not established in the text.
Fix
The reporter's recommendation is to use a WeakPtr for the frame host, or not to pass the raw pointer at all. The report does not describe the actual upstream patch that landed.
Variants to test
- Look for other call sites that capture
GetPrimaryMainFrame()or similar raw frame host pointers intoPostTaskorPostTaskAndReplyWithResultchains. A positive result is an ASan heap-use-after-free when the tab is closed while the task is pending. - Check other
base::Unretainedbindings of objects whose lifetime is tied to aWebContentsorFrameTree. A positive result is a crash whose free stack passes throughWebContentsImpl::~WebContentsImplorFrameTree::~FrameTree. - Exercise prerender-created frame hosts, since the allocation stack here comes from
PrerenderHost. A positive result is a UAF that only reproduces when the frame host was created by prerendering rather than by a normal navigation. - Add a temporary sleep before cross-thread posts in media capture paths and close the browser during the window. A positive result is a reproducible ASan report naming the delayed function.
What happened, in plain words
Chrome is made of several programs that run side by side. One of them, the browser process, is the one that can read your files, talk to the network and control the whole application. The others, the renderer processes, run the web pages themselves and are kept in a sandbox so that a malicious page cannot easily hurt your computer. When a bug lets a web page corrupt memory inside the browser process, that is serious, because the browser process is the part with all the privileges.
This report describes exactly that kind of bug. It is a memory safety flaw in the code Chrome uses for media capture, meaning the microphone and the camera. The bug is tracked as CVE-2024-6775. A CVE is a public identifier given to a known security flaw so that people can talk about it and track fixes. The affected component is called Media Stream, which is the part of Chrome that handles audio and video streams from devices.
The flaw is a use-after-free, often shortened to UAF. To understand it, imagine a hotel. You are given a room key (a pointer, which is a memory address). You put the key in your pocket and go for lunch. While you are away, the hotel checks you out, cleans the room and gives it to someone else. When you come back and use your key, you are walking into a room that is no longer yours. In a computer, the memory has been handed back to the system and may now hold something completely different. Reading or writing it can crash the program, and in the worst case an attacker can arrange for the memory to contain data they control.
The specific question this code answers is: which raw capture device IDs are currently open for this frame? A frame is one document inside a tab, for example the main page or an embedded iframe. A device ID is an internal identifier for a microphone or camera. The request travels through a function called WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened, which hands the work to a MediaStreamManager that lives on a different thread. A thread is an independent line of execution inside a program; Chrome uses several so that slow work does not freeze the interface.
The report was filed through the Chrome VRP. The VRP, or Vulnerability Reward Program, is a scheme where Google pays people who report security bugs responsibly instead of exploiting them. The reporter is credited as anonymous. The reporter is credited as anonymous.
Setup
Before reproducing, the reporter describes the environment:
- Target: Chromium built from source, run from
out/Default. Building from source means compiling the browser yourself from its code, which gives you debug builds and tools that a normal download does not include. - Operating system: macOS.
- Version: the report says "newest" Chrome version; no specific build number is given.
- Precondition: microphone or camera permissions must already be enabled for the origin used in the proof of concept. An origin is the combination of scheme, host and port that identifies a site, for example
http://[redacted]:9000. Permissions are the yes/no answers Chrome stores for questions like "may this site use the camera?". - The proof of concept is served locally at
http://[redacted]:9000/poc.htmland is opened alongsideabout:blank. A proof of concept, or PoC, is a small test page or program that demonstrates a bug.[redacted]is the loopback address, meaning this computer itself, andabout:blankis Chrome's built-in empty page. - Some interaction is required: the user has to click a button on the page. This matters because browsers deliberately restrict powerful features so that a page cannot trigger them without the user doing something.
- The crash was observed under AddressSanitizer, so an ASan build is needed to reproduce the reported output. AddressSanitizer, or ASan, is a tool compiled into the program that watches every memory access and shouts loudly when code touches memory it should not. Without it, a use-after-free might silently do nothing or crash in a confusing place.
Finding it
The reporter traced the call chain, meaning they followed the sequence of function calls from the entry point down to the dangerous operation, and noticed that a raw RenderFrameHostImpl* pointer is captured and then used later, after control has moved between threads. A RenderFrameHostImpl is Chrome's internal object representing one frame. The word raw here means the pointer carries no promise that the object is still alive; it is just a number that says where the object was.
The pointer comes from GetPrimaryMainFrame, which returns a raw pointer obtained through a const_cast:
RenderFrameHostImpl* WebContentsImpl::GetPrimaryMainFrame() {
return const_cast<RenderFrameHostImpl*>( //[1]
std::as_const(*this).GetPrimaryMainFrame());
}
Line by line:
RenderFrameHostImpl* WebContentsImpl::GetPrimaryMainFrame()declares a function that returns a pointer to aRenderFrameHostImpl. The*after the type is what makes it a pointer.return const_cast<RenderFrameHostImpl*>(starts a cast. A cast converts one type to another.const_castspecifically removes or adds theconstqualifier, which is a promise that a value will not be modified. Here the code is stripping that promise away so it can hand out a mutable pointer.std::as_const(*this).GetPrimaryMainFrame()calls the same function on a constant view of the current object, which returns a pointer to a constant object.- The closing
);finishes the call and the cast.
In plain words: the function takes a pointer that was supposed to be read-only and turns it into a normal writable pointer. Nothing here keeps the object alive.
That pointer is passed as a bound argument into a task posted to the IO thread:
void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened(
blink::mojom::MediaStreamType type,
base::OnceCallback<void(std::vector<std::string>)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CHECK(type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE ||
type == blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE);
MediaStreamManager* media_stream_manager =
BrowserMainLoop::GetInstance()->media_stream_manager();
if (!media_stream_manager) {
std::move(callback).Run({});
return;
}
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame,
base::Unretained(media_stream_manager),
GetPrimaryMainFrame(), type, //[0]
base::BindPostTaskToCurrentDefault(std::move(callback))));
}
Line by line:
void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpened(begins a function that returns nothing (void). It takes two parameters.blink::mojom::MediaStreamType type,is the kind of capture device being asked about.blinkis Chrome's web engine, andmojomis the interface definition system Chrome uses to talk between processes.base::OnceCallback<void(std::vector<std::string>)> callback)is a callback: a function you hand over so that it can be called later with the answer.OnceCallbackmeans it can be called exactly once. The answer is a list of strings, which will be the device IDs.DCHECK_CURRENTLY_ON(BrowserThread::UI);is a debug-only assertion that this code is running on the UI thread, the thread that handles the browser's user interface.CHECK(type == ... || type == ...);stops the program unless the type is audio capture or video capture. This is a guard so the function is only used for the two device kinds it understands.MediaStreamManager* media_stream_manager =declares a pointer to the manager object.BrowserMainLoop::GetInstance()->media_stream_manager();fetches the global browser main loop and asks it for the media stream manager.if (!media_stream_manager) {checks whether the manager exists.std::move(callback).Run({});if it does not, calls the callback immediately with an empty list and returns.std::movetransfers ownership of the callback.GetIOThreadTaskRunner({})->PostTask(asks for the task runner of the IO thread and posts a task to it. The IO thread handles input and output work such as network and device traffic.FROM_HERE,records the source location for debugging.base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame,builds a callable that will invoke that manager function once.base::Unretained(media_stream_manager),passes the manager pointer without any lifetime tracking.Unretainedliterally means "I am not retaining this object", so nothing keeps it alive.GetPrimaryMainFrame(), type,passes the raw frame host pointer from the previous snippet, plus the device type. The comment//[0]marks this as the first point in the chain.base::BindPostTaskToCurrentDefault(std::move(callback))));wraps the original callback so that when the answer comes back it is delivered on the thread that is current by default, which is the UI thread.
Nothing in this code keeps the frame host alive while the task is in flight. If the frame host is destroyed in the meantime, the pointer bound into the task dangles, meaning it points at memory that is no longer the object.
Exploitation
Step 1: enable capture permissions
Make sure the microphone or camera permissions are enabled, so the media capture path can be reached without a permission prompt blocking the flow. A permission prompt is the little dialog Chrome shows asking whether a site may use the camera or microphone. If it appears mid-test, the automated flow stops and the bug is never reached.
Step 2: launch Chromium with the proof of concept
out/Default/Chromium.app/Contents/MacOS/Chromium http://[redacted]:9000/poc.html about:blank
This is a shell command. out/Default/Chromium.app/Contents/MacOS/Chromium is the path to the browser binary inside a build directory. The two arguments are the pages to open: the local proof of concept page and a blank tab. Prerendering is Chrome's trick of quietly loading a page in the background before you navigate to it, so it appears instantly. The omnibox is the address bar.
Step 3: interact with the page
Click the button on the page. This is the only user interaction the report asks for. The click drives the code into GetMediaCaptureRawDeviceIdsOpened, which posts the task carrying the raw frame host pointer to the IO thread. The click is needed because browsers do not let pages start capture silently; a real user gesture is required.
Step 4: let the frame host die before the task runs
The bound pointer is dereferenced later, on the UI thread, inside the callback that enumerates frame hosts. Dereferencing means following the pointer to read the object it points at.
void MediaStreamManager::GetRawDeviceIdsOpenedForFrame(
RenderFrameHost* render_frame_host,
blink::mojom::MediaStreamType type,
GetRawDeviceIdsOpenedForFrameCallback callback) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
CHECK(render_frame_host);
auto collect_all_render_frame_host_ids = base::BindOnce(
[](RenderFrameHost* render_frame_host) {
base::flat_set<GlobalRenderFrameHostId> all_render_frame_host_ids;
render_frame_host->ForEachRenderFrameHost( //[2] UAF occur
[&all_render_frame_host_ids](RenderFrameHost* render_frame_host) {
all_render_frame_host_ids.insert(
render_frame_host->GetGlobalId());
});
return all_render_frame_host_ids;
},
render_frame_host);
GetUIThreadTaskRunner()->PostTaskAndReplyWithResult(
FROM_HERE, std::move(collect_all_render_frame_host_ids),
base::BindPostTaskToCurrentDefault(
base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrameIds,
base::Unretained(this), type, std::move(callback))));
}
Line by line:
void MediaStreamManager::GetRawDeviceIdsOpenedForFrame(begins the manager function. It returns nothing.RenderFrameHost* render_frame_host,is the raw pointer that was captured earlier. This is the object that may already be dead.blink::mojom::MediaStreamType type,is the device type, passed through unchanged.GetRawDeviceIdsOpenedForFrameCallback callback) const {is the callback that will receive the list of IDs. The trailingconstmeans the function does not modify the manager object.DCHECK_CURRENTLY_ON(BrowserThread::IO);asserts in debug builds that this runs on the IO thread.CHECK(render_frame_host);checks that the pointer is not null. This is important to understand: it only proves the pointer is not zero. It says nothing about whether the object still exists.auto collect_all_render_frame_host_ids = base::BindOnce(creates a callable that will collect the IDs.autolets the compiler work out the type.[](RenderFrameHost* render_frame_host) {starts a lambda, which is an unnamed function written inline. It takes the frame host pointer again.base::flat_set<GlobalRenderFrameHostId> all_render_frame_host_ids;declares a set, a collection that keeps unique values, to hold the IDs. AGlobalRenderFrameHostIdis a process-wide identifier for a frame.render_frame_host->ForEachRenderFrameHost( //[2] UAF occurcalls a method on the captured pointer to walk every frame in the tree. The comment marks this as the use-after-free site.[&all_render_frame_host_ids](RenderFrameHost* render_frame_host) {is a nested lambda that captures the set by reference, so it can add to it.all_render_frame_host_ids.insert(adds an entry.render_frame_host->GetGlobalId());reads each frame's global ID.});closes the nested lambda and theForEachRenderFrameHostcall.return all_render_frame_host_ids;returns the collected set.},closes the outer lambda.render_frame_host);binds the raw pointer as the argument to that lambda. This is the moment the dangling pointer is stored for later use.GetUIThreadTaskRunner()->PostTaskAndReplyWithResult(posts the collection work to the UI thread and arranges for a reply with its result.FROM_HERE, std::move(collect_all_render_frame_host_ids),passes the callable and its source location.base::BindPostTaskToCurrentDefault(wraps the final callback so it runs on the right thread.base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrameIds,builds the function that will receive the IDs.base::Unretained(this), type, std::move(callback))));passes the manager itself without lifetime tracking, plus the type and the original callback.
The ForEachRenderFrameHost call on the captured pointer is where the use-after-free happens. In the reported run, the frame host had already been freed because the browser was being closed: the free stack shows RenderFrameHostManager::~RenderFrameHostManager, FrameTreeNode::~FrameTreeNode, FrameTree::~FrameTree and WebContentsImpl::~WebContentsImpl, reached from TabStripModel::CloseAllTabs and BrowserView::OnWindowCloseRequested during application termination. The ~ in those names marks a destructor, the function that runs when an object is destroyed. In plain words: closing the browser tore down the frame tree, and the pending task still held a pointer into that torn-down tree.
Step 5: observe the ASan report
The crash is a heap-use-after-free, a READ of size 8, in the invoker for the lambda inside GetRawDeviceIdsOpenedForFrame. The heap is the pool of memory used for objects created while the program runs. A READ of size 8 means the program tried to read eight bytes, which on a 64-bit machine is the size of a pointer.
==21851==ERROR: AddressSanitizer: heap-use-after-free on address 0x622000354100 at pc 0x00010f635a40 bp 0x00016ee74fd0 sp 0x00016ee74fc8
READ of size 8 at 0x622000354100 thread T0
Line by line:
==21851==ERROR:is ASan's prefix, where 21851 is the process ID of the crashing browser.AddressSanitizer: heap-use-after-freenames the kind of problem: memory from the heap was used after it was freed.on address 0x622000354100is the memory address that was touched.at pc 0x00010f635a40 bp 0x00016ee74fd0 sp 0x00016ee74fc8gives the program counter, base pointer and stack pointer, which are CPU registers that record where execution was. Registers are tiny storage slots inside the processor.READ of size 8 at 0x622000354100 thread T0says the access was a read of eight bytes, on thread T0, the main thread.
The summary line names the same location:
SUMMARY: AddressSanitizer: heap-use-after-free (/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b05a3c) in base::internal::Invoker<base::internal::FunctorTraits<content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0&&, content::RenderFrameHost*&&>, base::internal::BindState<false, false, false, content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(content::RenderFrameHost*, blink::mojom::MediaStreamType, base::OnceCallback<void (std::__Cr::vector<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>, std::__Cr::allocator<std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>>>>)>) const::$_0, base::internal::UnretainedWrapper<content::RenderFrameHost, base::unretained_traits::MayNotDangle, (partition_alloc::internal::RawPtrTraits)0>>, base::internal::flat_tree<content::GlobalRenderFrameHostId, std::__Cr::identity, std::__Cr::less<void>, std::__Cr::vector<content::GlobalRenderFrameHostId, std::__Cr::allocator<content::GlobalRenderFrameHostId>>> ()>::RunOnce(base::internal::BindStateBase*)+0x254
This is one very long line. You do not need to read every character. The useful parts are:
SUMMARY: AddressSanitizer: heap-use-after-freerepeats the verdict.(/Users/test/chromium/src/out/Default/libcontent.dylib:arm64+0x1b05a3c)says which library and offset the crash was in.libcontent.dylibis the compiled content module, andarm64is the processor architecture.in base::internal::Invoker<...>names the internal template that was running. Templates are generic code patterns that the compiler fills in with specific types.content::MediaStreamManager::GetRawDeviceIdsOpenedForFrame(...)inside the angle brackets is the function whose lambda was being invoked.base::internal::UnretainedWrapper<content::RenderFrameHost, ...>shows that the frame host was stored in an unretained wrapper, which is exactly the lifetime problem described above.+0x254is the offset inside that function where the bad read happened.
The freed region is 5328 bytes, and the allocation stack shows the frame host being created through RenderFrameHostFactory::Create and RenderFrameHostManager::CreateRenderFrameHost, reached from PrerenderHost::PrerenderHost and PrerenderHostRegistry::CreateAndStartHost, which in turn came from PrerenderManager::StartPrerenderDirectUrlInput and predictors::AutocompleteActionPredictor::StartPrerendering triggered by omnibox input. In plain words: the frame host was born because Chrome prerendered a page based on what was typed in the address bar, and it died when the browser closed.
Step 6: widen the race window
The reporter added a deliberate delay to make the bug easier to trigger, in a local patch. A patch is a small edit to source code, and a diff is the format that shows added and removed lines. A race condition is a bug that depends on timing: two things happen in an order that is not guaranteed, and only the unlucky order breaks. Widening the window means making the unlucky order much more likely.
@@ -11116,6 +11039,9 @@ void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpene
return;
}
+ LOG(ERROR)"<<"GetRawDeviceIdsOpenedForFrame----------";
+ sleep(5);
+
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&MediaStreamManager::GetRawDeviceIdsOpenedForFrame,
@@ -11125,3 +11051,4 @@ void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpene
Line by line:
@@ -11116,6 +11039,9 @@is the hunk header. It says the change starts around line 11116 in the old file and line 11039 in the new file, showing six old lines and nine new lines.void WebContentsImpl::GetMediaCaptureRawDeviceIdsOpeneis the context line, the function the change sits in.return;and}are unchanged context lines.+ LOG(ERROR)"<<"GetRawDeviceIdsOpenedForFrame----------";is an added line that prints a marker to the log, so the reporter can see the function was reached.+ sleep(5);is the key added line: it pauses for five seconds.+on its own is an added blank line.- The following lines starting with a space are unchanged: the
PostTaskcall and its arguments. - The second hunk header
@@ -11125,3 +11051,4 @@marks another region of the file, with no visible changed lines in the excerpt.
The five second sleep before posting the task makes the bug easier to trigger.
Root cause
GetPrimaryMainFrame hands out a raw RenderFrameHostImpl* with no ownership or lifetime guarantee. Ownership is the idea that some piece of code is responsible for destroying an object; a raw pointer does not express that responsibility at all. That pointer is bound into a task that crosses from the UI thread to the IO thread and back to the UI thread before it is dereferenced. Between the post and the dereference, the frame host can be destroyed, for example when the tab or browser is closed.
The CHECK(render_frame_host) in GetRawDeviceIdsOpenedForFrame only proves the pointer is non-null, not that it still points at a live object, so it does not help. A null check is like checking that a phone number has digits; it does not tell you whether anyone still answers.
The base::Unretained wrappers used for the manager and the frame host likewise express no lifetime relationship. The reporter's suggested fix is to use a WeakPtr or to avoid holding the pointer at all. A WeakPtr is a pointer that knows when the object it refers to has been destroyed and becomes null instead of dangling, so the code can check before using it.
The report also links the change that introduced the code: https://chromium-review.googlesource.com/c/chromium/src/+/4976193.
Impact
This is a browser-process use-after-free in the media capture path, triggered after a user click. A UAF in the browser process is the kind of primitive that can lead to memory corruption and potentially to code execution in the most privileged Chrome process, though the report itself only demonstrates a crash under ASan. The report does not describe a full exploit chain, and the practical exploitability beyond the crash is not established in the text.
Fix
The reporter's recommendation is to use a WeakPtr for the frame host, or not to pass the raw pointer at all. The report does not describe the actual upstream patch that landed.
Variants to test
- Look for other call sites that capture
GetPrimaryMainFrame()or similar raw frame host pointers intoPostTaskorPostTaskAndReplyWithResultchains. A positive result is an ASan heap-use-after-free when the tab is closed while the task is pending. - Check other
base::Unretainedbindings of objects whose lifetime is tied to aWebContentsorFrameTree. A positive result is a crash whose free stack passes throughWebContentsImpl::~WebContentsImplorFrameTree::~FrameTree. - Exercise prerender-created frame hosts, since the allocation stack here comes from
PrerenderHost. A positive result is a UAF that only reproduces when the frame host was created by prerendering rather than by a normal navigation. - Add a temporary sleep before cross-thread posts in media capture paths and close the browser during the window. A positive result is a reproducible ASan report naming the delayed function.
Glossary
- AddressSanitizer (ASan): a tool built into a program that detects invalid memory accesses, such as reading memory after it has been freed, and prints a detailed report.
- API: an interface that lets one piece of software ask another to do something, like a menu of allowed requests.
- Browser process: the central Chrome process that has full privileges and coordinates tabs, network and devices.
- Callback: a function passed to other code so it can be called later with a result.
- CVE: a public identifier for a known security vulnerability.
- Dangling pointer: a pointer that still holds an address after the object at that address has been destroyed.
- Dereference: to follow a pointer and access the object it points to.
- Destructor: the function that runs when an object is destroyed, written with a leading
~in C++. - Diff / patch: a text showing lines added and removed to change source code.
- Frame: one document inside a tab, such as the main page or an embedded iframe.
- Heap: the pool of memory used for objects created while a program runs.
- IO thread: a Chrome thread that handles input and output work such as network and device traffic.
- Lambda: an unnamed function written inline in code.
- Media Stream: the Chrome component that handles audio and video capture and playback.
- Omnibox: the address bar in Chrome.
- Origin: the combination of scheme, host and port that identifies a site.
- Pointer: a value that holds a memory address, like a room key.
- Prerendering: loading a page in the background before the user navigates to it, so it appears instantly.
- Proof of concept (PoC): a small test that demonstrates a bug.
- Race condition: a bug that depends on the timing or order of events.
- Raw pointer: a pointer with no lifetime tracking or ownership guarantee.
- Renderer process: the sandboxed Chrome process that runs web pages.
- Thread: an independent line of execution inside a program.
- UI thread: the thread that handles the browser's user interface.
- Use-after-free (UAF): using memory after it has been freed, which can crash the program or allow memory corruption.
- VRP (Vulnerability Reward Program): a scheme that pays people for responsibly reporting security bugs.
- WeakPtr: a pointer that becomes null when the object it refers to is destroyed, instead of dangling.