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

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: Rebased over VA decode flag change. Created 8 years, 4 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 IsAcceleratedVideoDecodeEnabled() {
jln (very slow on Chromium) 2012/07/26 17:53:54 Any chance that gpu/ could export a function like
Jorge Lucangeli Obes 2012/07/26 18:33:36 The code does not live in gpu/, it lives in conten
jln (very slow on Chromium) 2012/07/26 19:06:39 Ok, we don't want to start refactoring code just f
151 // Accelerated video decode is currently enabled on Chrome OS,
152 // but not on Linux: crbug.com/137247.
153 bool is_enabled = false;
154 #if defined(OS_CHROMEOS)
jln (very slow on Chromium) 2012/07/26 17:53:54 Please use IsChromeOS().
Jorge Lucangeli Obes 2012/07/26 18:33:36 Done.
piman 2012/07/26 20:33:52 FYI, IsChromeOS is different from #ifdef OS_CHROME
155 is_enabled = true;
156 #endif
157
158 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
159 is_enabled &= !command_line.HasSwitch(
jln (very slow on Chromium) 2012/07/26 17:53:54 please, use && here so that we benefit from lazy e
Jorge Lucangeli Obes 2012/07/26 18:33:36 Done.
160 switches::kDisableAcceleratedVideoDecode);
161
162 return is_enabled;
163 }
164
149 static const char kDriRcPath[] = "/etc/drirc"; 165 static const char kDriRcPath[] = "/etc/drirc";
150 166
151 // TODO(jorgelo): limited to /etc/drirc for now, extend this to cover 167 // TODO(jorgelo): limited to /etc/drirc for now, extend this to cover
152 // other sandboxed file access cases. 168 // other sandboxed file access cases.
153 int OpenWithCache(const char* pathname, int flags) { 169 int OpenWithCache(const char* pathname, int flags) {
154 static int drircfd = -1; 170 static int drircfd = -1;
155 static bool do_open = true; 171 static bool do_open = true;
156 int res = -1; 172 int res = -1;
157 173
158 if (strcmp(pathname, kDriRcPath) == 0 && flags == O_RDONLY) { 174 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. 279 case __NR_getpid: // Nvidia binary driver.
264 case __NR_getppid: // ATI binary driver. 280 case __NR_getppid: // ATI binary driver.
265 case __NR_shutdown: // Virtual driver. 281 case __NR_shutdown: // Virtual driver.
266 case __NR_rt_sigaction: // Breakpad signal handler. 282 case __NR_rt_sigaction: // Breakpad signal handler.
267 return playground2::Sandbox::SB_ALLOWED; 283 return playground2::Sandbox::SB_ALLOWED;
268 case __NR_socket: 284 case __NR_socket:
269 return EACCES; // Nvidia binary driver. 285 return EACCES; // Nvidia binary driver.
270 case __NR_fchmod: 286 case __NR_fchmod:
271 return EPERM; // ATI binary driver. 287 return EPERM; // ATI binary driver.
272 case __NR_open: 288 case __NR_open:
273 // Hook open() in the GPU process to allow opening /etc/drirc, 289 // Accelerated video decode is enabled by default only on Chrome OS.
274 // needed by Mesa. 290 if (IsAcceleratedVideoDecodeEnabled()) {
275 // The hook needs dup(), lseek(), and close() to be allowed. 291 // Accelerated video decode needs to open /dev/dri/card0, and
276 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); 292 // dup()'ing an already open file descriptor does not work.
293 // Allow open() even though it severely weakens the sandbox,
294 // to test the sandboxing mechanism in general.
295 // TODO(jorgelo): remove this once we solve the libva issue.
296 return playground2::Sandbox::SB_ALLOWED;
297 } else {
298 // Hook open() in the GPU process to allow opening /etc/drirc,
299 // needed by Mesa.
300 // The hook needs dup(), lseek(), and close() to be allowed.
301 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL);
302 }
277 default: 303 default:
278 if (IsGettimeSyscall(sysno) || 304 if (IsGettimeSyscall(sysno) ||
279 IsKillSyscall(sysno)) { // GPU watchdog. 305 IsKillSyscall(sysno)) { // GPU watchdog.
280 return playground2::Sandbox::SB_ALLOWED; 306 return playground2::Sandbox::SB_ALLOWED;
281 } 307 }
282 // Generally, filename-based syscalls will fail with ENOENT to behave 308 // Generally, filename-based syscalls will fail with ENOENT to behave
283 // similarly to a possible future setuid sandbox. 309 // similarly to a possible future setuid sandbox.
284 if (IsFileSystemSyscall(sysno)) { 310 if (IsFileSystemSyscall(sysno)) {
285 return ENOENT; 311 return ENOENT;
286 } 312 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // TODO(jln) we should not have to do that in a trivial policy. 409 // TODO(jln) we should not have to do that in a trivial policy.
384 return ENOSYS; 410 return ENOSYS;
385 } else { 411 } else {
386 return playground2::Sandbox::SB_ALLOWED; 412 return playground2::Sandbox::SB_ALLOWED;
387 } 413 }
388 } 414 }
389 415
390 // Warms up/preloads resources needed by the policies. 416 // Warms up/preloads resources needed by the policies.
391 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) { 417 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) {
392 #if defined(__x86_64__) 418 #if defined(__x86_64__)
393 if (policy == GpuProcessPolicy_x86_64) 419 if (policy == GpuProcessPolicy_x86_64) {
394 OpenWithCache(kDriRcPath, O_RDONLY); 420 OpenWithCache(kDriRcPath, O_RDONLY);
421 // Accelerated video decode dlopen()'s this shared object
422 // inside the sandbox, so preload it now.
423 // TODO(jorgelo): generalize this to other platforms.
424 if (IsAcceleratedVideoDecodeEnabled()) {
425 const char kI965DrvVideoPath_64[] =
426 "/usr/lib64/va/drivers/i965_drv_video.so";
427 dlopen(kI965DrvVideoPath_64, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
428 }
429 }
395 #endif 430 #endif
396 } 431 }
397 432
398 // Is the sandbox fully disabled for this process? 433 // Is the sandbox fully disabled for this process?
399 bool ShouldDisableSandbox(const CommandLine& command_line, 434 bool ShouldDisableSandbox(const CommandLine& command_line,
400 const std::string& process_type) { 435 const std::string& process_type) {
401 if (command_line.HasSwitch(switches::kNoSandbox) || 436 if (command_line.HasSwitch(switches::kNoSandbox) ||
402 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { 437 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) {
403 return true; 438 return true;
404 } 439 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 561
527 namespace content { 562 namespace content {
528 563
529 void InitializeSandbox() { 564 void InitializeSandbox() {
530 #if defined(__i386__) || defined(__x86_64__) 565 #if defined(__i386__) || defined(__x86_64__)
531 InitializeSandbox_x86(); 566 InitializeSandbox_x86();
532 #endif 567 #endif
533 } 568 }
534 569
535 } // namespace content 570 } // 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