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

Side by Side Diff: content/zygote/zygote_main_linux.cc

Issue 10826093: Create a LinuxSandbox class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address first round of comments from Markus. Created 8 years, 4 months 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
OLDNEW
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
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_methods_linux.h" 31 #include "content/common/sandbox_linux.h"
32 #include "content/common/seccomp_sandbox.h"
33 #include "content/common/zygote_commands_linux.h" 32 #include "content/common/zygote_commands_linux.h"
34 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
35 #include "content/public/common/main_function_params.h" 34 #include "content/public/common/main_function_params.h"
36 #include "content/public/common/sandbox_linux.h" 35 #include "content/public/common/sandbox_linux.h"
37 #include "content/public/common/zygote_fork_delegate_linux.h" 36 #include "content/public/common/zygote_fork_delegate_linux.h"
38 #include "content/zygote/zygote_linux.h" 37 #include "content/zygote/zygote_linux.h"
39 #include "sandbox/linux/services/libc_urandom_override.h" 38 #include "sandbox/linux/services/libc_urandom_override.h"
40 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" 39 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
41 #include "skia/ext/SkFontHost_fontconfig_control.h" 40 #include "skia/ext/SkFontHost_fontconfig_control.h"
42 #include "unicode/timezone.h" 41 #include "unicode/timezone.h"
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 444
446 #endif // CHROMIUM_SELINUX 445 #endif // CHROMIUM_SELINUX
447 446
448 bool ZygoteMain(const MainFunctionParams& params, 447 bool ZygoteMain(const MainFunctionParams& params,
449 ZygoteForkDelegate* forkdelegate) { 448 ZygoteForkDelegate* forkdelegate) {
450 #if !defined(CHROMIUM_SELINUX) 449 #if !defined(CHROMIUM_SELINUX)
451 g_am_zygote_or_renderer = true; 450 g_am_zygote_or_renderer = true;
452 sandbox::InitLibcUrandomOverrides(); 451 sandbox::InitLibcUrandomOverrides();
453 #endif 452 #endif
454 453
455 int proc_fd_for_seccomp = -1; 454 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance();
456 #if defined(SECCOMP_SANDBOX) 455 // This will pre-initialize the various sandboxes that need it.
457 if (SeccompSandboxEnabled()) { 456 // There need to be a corresponding call to PreinitializeSandboxFinish()
458 // The seccomp sandbox needs access to files in /proc, which might be denied 457 // for each new process, this will be done in the Zygote child, once we know
459 // after one of the other sandboxes have been started. So, obtain a suitable 458 // our process type.
460 // file handle in advance. 459 linux_sandbox->PreinitializeSandbox();
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
468 460
469 scoped_ptr<sandbox::SetuidSandboxClient> 461 sandbox::SetuidSandboxClient* setuid_sandbox =
470 setuid_sandbox(sandbox::SetuidSandboxClient::Create()); 462 linux_sandbox->setuid_sandbox();
471
472 if (setuid_sandbox == NULL) {
473 LOG(FATAL) << "Failed to instantiate the setuid sandbox client.";
474 return false;
475 }
476 463
477 if (forkdelegate != NULL) { 464 if (forkdelegate != NULL) {
478 VLOG(1) << "ZygoteMain: initializing fork delegate"; 465 VLOG(1) << "ZygoteMain: initializing fork delegate";
479 forkdelegate->Init(setuid_sandbox->IsSuidSandboxChild(), 466 forkdelegate->Init(setuid_sandbox->IsSuidSandboxChild(),
480 Zygote::kBrowserDescriptor, 467 Zygote::kBrowserDescriptor,
481 Zygote::kMagicSandboxIPCDescriptor); 468 Zygote::kMagicSandboxIPCDescriptor);
482 } else { 469 } else {
483 VLOG(1) << "ZygoteMain: fork delegate is NULL"; 470 VLOG(1) << "ZygoteMain: fork delegate is NULL";
484 } 471 }
485 472
486 // Turn on the SELinux or SUID sandbox. 473 // Turn on the SELinux or SUID sandbox.
487 bool using_suid_sandbox = false; 474 bool using_suid_sandbox = false;
488 bool has_started_new_init = false; 475 bool has_started_new_init = false;
489 if (!EnterSandbox(setuid_sandbox.get(), 476
477 if (!EnterSandbox(setuid_sandbox,
490 &using_suid_sandbox, 478 &using_suid_sandbox,
491 &has_started_new_init)) { 479 &has_started_new_init)) {
492 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " 480 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: "
493 << errno << ")"; 481 << errno << ")";
494 return false; 482 return false;
495 } 483 }
496 484
497 int sandbox_flags = 0; 485 if (setuid_sandbox->IsInNewNETNamespace() && !has_started_new_init) {
Jorge Lucangeli Obes 2012/08/01 22:37:50 PID namespace?
jln (very slow on Chromium) 2012/08/01 22:48:11 Good catch, thanks!
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) {
507 LOG(ERROR) << "The SUID sandbox created a new PID namespace but Zygote " 486 LOG(ERROR) << "The SUID sandbox created a new PID namespace but Zygote "
508 "is not the init process. Please, make sure the SUID " 487 "is not the init process. Please, make sure the SUID "
509 "binary is up to date."; 488 "binary is up to date.";
510 } 489 }
511 490
512 #if defined(SECCOMP_SANDBOX) 491 int sandbox_flags = linux_sandbox->GetStatus();
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
533 492
534 Zygote zygote(sandbox_flags, forkdelegate, proc_fd_for_seccomp); 493 Zygote zygote(sandbox_flags, forkdelegate);
535 // This function call can return multiple times, once per fork(). 494 // This function call can return multiple times, once per fork().
536 return zygote.ProcessRequests(); 495 return zygote.ProcessRequests();
537 } 496 }
538 497
539 } // namespace content 498 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698