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

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: review fixups 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
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_process.h" 32 #include "sandbox/linux/syscall_broker/broker_process.h"
Jorge Lucangeli Obes 2014/11/20 21:02:59 Do you need to include "broker_file_permission.h"
leecam 2014/11/20 21:46:19 Done.
33 33
34 using sandbox::syscall_broker::BrokerProcess;
35 using sandbox::SyscallSets;
36 using sandbox::arch_seccomp_data; 34 using sandbox::arch_seccomp_data;
37 using sandbox::bpf_dsl::Allow; 35 using sandbox::bpf_dsl::Allow;
38 using sandbox::bpf_dsl::ResultExpr; 36 using sandbox::bpf_dsl::ResultExpr;
39 using sandbox::bpf_dsl::Trap; 37 using sandbox::bpf_dsl::Trap;
38 using sandbox::syscall_broker::BrokerFilePermission;
39 using sandbox::syscall_broker::BrokerProcess;
40 using sandbox::SyscallSets;
40 41
41 namespace content { 42 namespace content {
42 43
43 namespace { 44 namespace {
44 45
45 inline bool IsChromeOS() { 46 inline bool IsChromeOS() {
46 #if defined(OS_CHROMEOS) 47 #if defined(OS_CHROMEOS)
47 return true; 48 return true;
48 #else 49 #else
49 return false; 50 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 225 // Warm up resources needed by the policy we're about to enable and
225 // eventually start a broker process. 226 // eventually start a broker process.
226 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); 227 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm();
227 // This policy is for x86 or Desktop. 228 // This policy is for x86 or Desktop.
228 DCHECK(!chromeos_arm_gpu); 229 DCHECK(!chromeos_arm_gpu);
229 230
230 DCHECK(!broker_process()); 231 DCHECK(!broker_process());
231 // Create a new broker process. 232 // Create a new broker process.
232 InitGpuBrokerProcess( 233 InitGpuBrokerProcess(
233 GpuBrokerProcessPolicy::Create, 234 GpuBrokerProcessPolicy::Create,
234 std::vector<std::string>(), // No extra files in whitelist. 235 std::vector<BrokerFilePermission>()); // No extra files in whitelist.
235 std::vector<std::string>());
236 236
237 if (IsArchitectureX86_64() || IsArchitectureI386()) { 237 if (IsArchitectureX86_64() || IsArchitectureI386()) {
238 // Accelerated video dlopen()'s some shared objects 238 // Accelerated video dlopen()'s some shared objects
239 // inside the sandbox, so preload them now. 239 // inside the sandbox, so preload them now.
240 if (IsAcceleratedVideoEnabled()) { 240 if (IsAcceleratedVideoEnabled()) {
241 const char* I965DrvVideoPath = NULL; 241 const char* I965DrvVideoPath = NULL;
242 242
243 if (IsArchitectureX86_64()) { 243 if (IsArchitectureX86_64()) {
244 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; 244 I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so";
245 } else if (IsArchitectureI386()) { 245 } else if (IsArchitectureI386()) {
246 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; 246 I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so";
247 } 247 }
248 248
249 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 249 dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
250 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 250 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
251 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); 251 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
252 } 252 }
253 } 253 }
254 254
255 return true; 255 return true;
256 } 256 }
257 257
258 void GpuProcessPolicy::InitGpuBrokerProcess( 258 void GpuProcessPolicy::InitGpuBrokerProcess(
259 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), 259 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void),
260 const std::vector<std::string>& read_whitelist_extra, 260 const std::vector<BrokerFilePermission>& permissions_extra) {
261 const std::vector<std::string>& write_whitelist_extra) {
262 static const char kDriRcPath[] = "/etc/drirc"; 261 static const char kDriRcPath[] = "/etc/drirc";
263 static const char kDriCard0Path[] = "/dev/dri/card0"; 262 static const char kDriCard0Path[] = "/dev/dri/card0";
264 263
265 CHECK(broker_process_ == NULL); 264 CHECK(broker_process_ == NULL);
266 265
267 // All GPU process policies need these files brokered out. 266 // All GPU process policies need these files brokered out.
268 std::vector<std::string> read_whitelist; 267 std::vector<BrokerFilePermission> permissions;
269 read_whitelist.push_back(kDriCard0Path); 268 permissions.push_back(BrokerFilePermission::ReadWrite(kDriCard0Path));
270 read_whitelist.push_back(kDriRcPath); 269 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 270
276 std::vector<std::string> write_whitelist; 271 // Add eventual extra files from permissions_extra.
277 write_whitelist.push_back(kDriCard0Path); 272 for (const auto& perm : permissions_extra) {
278 // Add eventual extra files from write_whitelist_extra. 273 permissions.push_back(perm);
279 write_whitelist.insert(write_whitelist.end(), 274 }
280 write_whitelist_extra.begin(),
281 write_whitelist_extra.end());
282 275
283 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), 276 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions);
284 read_whitelist,
285 write_whitelist);
286 // The initialization callback will perform generic initialization and then 277 // The initialization callback will perform generic initialization and then
287 // call broker_sandboxer_callback. 278 // call broker_sandboxer_callback.
288 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, 279 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox,
289 broker_sandboxer_allocator))); 280 broker_sandboxer_allocator)));
290 } 281 }
291 282
292 } // namespace content 283 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698