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

Side by Side Diff: content/common/sandbox_init_linux.cc

Issue 10824019: Tweak the GPU process sandbox to allow accelerated video decode. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix incorrect path for shared object. Created 8 years, 5 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
« no previous file with comments | « content/browser/gpu/gpu_process_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/public/common/sandbox_init.h" 5 #include "content/public/common/sandbox_init.h"
6 6
7 #if defined(__i386__) || defined(__x86_64__) 7 #if defined(__i386__) || defined(__x86_64__)
8 8
9 // This is an assert for GYP 9 // This is an assert for GYP
10 #if !defined(OS_LINUX) 10 #if !defined(OS_LINUX)
11 #error "Linux specific file compiled on non Linux OS!" 11 #error "Linux specific file compiled on non Linux OS!"
12 #endif 12 #endif
13 13
14 #include <asm/unistd.h> 14 #include <asm/unistd.h>
15 #include <dlfcn.h>
15 #include <errno.h> 16 #include <errno.h>
16 #include <fcntl.h> 17 #include <fcntl.h>
17 #include <linux/audit.h> 18 #include <linux/audit.h>
18 #include <linux/filter.h> 19 #include <linux/filter.h>
19 #include <signal.h> 20 #include <signal.h>
20 #include <string.h> 21 #include <string.h>
21 #include <sys/prctl.h> 22 #include <sys/prctl.h>
22 #include <sys/stat.h> 23 #include <sys/stat.h>
23 #include <sys/types.h> 24 #include <sys/types.h>
24 #include <ucontext.h> 25 #include <ucontext.h>
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 case __NR_lstat: 140 case __NR_lstat:
140 case __NR_chdir: 141 case __NR_chdir:
141 case __NR_mknod: 142 case __NR_mknod:
142 case __NR_mknodat: 143 case __NR_mknodat:
143 return true; 144 return true;
144 default: 145 default:
145 return false; 146 return false;
146 } 147 }
147 } 148 }
148 149
150 bool EnabledAcceleratedVideoDecode() {
jln (very slow on Chromium) 2012/07/25 23:47:56 Rename to AcceleratedVideoDecodeIsEnabled() to bet
Jorge Lucangeli Obes 2012/07/26 00:43:28 Done.
151 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
152 return command_line.HasSwitch(switches::kEnableAcceleratedVideoDecode);
153 }
154
149 static const char kDriRcPath[] = "/etc/drirc"; 155 static const char kDriRcPath[] = "/etc/drirc";
150 156
151 // TODO(jorgelo): limited to /etc/drirc for now, extend this to cover 157 // TODO(jorgelo): limited to /etc/drirc for now, extend this to cover
152 // other sandboxed file access cases. 158 // other sandboxed file access cases.
153 int OpenWithCache(const char* pathname, int flags) { 159 int OpenWithCache(const char* pathname, int flags) {
154 static int drircfd = -1; 160 static int drircfd = -1;
155 static bool do_open = true; 161 static bool do_open = true;
156 int res = -1; 162 int res = -1;
157 163
158 if (strcmp(pathname, kDriRcPath) == 0 && flags == O_RDONLY) { 164 if (strcmp(pathname, kDriRcPath) == 0 && flags == O_RDONLY) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 case __NR_getpid: // Nvidia binary driver. 269 case __NR_getpid: // Nvidia binary driver.
264 case __NR_getppid: // ATI binary driver. 270 case __NR_getppid: // ATI binary driver.
265 case __NR_shutdown: // Virtual driver. 271 case __NR_shutdown: // Virtual driver.
266 case __NR_rt_sigaction: // Breakpad signal handler. 272 case __NR_rt_sigaction: // Breakpad signal handler.
267 return playground2::Sandbox::SB_ALLOWED; 273 return playground2::Sandbox::SB_ALLOWED;
268 case __NR_socket: 274 case __NR_socket:
269 return EACCES; // Nvidia binary driver. 275 return EACCES; // Nvidia binary driver.
270 case __NR_fchmod: 276 case __NR_fchmod:
271 return EPERM; // ATI binary driver. 277 return EPERM; // ATI binary driver.
272 case __NR_open: 278 case __NR_open:
273 // Hook open() in the GPU process to allow opening /etc/drirc, 279 // Accelerated video decode is *not* enabled by default.
274 // needed by Mesa. 280 if (EnabledAcceleratedVideoDecode())
jln (very slow on Chromium) 2012/07/25 23:47:56 Style: please add braces around these multi lines
Jorge Lucangeli Obes 2012/07/26 00:43:28 Done.
275 // The hook needs dup(), lseek(), and close() to be allowed. 281 // Accelerated video decode needs to open /dev/dri/card0, and
276 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); 282 // dup()'ing an already open fd does not work.
jln (very slow on Chromium) 2012/07/25 23:47:56 Can you add a comment along the lines of: "This es
Jorge Lucangeli Obes 2012/07/26 00:43:28 Done.
283 return playground2::Sandbox::SB_ALLOWED;
284 else
285 // Hook open() in the GPU process to allow opening /etc/drirc,
286 // needed by Mesa.
287 // The hook needs dup(), lseek(), and close() to be allowed.
288 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL);
277 default: 289 default:
278 if (IsGettimeSyscall(sysno) || 290 if (IsGettimeSyscall(sysno) ||
279 IsKillSyscall(sysno)) { // GPU watchdog. 291 IsKillSyscall(sysno)) { // GPU watchdog.
280 return playground2::Sandbox::SB_ALLOWED; 292 return playground2::Sandbox::SB_ALLOWED;
281 } 293 }
282 // Generally, filename-based syscalls will fail with ENOENT to behave 294 // Generally, filename-based syscalls will fail with ENOENT to behave
283 // similarly to a possible future setuid sandbox. 295 // similarly to a possible future setuid sandbox.
284 if (IsFileSystemSyscall(sysno)) { 296 if (IsFileSystemSyscall(sysno)) {
285 return ENOENT; 297 return ENOENT;
286 } 298 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 playground2::Sandbox::ErrorCode AllowAllPolicy(int sysno) { 392 playground2::Sandbox::ErrorCode AllowAllPolicy(int sysno) {
381 if (sysno < static_cast<int>(MIN_SYSCALL) || 393 if (sysno < static_cast<int>(MIN_SYSCALL) ||
382 sysno > static_cast<int>(MAX_SYSCALL)) { 394 sysno > static_cast<int>(MAX_SYSCALL)) {
383 // TODO(jln) we should not have to do that in a trivial policy. 395 // TODO(jln) we should not have to do that in a trivial policy.
384 return ENOSYS; 396 return ENOSYS;
385 } else { 397 } else {
386 return playground2::Sandbox::SB_ALLOWED; 398 return playground2::Sandbox::SB_ALLOWED;
387 } 399 }
388 } 400 }
389 401
402 static const char kI965DrvVideoPath_64[] =
403 "/usr/lib64/va/drivers/i965_drv_video.so";
jln (very slow on Chromium) 2012/07/25 23:47:56 This should be scoped in the if with the dlopen be
Jorge Lucangeli Obes 2012/07/26 00:43:28 Unfortunately no. libva uses the full path when it
404
390 // Warms up/preloads resources needed by the policies. 405 // Warms up/preloads resources needed by the policies.
391 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) { 406 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) {
392 #if defined(__x86_64__) 407 #if defined(__x86_64__)
393 if (policy == GpuProcessPolicy_x86_64) 408 if (policy == GpuProcessPolicy_x86_64) {
394 OpenWithCache(kDriRcPath, O_RDONLY); 409 OpenWithCache(kDriRcPath, O_RDONLY);
410 // Accelerated video decode dlopen()'s this shared object
411 // inside the sandbox, so preload it now.
412 if (EnabledAcceleratedVideoDecode())
413 dlopen(kI965DrvVideoPath_64, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
414 }
395 #endif 415 #endif
396 } 416 }
397 417
398 // Is the sandbox fully disabled for this process? 418 // Is the sandbox fully disabled for this process?
399 bool ShouldDisableSandbox(const CommandLine& command_line, 419 bool ShouldDisableSandbox(const CommandLine& command_line,
400 const std::string& process_type) { 420 const std::string& process_type) {
401 if (command_line.HasSwitch(switches::kNoSandbox) || 421 if (command_line.HasSwitch(switches::kNoSandbox) ||
402 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { 422 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) {
403 return true; 423 return true;
404 } 424 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 546
527 namespace content { 547 namespace content {
528 548
529 void InitializeSandbox() { 549 void InitializeSandbox() {
530 #if defined(__i386__) || defined(__x86_64__) 550 #if defined(__i386__) || defined(__x86_64__)
531 InitializeSandbox_x86(); 551 InitializeSandbox_x86();
532 #endif 552 #endif
533 } 553 }
534 554
535 } // namespace content 555 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698