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 <dlfcn.h> | 5 #include <dlfcn.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <pthread.h> | 7 #include <pthread.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "base/pickle.h" | 22 #include "base/pickle.h" |
23 #include "base/posix/unix_domain_socket.h" | 23 #include "base/posix/unix_domain_socket.h" |
24 #include "base/process_util.h" | 24 #include "base/process_util.h" |
25 #include "base/rand_util.h" | 25 #include "base/rand_util.h" |
26 #include "base/sys_info.h" | 26 #include "base/sys_info.h" |
27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
28 #include "crypto/nss_util.h" | 28 #include "crypto/nss_util.h" |
29 #include "content/common/font_config_ipc_linux.h" | 29 #include "content/common/font_config_ipc_linux.h" |
30 #include "content/common/pepper_plugin_registry.h" | 30 #include "content/common/pepper_plugin_registry.h" |
31 #include "content/common/sandbox_linux.h" | 31 #include "content/common/sandbox_methods_linux.h" |
| 32 #include "content/common/seccomp_sandbox.h" |
32 #include "content/common/zygote_commands_linux.h" | 33 #include "content/common/zygote_commands_linux.h" |
33 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
34 #include "content/public/common/main_function_params.h" | 35 #include "content/public/common/main_function_params.h" |
35 #include "content/public/common/sandbox_linux.h" | 36 #include "content/public/common/sandbox_linux.h" |
36 #include "content/public/common/zygote_fork_delegate_linux.h" | 37 #include "content/public/common/zygote_fork_delegate_linux.h" |
37 #include "content/zygote/zygote_linux.h" | 38 #include "content/zygote/zygote_linux.h" |
38 #include "sandbox/linux/services/libc_urandom_override.h" | 39 #include "sandbox/linux/services/libc_urandom_override.h" |
39 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" | 40 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" |
40 #include "skia/ext/SkFontHost_fontconfig_control.h" | 41 #include "skia/ext/SkFontHost_fontconfig_control.h" |
41 #include "unicode/timezone.h" | 42 #include "unicode/timezone.h" |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 445 |
445 #endif // CHROMIUM_SELINUX | 446 #endif // CHROMIUM_SELINUX |
446 | 447 |
447 bool ZygoteMain(const MainFunctionParams& params, | 448 bool ZygoteMain(const MainFunctionParams& params, |
448 ZygoteForkDelegate* forkdelegate) { | 449 ZygoteForkDelegate* forkdelegate) { |
449 #if !defined(CHROMIUM_SELINUX) | 450 #if !defined(CHROMIUM_SELINUX) |
450 g_am_zygote_or_renderer = true; | 451 g_am_zygote_or_renderer = true; |
451 sandbox::InitLibcUrandomOverrides(); | 452 sandbox::InitLibcUrandomOverrides(); |
452 #endif | 453 #endif |
453 | 454 |
454 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); | 455 int proc_fd_for_seccomp = -1; |
455 // This will pre-initialize the various sandboxes that need it. | 456 #if defined(SECCOMP_SANDBOX) |
456 // There need to be a corresponding call to PreinitializeSandboxFinish() | 457 if (SeccompSandboxEnabled()) { |
457 // for each new process, this will be done in the Zygote child, once we know | 458 // The seccomp sandbox needs access to files in /proc, which might be denied |
458 // our process type. | 459 // after one of the other sandboxes have been started. So, obtain a suitable |
459 linux_sandbox->PreinitializeSandboxBegin(); | 460 // file handle in advance. |
| 461 proc_fd_for_seccomp = open("/proc", O_DIRECTORY | O_RDONLY); |
| 462 if (proc_fd_for_seccomp < 0) { |
| 463 LOG(ERROR) << "WARNING! Cannot access \"/proc\". Disabling seccomp " |
| 464 "sandboxing."; |
| 465 } |
| 466 } |
| 467 #endif // SECCOMP_SANDBOX |
460 | 468 |
461 sandbox::SetuidSandboxClient* setuid_sandbox = | 469 scoped_ptr<sandbox::SetuidSandboxClient> |
462 linux_sandbox->setuid_sandbox_client(); | 470 setuid_sandbox(sandbox::SetuidSandboxClient::Create()); |
| 471 |
| 472 if (setuid_sandbox == NULL) { |
| 473 LOG(FATAL) << "Failed to instantiate the setuid sandbox client."; |
| 474 return false; |
| 475 } |
463 | 476 |
464 if (forkdelegate != NULL) { | 477 if (forkdelegate != NULL) { |
465 VLOG(1) << "ZygoteMain: initializing fork delegate"; | 478 VLOG(1) << "ZygoteMain: initializing fork delegate"; |
466 forkdelegate->Init(setuid_sandbox->IsSuidSandboxChild(), | 479 forkdelegate->Init(setuid_sandbox->IsSuidSandboxChild(), |
467 Zygote::kBrowserDescriptor, | 480 Zygote::kBrowserDescriptor, |
468 Zygote::kMagicSandboxIPCDescriptor); | 481 Zygote::kMagicSandboxIPCDescriptor); |
469 } else { | 482 } else { |
470 VLOG(1) << "ZygoteMain: fork delegate is NULL"; | 483 VLOG(1) << "ZygoteMain: fork delegate is NULL"; |
471 } | 484 } |
472 | 485 |
473 // Turn on the SELinux or SUID sandbox. | 486 // Turn on the SELinux or SUID sandbox. |
474 bool using_suid_sandbox = false; | 487 bool using_suid_sandbox = false; |
475 bool has_started_new_init = false; | 488 bool has_started_new_init = false; |
476 | 489 if (!EnterSandbox(setuid_sandbox.get(), |
477 if (!EnterSandbox(setuid_sandbox, | |
478 &using_suid_sandbox, | 490 &using_suid_sandbox, |
479 &has_started_new_init)) { | 491 &has_started_new_init)) { |
480 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " | 492 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " |
481 << errno << ")"; | 493 << errno << ")"; |
482 return false; | 494 return false; |
483 } | 495 } |
484 | 496 |
485 if (setuid_sandbox->IsInNewPIDNamespace() && !has_started_new_init) { | 497 int sandbox_flags = 0; |
| 498 if (using_suid_sandbox) { |
| 499 sandbox_flags |= kSandboxLinuxSUID; |
| 500 if (setuid_sandbox->IsInNewPIDNamespace()) |
| 501 sandbox_flags |= kSandboxLinuxPIDNS; |
| 502 if (setuid_sandbox->IsInNewNETNamespace()) |
| 503 sandbox_flags |= kSandboxLinuxNetNS; |
| 504 } |
| 505 |
| 506 if ((sandbox_flags & kSandboxLinuxPIDNS) && !has_started_new_init) { |
486 LOG(ERROR) << "The SUID sandbox created a new PID namespace but Zygote " | 507 LOG(ERROR) << "The SUID sandbox created a new PID namespace but Zygote " |
487 "is not the init process. Please, make sure the SUID " | 508 "is not the init process. Please, make sure the SUID " |
488 "binary is up to date."; | 509 "binary is up to date."; |
489 } | 510 } |
490 | 511 |
491 int sandbox_flags = linux_sandbox->GetStatus(); | 512 #if defined(SECCOMP_SANDBOX) |
| 513 // The seccomp sandbox will be turned on when the renderers start. But we can |
| 514 // already check if sufficient support is available so that we only need to |
| 515 // print one error message for the entire browser session. |
| 516 if (proc_fd_for_seccomp >= 0 && SeccompSandboxEnabled()) { |
| 517 if (!SupportsSeccompSandbox(proc_fd_for_seccomp)) { |
| 518 // There are a good number of users who cannot use the seccomp sandbox |
| 519 // (e.g. because their distribution does not enable seccomp mode by |
| 520 // default). While we would prefer to deny execution in this case, it |
| 521 // seems more realistic to continue in degraded mode. |
| 522 LOG(ERROR) << "WARNING! This machine lacks support needed for the " |
| 523 "Seccomp sandbox. Running renderers with Seccomp " |
| 524 "sandboxing disabled."; |
| 525 close(proc_fd_for_seccomp); |
| 526 proc_fd_for_seccomp = -1; |
| 527 } else { |
| 528 VLOG(1) << "Enabling experimental Seccomp sandbox."; |
| 529 sandbox_flags |= kSandboxLinuxSeccomp; |
| 530 } |
| 531 } |
| 532 #endif // SECCOMP_SANDBOX |
492 | 533 |
493 Zygote zygote(sandbox_flags, forkdelegate); | 534 Zygote zygote(sandbox_flags, forkdelegate, proc_fd_for_seccomp); |
494 // This function call can return multiple times, once per fork(). | 535 // This function call can return multiple times, once per fork(). |
495 return zygote.ProcessRequests(); | 536 return zygote.ProcessRequests(); |
496 } | 537 } |
497 | 538 |
498 } // namespace content | 539 } // namespace content |
OLD | NEW |