Chromium Code Reviews| 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/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 5 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/common/sandbox_linux/bpf_utility_policy_linux.h" | 27 #include "content/common/sandbox_linux/bpf_utility_policy_linux.h" |
| 28 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 28 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
| 29 #include "content/common/sandbox_linux/sandbox_linux.h" | 29 #include "content/common/sandbox_linux/sandbox_linux.h" |
| 30 #include "sandbox/linux/seccomp-bpf-helpers/baseline_policy.h" | 30 #include "sandbox/linux/seccomp-bpf-helpers/baseline_policy.h" |
| 31 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | 31 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" |
| 32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" | 32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
| 33 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 33 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
| 34 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 34 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 35 #include "sandbox/linux/services/linux_syscalls.h" | 35 #include "sandbox/linux/services/linux_syscalls.h" |
| 36 | 36 |
| 37 #if !defined(IN_NACL_HELPER) | |
| 38 #include "ui/gl/gl_switches.h" | |
| 39 #endif | |
| 40 | |
| 37 using sandbox::BaselinePolicy; | 41 using sandbox::BaselinePolicy; |
| 38 using sandbox::SandboxBPF; | 42 using sandbox::SandboxBPF; |
| 39 using sandbox::SyscallSets; | 43 using sandbox::SyscallSets; |
| 40 using sandbox::bpf_dsl::Allow; | 44 using sandbox::bpf_dsl::Allow; |
| 41 using sandbox::bpf_dsl::ResultExpr; | 45 using sandbox::bpf_dsl::ResultExpr; |
| 42 | 46 |
| 43 #else | 47 #else |
| 44 | 48 |
| 45 // Make sure that seccomp-bpf does not get disabled by mistake. Also make sure | 49 // Make sure that seccomp-bpf does not get disabled by mistake. Also make sure |
| 46 // that we think twice about this when adding a new architecture. | 50 // that we think twice about this when adding a new architecture. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 // the object to be destroyed after the sandbox has been started. Note that | 151 // the object to be destroyed after the sandbox has been started. Note that |
| 148 // doing so does not stop the sandbox. | 152 // doing so does not stop the sandbox. |
| 149 SandboxBPF sandbox; | 153 SandboxBPF sandbox; |
| 150 sandbox.SetSandboxPolicy(policy); | 154 sandbox.SetSandboxPolicy(policy); |
| 151 CHECK(sandbox.StartSandbox(SandboxBPF::PROCESS_SINGLE_THREADED)); | 155 CHECK(sandbox.StartSandbox(SandboxBPF::PROCESS_SINGLE_THREADED)); |
| 152 } | 156 } |
| 153 | 157 |
| 154 // nacl_helper needs to be tiny and includes only part of content/ | 158 // nacl_helper needs to be tiny and includes only part of content/ |
| 155 // in its dependencies. Make sure to not link things that are not needed. | 159 // in its dependencies. Make sure to not link things that are not needed. |
| 156 #if !defined(IN_NACL_HELPER) | 160 #if !defined(IN_NACL_HELPER) |
| 161 class GpuEGLProcessPolicy : public GpuProcessPolicy { | |
|
jln (very slow on Chromium)
2014/10/17 18:13:38
Why make it a new class? If you really need this,
| |
| 162 public: | |
| 163 GpuEGLProcessPolicy() { } | |
| 164 virtual ~GpuEGLProcessPolicy() {} | |
| 165 | |
| 166 virtual ResultExpr EvaluateSyscall( | |
| 167 int sysno) const override; | |
| 168 | |
| 169 private: | |
| 170 DISALLOW_COPY_AND_ASSIGN(GpuEGLProcessPolicy); | |
| 171 }; | |
| 172 | |
| 173 ResultExpr GpuEGLProcessPolicy::EvaluateSyscall(int sysno) const { | |
| 174 switch (sysno) { | |
| 175 // eglCreateWindowSurface() needs mincore(). | |
| 176 case __NR_mincore: | |
| 177 return Allow(); | |
| 178 default: | |
| 179 return GpuProcessPolicy::EvaluateSyscall(sysno); | |
| 180 } | |
| 181 } | |
| 182 | |
| 157 scoped_ptr<SandboxBPFBasePolicy> GetGpuProcessSandbox() { | 183 scoped_ptr<SandboxBPFBasePolicy> GetGpuProcessSandbox() { |
| 158 const base::CommandLine& command_line = | 184 const base::CommandLine& command_line = |
| 159 *base::CommandLine::ForCurrentProcess(); | 185 *base::CommandLine::ForCurrentProcess(); |
| 160 bool allow_sysv_shm = false; | 186 bool allow_sysv_shm = false; |
| 161 if (command_line.HasSwitch(switches::kGpuSandboxAllowSysVShm)) { | 187 if (command_line.HasSwitch(switches::kGpuSandboxAllowSysVShm)) { |
| 162 DCHECK(IsArchitectureArm()); | 188 DCHECK(IsArchitectureArm()); |
| 163 allow_sysv_shm = true; | 189 allow_sysv_shm = true; |
| 164 } | 190 } |
| 165 | 191 |
| 166 if (IsChromeOS() && IsArchitectureArm()) { | 192 if (IsChromeOS() && IsArchitectureArm()) { |
| 167 return scoped_ptr<SandboxBPFBasePolicy>( | 193 return scoped_ptr<SandboxBPFBasePolicy>( |
| 168 new CrosArmGpuProcessPolicy(allow_sysv_shm)); | 194 new CrosArmGpuProcessPolicy(allow_sysv_shm)); |
| 169 } else { | 195 } else { |
| 170 return scoped_ptr<SandboxBPFBasePolicy>(new GpuProcessPolicy); | 196 if (command_line.HasSwitch(switches::kUseGL) && |
| 197 command_line.GetSwitchValueASCII(switches::kUseGL) == | |
| 198 gfx::kGLImplementationEGLName) { | |
| 199 return scoped_ptr<SandboxBPFBasePolicy>(new GpuEGLProcessPolicy); | |
| 200 } else { | |
| 201 return scoped_ptr<SandboxBPFBasePolicy>(new GpuProcessPolicy); | |
| 202 } | |
| 171 } | 203 } |
| 172 } | 204 } |
| 173 | 205 |
| 174 // Initialize the seccomp-bpf sandbox. | 206 // Initialize the seccomp-bpf sandbox. |
| 175 bool StartBPFSandbox(const base::CommandLine& command_line, | 207 bool StartBPFSandbox(const base::CommandLine& command_line, |
| 176 const std::string& process_type) { | 208 const std::string& process_type) { |
| 177 scoped_ptr<SandboxBPFBasePolicy> policy; | 209 scoped_ptr<SandboxBPFBasePolicy> policy; |
| 178 | 210 |
| 179 if (process_type == switches::kGpuProcess) { | 211 if (process_type == switches::kGpuProcess) { |
| 180 policy.reset(GetGpuProcessSandbox().release()); | 212 policy.reset(GetGpuProcessSandbox().release()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 scoped_ptr<sandbox::bpf_dsl::SandboxBPFDSLPolicy> | 318 scoped_ptr<sandbox::bpf_dsl::SandboxBPFDSLPolicy> |
| 287 SandboxSeccompBPF::GetBaselinePolicy() { | 319 SandboxSeccompBPF::GetBaselinePolicy() { |
| 288 #if defined(USE_SECCOMP_BPF) | 320 #if defined(USE_SECCOMP_BPF) |
| 289 return scoped_ptr<sandbox::bpf_dsl::SandboxBPFDSLPolicy>(new BaselinePolicy); | 321 return scoped_ptr<sandbox::bpf_dsl::SandboxBPFDSLPolicy>(new BaselinePolicy); |
| 290 #else | 322 #else |
| 291 return scoped_ptr<sandbox::bpf_dsl::SandboxBPFDSLPolicy>(); | 323 return scoped_ptr<sandbox::bpf_dsl::SandboxBPFDSLPolicy>(); |
| 292 #endif // defined(USE_SECCOMP_BPF) | 324 #endif // defined(USE_SECCOMP_BPF) |
| 293 } | 325 } |
| 294 | 326 |
| 295 } // namespace content | 327 } // namespace content |
| OLD | NEW |