Commit d32bde94 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Prevent potential UAF in PrintCompositeClient.

Identify RenderFrameHosts using ID pairs instead of raw pointers, to
make it possible to check if the IDs are still valid when used later.

Bug: 1106342
Change-Id: I8ada468136a61eb837ad7d8b092915d17e958e45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2305191Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarJeongeun Kim <je_julie.kim@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791150}
parent 3860e808
...@@ -118,7 +118,8 @@ void PrintCompositeClient::RenderFrameDeleted( ...@@ -118,7 +118,8 @@ void PrintCompositeClient::RenderFrameDeleted(
} }
void PrintCompositeClient::OnDidPrintFrameContent( void PrintCompositeClient::OnDidPrintFrameContent(
content::RenderFrameHost* render_frame_host, int render_process_id,
int render_frame_id,
int document_cookie, int document_cookie,
mojom::DidPrintContentParamsPtr params) { mojom::DidPrintContentParamsPtr params) {
auto* outer_contents = web_contents()->GetOuterWebContents(); auto* outer_contents = web_contents()->GetOuterWebContents();
...@@ -131,14 +132,19 @@ void PrintCompositeClient::OnDidPrintFrameContent( ...@@ -131,14 +132,19 @@ void PrintCompositeClient::OnDidPrintFrameContent(
// contents nested in multiple layers. // contents nested in multiple layers.
auto* outer_client = PrintCompositeClient::FromWebContents(outer_contents); auto* outer_client = PrintCompositeClient::FromWebContents(outer_contents);
DCHECK(outer_client); DCHECK(outer_client);
outer_client->OnDidPrintFrameContent(render_frame_host, document_cookie, outer_client->OnDidPrintFrameContent(render_process_id, render_frame_id,
std::move(params)); document_cookie, std::move(params));
return; return;
} }
if (document_cookie_ != document_cookie) if (document_cookie_ != document_cookie)
return; return;
auto* render_frame_host =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
if (!render_frame_host)
return;
// Content in |params| is sent from untrusted source; only minimal processing // Content in |params| is sent from untrusted source; only minimal processing
// is done here. Most of it will be directly forwarded to print compositor // is done here. Most of it will be directly forwarded to print compositor
// service. // service.
...@@ -182,11 +188,14 @@ void PrintCompositeClient::PrintCrossProcessSubframe( ...@@ -182,11 +188,14 @@ void PrintCompositeClient::PrintCrossProcessSubframe(
} }
// Send the request to the destination frame. // Send the request to the destination frame.
int render_process_id = subframe_host->GetProcess()->GetID();
int render_frame_id = subframe_host->GetRoutingID();
GetPrintRenderFrame(subframe_host) GetPrintRenderFrame(subframe_host)
->PrintFrameContent( ->PrintFrameContent(
std::move(params), std::move(params),
base::BindOnce(&PrintCompositeClient::OnDidPrintFrameContent, base::BindOnce(&PrintCompositeClient::OnDidPrintFrameContent,
weak_ptr_factory_.GetWeakPtr(), subframe_host)); weak_ptr_factory_.GetWeakPtr(), render_process_id,
render_frame_id));
pending_subframes_.insert(subframe_host); pending_subframes_.insert(subframe_host);
} }
......
...@@ -114,7 +114,8 @@ class PrintCompositeClient ...@@ -114,7 +114,8 @@ class PrintCompositeClient
mojom::PrintCompositor::Status status, mojom::PrintCompositor::Status status,
base::ReadOnlySharedMemoryRegion region); base::ReadOnlySharedMemoryRegion region);
void OnDidPrintFrameContent(content::RenderFrameHost* render_frame_host, void OnDidPrintFrameContent(int render_process_id,
int render_frame_id,
int document_cookie, int document_cookie,
mojom::DidPrintContentParamsPtr params); mojom::DidPrintContentParamsPtr params);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment