Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: content/common/sandbox_policy.cc

Issue 8760011: Move the ProcessType enum out to its own file. This is in preparation for getting rid of ChildPro... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/debug_flags.cc ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/process_util.h" 15 #include "base/process_util.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
19 #include "content/common/child_process_info.h"
20 #include "content/common/debug_flags.h" 19 #include "content/common/debug_flags.h"
21 #include "content/public/common/content_client.h" 20 #include "content/public/common/content_client.h"
22 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 #include "content/public/common/process_type.h"
23 #include "sandbox/src/sandbox.h" 23 #include "sandbox/src/sandbox.h"
24 #include "ui/gfx/gl/gl_switches.h" 24 #include "ui/gfx/gl/gl_switches.h"
25 25
26 static sandbox::BrokerServices* g_broker_services = NULL; 26 static sandbox::BrokerServices* g_broker_services = NULL;
27 27
28 namespace { 28 namespace {
29 29
30 // The DLLs listed here are known (or under strong suspicion) of causing crashes 30 // The DLLs listed here are known (or under strong suspicion) of causing crashes
31 // when they are loaded in the renderer. Note: at runtime we generate short 31 // when they are loaded in the renderer. Note: at runtime we generate short
32 // versions of the dll name only if the dll has an extension. 32 // versions of the dll name only if the dll has an extension.
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 DCHECK(broker_services); 377 DCHECK(broker_services);
378 DCHECK(!g_broker_services); 378 DCHECK(!g_broker_services);
379 broker_services->Init(); 379 broker_services->Init();
380 g_broker_services = broker_services; 380 g_broker_services = broker_services;
381 } 381 }
382 382
383 base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line, 383 base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line,
384 const FilePath& exposed_dir) { 384 const FilePath& exposed_dir) {
385 base::ProcessHandle process = 0; 385 base::ProcessHandle process = 0;
386 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 386 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
387 ChildProcessInfo::ProcessType type; 387 content::ProcessType type;
388 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType); 388 std::string type_str = cmd_line->GetSwitchValueASCII(switches::kProcessType);
389 if (type_str == switches::kRendererProcess) { 389 if (type_str == switches::kRendererProcess) {
390 type = ChildProcessInfo::RENDER_PROCESS; 390 type = content::PROCESS_TYPE_RENDERER;
391 } else if (type_str == switches::kPluginProcess) { 391 } else if (type_str == switches::kPluginProcess) {
392 type = ChildProcessInfo::PLUGIN_PROCESS; 392 type = content::PROCESS_TYPE_PLUGIN;
393 } else if (type_str == switches::kWorkerProcess) { 393 } else if (type_str == switches::kWorkerProcess) {
394 type = ChildProcessInfo::WORKER_PROCESS; 394 type = content::PROCESS_TYPE_WORKER;
395 } else if (type_str == switches::kNaClLoaderProcess) { 395 } else if (type_str == switches::kNaClLoaderProcess) {
396 type = ChildProcessInfo::NACL_LOADER_PROCESS; 396 type = content::PROCESS_TYPE_NACL_LOADER;
397 } else if (type_str == switches::kUtilityProcess) { 397 } else if (type_str == switches::kUtilityProcess) {
398 type = ChildProcessInfo::UTILITY_PROCESS; 398 type = content::PROCESS_TYPE_UTILITY;
399 } else if (type_str == switches::kNaClBrokerProcess) { 399 } else if (type_str == switches::kNaClBrokerProcess) {
400 type = ChildProcessInfo::NACL_BROKER_PROCESS; 400 type = content::PROCESS_TYPE_NACL_BROKER;
401 } else if (type_str == switches::kGpuProcess) { 401 } else if (type_str == switches::kGpuProcess) {
402 type = ChildProcessInfo::GPU_PROCESS; 402 type = content::PROCESS_TYPE_GPU;
403 } else if (type_str == switches::kPpapiPluginProcess) { 403 } else if (type_str == switches::kPpapiPluginProcess) {
404 type = ChildProcessInfo::PPAPI_PLUGIN_PROCESS; 404 type = content::PROCESS_TYPE_PPAPI_PLUGIN;
405 } else if (type_str == switches::kPpapiBrokerProcess) { 405 } else if (type_str == switches::kPpapiBrokerProcess) {
406 type = ChildProcessInfo::PPAPI_BROKER_PROCESS; 406 type = content::PROCESS_TYPE_PPAPI_BROKER;
407 } else { 407 } else {
408 NOTREACHED(); 408 NOTREACHED();
409 return 0; 409 return 0;
410 } 410 }
411 411
412 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str); 412 TRACE_EVENT_BEGIN_ETW("StartProcessWithAccess", 0, type_str);
413 413
414 // To decide if the process is going to be sandboxed we have two cases. 414 // To decide if the process is going to be sandboxed we have two cases.
415 // First case: all process types except the nacl broker, and the plugin 415 // First case: all process types except the nacl broker, and the plugin
416 // process are sandboxed by default. 416 // process are sandboxed by default.
417 bool in_sandbox = 417 bool in_sandbox =
418 (type != ChildProcessInfo::NACL_BROKER_PROCESS) && 418 (type != content::PROCESS_TYPE_NACL_BROKER) &&
419 (type != ChildProcessInfo::PLUGIN_PROCESS) && 419 (type != content::PROCESS_TYPE_PLUGIN) &&
420 (type != ChildProcessInfo::PPAPI_BROKER_PROCESS); 420 (type != content::PROCESS_TYPE_PPAPI_BROKER);
421 421
422 // If it is the GPU process then it can be disabled by a command line flag. 422 // If it is the GPU process then it can be disabled by a command line flag.
423 if ((type == ChildProcessInfo::GPU_PROCESS) && 423 if ((type == content::PROCESS_TYPE_GPU) &&
424 (browser_command_line.HasSwitch(switches::kDisableGpuSandbox))) { 424 (browser_command_line.HasSwitch(switches::kDisableGpuSandbox))) {
425 in_sandbox = false; 425 in_sandbox = false;
426 DVLOG(1) << "GPU sandbox is disabled"; 426 DVLOG(1) << "GPU sandbox is disabled";
427 } 427 }
428 428
429 if (browser_command_line.HasSwitch(switches::kNoSandbox) || 429 if (browser_command_line.HasSwitch(switches::kNoSandbox) ||
430 cmd_line->HasSwitch(switches::kNoSandbox)) { 430 cmd_line->HasSwitch(switches::kNoSandbox)) {
431 // The user or the caller has explicity opted-out from all sandboxing. 431 // The user or the caller has explicity opted-out from all sandboxing.
432 in_sandbox = false; 432 in_sandbox = false;
433 } 433 }
(...skipping 24 matching lines...) Expand all
458 // Prefetch hints on windows: 458 // Prefetch hints on windows:
459 // Using a different prefetch profile per process type will allow Windows 459 // Using a different prefetch profile per process type will allow Windows
460 // to create separate pretetch settings for browser, renderer etc. 460 // to create separate pretetch settings for browser, renderer etc.
461 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type)); 461 cmd_line->AppendArg(base::StringPrintf("/prefetch:%d", type));
462 462
463 sandbox::ResultCode result; 463 sandbox::ResultCode result;
464 PROCESS_INFORMATION target = {0}; 464 PROCESS_INFORMATION target = {0};
465 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy(); 465 sandbox::TargetPolicy* policy = g_broker_services->CreatePolicy();
466 466
467 #if !defined(NACL_WIN64) // We don't need this code on win nacl64. 467 #if !defined(NACL_WIN64) // We don't need this code on win nacl64.
468 if (type == ChildProcessInfo::PLUGIN_PROCESS && 468 if (type == content::PROCESS_TYPE_PLUGIN &&
469 !browser_command_line.HasSwitch(switches::kNoSandbox) && 469 !browser_command_line.HasSwitch(switches::kNoSandbox) &&
470 content::GetContentClient()->SandboxPlugin(cmd_line, policy)) { 470 content::GetContentClient()->SandboxPlugin(cmd_line, policy)) {
471 in_sandbox = true; 471 in_sandbox = true;
472 } 472 }
473 #endif 473 #endif
474 474
475 if (!in_sandbox) { 475 if (!in_sandbox) {
476 policy->Release(); 476 policy->Release();
477 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process); 477 base::LaunchProcess(*cmd_line, base::LaunchOptions(), &process);
478 return process; 478 return process;
479 } 479 }
480 480
481 if (type == ChildProcessInfo::PLUGIN_PROCESS) { 481 if (type == content::PROCESS_TYPE_PLUGIN) {
482 AddGenericDllEvictionPolicy(policy); 482 AddGenericDllEvictionPolicy(policy);
483 AddPluginDllEvictionPolicy(policy); 483 AddPluginDllEvictionPolicy(policy);
484 } else if (type == ChildProcessInfo::GPU_PROCESS) { 484 } else if (type == content::PROCESS_TYPE_GPU) {
485 if (!AddPolicyForGPU(cmd_line, policy)) 485 if (!AddPolicyForGPU(cmd_line, policy))
486 return 0; 486 return 0;
487 } else if (type == ChildProcessInfo::PPAPI_PLUGIN_PROCESS) { 487 } else if (type == content::PROCESS_TYPE_PPAPI_PLUGIN) {
488 if (!AddPolicyForPepperPlugin(policy)) 488 if (!AddPolicyForPepperPlugin(policy))
489 return 0; 489 return 0;
490 } else { 490 } else {
491 AddPolicyForRenderer(policy); 491 AddPolicyForRenderer(policy);
492 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper. 492 // TODO(jschuh): Need get these restrictions applied to NaCl and Pepper.
493 // Just have to figure out what needs to be warmed up first. 493 // Just have to figure out what needs to be warmed up first.
494 if (type == ChildProcessInfo::RENDER_PROCESS || 494 if (type == content::PROCESS_TYPE_RENDERER ||
495 type == ChildProcessInfo::WORKER_PROCESS) { 495 type == content::PROCESS_TYPE_WORKER) {
496 AddBaseHandleClosePolicy(policy); 496 AddBaseHandleClosePolicy(policy);
497 } 497 }
498 498
499 if (type_str != switches::kRendererProcess) { 499 if (type_str != switches::kRendererProcess) {
500 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into 500 // Hack for Google Desktop crash. Trick GD into not injecting its DLL into
501 // this subprocess. See 501 // this subprocess. See
502 // http://code.google.com/p/chromium/issues/detail?id=25580 502 // http://code.google.com/p/chromium/issues/detail?id=25580
503 cmd_line->AppendSwitchASCII("ignored", " --type=renderer "); 503 cmd_line->AppendSwitchASCII("ignored", " --type=renderer ");
504 } 504 }
505 } 505 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 DLOG(ERROR) << "Failed to launch process. Error: " << result; 538 DLOG(ERROR) << "Failed to launch process. Error: " << result;
539 return 0; 539 return 0;
540 } 540 }
541 541
542 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of 542 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of
543 // address space to prevent later failure due to address space fragmentation 543 // address space to prevent later failure due to address space fragmentation
544 // from .dll loading. The NaCl process will attempt to locate this space by 544 // from .dll loading. The NaCl process will attempt to locate this space by
545 // scanning the address space using VirtualQuery. 545 // scanning the address space using VirtualQuery.
546 // TODO(bbudge) Handle the --no-sandbox case. 546 // TODO(bbudge) Handle the --no-sandbox case.
547 // http://code.google.com/p/nativeclient/issues/detail?id=2131 547 // http://code.google.com/p/nativeclient/issues/detail?id=2131
548 if (type == ChildProcessInfo::NACL_LOADER_PROCESS && 548 if (type == content::PROCESS_TYPE_NACL_LOADER &&
549 (base::win::OSInfo::GetInstance()->wow64_status() == 549 (base::win::OSInfo::GetInstance()->wow64_status() ==
550 base::win::OSInfo::WOW64_DISABLED)) { 550 base::win::OSInfo::WOW64_DISABLED)) {
551 const SIZE_T kOneGigabyte = 1 << 30; 551 const SIZE_T kOneGigabyte = 1 << 30;
552 void *nacl_mem = VirtualAllocEx(target.hProcess, 552 void *nacl_mem = VirtualAllocEx(target.hProcess,
553 NULL, 553 NULL,
554 kOneGigabyte, 554 kOneGigabyte,
555 MEM_RESERVE, 555 MEM_RESERVE,
556 PAGE_NOACCESS); 556 PAGE_NOACCESS);
557 if (!nacl_mem) { 557 if (!nacl_mem) {
558 DLOG(WARNING) << "Failed to reserve address space for Native Client"; 558 DLOG(WARNING) << "Failed to reserve address space for Native Client";
559 } 559 }
560 } 560 }
561 561
562 ResumeThread(target.hThread); 562 ResumeThread(target.hThread);
563 CloseHandle(target.hThread); 563 CloseHandle(target.hThread);
564 process = target.hProcess; 564 process = target.hProcess;
565 565
566 // Help the process a little. It can't start the debugger by itself if 566 // Help the process a little. It can't start the debugger by itself if
567 // the process is in a sandbox. 567 // the process is in a sandbox.
568 if (child_needs_help) 568 if (child_needs_help)
569 base::debug::SpawnDebuggerOnProcess(target.dwProcessId); 569 base::debug::SpawnDebuggerOnProcess(target.dwProcessId);
570 570
571 return process; 571 return process;
572 } 572 }
573 573
574 } // namespace sandbox 574 } // namespace sandbox
OLDNEW
« no previous file with comments | « content/common/debug_flags.cc ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698