Chromium Code Reviews| 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 <memory> | 15 #include <memory> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/bind.h" | 19 #include "base/bind.h" |
| 20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
| 22 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/macros.h" | 23 #include "base/macros.h" |
| 24 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
| 25 #include "base/sys_info.h" | |
| 25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 26 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 27 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
| 27 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 28 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
| 28 #include "content/common/set_process_title.h" | 29 #include "content/common/set_process_title.h" |
| 29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 30 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 31 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
| 31 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" | 32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
| 32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 33 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
| 33 #include "sandbox/linux/syscall_broker/broker_file_permission.h" | 34 #include "sandbox/linux/syscall_broker/broker_file_permission.h" |
| 34 #include "sandbox/linux/syscall_broker/broker_process.h" | 35 #include "sandbox/linux/syscall_broker/broker_process.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 #endif | 105 #endif |
| 105 return accelerated_encode_enabled; | 106 return accelerated_encode_enabled; |
| 106 } | 107 } |
| 107 | 108 |
| 108 bool IsAcceleratedVideoDecodeEnabled() { | 109 bool IsAcceleratedVideoDecodeEnabled() { |
| 109 const base::CommandLine& command_line = | 110 const base::CommandLine& command_line = |
| 110 *base::CommandLine::ForCurrentProcess(); | 111 *base::CommandLine::ForCurrentProcess(); |
| 111 return !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode); | 112 return !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode); |
| 112 } | 113 } |
| 113 | 114 |
| 115 bool IsLLVMPipeDriver() { | |
| 116 // The only white-listed Mesa driver that starts threads is the llvmpipe | |
| 117 // driver. So only this driver will set kGpuSandboxStartEarly. | |
| 118 const base::CommandLine& command_line = | |
| 119 *base::CommandLine::ForCurrentProcess(); | |
| 120 return command_line.HasSwitch(switches::kGpuSandboxStartEarly) && | |
| 121 command_line.HasSwitch(switches::kGpuDriverVendor) && | |
| 122 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor) == "Mesa"; | |
| 123 } | |
| 124 | |
| 114 intptr_t GpuSIGSYS_Handler(const struct arch_seccomp_data& args, | 125 intptr_t GpuSIGSYS_Handler(const struct arch_seccomp_data& args, |
| 115 void* aux_broker_process) { | 126 void* aux_broker_process) { |
| 116 RAW_CHECK(aux_broker_process); | 127 RAW_CHECK(aux_broker_process); |
| 117 BrokerProcess* broker_process = | 128 BrokerProcess* broker_process = |
| 118 static_cast<BrokerProcess*>(aux_broker_process); | 129 static_cast<BrokerProcess*>(aux_broker_process); |
| 119 switch (args.nr) { | 130 switch (args.nr) { |
| 120 #if !defined(__aarch64__) | 131 #if !defined(__aarch64__) |
| 121 case __NR_access: | 132 case __NR_access: |
| 122 return broker_process->Access(reinterpret_cast<const char*>(args.args[0]), | 133 return broker_process->Access(reinterpret_cast<const char*>(args.args[0]), |
| 123 static_cast<int>(args.args[1])); | 134 static_cast<int>(args.args[1])); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 dlopen(I965HybridDrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 328 dlopen(I965HybridDrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 318 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 329 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 319 #if defined(USE_OZONE) | 330 #if defined(USE_OZONE) |
| 320 dlopen("libva-drm.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 331 dlopen("libva-drm.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 321 #elif defined(USE_X11) | 332 #elif defined(USE_X11) |
| 322 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 333 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 323 #endif | 334 #endif |
| 324 } | 335 } |
| 325 } | 336 } |
| 326 | 337 |
| 338 if (IsLLVMPipeDriver()) { | |
| 339 // uname is used from GpuControlList when calling | |
| 340 // gpu::ApplyGpuDriverBugWorkarounds. | |
| 341 base::SysInfo::OperatingSystemVersion(); | |
| 342 | |
| 343 std::vector<std::string> driver_libraries; | |
| 344 | |
| 345 // TODO(j.isorce): crbug.com/264818 refactor ui/gl/gl_implementation.cc to | |
| 346 // return a list of libs to load depending on the gl implementation that is | |
| 347 // going to be used. | |
| 348 driver_libraries.push_back("libGL.so"); | |
| 349 driver_libraries.push_back("libGLESv2.so.2"); | |
| 350 driver_libraries.push_back("libEGL.so.1"); | |
| 351 | |
| 352 // FIXME(j.isorce): During gyp/gn step parse "dridriverdir" variable from | |
|
Ken Russell (switch to Gerrit)
2016/05/05 21:38:03
FIXME -> TODO
| |
| 353 // pkgconfig/dri.pc to get the path to dri directory | |
| 354 // dri.pc comes from mesa-common-dev package. | |
| 355 // example: dridriverdir=/usr/lib/x86_64-linux-gnu/dri | |
| 356 // example: dridriverdir=/usr/local/lib/dri | |
| 357 // driver_libraries.push_back($dridriverdir"/swrast_dri.so"); | |
| 358 // because dri is never in ld.so.conf and relative path only work from | |
| 359 // executable dir (i.e. chrome). | |
| 360 driver_libraries.push_back("/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so"); | |
| 361 | |
| 362 for (size_t i = 0; i < driver_libraries.size(); ++i) { | |
| 363 dlopen(driver_libraries[i].c_str(), | |
| 364 RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); | |
| 365 } | |
| 366 } | |
| 367 | |
| 327 return true; | 368 return true; |
| 328 } | 369 } |
| 329 | 370 |
| 330 void GpuProcessPolicy::InitGpuBrokerProcess( | 371 void GpuProcessPolicy::InitGpuBrokerProcess( |
| 331 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), | 372 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), |
| 332 const std::vector<BrokerFilePermission>& permissions_extra) { | 373 const std::vector<BrokerFilePermission>& permissions_extra) { |
| 333 static const char kDriRcPath[] = "/etc/drirc"; | 374 static const char kDriRcPath[] = "/etc/drirc"; |
| 334 static const char kDriCard0Path[] = "/dev/dri/card0"; | 375 static const char kDriCard0Path[] = "/dev/dri/card0"; |
| 335 static const char kDevShm[] = "/dev/shm/"; | 376 static const char kDevShm[] = "/dev/shm/"; |
| 336 | 377 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 359 } | 400 } |
| 360 | 401 |
| 361 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); | 402 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); |
| 362 // The initialization callback will perform generic initialization and then | 403 // The initialization callback will perform generic initialization and then |
| 363 // call broker_sandboxer_callback. | 404 // call broker_sandboxer_callback. |
| 364 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, | 405 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
| 365 broker_sandboxer_allocator))); | 406 broker_sandboxer_allocator))); |
| 366 } | 407 } |
| 367 | 408 |
| 368 } // namespace content | 409 } // namespace content |
| OLD | NEW |