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

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

Powered by Google App Engine
This is Rietveld 408576698