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

Side by Side Diff: content/common/sandbox_linux/bpf_gpu_policy_linux.cc

Issue 721553002: sandbox: Extend BrokerPolicy to support file creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 6 years 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 | « content/common/sandbox_linux/bpf_gpu_policy_linux.h ('k') | sandbox/linux/BUILD.gn » ('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) 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>
(...skipping 11 matching lines...) Expand all
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/bpf_dsl/bpf_dsl.h" 28 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
29 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" 29 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
30 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" 30 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
31 #include "sandbox/linux/services/linux_syscalls.h" 31 #include "sandbox/linux/services/linux_syscalls.h"
32 #include "sandbox/linux/syscall_broker/broker_file_permission.h"
32 #include "sandbox/linux/syscall_broker/broker_process.h" 33 #include "sandbox/linux/syscall_broker/broker_process.h"
33 34
34 using sandbox::syscall_broker::BrokerProcess;
35 using sandbox::SyscallSets;
36 using sandbox::arch_seccomp_data; 35 using sandbox::arch_seccomp_data;
37 using sandbox::bpf_dsl::Allow; 36 using sandbox::bpf_dsl::Allow;
38 using sandbox::bpf_dsl::ResultExpr; 37 using sandbox::bpf_dsl::ResultExpr;
39 using sandbox::bpf_dsl::Trap; 38 using sandbox::bpf_dsl::Trap;
39 using sandbox::syscall_broker::BrokerFilePermission;
40 using sandbox::syscall_broker::BrokerProcess;
41 using sandbox::SyscallSets;
40 42
41 namespace content { 43 namespace content {
42 44
43 namespace { 45 namespace {
44 46
45 inline bool IsChromeOS() { 47 inline bool IsChromeOS() {
46 #if defined(OS_CHROMEOS) 48 #if defined(OS_CHROMEOS)
47 return true; 49 return true;
48 #else 50 #else
49 return false; 51 return false;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // Warm up resources needed by the policy we're about to enable and 226 // Warm up resources needed by the policy we're about to enable and
225 // eventually start a broker process. 227 // eventually start a broker process.
226 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); 228 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm();
227 // This policy is for x86 or Desktop. 229 // This policy is for x86 or Desktop.
228 DCHECK(!chromeos_arm_gpu); 230 DCHECK(!chromeos_arm_gpu);
229 231
230 DCHECK(!broker_process()); 232 DCHECK(!broker_process());
231 // Create a new broker process. 233 // Create a new broker process.
232 InitGpuBrokerProcess( 234 InitGpuBrokerProcess(
233 GpuBrokerProcessPolicy::Create, 235 GpuBrokerProcessPolicy::Create,
234 std::vector<std::string>(), // No extra files in whitelist. 236 std::vector<BrokerFilePermission>()); // No extra files in whitelist.
235 std::vector<std::string>());
236 237
237 if (IsArchitectureX86_64() || IsArchitectureI386()) { 238 if (IsArchitectureX86_64() || IsArchitectureI386()) {
238 // Accelerated video dlopen()'s some shared objects 239 // Accelerated video dlopen()'s some shared objects
239 // inside the sandbox, so preload them now. 240 // inside the sandbox, so preload them now.
240 if (IsAcceleratedVideoEnabled()) { 241 if (IsAcceleratedVideoEnabled()) {
241 const char* I965DrvVideoPath = NULL; 242 const char* I965DrvVideoPath = NULL;
242 243
243 if (IsArchitectureX86_64()) { 244 if (IsArchitectureX86_64()) {
244 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; 245 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so";
245 } else if (IsArchitectureI386()) { 246 } else if (IsArchitectureI386()) {
246 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; 247 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so";
247 } 248 }
248 249
249 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 250 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
250 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 251 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
251 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 252 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
252 } 253 }
253 } 254 }
254 255
255 return true; 256 return true;
256 } 257 }
257 258
258 void GpuProcessPolicy::InitGpuBrokerProcess( 259 void GpuProcessPolicy::InitGpuBrokerProcess(
259 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), 260 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void),
260 const std::vector<std::string>& read_whitelist_extra, 261 const std::vector<BrokerFilePermission>& permissions_extra) {
261 const std::vector<std::string>& write_whitelist_extra) {
262 static const char kDriRcPath[] = "/etc/drirc"; 262 static const char kDriRcPath[] = "/etc/drirc";
263 static const char kDriCard0Path[] = "/dev/dri/card0"; 263 static const char kDriCard0Path[] = "/dev/dri/card0";
264 264
265 CHECK(broker_process_ == NULL); 265 CHECK(broker_process_ == NULL);
266 266
267 // All GPU process policies need these files brokered out. 267 // All GPU process policies need these files brokered out.
268 std::vector<std::string> read_whitelist; 268 std::vector<BrokerFilePermission> permissions;
269 read_whitelist.push_back(kDriCard0Path); 269 permissions.push_back(BrokerFilePermission::ReadWrite(kDriCard0Path));
270 read_whitelist.push_back(kDriRcPath); 270 permissions.push_back(BrokerFilePermission::ReadOnly(kDriRcPath));
271 // Add eventual extra files from read_whitelist_extra.
272 read_whitelist.insert(read_whitelist.end(),
273 read_whitelist_extra.begin(),
274 read_whitelist_extra.end());
275 271
276 std::vector<std::string> write_whitelist; 272 // Add eventual extra files from permissions_extra.
277 write_whitelist.push_back(kDriCard0Path); 273 for (const auto& perm : permissions_extra) {
278 // Add eventual extra files from write_whitelist_extra. 274 permissions.push_back(perm);
279 write_whitelist.insert(write_whitelist.end(), 275 }
280 write_whitelist_extra.begin(),
281 write_whitelist_extra.end());
282 276
283 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), 277 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions);
284 read_whitelist,
285 write_whitelist);
286 // The initialization callback will perform generic initialization and then 278 // The initialization callback will perform generic initialization and then
287 // call broker_sandboxer_callback. 279 // call broker_sandboxer_callback.
288 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, 280 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox,
289 broker_sandboxer_allocator))); 281 broker_sandboxer_allocator)));
290 } 282 }
291 283
292 } // namespace content 284 } // namespace content
OLDNEW
« no previous file with comments | « content/common/sandbox_linux/bpf_gpu_policy_linux.h ('k') | sandbox/linux/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698