OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/sandbox_linux/bpf_gpu_policy_linux.h" | 5 #include "content/common/sandbox_linux/bpf_gpu_policy_linux.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 #include <unistd.h> | 13 #include <unistd.h> |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 24 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
25 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 25 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
26 #include "content/common/set_process_title.h" | 26 #include "content/common/set_process_title.h" |
27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
28 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 28 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" // for arch_seccomp_data |
30 #include "sandbox/linux/services/broker_process.h" | 30 #include "sandbox/linux/services/broker_process.h" |
31 #include "sandbox/linux/services/linux_syscalls.h" | 31 #include "sandbox/linux/services/linux_syscalls.h" |
32 | 32 |
33 using sandbox::BrokerProcess; | 33 using sandbox::BrokerProcess; |
34 using sandbox::SyscallSets; | 34 using sandbox::SyscallSets; |
35 using sandbox::arch_seccomp_data; | 35 using sandbox::arch_seccomp_data; |
36 using sandbox::bpf_dsl::Allow; | 36 using sandbox::bpf_dsl::Allow; |
37 using sandbox::bpf_dsl::ResultExpr; | 37 using sandbox::bpf_dsl::ResultExpr; |
38 | 38 |
39 namespace content { | 39 namespace content { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return -EPERM; | 110 return -EPERM; |
111 } | 111 } |
112 default: | 112 default: |
113 RAW_CHECK(false); | 113 RAW_CHECK(false); |
114 return -ENOSYS; | 114 return -ENOSYS; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 class GpuBrokerProcessPolicy : public GpuProcessPolicy { | 118 class GpuBrokerProcessPolicy : public GpuProcessPolicy { |
119 public: | 119 public: |
120 static sandbox::SandboxBPFPolicy* Create() { | 120 static sandbox::bpf_dsl::SandboxBPFDSLPolicy* Create() { |
121 return new GpuBrokerProcessPolicy(); | 121 return new GpuBrokerProcessPolicy(); |
122 } | 122 } |
123 virtual ~GpuBrokerProcessPolicy() {} | 123 virtual ~GpuBrokerProcessPolicy() {} |
124 | 124 |
125 virtual ResultExpr EvaluateSyscall(int system_call_number) const OVERRIDE; | 125 virtual ResultExpr EvaluateSyscall(int system_call_number) const OVERRIDE; |
126 | 126 |
127 private: | 127 private: |
128 GpuBrokerProcessPolicy() {} | 128 GpuBrokerProcessPolicy() {} |
129 DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy); | 129 DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy); |
130 }; | 130 }; |
(...skipping 20 matching lines...) Expand all Loading... |
151 base::CommandLine::ForCurrentProcess()->InitFromArgv(exec); | 151 base::CommandLine::ForCurrentProcess()->InitFromArgv(exec); |
152 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 152 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
153 switches::kProcessType, "gpu-broker"); | 153 switches::kProcessType, "gpu-broker"); |
154 | 154 |
155 // Update the process title. The argv was already cached by the call to | 155 // Update the process title. The argv was already cached by the call to |
156 // SetProcessTitleFromCommandLine in content_main_runner.cc, so we can pass | 156 // SetProcessTitleFromCommandLine in content_main_runner.cc, so we can pass |
157 // NULL here (we don't have the original argv at this point). | 157 // NULL here (we don't have the original argv at this point). |
158 SetProcessTitleFromCommandLine(NULL); | 158 SetProcessTitleFromCommandLine(NULL); |
159 } | 159 } |
160 | 160 |
161 bool UpdateProcessTypeAndEnableSandbox( | 161 bool UpdateProcessTypeAndEnableSandbox(sandbox::bpf_dsl::SandboxBPFDSLPolicy* ( |
162 sandbox::SandboxBPFPolicy* (*broker_sandboxer_allocator)(void)) { | 162 *broker_sandboxer_allocator)(void)) { |
163 DCHECK(broker_sandboxer_allocator); | 163 DCHECK(broker_sandboxer_allocator); |
164 UpdateProcessTypeToGpuBroker(); | 164 UpdateProcessTypeToGpuBroker(); |
165 return SandboxSeccompBPF::StartSandboxWithExternalPolicy( | 165 return SandboxSeccompBPF::StartSandboxWithExternalPolicy( |
166 make_scoped_ptr(broker_sandboxer_allocator())); | 166 make_scoped_ptr(broker_sandboxer_allocator())); |
167 } | 167 } |
168 | 168 |
169 } // namespace | 169 } // namespace |
170 | 170 |
171 GpuProcessPolicy::GpuProcessPolicy() : broker_process_(NULL) {} | 171 GpuProcessPolicy::GpuProcessPolicy() : broker_process_(NULL) {} |
172 | 172 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 233 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
234 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 234 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
235 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 235 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 return true; | 239 return true; |
240 } | 240 } |
241 | 241 |
242 void GpuProcessPolicy::InitGpuBrokerProcess( | 242 void GpuProcessPolicy::InitGpuBrokerProcess( |
243 sandbox::SandboxBPFPolicy* (*broker_sandboxer_allocator)(void), | 243 sandbox::bpf_dsl::SandboxBPFDSLPolicy* (*broker_sandboxer_allocator)(void), |
244 const std::vector<std::string>& read_whitelist_extra, | 244 const std::vector<std::string>& read_whitelist_extra, |
245 const std::vector<std::string>& write_whitelist_extra) { | 245 const std::vector<std::string>& write_whitelist_extra) { |
246 static const char kDriRcPath[] = "/etc/drirc"; | 246 static const char kDriRcPath[] = "/etc/drirc"; |
247 static const char kDriCard0Path[] = "/dev/dri/card0"; | 247 static const char kDriCard0Path[] = "/dev/dri/card0"; |
248 | 248 |
249 CHECK(broker_process_ == NULL); | 249 CHECK(broker_process_ == NULL); |
250 | 250 |
251 // All GPU process policies need these files brokered out. | 251 // All GPU process policies need these files brokered out. |
252 std::vector<std::string> read_whitelist; | 252 std::vector<std::string> read_whitelist; |
253 read_whitelist.push_back(kDriCard0Path); | 253 read_whitelist.push_back(kDriCard0Path); |
(...skipping 13 matching lines...) Expand all Loading... |
267 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), | 267 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), |
268 read_whitelist, | 268 read_whitelist, |
269 write_whitelist); | 269 write_whitelist); |
270 // The initialization callback will perform generic initialization and then | 270 // The initialization callback will perform generic initialization and then |
271 // call broker_sandboxer_callback. | 271 // call broker_sandboxer_callback. |
272 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, | 272 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
273 broker_sandboxer_allocator))); | 273 broker_sandboxer_allocator))); |
274 } | 274 } |
275 | 275 |
276 } // namespace content | 276 } // namespace content |
OLD | NEW |