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" |
35 #include "sandbox/linux/system_headers/linux_syscalls.h" | 36 #include "sandbox/linux/system_headers/linux_syscalls.h" |
| 37 #include "ui/gl/gl_implementation.h" |
36 | 38 |
37 using sandbox::arch_seccomp_data; | 39 using sandbox::arch_seccomp_data; |
38 using sandbox::bpf_dsl::Allow; | 40 using sandbox::bpf_dsl::Allow; |
39 using sandbox::bpf_dsl::ResultExpr; | 41 using sandbox::bpf_dsl::ResultExpr; |
40 using sandbox::bpf_dsl::Trap; | 42 using sandbox::bpf_dsl::Trap; |
41 using sandbox::syscall_broker::BrokerFilePermission; | 43 using sandbox::syscall_broker::BrokerFilePermission; |
42 using sandbox::syscall_broker::BrokerProcess; | 44 using sandbox::syscall_broker::BrokerProcess; |
43 using sandbox::SyscallSets; | 45 using sandbox::SyscallSets; |
44 | 46 |
45 namespace content { | 47 namespace content { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 dlopen(I965HybridDrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 319 dlopen(I965HybridDrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
318 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 320 dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
319 #if defined(USE_OZONE) | 321 #if defined(USE_OZONE) |
320 dlopen("libva-drm.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 322 dlopen("libva-drm.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
321 #elif defined(USE_X11) | 323 #elif defined(USE_X11) |
322 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | 324 dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); |
323 #endif | 325 #endif |
324 } | 326 } |
325 } | 327 } |
326 | 328 |
| 329 // If kGpuSandboxStartEarly is set then we need to warmup by loading gl and |
| 330 // driver libraries before to actually run the sandbox. Another approach would |
| 331 // be to white list these libraries using the broker file permissons. But |
| 332 // that would require to white list all single dependencies which is not easy |
| 333 // and there is no much value compared to the following. |
| 334 const base::CommandLine& command_line = |
| 335 *base::CommandLine::ForCurrentProcess(); |
| 336 if (command_line.HasSwitch(switches::kGpuSandboxStartEarly)) { |
| 337 // uname is used from GpuControlList when calling |
| 338 // gpu::ApplyGpuDriverBugWorkarounds. |
| 339 base::SysInfo::OperatingSystemVersion(); |
| 340 |
| 341 gfx::GLImplementation gl_iml = gfx::kGLImplementationNone; |
| 342 bool fallback_to_osmesa = false; |
| 343 bool result = gfx::SelectGLImplementation(&gl_iml, &fallback_to_osmesa); |
| 344 if (!result) |
| 345 LOG(ERROR) << "Failed to select a gl implementation"; |
| 346 |
| 347 std::vector<std::string> driver_libraries; |
| 348 if (result) { |
| 349 result = gfx::GetNativeLibraryNamesFromGLImplementation( |
| 350 gl_iml, &driver_libraries); |
| 351 if (!result) |
| 352 LOG(ERROR) << "Failed to retrieve libraries for " |
| 353 << gfx::GetGLImplementationName(gl_iml); |
| 354 } |
| 355 |
| 356 #if defined(DRI_DRIVER_DIR) |
| 357 // Mesa always fallback to software driver in the 3 following cases: |
| 358 // 1- there is no real driver. |
| 359 // 2- it fails to load a real driver. |
| 360 // 3- User set the env var LIBGL_ALWAYS_SOFTWARE. |
| 361 if (result && command_line.HasSwitch(switches::kGpuDriverVendor) && |
| 362 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor) == |
| 363 "Mesa") { |
| 364 base::FilePath swrast_lib(DRI_DRIVER_DIR); |
| 365 swrast_lib = swrast_lib.Append("swrast_dri.so"); |
| 366 driver_libraries.push_back(swrast_lib.value()); |
| 367 } |
| 368 #endif |
| 369 |
| 370 for (const auto& lib_name : driver_libraries) { |
| 371 void* dl = |
| 372 dlopen(lib_name.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
| 373 if (!dl) |
| 374 LOG(ERROR) << "Failed to open " << lib_name << " with error " |
| 375 << dlerror(); |
| 376 } |
| 377 } |
| 378 |
327 return true; | 379 return true; |
328 } | 380 } |
329 | 381 |
330 void GpuProcessPolicy::InitGpuBrokerProcess( | 382 void GpuProcessPolicy::InitGpuBrokerProcess( |
331 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), | 383 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), |
332 const std::vector<BrokerFilePermission>& permissions_extra) { | 384 const std::vector<BrokerFilePermission>& permissions_extra) { |
333 static const char kDriRcPath[] = "/etc/drirc"; | 385 static const char kDriRcPath[] = "/etc/drirc"; |
334 static const char kDriCard0Path[] = "/dev/dri/card0"; | 386 static const char kDriCard0Path[] = "/dev/dri/card0"; |
335 static const char kDevShm[] = "/dev/shm/"; | 387 static const char kDevShm[] = "/dev/shm/"; |
336 | 388 |
(...skipping 22 matching lines...) Expand all Loading... |
359 } | 411 } |
360 | 412 |
361 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); | 413 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); |
362 // The initialization callback will perform generic initialization and then | 414 // The initialization callback will perform generic initialization and then |
363 // call broker_sandboxer_callback. | 415 // call broker_sandboxer_callback. |
364 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, | 416 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, |
365 broker_sandboxer_allocator))); | 417 broker_sandboxer_allocator))); |
366 } | 418 } |
367 | 419 |
368 } // namespace content | 420 } // namespace content |
OLD | NEW |