Skip to content

Commit

Permalink
Add CHECKs in HostFrameSinkManager
Browse files Browse the repository at this point in the history
It looks like it's possible for a compromised renderer to get multiple
things to register the same FrameSinkId with HostFrameSinkManager. This
violates assumptions around ownership so turn DCHECKs here into CHECKs.
Also convert DCHECKs into CHECKs for registering/unregistering frame
sink hierarchy just in case.

Bug: 1414018
Change-Id: If948e758a8484024666f4066360620bc3a9cb493
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4283141
Reviewed-by: Martin Kreichgauer <martinkr@google.com>
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Commit-Queue: Kyle Charbonneau <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1109533}
  • Loading branch information
kylechar authored and Chromium LUCI CQ committed Feb 24, 2023
1 parent a2115ad commit a707ac2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions components/viz/host/host_frame_sink_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void HostFrameSinkManager::RegisterFrameSinkId(
DCHECK(client);

FrameSinkData& data = frame_sink_data_map_[frame_sink_id];
DCHECK(!data.IsFrameSinkRegistered());
CHECK(!data.IsFrameSinkRegistered());
DCHECK(!data.has_created_compositor_frame_sink);
data.client = client;
data.report_activation = report_activation;
Expand All @@ -84,7 +84,7 @@ void HostFrameSinkManager::InvalidateFrameSinkId(
DCHECK(frame_sink_id.is_valid());

FrameSinkData& data = frame_sink_data_map_[frame_sink_id];
DCHECK(data.IsFrameSinkRegistered());
CHECK(data.IsFrameSinkRegistered());

const bool destroy_synchronously =
data.has_created_compositor_frame_sink && data.wait_on_destruction;
Expand Down Expand Up @@ -225,14 +225,14 @@ bool HostFrameSinkManager::RegisterFrameSinkHierarchy(
return false;
}

FrameSinkData& parent_data = iter->second;
CHECK(!base::Contains(parent_data.children, child_frame_sink_id));
parent_data.children.push_back(child_frame_sink_id);

// Register and store the parent.
frame_sink_manager_->RegisterFrameSinkHierarchy(parent_frame_sink_id,
child_frame_sink_id);

FrameSinkData& parent_data = iter->second;
DCHECK(!base::Contains(parent_data.children, child_frame_sink_id));
parent_data.children.push_back(child_frame_sink_id);

return true;
}

Expand All @@ -241,8 +241,9 @@ void HostFrameSinkManager::UnregisterFrameSinkHierarchy(
const FrameSinkId& child_frame_sink_id) {
// Unregister and clear the stored parent.
FrameSinkData& parent_data = frame_sink_data_map_[parent_frame_sink_id];
DCHECK(base::Contains(parent_data.children, child_frame_sink_id));
base::Erase(parent_data.children, child_frame_sink_id);
size_t num_erased = base::Erase(parent_data.children, child_frame_sink_id);
CHECK_EQ(num_erased, 1u);

if (parent_data.IsEmpty())
frame_sink_data_map_.erase(parent_frame_sink_id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void FrameSinkManagerImpl::UnregisterFrameSinkHierarchy(
}

auto iter = frame_sink_source_map_.find(parent_frame_sink_id);
DCHECK(iter != frame_sink_source_map_.end());
CHECK(iter != frame_sink_source_map_.end());

// Remove |child_frame_sink_id| from parents list of children.
auto& mapping = iter->second;
Expand Down

0 comments on commit a707ac2

Please sign in to comment.