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

Side by Side Diff: components/nacl/loader/sandbox_linux/nacl_bpf_sandbox_linux.cc

Issue 670603002: Linux sandbox: Tighten up the NaCl sandbox policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 1 month 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 | « components/nacl/loader/DEPS ('k') | components/nacl/zygote/nacl_fork_delegate_linux.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/nacl/loader/sandbox_linux/nacl_bpf_sandbox_linux.h" 5 #include "components/nacl/loader/sandbox_linux/nacl_bpf_sandbox_linux.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(USE_SECCOMP_BPF) 9 #if defined(USE_SECCOMP_BPF)
10 10
11 #include <errno.h> 11 #include <errno.h>
12 #include <signal.h> 12 #include <signal.h>
13 #include <sys/ptrace.h> 13 #include <sys/ptrace.h>
14 #include <sys/types.h>
15 #include <unistd.h>
14 16
15 #include "base/basictypes.h" 17 #include "base/basictypes.h"
16 #include "base/callback.h" 18 #include "base/callback.h"
19 #include "base/command_line.h"
17 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
18 #include "base/logging.h" 21 #include "base/logging.h"
19 22
23 #include "components/nacl/common/nacl_switches.h"
20 #include "content/public/common/sandbox_init.h" 24 #include "content/public/common/sandbox_init.h"
21 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 25 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
22 #include "sandbox/linux/bpf_dsl/policy.h" 26 #include "sandbox/linux/bpf_dsl/policy.h"
27 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
23 #include "sandbox/linux/services/linux_syscalls.h" 28 #include "sandbox/linux/services/linux_syscalls.h"
24 29
25 #endif // defined(USE_SECCOMP_BPF) 30 #endif // defined(USE_SECCOMP_BPF)
26 31
27 namespace nacl { 32 namespace nacl {
28 33
29 #if defined(USE_SECCOMP_BPF) 34 #if defined(USE_SECCOMP_BPF)
30 35
31 namespace { 36 namespace {
32 37
33 using sandbox::bpf_dsl::Allow; 38 using sandbox::bpf_dsl::Allow;
34 using sandbox::bpf_dsl::Error; 39 using sandbox::bpf_dsl::Error;
35 using sandbox::bpf_dsl::ResultExpr; 40 using sandbox::bpf_dsl::ResultExpr;
36 41
37 class NaClBPFSandboxPolicy : public sandbox::bpf_dsl::Policy { 42 class NaClBPFSandboxPolicy : public sandbox::bpf_dsl::Policy {
38 public: 43 public:
39 NaClBPFSandboxPolicy() 44 NaClBPFSandboxPolicy()
40 : baseline_policy_(content::GetBPFSandboxBaselinePolicy()) {} 45 : baseline_policy_(content::GetBPFSandboxBaselinePolicy()),
46 policy_pid_(getpid()) {
47 const base::CommandLine* command_line =
48 base::CommandLine::ForCurrentProcess();
49 enable_nacl_debug_ = command_line->HasSwitch(switches::kEnableNaClDebug);
Mark Seaborn 2014/10/28 00:30:14 Maybe add a comment like: // nacl_process_host.cc
rickyz (no longer on Chrome) 2014/10/29 21:07:36 Done.
50 }
41 virtual ~NaClBPFSandboxPolicy() {} 51 virtual ~NaClBPFSandboxPolicy() {}
42 52
43 virtual ResultExpr EvaluateSyscall(int system_call_number) const override; 53 virtual ResultExpr EvaluateSyscall(int system_call_number) const override;
44 virtual ResultExpr InvalidSyscall() const override { 54 virtual ResultExpr InvalidSyscall() const override {
45 return baseline_policy_->InvalidSyscall(); 55 return baseline_policy_->InvalidSyscall();
46 } 56 }
47 57
48 private: 58 private:
49 scoped_ptr<sandbox::bpf_dsl::Policy> baseline_policy_; 59 scoped_ptr<sandbox::bpf_dsl::Policy> baseline_policy_;
60 bool enable_nacl_debug_;
61 pid_t policy_pid_;
jln (very slow on Chromium) 2014/10/29 18:44:45 const
rickyz (no longer on Chrome) 2014/10/29 21:07:36 Done.
50 62
51 DISALLOW_COPY_AND_ASSIGN(NaClBPFSandboxPolicy); 63 DISALLOW_COPY_AND_ASSIGN(NaClBPFSandboxPolicy);
52 }; 64 };
53 65
54 ResultExpr NaClBPFSandboxPolicy::EvaluateSyscall(int sysno) const { 66 ResultExpr NaClBPFSandboxPolicy::EvaluateSyscall(int sysno) const {
55 DCHECK(baseline_policy_); 67 DCHECK(baseline_policy_);
68
69 // NaCl's GDB debug stub uses the following socket system calls. We only
70 // allow then when --enable-nacl-debug is specified.
Mark Seaborn 2014/10/28 00:30:14 "then" -> "them"
71 if (enable_nacl_debug_) {
72 switch (sysno) {
73 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
74 // transport_common.cc needs this.
75 case __NR_accept:
76 case __NR_setsockopt:
77 return Allow();
78 #elif defined(__i386__)
79 case __NR_socketcall:
80 return Allow();
81 #endif
82 default:
83 break;
84 }
85 }
86
56 switch (sysno) { 87 switch (sysno) {
57 // TODO(jln): NaCl's GDB debug stub uses the following socket system calls, 88 // trusted/service_runtime/linux/thread_suspension.c needs sigwait()
58 // see if it can be restricted a bit.
59 #if defined(__x86_64__) || defined(__arm__) || defined(__mips__)
60 // transport_common.cc needs this.
61 case __NR_accept:
62 case __NR_setsockopt:
63 #elif defined(__i386__)
64 case __NR_socketcall:
65 #endif
66 // trusted/service_runtime/linux/thread_suspension.c needs sigwait() and is
67 // used by NaCl's GDB debug stub.
Mark Seaborn 2014/10/28 00:30:14 I think it would be worth keeping this comment and
rickyz (no longer on Chrome) 2014/10/29 21:07:36 Ah, OK - moved it into the list of syscalls only a
68 case __NR_rt_sigtimedwait: 89 case __NR_rt_sigtimedwait:
69 #if defined(__i386__) || defined(__mips__) 90 #if defined(__i386__) || defined(__mips__)
70 // Needed on i386 to set-up the custom segments. 91 // Needed on i386 to set-up the custom segments.
71 case __NR_modify_ldt: 92 case __NR_modify_ldt:
72 #endif 93 #endif
73 // NaClAddrSpaceBeforeAlloc needs prlimit64. 94 // NaClAddrSpaceBeforeAlloc needs prlimit64.
74 case __NR_prlimit64: 95 case __NR_prlimit64:
75 // NaCl uses custom signal stacks. 96 // NaCl uses custom signal stacks.
76 case __NR_sigaltstack: 97 case __NR_sigaltstack:
77 // Below is fairly similar to the policy for a Chromium renderer. 98 // Below is fairly similar to the policy for a Chromium renderer.
78 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__) 99 #if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
79 case __NR_getrlimit: 100 case __NR_getrlimit:
80 #endif 101 #endif
81 #if defined(__i386__) || defined(__arm__) 102 #if defined(__i386__) || defined(__arm__)
82 case __NR_ugetrlimit: 103 case __NR_ugetrlimit:
83 #endif 104 #endif
84 // NaCl runtime exposes clock_getres to untrusted code. 105 // NaCl runtime exposes clock_getres to untrusted code.
85 case __NR_clock_getres: 106 case __NR_clock_getres:
86 // NaCl runtime uses flock to simulate POSIX behavior for pwrite. 107 // NaCl runtime uses flock to simulate POSIX behavior for pwrite.
87 case __NR_flock: 108 case __NR_flock:
88 case __NR_pread64: 109 case __NR_pread64:
89 case __NR_pwrite64: 110 case __NR_pwrite64:
90 case __NR_sched_get_priority_max: 111 case __NR_sched_get_priority_max:
91 case __NR_sched_get_priority_min: 112 case __NR_sched_get_priority_min:
92 case __NR_sched_getaffinity:
93 case __NR_sched_getparam:
94 case __NR_sched_getscheduler:
95 case __NR_sched_setscheduler:
96 case __NR_sysinfo: 113 case __NR_sysinfo:
97 // __NR_times needed as clock() is called by CommandBufferHelper, which is 114 // __NR_times needed as clock() is called by CommandBufferHelper, which is
98 // used by NaCl applications that use Pepper's 3D interfaces. 115 // used by NaCl applications that use Pepper's 3D interfaces.
99 // See crbug.com/264856 for details. 116 // See crbug.com/264856 for details.
100 case __NR_times: 117 case __NR_times:
101 case __NR_uname: 118 case __NR_uname:
102 return Allow(); 119 return Allow();
103 case __NR_ioctl: 120 case __NR_ioctl:
104 case __NR_ptrace: 121 case __NR_ptrace:
105 return Error(EPERM); 122 return Error(EPERM);
123 case __NR_sched_getaffinity:
124 case __NR_sched_getparam:
125 case __NR_sched_getscheduler:
126 case __NR_sched_setscheduler:
127 return sandbox::RestrictSchedTarget(policy_pid_, sysno);
Mark Seaborn 2014/10/28 00:30:14 Why not call getpid() here? I'm not sure why you'
jln (very slow on Chromium) 2014/10/29 18:40:16 I actually requested that (see previous comments).
rickyz (no longer on Chrome) 2014/10/29 21:07:36 I added a CHECK in EvaluateSyscall - hopefully tha
106 default: 128 default:
107 return baseline_policy_->EvaluateSyscall(sysno); 129 return baseline_policy_->EvaluateSyscall(sysno);
108 } 130 }
109 NOTREACHED(); 131 NOTREACHED();
110 // GCC wants this. 132 // GCC wants this.
111 return Error(EPERM); 133 return Error(EPERM);
112 } 134 }
113 135
114 void RunSandboxSanityChecks() { 136 void RunSandboxSanityChecks() {
115 errno = 0; 137 errno = 0;
(...skipping 18 matching lines...) Expand all
134 scoped_ptr<sandbox::bpf_dsl::Policy>(new NaClBPFSandboxPolicy)); 156 scoped_ptr<sandbox::bpf_dsl::Policy>(new NaClBPFSandboxPolicy));
135 if (sandbox_is_initialized) { 157 if (sandbox_is_initialized) {
136 RunSandboxSanityChecks(); 158 RunSandboxSanityChecks();
137 return true; 159 return true;
138 } 160 }
139 #endif // defined(USE_SECCOMP_BPF) 161 #endif // defined(USE_SECCOMP_BPF)
140 return false; 162 return false;
141 } 163 }
142 164
143 } // namespace nacl 165 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/loader/DEPS ('k') | components/nacl/zygote/nacl_fork_delegate_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698