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 "content/common/seccomp_sandbox.h" | 5 #include "content/common/seccomp_sandbox.h" |
6 #include "content/public/common/sandbox_init.h" | 6 #include "content/public/common/sandbox_init.h" |
7 | 7 |
8 #if defined(__i386__) || defined(__x86_64__) | 8 #if defined(__i386__) || defined(__x86_64__) |
9 | 9 |
10 // This is an assert for GYP | 10 // This is an assert for GYP |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include <sys/types.h> | 25 #include <sys/types.h> |
26 #include <ucontext.h> | 26 #include <ucontext.h> |
27 #include <unistd.h> | 27 #include <unistd.h> |
28 | 28 |
29 #include <vector> | 29 #include <vector> |
30 | 30 |
31 #include "base/command_line.h" | 31 #include "base/command_line.h" |
32 #include "base/file_util.h" | 32 #include "base/file_util.h" |
33 #include "base/logging.h" | 33 #include "base/logging.h" |
34 #include "base/time.h" | 34 #include "base/time.h" |
35 #include "content/common/sandbox_linux.h" | |
36 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
37 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 36 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
38 | 37 |
39 // These are fairly new and not defined in all headers yet. | 38 // These are fairly new and not defined in all headers yet. |
40 #if defined(__x86_64__) | 39 #if defined(__x86_64__) |
41 | 40 |
42 #ifndef __NR_process_vm_readv | 41 #ifndef __NR_process_vm_readv |
43 #define __NR_process_vm_readv 310 | 42 #define __NR_process_vm_readv 310 |
44 #endif | 43 #endif |
45 | 44 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 531 |
533 // Warms up resources needed by the policy we're about to enable. | 532 // Warms up resources needed by the policy we're about to enable. |
534 WarmupPolicy(SyscallPolicy); | 533 WarmupPolicy(SyscallPolicy); |
535 | 534 |
536 playground2::Sandbox::setSandboxPolicy(SyscallPolicy, NULL); | 535 playground2::Sandbox::setSandboxPolicy(SyscallPolicy, NULL); |
537 playground2::Sandbox::startSandbox(); | 536 playground2::Sandbox::startSandbox(); |
538 | 537 |
539 return true; | 538 return true; |
540 } | 539 } |
541 | 540 |
| 541 bool InitializeLegacySandbox_x86(const CommandLine& command_line, |
| 542 const std::string& process_type) { |
| 543 #if defined(SECCOMP_SANDBOX) |
| 544 // Start the old seccomp mode 1 (sandbox/linux/seccomp-legacy). |
| 545 if (process_type == switches::kRendererProcess && SeccompSandboxEnabled()) { |
| 546 // N.b. SupportsSeccompSandbox() returns a cached result, as we already |
| 547 // called it earlier in the zygote. Thus, it is OK for us to not pass in |
| 548 // a file descriptor for "/proc". |
| 549 if (SupportsSeccompSandbox(-1)) { |
| 550 StartSeccompSandbox(); |
| 551 return true; |
| 552 } |
| 553 } |
| 554 #endif |
| 555 return false; |
| 556 } |
| 557 |
542 } // anonymous namespace | 558 } // anonymous namespace |
543 | 559 |
544 #endif // defined(__i386__) || defined(__x86_64__) | 560 #endif // defined(__i386__) || defined(__x86_64__) |
545 | 561 |
546 namespace content { | 562 namespace content { |
547 | 563 |
548 void InitializeSandbox() { | 564 void InitializeSandbox() { |
549 #if defined(__i386__) || defined(__x86_64__) | 565 #if defined(__i386__) || defined(__x86_64__) |
550 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 566 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
551 const std::string process_type = | 567 const std::string process_type = |
552 command_line.GetSwitchValueASCII(switches::kProcessType); | 568 command_line.GetSwitchValueASCII(switches::kProcessType); |
553 bool seccomp_legacy_started = false; | 569 bool seccomp_legacy_started = false; |
554 bool seccomp_bpf_started = false; | 570 bool seccomp_bpf_started = false; |
555 | 571 |
556 // First, try to enable seccomp-legacy. | 572 // First, try to enable seccomp-legacy. |
557 seccomp_legacy_started = | 573 seccomp_legacy_started = |
558 LinuxSandbox::GetInstance()->StartSeccompLegacy(process_type); | 574 InitializeLegacySandbox_x86(command_line, process_type); |
559 if (seccomp_legacy_started) | 575 if (seccomp_legacy_started) |
560 LogSandboxStarted("seccomp-legacy", process_type); | 576 LogSandboxStarted("seccomp-legacy", process_type); |
561 | 577 |
562 // Then, try to enable seccomp-bpf. | 578 // Then, try to enable seccomp-bpf. |
563 // If seccomp-legacy is enabled, seccomp-bpf initialization will crash | 579 // If seccomp-legacy is enabled, seccomp-bpf initialization will crash |
564 // instead of failing gracefully. | 580 // instead of failing gracefully. |
565 // TODO(markus): fix this (crbug.com/139872). | 581 // TODO(markus): fix this (crbug.com/139872). |
566 if (!seccomp_legacy_started) { | 582 if (!seccomp_legacy_started) { |
567 seccomp_bpf_started = | 583 seccomp_bpf_started = |
568 InitializeBpfSandbox_x86(command_line, process_type); | 584 InitializeBpfSandbox_x86(command_line, process_type); |
569 } | 585 } |
570 if (seccomp_bpf_started) | 586 if (seccomp_bpf_started) |
571 LogSandboxStarted("seccomp-bpf", process_type); | 587 LogSandboxStarted("seccomp-bpf", process_type); |
572 #endif | 588 #endif |
573 } | 589 } |
574 | 590 |
575 } // namespace content | 591 } // namespace content |
OLD | NEW |