OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <objbase.h> | 8 #include <objbase.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return 2; | 82 return 2; |
83 } | 83 } |
84 | 84 |
85 void DestroyIMEForFlash() { | 85 void DestroyIMEForFlash() { |
86 if (g_ime_window) { | 86 if (g_ime_window) { |
87 DestroyWindow(g_ime_window); | 87 DestroyWindow(g_ime_window); |
88 g_ime_window = NULL; | 88 g_ime_window = NULL; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // VirtualAlloc doesn't randomize well, so we use these calls to poke a | |
93 // random-sized hole in the address space and set an event to later remove it. | |
94 void FreeRandomMemoryHole(void *hole) { | |
95 ::VirtualFree(hole, 0, MEM_RELEASE); | |
96 } | |
97 | |
98 bool CreateRandomMemoryHole() { | |
99 const uint32_t kRandomValueMax = 8 * 1024; // Yields a 512mb max hole. | |
100 const uint32_t kRandomValueDivisor = 8; | |
101 const uint32_t kMaxWaitSeconds = 18 * 60; // 18 Minutes in seconds. | |
102 COMPILE_ASSERT((kMaxWaitSeconds > (kRandomValueMax / kRandomValueDivisor)), | |
103 kMaxWaitSeconds_value_too_small); | |
104 | |
105 uint32_t rand_val; | |
106 if (rand_s(&rand_val) != S_OK) { | |
107 DVLOG(ERROR) << "rand_s() failed"; | |
108 } | |
109 | |
110 rand_val %= kRandomValueMax; | |
111 // Reserve a (randomly selected) range of address space. | |
112 if (void* hole = ::VirtualAlloc(NULL, 65536 * (1 + rand_val), | |
113 MEM_RESERVE, PAGE_NOACCESS)) { | |
114 // Set up an event to remove the memory hole. Base the wait time on the | |
115 // inverse of the allocation size, meaning a bigger hole gets a shorter | |
116 // wait (ranging from 1-18 minutes). | |
117 const uint32_t wait = kMaxWaitSeconds - (rand_val / kRandomValueDivisor); | |
118 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
119 base::Bind(&FreeRandomMemoryHole, hole), | |
120 base::TimeDelta::FromSeconds(wait)); | |
121 return true; | |
122 } | |
123 | |
124 return false; | |
125 } | |
126 | |
127 #endif | 92 #endif |
128 | 93 |
129 // main() routine for running as the plugin process. | 94 // main() routine for running as the plugin process. |
130 int PluginMain(const content::MainFunctionParams& parameters) { | 95 int PluginMain(const content::MainFunctionParams& parameters) { |
131 // The main thread of the plugin services UI. | 96 // The main thread of the plugin services UI. |
132 #if defined(OS_MACOSX) | 97 #if defined(OS_MACOSX) |
133 #if !defined(__LP64__) | 98 #if !defined(__LP64__) |
134 TrimInterposeEnvironment(); | 99 TrimInterposeEnvironment(); |
135 #endif | 100 #endif |
136 InitializeChromeApplication(); | 101 InitializeChromeApplication(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 ChildProcess plugin_process; | 143 ChildProcess plugin_process; |
179 plugin_process.set_main_thread(new PluginThread()); | 144 plugin_process.set_main_thread(new PluginThread()); |
180 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
181 if (!no_sandbox && target_services) { | 146 if (!no_sandbox && target_services) { |
182 // We are sandboxing the plugin. If it is a generic plug-in, we lock down | 147 // We are sandboxing the plugin. If it is a generic plug-in, we lock down |
183 // the sandbox right away, but if it is the built-in flash we let flash | 148 // the sandbox right away, but if it is the built-in flash we let flash |
184 // start elevated and it will call DelayedLowerToken(0) when it's ready. | 149 // start elevated and it will call DelayedLowerToken(0) when it's ready. |
185 if (IsPluginBuiltInFlash(parsed_command_line)) { | 150 if (IsPluginBuiltInFlash(parsed_command_line)) { |
186 DVLOG(1) << "Sandboxing flash"; | 151 DVLOG(1) << "Sandboxing flash"; |
187 | 152 |
188 // Poke hole in the address space to improve randomization. | |
189 if (!CreateRandomMemoryHole()) { | |
190 DVLOG(ERROR) << "Failed to create random memory hole"; | |
191 } | |
192 | |
193 if (!PreloadIMEForFlash()) | 153 if (!PreloadIMEForFlash()) |
194 DVLOG(1) << "IME preload failed"; | 154 DVLOG(1) << "IME preload failed"; |
195 DelayedLowerToken(target_services); | 155 DelayedLowerToken(target_services); |
196 } else { | 156 } else { |
197 target_services->LowerToken(); | 157 target_services->LowerToken(); |
198 } | 158 } |
199 } | 159 } |
200 if (sandbox_test_module) { | 160 if (sandbox_test_module) { |
201 RunPluginTests run_security_tests = | 161 RunPluginTests run_security_tests = |
202 reinterpret_cast<RunPluginTests>(GetProcAddress(sandbox_test_module, | 162 reinterpret_cast<RunPluginTests>(GetProcAddress(sandbox_test_module, |
(...skipping 18 matching lines...) Expand all Loading... |
221 MessageLoop::current()->Run(); | 181 MessageLoop::current()->Run(); |
222 } | 182 } |
223 | 183 |
224 #if defined(OS_WIN) | 184 #if defined(OS_WIN) |
225 DestroyIMEForFlash(); | 185 DestroyIMEForFlash(); |
226 CoUninitialize(); | 186 CoUninitialize(); |
227 #endif | 187 #endif |
228 | 188 |
229 return 0; | 189 return 0; |
230 } | 190 } |
OLD | NEW |