Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/containers/hash_tables.h" | |
| 7 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" | |
| 8 #include "content/browser/dom_storage/session_storage_namespace_impl.h" | |
| 9 #include "content/browser/renderer_host/render_view_host_factory.h" | |
| 6 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 7 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/common/view_messages.h" | |
| 13 #include "content/public/browser/browser_context.h" | |
| 8 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 9 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
| 16 #include "content/public/browser/storage_partition.h" | |
| 10 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/test/browser_test_utils.h" | |
| 11 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
| 12 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 13 #include "content/test/content_browser_test.h" | 21 #include "content/test/content_browser_test.h" |
| 14 #include "content/test/content_browser_test_utils.h" | 22 #include "content/test/content_browser_test_utils.h" |
| 15 | 23 |
| 16 namespace content { | 24 namespace content { |
| 17 | 25 |
| 18 // The goal of these tests will be to "simulate" exploited renderer processes, | 26 // The goal of these tests will be to "simulate" exploited renderer processes, |
| 19 // which can send arbitrary IPC messages and confuse browser process internal | 27 // which can send arbitrary IPC messages and confuse browser process internal |
| 20 // state, leading to security bugs. We are trying to verify that the browser | 28 // state, leading to security bugs. We are trying to verify that the browser |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 45 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); | 53 shell()->web_contents()->GetRenderViewHost()->GetEnabledBindings()); |
| 46 | 54 |
| 47 content::WindowedNotificationObserver terminated( | 55 content::WindowedNotificationObserver terminated( |
| 48 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 56 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 49 content::NotificationService::AllSources()); | 57 content::NotificationService::AllSources()); |
| 50 shell()->web_contents()->GetRenderViewHost()->SetWebUIProperty( | 58 shell()->web_contents()->GetRenderViewHost()->SetWebUIProperty( |
| 51 "toolkit", "views"); | 59 "toolkit", "views"); |
| 52 terminated.Wait(); | 60 terminated.Wait(); |
| 53 } | 61 } |
| 54 | 62 |
| 63 namespace { | |
| 64 | |
| 65 // This is a helper function for the tests which attempt to create a | |
|
Charlie Reis
2013/12/03 22:15:49
I think helper functions for tests usually go at t
nasko
2013/12/03 22:25:38
Done.
| |
| 66 // duplicate RenderViewHost or RenderWidgetHost. It tries to create two objects | |
| 67 // with the same process and routing ids, which causes a collision. | |
| 68 // It creates a couple of windows in process 1, which causes a few routing ids | |
| 69 // to be allocated. Then a cross-process navigation is initiated, which causes a | |
| 70 // new process 2 to be created and have a pending RenderViewHost for it. | |
|
Charlie Reis
2013/12/03 22:15:49
Please mention something about how the pending Ren
nasko
2013/12/03 22:25:38
Done.
| |
| 71 RenderViewHostImpl* SetupForDuplicateHosts(Shell* shell, | |
| 72 int* duplicate_routing_id) { | |
| 73 GURL foo("http://foo.com/files/simple_page.html"); | |
| 74 | |
| 75 // Start off with initial navigation, so we get the first process allocated. | |
| 76 NavigateToURL(shell, foo); | |
| 77 | |
| 78 // Open another window, so we generate some more routing ids. | |
| 79 ShellAddedObserver shell2_observer; | |
| 80 EXPECT_TRUE(ExecuteScript( | |
| 81 shell->web_contents(), "window.open(document.URL + '#2');")); | |
| 82 Shell* shell2 = shell2_observer.GetShell(); | |
| 83 | |
| 84 // The new window must be in the same process, but have a new routing id. | |
| 85 EXPECT_EQ(shell->web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | |
| 86 shell2->web_contents()->GetRenderViewHost()->GetProcess()->GetID()); | |
| 87 *duplicate_routing_id = | |
| 88 shell2->web_contents()->GetRenderViewHost()->GetRoutingID(); | |
| 89 EXPECT_NE(*duplicate_routing_id, | |
| 90 shell->web_contents()->GetRenderViewHost()->GetRoutingID()); | |
| 91 | |
| 92 // Now, simulate a link click coming from the renderer. | |
| 93 GURL extension_url("https://bar.com/files/simple_page.html"); | |
| 94 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell->web_contents()); | |
| 95 wc->RequestOpenURL( | |
| 96 shell->web_contents()->GetRenderViewHost(), extension_url, | |
| 97 Referrer(), CURRENT_TAB, wc->GetFrameTree()->root()->frame_id(), | |
| 98 false, true); | |
| 99 | |
| 100 // Since the navigation above requires a cross-process swap, there will be a | |
| 101 // pending RenderViewHost. Ensure it exists and is in a different process | |
| 102 // than the initial page. | |
| 103 RenderViewHostImpl* pending_rvh = | |
| 104 wc->GetRenderManagerForTesting()->pending_render_view_host(); | |
| 105 EXPECT_TRUE(pending_rvh != NULL); | |
| 106 EXPECT_NE(shell->web_contents()->GetRenderViewHost()->GetProcess()->GetID(), | |
| 107 pending_rvh->GetProcess()->GetID()); | |
| 108 | |
| 109 return pending_rvh; | |
| 55 } | 110 } |
| 111 | |
| 112 } // namespace | |
| 113 | |
| 114 // This is a test for crbug.com/312016 attempting to create duplicate | |
| 115 // RenderViewHosts. SetupForDuplicateHosts sets up this test case and leaves | |
| 116 // it in a state with pending RenderViewHost. Before the commit of the new | |
| 117 // pending RenderViewHost, this test case creates a new window through the new | |
| 118 // process. | |
| 119 IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, | |
| 120 AttemptDuplicateRenderViewHost) { | |
| 121 int duplicate_routing_id = MSG_ROUTING_NONE; | |
| 122 RenderViewHostImpl* pending_rvh = | |
| 123 SetupForDuplicateHosts(shell(), &duplicate_routing_id); | |
|
Charlie Reis
2013/12/03 22:15:49
Let's check that this is no longer MSG_ROUTING_NON
nasko
2013/12/03 22:25:38
Done.
| |
| 124 | |
| 125 // Since this test executes on the UI thread and hopping threads might cause | |
| 126 // different timing in the test, let's simulate a CreateNewWindow call coming | |
| 127 // from the IO thread. | |
| 128 ViewHostMsg_CreateWindow_Params params; | |
| 129 DOMStorageContextWrapper* dom_storage_context = | |
| 130 static_cast<DOMStorageContextWrapper*>( | |
| 131 BrowserContext::GetStoragePartition( | |
| 132 shell()->web_contents()->GetBrowserContext(), | |
| 133 pending_rvh->GetSiteInstance())->GetDOMStorageContext()); | |
| 134 SessionStorageNamespaceImpl* session_storage = | |
| 135 new SessionStorageNamespaceImpl(dom_storage_context); | |
| 136 // Cause a deliberate collision in routing ids. | |
| 137 int main_frame_routing_id = duplicate_routing_id + 1; | |
| 138 | |
|
Charlie Reis
2013/12/03 22:15:49
nit: No blank line needed.
nasko
2013/12/03 22:25:38
Done.
| |
| 139 pending_rvh->CreateNewWindow( | |
| 140 duplicate_routing_id, main_frame_routing_id, params, session_storage); | |
| 141 | |
| 142 // If the above operation doesn't cause a crash, the test has succeeded! | |
| 143 } | |
| 144 | |
| 145 } // namespace content | |
| OLD | NEW |