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

Side by Side Diff: chrome/browser/zygote_main_linux.cc

Issue 1558003: linux: enable seccomp sandbox by default (Closed)
Patch Set: better Created 10 years, 8 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
« no previous file with comments | « chrome/browser/zygote_host_linux.cc ('k') | chrome/common/chrome_switches.h » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <sys/epoll.h> 7 #include <sys/epoll.h>
8 #include <sys/prctl.h> 8 #include <sys/prctl.h>
9 #include <sys/signal.h> 9 #include <sys/signal.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 media::InitializeMediaLibrary(module_path); 502 media::InitializeMediaLibrary(module_path);
503 } 503 }
504 504
505 #if !defined(CHROMIUM_SELINUX) 505 #if !defined(CHROMIUM_SELINUX)
506 static bool EnterSandbox() { 506 static bool EnterSandbox() {
507 // The SUID sandbox sets this environment variable to a file descriptor 507 // The SUID sandbox sets this environment variable to a file descriptor
508 // over which we can signal that we have completed our startup and can be 508 // over which we can signal that we have completed our startup and can be
509 // chrooted. 509 // chrooted.
510 const char* const sandbox_fd_string = getenv("SBX_D"); 510 const char* const sandbox_fd_string = getenv("SBX_D");
511 511
512 if (CommandLine::ForCurrentProcess()->HasSwitch( 512 if (switches::SeccompSandboxEnabled()) {
513 switches::kEnableSeccompSandbox)) {
514 PreSandboxInit(); 513 PreSandboxInit();
515 SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor); 514 SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor);
516 } else if (sandbox_fd_string) { // Use the SUID sandbox. 515 } else if (sandbox_fd_string) { // Use the SUID sandbox.
517 g_suid_sandbox_active = true; 516 g_suid_sandbox_active = true;
518 517
519 char* endptr; 518 char* endptr;
520 const long fd_long = strtol(sandbox_fd_string, &endptr, 10); 519 const long fd_long = strtol(sandbox_fd_string, &endptr, 10);
521 if (!*sandbox_fd_string || *endptr || fd_long < 0 || fd_long > INT_MAX) 520 if (!*sandbox_fd_string || *endptr || fd_long < 0 || fd_long > INT_MAX)
522 return false; 521 return false;
523 const int fd = fd_long; 522 const int fd = fd_long;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 610
612 bool ZygoteMain(const MainFunctionParams& params) { 611 bool ZygoteMain(const MainFunctionParams& params) {
613 #if !defined(CHROMIUM_SELINUX) 612 #if !defined(CHROMIUM_SELINUX)
614 g_am_zygote_or_renderer = true; 613 g_am_zygote_or_renderer = true;
615 #endif 614 #endif
616 615
617 #if defined(SECCOMP_SANDBOX) 616 #if defined(SECCOMP_SANDBOX)
618 // The seccomp sandbox needs access to files in /proc, which might be denied 617 // The seccomp sandbox needs access to files in /proc, which might be denied
619 // after one of the other sandboxes have been started. So, obtain a suitable 618 // after one of the other sandboxes have been started. So, obtain a suitable
620 // file handle in advance. 619 // file handle in advance.
621 if (CommandLine::ForCurrentProcess()->HasSwitch( 620 if (switches::SeccompSandboxEnabled()) {
622 switches::kEnableSeccompSandbox)) {
623 g_proc_fd = open("/proc", O_DIRECTORY | O_RDONLY); 621 g_proc_fd = open("/proc", O_DIRECTORY | O_RDONLY);
624 if (g_proc_fd < 0) { 622 if (g_proc_fd < 0) {
625 LOG(ERROR) << "WARNING! Cannot access \"/proc\". Disabling seccomp " 623 LOG(ERROR) << "WARNING! Cannot access \"/proc\". Disabling seccomp "
626 "sandboxing."; 624 "sandboxing.";
627 } 625 }
628 } 626 }
629 #endif // SECCOMP_SANDBOX 627 #endif // SECCOMP_SANDBOX
630 628
631 // Turn on the SELinux or SUID sandbox 629 // Turn on the SELinux or SUID sandbox
632 if (!EnterSandbox()) { 630 if (!EnterSandbox()) {
633 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " 631 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: "
634 << errno << ")"; 632 << errno << ")";
635 return false; 633 return false;
636 } 634 }
637 635
638 #if defined(SECCOMP_SANDBOX) 636 #if defined(SECCOMP_SANDBOX)
639 // The seccomp sandbox will be turned on when the renderers start. But we can 637 // The seccomp sandbox will be turned on when the renderers start. But we can
640 // already check if sufficient support is available so that we only need to 638 // already check if sufficient support is available so that we only need to
641 // print one error message for the entire browser session. 639 // print one error message for the entire browser session.
642 if (g_proc_fd >= 0 && 640 if (g_proc_fd >= 0 && switches::SeccompSandboxEnabled()) {
643 CommandLine::ForCurrentProcess()->HasSwitch(
644 switches::kEnableSeccompSandbox)) {
645 if (!SupportsSeccompSandbox(g_proc_fd)) { 641 if (!SupportsSeccompSandbox(g_proc_fd)) {
646 // There are a good number of users who cannot use the seccomp sandbox 642 // There are a good number of users who cannot use the seccomp sandbox
647 // (e.g. because their distribution does not enable seccomp mode by 643 // (e.g. because their distribution does not enable seccomp mode by
648 // default). While we would prefer to deny execution in this case, it 644 // default). While we would prefer to deny execution in this case, it
649 // seems more realistic to continue in degraded mode. 645 // seems more realistic to continue in degraded mode.
650 LOG(ERROR) << "WARNING! This machine lacks support needed for the " 646 LOG(ERROR) << "WARNING! This machine lacks support needed for the "
651 "Seccomp sandbox. Running renderers with Seccomp " 647 "Seccomp sandbox. Running renderers with Seccomp "
652 "sandboxing disabled."; 648 "sandboxing disabled.";
653 } else { 649 } else {
654 LOG(INFO) << "Enabling experimental Seccomp sandbox."; 650 LOG(INFO) << "Enabling experimental Seccomp sandbox.";
655 } 651 }
656 } 652 }
657 #endif // SECCOMP_SANDBOX 653 #endif // SECCOMP_SANDBOX
658 654
659 Zygote zygote; 655 Zygote zygote;
660 // This function call can return multiple times, once per fork(). 656 // This function call can return multiple times, once per fork().
661 return zygote.ProcessRequests(); 657 return zygote.ProcessRequests();
662 } 658 }
OLDNEW
« no previous file with comments | « chrome/browser/zygote_host_linux.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698