| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/sandbox_policy.h" | 5 #include "content/common/sandbox_policy.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 return true; | 287 return true; |
| 288 } | 288 } |
| 289 | 289 |
| 290 // For the GPU process we gotten as far as USER_LIMITED. The next level | 290 // For the GPU process we gotten as far as USER_LIMITED. The next level |
| 291 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL | 291 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL |
| 292 // backend. Note that the GPU process is connected to the interactive | 292 // backend. Note that the GPU process is connected to the interactive |
| 293 // desktop. | 293 // desktop. |
| 294 // TODO(cpu): Lock down the sandbox more if possible. | 294 // TODO(cpu): Lock down the sandbox more if possible. |
| 295 // TODO(apatrick): Use D3D9Ex to render windowless. | 295 // TODO(apatrick): Use D3D9Ex to render windowless. |
| 296 bool AddPolicyForGPU(CommandLine* cmd_line, sandbox::TargetPolicy* policy) { | 296 bool AddPolicyForGPU(CommandLine* cmd_line, sandbox::TargetPolicy* policy) { |
| 297 #if !defined(NACL_WIN64) // We don't need this code on win nacl64. |
| 297 if (base::win::GetVersion() > base::win::VERSION_XP) { | 298 if (base::win::GetVersion() > base::win::VERSION_XP) { |
| 298 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS, | 299 policy->SetTokenLevel(sandbox::USER_RESTRICTED_SAME_ACCESS, |
| 299 sandbox::USER_LIMITED); | 300 sandbox::USER_LIMITED); |
| 300 if (cmd_line->GetSwitchValueASCII(switches::kUseGL) == | 301 if (cmd_line->GetSwitchValueASCII(switches::kUseGL) == |
| 301 gfx::kGLImplementationDesktopName) { | 302 gfx::kGLImplementationDesktopName) { |
| 302 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | 303 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); |
| 303 policy->SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | 304 policy->SetIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); |
| 304 } else { | 305 } else { |
| 305 // UI restrictions break when we access Windows from outside our job. | 306 // UI restrictions break when we access Windows from outside our job. |
| 306 // However, we don't want a proxy window in this process because it can | 307 // However, we don't want a proxy window in this process because it can |
| 307 // introduce deadlocks where the renderer blocks on the gpu, which in | 308 // introduce deadlocks where the renderer blocks on the gpu, which in |
| 308 // turn blocks on the browser UI thread. So, instead we forgo a window | 309 // turn blocks on the browser UI thread. So, instead we forgo a window |
| 309 // message pump entirely and just add job restrictions to prevent child | 310 // message pump entirely and just add job restrictions to prevent child |
| 310 // processes. | 311 // processes. |
| 311 policy->SetJobLevel(sandbox::JOB_LIMITED_USER, | 312 policy->SetJobLevel(sandbox::JOB_LIMITED_USER, |
| 312 JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | | 313 JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | |
| 313 JOB_OBJECT_UILIMIT_DESKTOP | | 314 JOB_OBJECT_UILIMIT_DESKTOP | |
| 314 JOB_OBJECT_UILIMIT_EXITWINDOWS | | 315 JOB_OBJECT_UILIMIT_EXITWINDOWS | |
| 315 JOB_OBJECT_UILIMIT_DISPLAYSETTINGS); | 316 JOB_OBJECT_UILIMIT_DISPLAYSETTINGS); |
| 316 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); | 317 policy->SetDelayedIntegrityLevel(sandbox::INTEGRITY_LEVEL_LOW); |
| 317 } | 318 } |
| 318 } else { | 319 } else { |
| 319 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); | 320 policy->SetJobLevel(sandbox::JOB_UNPROTECTED, 0); |
| 320 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, | 321 policy->SetTokenLevel(sandbox::USER_UNPROTECTED, |
| 321 sandbox::USER_LIMITED); | 322 sandbox::USER_LIMITED); |
| 322 } | 323 } |
| 323 | 324 |
| 324 AddGenericDllEvictionPolicy(policy); | 325 AddGenericDllEvictionPolicy(policy); |
| 326 #endif |
| 325 return true; | 327 return true; |
| 326 } | 328 } |
| 327 | 329 |
| 328 void AddPolicyForRenderer(sandbox::TargetPolicy* policy) { | 330 void AddPolicyForRenderer(sandbox::TargetPolicy* policy) { |
| 329 policy->SetJobLevel(sandbox::JOB_LOCKDOWN, 0); | 331 policy->SetJobLevel(sandbox::JOB_LOCKDOWN, 0); |
| 330 | 332 |
| 331 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; | 333 sandbox::TokenLevel initial_token = sandbox::USER_UNPROTECTED; |
| 332 if (base::win::GetVersion() > base::win::VERSION_XP) { | 334 if (base::win::GetVersion() > base::win::VERSION_XP) { |
| 333 // On 2003/Vista the initial token has to be restricted if the main | 335 // On 2003/Vista the initial token has to be restricted if the main |
| 334 // token is restricted. | 336 // token is restricted. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 454 |
| 453 // Prefetch hints on windows: | 455 // Prefetch hints on windows: |
| 454 // Using a different prefetch profile per process type will allow Windows | 456 // Using a different prefetch profile per process type will allow Windows |
| 455 // to create separate pretetch settings for browser, renderer etc. | 457 // to create separate pretetch settings for browser, renderer etc. |
| 456 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); | 458 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); |
| 457 | 459 |
| 458 sandbox::ResultCode result; | 460 sandbox::ResultCode result; |
| 459 PROCESS_INFORMATION target = {0}; | 461 PROCESS_INFORMATION target = {0}; |
| 460 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); | 462 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); |
| 461 | 463 |
| 464 #if !defined(NACL_WIN64) // We don't need this code on win nacl64. |
| 462 if (type == ChildProcessInfo::PLUGIN_PROCESS && | 465 if (type == ChildProcessInfo::PLUGIN_PROCESS && |
| 463 !browser_command_line.HasSwitch(switches::kNoSandbox) && | 466 !browser_command_line.HasSwitch(switches::kNoSandbox) && |
| 464 content::GetContentClient()->SandboxPlugin(cmd_line, policy)) { | 467 content::GetContentClient()->SandboxPlugin(cmd_line, policy)) { |
| 465 in_sandbox = true; | 468 in_sandbox = true; |
| 466 } | 469 } |
| 470 #endif |
| 467 | 471 |
| 468 if (!in_sandbox) { | 472 if (!in_sandbox) { |
| 469 policy->Release(); | 473 policy->Release(); |
| 470 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); | 474 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); |
| 471 return process; | 475 return process; |
| 472 } | 476 } |
| 473 | 477 |
| 474 if (type == ChildProcessInfo::PLUGIN_PROCESS) { | 478 if (type == ChildProcessInfo::PLUGIN_PROCESS) { |
| 475 AddGenericDllEvictionPolicy(policy); | 479 AddGenericDllEvictionPolicy(policy); |
| 476 AddPluginDllEvictionPolicy(policy); | 480 AddPluginDllEvictionPolicy(policy); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 560 |
| 557 // Help the process a little. It can't start the debugger by itself if | 561 // Help the process a little. It can't start the debugger by itself if |
| 558 // the process is in a sandbox. | 562 // the process is in a sandbox. |
| 559 if (child_needs_help) | 563 if (child_needs_help) |
| 560 base::debug::SpawnDebuggerOnProcess(target.dwProcessId); | 564 base::debug::SpawnDebuggerOnProcess(target.dwProcessId); |
| 561 | 565 |
| 562 return process; | 566 return process; |
| 563 } | 567 } |
| 564 | 568 |
| 565 } // namespace sandbox | 569 } // namespace sandbox |
| OLD | NEW |