Chromium Code Reviews| 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 "content/browser/gpu/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/process_util.h" | 16 #include "base/process_util.h" |
| 16 #include "base/sha1.h" | 17 #include "base/sha1.h" |
| 17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 18 #include "content/browser/browser_child_process_host_impl.h" | 19 #include "content/browser/browser_child_process_host_impl.h" |
| 19 #include "content/browser/gpu/gpu_data_manager_impl.h" | 20 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 20 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 21 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 21 #include "content/browser/gpu/gpu_surface_tracker.h" | 22 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 22 #include "content/browser/gpu/shader_disk_cache.h" | 23 #include "content/browser/gpu/shader_disk_cache.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 38 #include "gpu/command_buffer/service/gpu_switches.h" | 39 #include "gpu/command_buffer/service/gpu_switches.h" |
| 39 #include "ipc/ipc_channel_handle.h" | 40 #include "ipc/ipc_channel_handle.h" |
| 40 #include "ipc/ipc_switches.h" | 41 #include "ipc/ipc_switches.h" |
| 41 #include "ui/gl/gl_switches.h" | 42 #include "ui/gl/gl_switches.h" |
| 42 | 43 |
| 43 #if defined(TOOLKIT_GTK) | 44 #if defined(TOOLKIT_GTK) |
| 44 #include "ui/gfx/gtk_native_view_id_manager.h" | 45 #include "ui/gfx/gtk_native_view_id_manager.h" |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
| 49 #include "base/win/windows_version.h" | |
| 50 #include "content/common/sandbox_win.h" | |
| 51 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
| 52 #include "sandbox/win/src/sandbox_policy.h" | |
| 48 #include "ui/surface/accelerated_surface_win.h" | 53 #include "ui/surface/accelerated_surface_win.h" |
| 49 #endif | 54 #endif |
| 50 | 55 |
| 51 namespace content { | 56 namespace content { |
| 52 | 57 |
| 53 bool GpuProcessHost::gpu_enabled_ = true; | 58 bool GpuProcessHost::gpu_enabled_ = true; |
| 54 bool GpuProcessHost::hardware_gpu_enabled_ = true; | 59 bool GpuProcessHost::hardware_gpu_enabled_ = true; |
| 55 | 60 |
| 56 namespace { | 61 namespace { |
| 57 | 62 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 int surface_id, | 160 int surface_id, |
| 156 uint64 surface_handle, | 161 uint64 surface_handle, |
| 157 bool alive, | 162 bool alive, |
| 158 base::TimeTicks timebase, | 163 base::TimeTicks timebase, |
| 159 base::TimeDelta interval) { | 164 base::TimeDelta interval) { |
| 160 AcceleratedSurfaceBuffersSwappedCompletedForGPU(host_id, route_id, | 165 AcceleratedSurfaceBuffersSwappedCompletedForGPU(host_id, route_id, |
| 161 alive, surface_handle); | 166 alive, surface_handle); |
| 162 AcceleratedSurfaceBuffersSwappedCompletedForRenderer(surface_id, timebase, | 167 AcceleratedSurfaceBuffersSwappedCompletedForRenderer(surface_id, timebase, |
| 163 interval); | 168 interval); |
| 164 } | 169 } |
| 170 | |
| 171 // NOTE: changes to this class need to be reviewed by the security team. | |
| 172 class GpuSandboxedProcessLauncherDelegate | |
| 173 : public SandboxedProcessLauncherDelegate { | |
| 174 public: | |
| 175 explicit GpuSandboxedProcessLauncherDelegate(CommandLine* cmd_line) | |
| 176 : cmd_line_(cmd_line) {} | |
| 177 virtual ~GpuSandboxedProcessLauncherDelegate() {} | |
| 178 | |
| 179 virtual void PreSandbox(bool* disable_default_policy, | |
| 180 base::FilePath* exposed_dir) { | |
| 181 *disable_default_policy = true; | |
| 182 } | |
| 183 | |
| 184 // For the GPU process we gotten as far as USER_LIMITED. The next level | |
| 185 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL | |
| 186 // backend. Note that the GPU process is connected to the interactive | |
| 187 // desktop. | |
| 188 // TODO(cpu): Lock down the sandbox more if possible. | |
|
cpu_(ooo_6.6-7.5)
2013/03/19 21:22:55
please remove comment of line 188.
jam
2013/03/19 22:57:29
Done.
| |
| 189 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, | |
| 190 bool* success) { | |
| 191 if (base::win::GetVersion() > base::win::VERSION_XP) { | |
| 192 if (cmd_line_->GetSwitchValueASCII(switches::kUseGL) == | |
| 193 gfx::kGLImplementationDesktopName) { | |
| 194 // Open GL path. | |
| 195 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS, | |
| 196 sandbox::USER_LIMITED); | |
| 197 SetJobLevel(*cmd_line_, sandbox::JOB_UNPROTECTED, 0, policy); | |
| 198 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | |
| 199 } else { | |
| 200 if (cmd_line_->GetSwitchValueASCII(switches::kUseGL) == | |
| 201 gfx::kGLImplementationSwiftShaderName || | |
| 202 cmd_line_->HasSwitch(switches::kReduceGpuSandbox) || | |
| 203 cmd_line_->HasSwitch(switches::kDisableImageTransportSurface)) { | |
| 204 // Swiftshader path. | |
| 205 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS, | |
| 206 sandbox::USER_LIMITED); | |
| 207 } else { | |
| 208 // Angle + DirectX path. | |
| 209 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS, | |
| 210 sandbox::USER_RESTRICTED); | |
| 211 // This is a trick to keep the GPU out of low-integrity processes. It | |
| 212 // starts at low-integrity for UIPI to work, then drops below | |
| 213 // low-integrity after warm-up. | |
| 214 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_UNTRUSTED); | |
| 215 } | |
| 216 | |
| 217 // UI restrictions break when we access Windows from outside our job. | |
| 218 // However, we don't want a proxy window in this process because it can | |
| 219 // introduce deadlocks where the renderer blocks on the gpu, which in | |
| 220 // turn blocks on the browser UI thread. So, instead we forgo a window | |
| 221 // message pump entirely and just add job restrictions to prevent child | |
| 222 // processes. | |
| 223 SetJobLevel(*cmd_line_, | |
| 224 sandbox::JOB_LIMITED_USER, | |
| 225 JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | | |
| 226 JOB_OBJECT_UILIMIT_DESKTOP | | |
| 227 JOB_OBJECT_UILIMIT_EXITWINDOWS | | |
| 228 JOB_OBJECT_UILIMIT_DISPLAYSETTINGS, | |
| 229 policy); | |
| 230 | |
| 231 policy->SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | |
| 232 } | |
| 233 } else { | |
| 234 SetJobLevel(*cmd_line_, sandbox::JOB_UNPROTECTED, 0, policy); | |
| 235 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, | |
| 236 sandbox::USER_LIMITED); | |
| 237 } | |
| 238 | |
| 239 // Allow the server side of GPU sockets, which are pipes that have | |
| 240 // the "chrome.gpu" namespace and an arbitrary suffix. | |
| 241 sandbox::ResultCode result = policy->AddRule( | |
| 242 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, | |
| 243 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, | |
| 244 L"\\\\.\\pipe\\chrome.gpu.*"); | |
| 245 if (result != sandbox::SBOX_ALL_OK) { | |
| 246 *success = false; | |
| 247 return; | |
| 248 } | |
| 249 | |
| 250 #ifdef USE_AURA | |
| 251 // GPU also needs to add sections to the browser for aura | |
| 252 // TODO(jschuh): refactor the GPU channel to remove this. crbug.com/128786 | |
| 253 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, | |
| 254 sandbox::TargetPolicy::HANDLES_DUP_BROKER, | |
| 255 L"Section"); | |
| 256 if (result != sandbox::SBOX_ALL_OK) { | |
| 257 *success = false; | |
| 258 return; | |
| 259 } | |
| 260 #endif | |
| 261 | |
| 262 if (cmd_line_->HasSwitch(switches::kEnableLogging)) { | |
| 263 string16 log_file_path = logging::GetLogFileFullPath(); | |
| 264 if (!log_file_path.empty()) { | |
| 265 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, | |
| 266 sandbox::TargetPolicy::FILES_ALLOW_ANY, | |
| 267 log_file_path.c_str()); | |
| 268 if (result != sandbox::SBOX_ALL_OK) { | |
| 269 *success = false; | |
| 270 return; | |
| 271 } | |
| 272 } | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 private: | |
| 277 CommandLine* cmd_line_; | |
| 278 }; | |
| 165 #endif // defined(OS_WIN) | 279 #endif // defined(OS_WIN) |
| 166 | 280 |
| 167 } // anonymous namespace | 281 } // anonymous namespace |
| 168 | 282 |
| 169 #if defined(TOOLKIT_GTK) | 283 #if defined(TOOLKIT_GTK) |
| 170 // Used to put a lock on surfaces so that the window to which the GPU | 284 // Used to put a lock on surfaces so that the window to which the GPU |
| 171 // process is drawing to doesn't disappear while it is drawing when | 285 // process is drawing to doesn't disappear while it is drawing when |
| 172 // a WebContents is closed. | 286 // a WebContents is closed. |
| 173 class GpuProcessHost::SurfaceRef { | 287 class GpuProcessHost::SurfaceRef { |
| 174 public: | 288 public: |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1026 switches::kDisableSeccompFilterSandbox, | 1140 switches::kDisableSeccompFilterSandbox, |
| 1027 switches::kEnableGpuSandbox, | 1141 switches::kEnableGpuSandbox, |
| 1028 switches::kEnableLogging, | 1142 switches::kEnableLogging, |
| 1029 switches::kEnableVirtualGLContexts, | 1143 switches::kEnableVirtualGLContexts, |
| 1030 switches::kGpuStartupDialog, | 1144 switches::kGpuStartupDialog, |
| 1031 switches::kLoggingLevel, | 1145 switches::kLoggingLevel, |
| 1032 switches::kNoSandbox, | 1146 switches::kNoSandbox, |
| 1033 switches::kReduceGpuSandbox, | 1147 switches::kReduceGpuSandbox, |
| 1034 switches::kTestGLLib, | 1148 switches::kTestGLLib, |
| 1035 switches::kTraceStartup, | 1149 switches::kTraceStartup, |
| 1150 switches::kUseExynosVda, | |
| 1036 switches::kV, | 1151 switches::kV, |
| 1037 switches::kVModule, | 1152 switches::kVModule, |
| 1038 #if defined(OS_MACOSX) | 1153 #if defined(OS_MACOSX) |
| 1039 switches::kEnableSandboxLogging, | 1154 switches::kEnableSandboxLogging, |
| 1040 #endif | 1155 #endif |
| 1041 #if defined(USE_AURA) | 1156 #if defined(USE_AURA) |
| 1042 switches::kUIPrioritizeInGpuProcess, | 1157 switches::kUIPrioritizeInGpuProcess, |
| 1043 #endif | 1158 #endif |
| 1044 switches::kUseExynosVda, | |
| 1045 }; | 1159 }; |
| 1046 cmd_line->CopySwitchesFrom(browser_command_line, kSwitchNames, | 1160 cmd_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1047 arraysize(kSwitchNames)); | 1161 arraysize(kSwitchNames)); |
| 1048 cmd_line->CopySwitchesFrom( | 1162 cmd_line->CopySwitchesFrom( |
| 1049 browser_command_line, switches::kGpuSwitches, switches::kNumGpuSwitches); | 1163 browser_command_line, switches::kGpuSwitches, switches::kNumGpuSwitches); |
| 1050 cmd_line->CopySwitchesFrom( | 1164 cmd_line->CopySwitchesFrom( |
| 1051 browser_command_line, switches::kGLSwitchesCopiedFromGpuProcessHost, | 1165 browser_command_line, switches::kGLSwitchesCopiedFromGpuProcessHost, |
| 1052 switches::kGLSwitchesCopiedFromGpuProcessHostNumSwitches); | 1166 switches::kGLSwitchesCopiedFromGpuProcessHostNumSwitches); |
| 1053 | 1167 |
| 1054 GetContentClient()->browser()->AppendExtraCommandLineSwitches( | 1168 GetContentClient()->browser()->AppendExtraCommandLineSwitches( |
| 1055 cmd_line, process_->GetData().id); | 1169 cmd_line, process_->GetData().id); |
| 1056 | 1170 |
| 1057 GpuDataManagerImpl::GetInstance()->AppendGpuCommandLine(cmd_line); | 1171 GpuDataManagerImpl::GetInstance()->AppendGpuCommandLine(cmd_line); |
| 1058 | 1172 |
| 1059 if (cmd_line->HasSwitch(switches::kUseGL)) { | 1173 if (cmd_line->HasSwitch(switches::kUseGL)) { |
| 1060 software_rendering_ = | 1174 software_rendering_ = |
| 1061 (cmd_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"); | 1175 (cmd_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"); |
| 1062 } | 1176 } |
| 1063 | 1177 |
| 1064 UMA_HISTOGRAM_BOOLEAN("GPU.GPUProcessSoftwareRendering", software_rendering_); | 1178 UMA_HISTOGRAM_BOOLEAN("GPU.GPUProcessSoftwareRendering", software_rendering_); |
| 1065 | 1179 |
| 1066 #if defined(OS_WIN) | |
| 1067 // Make GoogleDesktopNetwork3.dll think that the GPU process is a renderer | |
| 1068 // process so the DLL unloads itself. http://crbug/129884 | |
| 1069 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); | |
| 1070 #endif | |
| 1071 | |
| 1072 // If specified, prepend a launcher program to the command line. | 1180 // If specified, prepend a launcher program to the command line. |
| 1073 if (!gpu_launcher.empty()) | 1181 if (!gpu_launcher.empty()) |
| 1074 cmd_line->PrependWrapper(gpu_launcher); | 1182 cmd_line->PrependWrapper(gpu_launcher); |
| 1075 | 1183 |
| 1076 process_->Launch( | 1184 process_->Launch( |
| 1077 #if defined(OS_WIN) | 1185 #if defined(OS_WIN) |
| 1078 base::FilePath(), | 1186 new GpuSandboxedProcessLauncherDelegate(cmd_line), |
| 1079 #elif defined(OS_POSIX) | 1187 #elif defined(OS_POSIX) |
| 1080 false, | 1188 false, |
| 1081 base::EnvironmentVector(), | 1189 base::EnvironmentVector(), |
| 1082 #endif | 1190 #endif |
| 1083 cmd_line); | 1191 cmd_line); |
| 1084 process_launched_ = true; | 1192 process_launched_ = true; |
| 1085 | 1193 |
| 1086 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", | 1194 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLifetimeEvents", |
| 1087 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); | 1195 LAUNCHED, GPU_PROCESS_LIFETIME_EVENT_MAX); |
| 1088 return true; | 1196 return true; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1261 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1154 ClientIdToShaderCacheMap::iterator iter = | 1262 ClientIdToShaderCacheMap::iterator iter = |
| 1155 client_id_to_shader_cache_.find(client_id); | 1263 client_id_to_shader_cache_.find(client_id); |
| 1156 // If the cache doesn't exist then this is an off the record profile. | 1264 // If the cache doesn't exist then this is an off the record profile. |
| 1157 if (iter == client_id_to_shader_cache_.end()) | 1265 if (iter == client_id_to_shader_cache_.end()) |
| 1158 return; | 1266 return; |
| 1159 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1267 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1160 } | 1268 } |
| 1161 | 1269 |
| 1162 } // namespace content | 1270 } // namespace content |
| OLD | NEW |