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

Side by Side Diff: content/common/sandbox_linux/bpf_gpu_policy_linux.cc

Issue 1542013005: Add a new driver bug workaround SANDBOX_START_EARLY Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and remove gyp support Created 4 years, 2 months 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 10 matching lines...) Expand all
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/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" 27 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h"
28 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" 28 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h"
29 #include "content/common/set_process_title.h" 29 #include "content/common/set_process_title.h"
30 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
31 #include "gpu/config/gpu_switches.h"
32 #include "gpu/ipc/service/switches.h"
31 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 33 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
32 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" 34 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
33 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" 35 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
34 #include "sandbox/linux/syscall_broker/broker_file_permission.h" 36 #include "sandbox/linux/syscall_broker/broker_file_permission.h"
35 #include "sandbox/linux/syscall_broker/broker_process.h" 37 #include "sandbox/linux/syscall_broker/broker_process.h"
36 #include "sandbox/linux/system_headers/linux_syscalls.h" 38 #include "sandbox/linux/system_headers/linux_syscalls.h"
39 #include "ui/gl/init/gl_factory.h"
37 40
38 using sandbox::arch_seccomp_data; 41 using sandbox::arch_seccomp_data;
39 using sandbox::bpf_dsl::Allow; 42 using sandbox::bpf_dsl::Allow;
40 using sandbox::bpf_dsl::ResultExpr; 43 using sandbox::bpf_dsl::ResultExpr;
41 using sandbox::bpf_dsl::Trap; 44 using sandbox::bpf_dsl::Trap;
42 using sandbox::syscall_broker::BrokerFilePermission; 45 using sandbox::syscall_broker::BrokerFilePermission;
43 using sandbox::syscall_broker::BrokerProcess; 46 using sandbox::syscall_broker::BrokerProcess;
44 using sandbox::SyscallSets; 47 using sandbox::SyscallSets;
45 48
46 namespace content { 49 namespace content {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 dlopen(I965HybridDrvVideoPath, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); 318 dlopen(I965HybridDrvVideoPath, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
316 dlopen("libva.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); 319 dlopen("libva.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
317 #if defined(USE_OZONE) 320 #if defined(USE_OZONE)
318 dlopen("libva-drm.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); 321 dlopen("libva-drm.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
319 #elif defined(USE_X11) 322 #elif defined(USE_X11)
320 dlopen("libva-x11.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); 323 dlopen("libva-x11.so.1", RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
321 #endif 324 #endif
322 } 325 }
323 } 326 }
324 327
328 // If kGpuSandboxStartEarly is set then we need to warmup by loading gl and
329 // driver libraries before to actually run the sandbox. Another approach would
330 // be to white list these libraries using the broker file permissons. But
331 // that would require to white list all single dependencies which is not easy
332 // and there is no much value compared to the following.
333 const base::CommandLine& command_line =
334 *base::CommandLine::ForCurrentProcess();
335 if (command_line.HasSwitch(switches::kGpuSandboxStartEarly)) {
336 gl::GLImplementation gl_iml = gl::kGLImplementationNone;
337 std::vector<gl::GLImplementation> allowed_impls =
338 gl::init::GetAllowedGLImplementations();
339 bool fallback_to_osmesa = false;
340 bool result =
341 gl::SelectGLImplementation(allowed_impls, &gl_iml, &fallback_to_osmesa);
342 if (!result)
343 LOG(ERROR) << "Failed to select a gl implementation";
344
345 std::vector<std::string> driver_libraries;
346 if (result) {
347 result = gl::init::GetNativeLibraryNamesFromGLImplementation(
348 gl_iml, &driver_libraries);
349 if (!result) {
350 LOG(ERROR) << "Failed to retrieve libraries for "
351 << gl::GetGLImplementationName(gl_iml);
352 }
353 }
354
355 #if defined(DRI_DRIVER_DIR)
356 // Mesa always fallback to software driver in the 3 following cases:
357 // 1- there is no real driver.
358 // 2- it fails to load a real driver.
359 // 3- User set the env var LIBGL_ALWAYS_SOFTWARE.
360 if (result && command_line.HasSwitch(switches::kGpuDriverVendor) &&
361 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor) ==
362 "Mesa") {
363 base::FilePath swrast_lib(DRI_DRIVER_DIR);
364 swrast_lib = swrast_lib.Append("swrast_dri.so");
365 driver_libraries.push_back(swrast_lib.value());
366 }
367 #endif
368
369 for (const auto& lib_name : driver_libraries) {
370 void* dl =
371 dlopen(lib_name.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
372 if (!dl) {
373 LOG(ERROR) << "Failed to open " << lib_name << " with error "
374 << dlerror();
375 }
376 }
377 }
378
325 return true; 379 return true;
326 } 380 }
327 381
328 void GpuProcessPolicy::InitGpuBrokerProcess( 382 void GpuProcessPolicy::InitGpuBrokerProcess(
329 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void), 383 sandbox::bpf_dsl::Policy* (*broker_sandboxer_allocator)(void),
330 const std::vector<BrokerFilePermission>& permissions_extra) { 384 const std::vector<BrokerFilePermission>& permissions_extra) {
331 static const char kDriRcPath[] = "/etc/drirc"; 385 static const char kDriRcPath[] = "/etc/drirc";
332 static const char kDriCard0Path[] = "/dev/dri/card0"; 386 static const char kDriCard0Path[] = "/dev/dri/card0";
333 static const char kDriCardBasePath[] = "/dev/dri/card"; 387 static const char kDriCardBasePath[] = "/dev/dri/card";
334 388
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 431 }
378 432
379 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions); 433 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), permissions);
380 // The initialization callback will perform generic initialization and then 434 // The initialization callback will perform generic initialization and then
381 // call broker_sandboxer_callback. 435 // call broker_sandboxer_callback.
382 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, 436 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox,
383 broker_sandboxer_allocator))); 437 broker_sandboxer_allocator)));
384 } 438 }
385 439
386 } // namespace content 440 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698