| 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 "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 26 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
| 27 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 27 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
| 28 #include "content/common/set_process_title.h" | 28 #include "content/common/set_process_title.h" |
| 29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 30 #include "media/gpu/v4l2_device.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" |
| 35 #include "sandbox/linux/system_headers/linux_syscalls.h" | 36 #include "sandbox/linux/system_headers/linux_syscalls.h" |
| 36 | 37 |
| 37 using sandbox::arch_seccomp_data; | 38 using sandbox::arch_seccomp_data; |
| 38 using sandbox::bpf_dsl::Allow; | 39 using sandbox::bpf_dsl::Allow; |
| 39 using sandbox::bpf_dsl::ResultExpr; | 40 using sandbox::bpf_dsl::ResultExpr; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 80 } |
| 80 | 81 |
| 81 inline bool IsOzone() { | 82 inline bool IsOzone() { |
| 82 #if defined(USE_OZONE) | 83 #if defined(USE_OZONE) |
| 83 return true; | 84 return true; |
| 84 #else | 85 #else |
| 85 return false; | 86 return false; |
| 86 #endif | 87 #endif |
| 87 } | 88 } |
| 88 | 89 |
| 89 inline bool UseLibV4L2() { | |
| 90 #if defined(USE_LIBV4L2) | |
| 91 return true; | |
| 92 #else | |
| 93 return false; | |
| 94 #endif | |
| 95 } | |
| 96 | |
| 97 bool IsAcceleratedVaapiVideoEncodeEnabled() { | 90 bool IsAcceleratedVaapiVideoEncodeEnabled() { |
| 98 bool accelerated_encode_enabled = false; | 91 bool accelerated_encode_enabled = false; |
| 99 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
| 100 const base::CommandLine& command_line = | 93 const base::CommandLine& command_line = |
| 101 *base::CommandLine::ForCurrentProcess(); | 94 *base::CommandLine::ForCurrentProcess(); |
| 102 accelerated_encode_enabled = | 95 accelerated_encode_enabled = |
| 103 !command_line.HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode); | 96 !command_line.HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode); |
| 104 #endif | 97 #endif |
| 105 return accelerated_encode_enabled; | 98 return accelerated_encode_enabled; |
| 106 } | 99 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 331 |
| 339 // All GPU process policies need these files brokered out. | 332 // All GPU process policies need these files brokered out. |
| 340 std::vector<BrokerFilePermission> permissions; | 333 std::vector<BrokerFilePermission> permissions; |
| 341 permissions.push_back(BrokerFilePermission::ReadWrite(kDriCard0Path)); | 334 permissions.push_back(BrokerFilePermission::ReadWrite(kDriCard0Path)); |
| 342 permissions.push_back(BrokerFilePermission::ReadOnly(kDriRcPath)); | 335 permissions.push_back(BrokerFilePermission::ReadOnly(kDriRcPath)); |
| 343 if (!IsChromeOS()) { | 336 if (!IsChromeOS()) { |
| 344 permissions.push_back( | 337 permissions.push_back( |
| 345 BrokerFilePermission::ReadWriteCreateUnlinkRecursive(kDevShm)); | 338 BrokerFilePermission::ReadWriteCreateUnlinkRecursive(kDevShm)); |
| 346 } else if (IsArchitectureArm() || IsOzone()){ | 339 } else if (IsArchitectureArm() || IsOzone()){ |
| 347 AddV4L2GpuWhitelist(&permissions); | 340 AddV4L2GpuWhitelist(&permissions); |
| 348 if (UseLibV4L2()) { | 341 if (media::V4L2Device::IsUsingLibV4L2()) { |
| 349 dlopen("/usr/lib/libv4l2.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 342 dlopen("/usr/lib/libv4l2.so", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 350 // This is a device-specific encoder plugin. | 343 // This is a device-specific encoder plugin. |
| 351 dlopen("/usr/lib/libv4l/plugins/libv4l-encplugin.so", | 344 dlopen("/usr/lib/libv4l/plugins/libv4l-encplugin.so", |
| 352 RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 345 RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
| 353 } | 346 } |
| 354 } | 347 } |
| 355 | 348 |
| 356 // Add eventual extra files from permissions_extra. | 349 // Add eventual extra files from permissions_extra. |
| 357 for (const auto& perm : permissions_extra) { | 350 for (const auto& perm : permissions_extra) { |
| 358 permissions.push_back(perm); | 351 permissions.push_back(perm); |
| 359 } | 352 } |
| 360 | 353 |
| 361 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); | 354 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); |
| 362 // The initialization callback will perform generic initialization and then | 355 // The initialization callback will perform generic initialization and then |
| 363 // call broker_sandboxer_callback. | 356 // call broker_sandboxer_callback. |
| 364 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, | 357 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
| 365 broker_sandboxer_allocator))); | 358 broker_sandboxer_allocator))); |
| 366 } | 359 } |
| 367 | 360 |
| 368 } // namespace content | 361 } // namespace content |
| OLD | NEW |