Skip to content

Commit 5cc54b6

Browse files
Scott Violetmibrunin
authored andcommitted
[Backport] Security bug 1185482
Manual backport of patch originally reviewed on https://chromium-review.googlesource.com/c/chromium/src/+/2779886: x11/ozone: fix two edge cases WindowTreeHost::OnHostMovedInPixels() may trigger a nested message loop (tab dragging), which when the stack unravels means this may be deleted. This adds an early out if this happens. X11WholeScreenMoveLoop has a similar issue, in so far as notifying the delegate may delete this. BUG=1185482 TEST=WindowTreeHostPlatform.DeleteHostFromOnHostMovedInPixels (cherry picked from commit 5e3a738b1204941aab9f15c0eb3d06e20fefd96e) Change-Id: Ieca1c90b3e4358da50b332abe2941fdbb50c5c25 Reviewed-by: Thomas Anderson <[email protected]> Commit-Queue: Scott Violet <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#860852} Cr-Commit-Position: refs/branch-heads/4389@{#1583} Cr-Branched-From: 9251c5db2b6d5a59fe4eac7aafa5fed37c139bb7-refs/heads/master@{#843830} Reviewed-by: Jüri Valdmann <[email protected]>
1 parent fcd5c56 commit 5cc54b6

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

chromium/ui/aura/window_tree_host.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ ui::EventSink* WindowTreeHost::event_sink() {
124124
return dispatcher_.get();
125125
}
126126

127+
base::WeakPtr<WindowTreeHost> WindowTreeHost::GetWeakPtr() {
128+
return weak_factory_.GetWeakPtr();
129+
}
130+
127131
gfx::Transform WindowTreeHost::GetRootTransform() const {
128132
gfx::Transform transform;
129133
transform.Scale(device_scale_factor_, device_scale_factor_);

chromium/ui/aura/window_tree_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
9090

9191
ui::Compositor* compositor() { return compositor_.get(); }
9292

93+
base::WeakPtr<WindowTreeHost> GetWeakPtr();
94+
9395
// Gets/Sets the root window's transform.
9496
virtual gfx::Transform GetRootTransform() const;
9597
virtual void SetRootTransform(const gfx::Transform& transform);

chromium/ui/aura/window_tree_host_platform.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,14 @@ void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) {
192192
float current_scale = compositor()->device_scale_factor();
193193
float new_scale = ui::GetScaleFactorForNativeView(window());
194194
gfx::Rect old_bounds = bounds_;
195+
auto weak_ref = GetWeakPtr();
195196
bounds_ = new_bounds;
196-
if (bounds_.origin() != old_bounds.origin())
197+
if (bounds_.origin() != old_bounds.origin()) {
197198
OnHostMovedInPixels(bounds_.origin());
199+
// Changing the bounds may destroy this.
200+
if (!weak_ref)
201+
return;
202+
}
198203
if (pending_local_surface_id_.is_valid() ||
199204
bounds_.size() != old_bounds.size() || current_scale != new_scale) {
200205
auto local_surface_id = bounds_.size() == pending_size_

chromium/ui/views/widget/desktop_aura/x11_whole_screen_move_loop.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ X11WholeScreenMoveLoop::~X11WholeScreenMoveLoop() {}
5959
void X11WholeScreenMoveLoop::DispatchMouseMovement() {
6060
if (!last_motion_in_screen_)
6161
return;
62+
auto weak_ref = weak_factory_.GetWeakPtr();
6263
delegate_->OnMouseMovement(last_motion_in_screen_->location(),
6364
last_motion_in_screen_->flags(),
6465
last_motion_in_screen_->time_stamp());
66+
// The delegate may delete this during dispatch.
67+
if (!weak_ref)
68+
return;
6569
last_motion_in_screen_.reset();
6670
}
6771

0 commit comments

Comments
 (0)