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

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: Addressed jln's comments. 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() {
151 // Accelerated video decode is currently enabled on Chrome OS,
152 // but not on Linux: crbug.com/137247.
153 bool is_enabled = IsChromeOS();
154
155 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
156 is_enabled = is_enabled &&
157 !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode);
158
159 return is_enabled;
160 }
161
149 static const char kDriRcPath[] = "/etc/drirc"; 162 static const char kDriRcPath[] = "/etc/drirc";
150 163
151 // TODO(jorgelo): limited to /etc/drirc for now, extend this to cover 164 // TODO(jorgelo): limited to /etc/drirc for now, extend this to cover
152 // other sandboxed file access cases. 165 // other sandboxed file access cases.
153 int OpenWithCache(const char* pathname, int flags) { 166 int OpenWithCache(const char* pathname, int flags) {
154 static int drircfd = -1; 167 static int drircfd = -1;
155 static bool do_open = true; 168 static bool do_open = true;
156 int res = -1; 169 int res = -1;
157 170
158 if (strcmp(pathname, kDriRcPath) == 0 && flags == O_RDONLY) { 171 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. 276 case __NR_getpid: // Nvidia binary driver.
264 case __NR_getppid: // ATI binary driver. 277 case __NR_getppid: // ATI binary driver.
265 case __NR_shutdown: // Virtual driver. 278 case __NR_shutdown: // Virtual driver.
266 case __NR_rt_sigaction: // Breakpad signal handler. 279 case __NR_rt_sigaction: // Breakpad signal handler.
267 return playground2::Sandbox::SB_ALLOWED; 280 return playground2::Sandbox::SB_ALLOWED;
268 case __NR_socket: 281 case __NR_socket:
269 return EACCES; // Nvidia binary driver. 282 return EACCES; // Nvidia binary driver.
270 case __NR_fchmod: 283 case __NR_fchmod:
271 return EPERM; // ATI binary driver. 284 return EPERM; // ATI binary driver.
272 case __NR_open: 285 case __NR_open:
273 // Hook open() in the GPU process to allow opening /etc/drirc, 286 // Accelerated video decode is enabled by default only on Chrome OS.
274 // needed by Mesa. 287 if (IsAcceleratedVideoDecodeEnabled()) {
275 // The hook needs dup(), lseek(), and close() to be allowed. 288 // Accelerated video decode needs to open /dev/dri/card0, and
276 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); 289 // dup()'ing an already open file descriptor does not work.
290 // Allow open() even though it severely weakens the sandbox,
291 // to test the sandboxing mechanism in general.
292 // TODO(jorgelo): remove this once we solve the libva issue.
293 return playground2::Sandbox::SB_ALLOWED;
294 } else {
295 // Hook open() in the GPU process to allow opening /etc/drirc,
296 // needed by Mesa.
297 // The hook needs dup(), lseek(), and close() to be allowed.
298 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL);
299 }
277 default: 300 default:
278 if (IsGettimeSyscall(sysno) || 301 if (IsGettimeSyscall(sysno) ||
279 IsKillSyscall(sysno)) { // GPU watchdog. 302 IsKillSyscall(sysno)) { // GPU watchdog.
280 return playground2::Sandbox::SB_ALLOWED; 303 return playground2::Sandbox::SB_ALLOWED;
281 } 304 }
282 // Generally, filename-based syscalls will fail with ENOENT to behave 305 // Generally, filename-based syscalls will fail with ENOENT to behave
283 // similarly to a possible future setuid sandbox. 306 // similarly to a possible future setuid sandbox.
284 if (IsFileSystemSyscall(sysno)) { 307 if (IsFileSystemSyscall(sysno)) {
285 return ENOENT; 308 return ENOENT;
286 } 309 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 case __NR_dup: // Flash Access. 357 case __NR_dup: // Flash Access.
335 // These are under investigation, and hopefully not here for the long term. 358 // These are under investigation, and hopefully not here for the long term.
336 case __NR_shmctl: 359 case __NR_shmctl:
337 case __NR_shmat: 360 case __NR_shmat:
338 case __NR_shmdt: 361 case __NR_shmdt:
339 return playground2::Sandbox::SB_ALLOWED; 362 return playground2::Sandbox::SB_ALLOWED;
340 case __NR_ioctl: 363 case __NR_ioctl:
341 return ENOTTY; // Flash Access. 364 return ENOTTY; // Flash Access.
342 case __NR_socket: 365 case __NR_socket:
343 return EACCES; 366 return EACCES;
344
345 default: 367 default:
346 if (IsGettimeSyscall(sysno) || 368 if (IsGettimeSyscall(sysno) ||
347 IsKillSyscall(sysno)) { 369 IsKillSyscall(sysno)) {
348 return playground2::Sandbox::SB_ALLOWED; 370 return playground2::Sandbox::SB_ALLOWED;
349 } 371 }
350 if (IsFileSystemSyscall(sysno)) { 372 if (IsFileSystemSyscall(sysno)) {
351 return ENOENT; 373 return ENOENT;
352 } 374 }
353 // In any other case crash the program with our SIGSYS handler. 375 // In any other case crash the program with our SIGSYS handler.
354 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL); 376 return playground2::Sandbox::ErrorCode(CrashSIGSYS_Handler, NULL);
(...skipping 28 matching lines...) Expand all
383 // TODO(jln) we should not have to do that in a trivial policy. 405 // TODO(jln) we should not have to do that in a trivial policy.
384 return ENOSYS; 406 return ENOSYS;
385 } else { 407 } else {
386 return playground2::Sandbox::SB_ALLOWED; 408 return playground2::Sandbox::SB_ALLOWED;
387 } 409 }
388 } 410 }
389 411
390 // Warms up/preloads resources needed by the policies. 412 // Warms up/preloads resources needed by the policies.
391 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) { 413 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) {
392 #if defined(__x86_64__) 414 #if defined(__x86_64__)
393 if (policy == GpuProcessPolicy_x86_64) 415 if (policy == GpuProcessPolicy_x86_64) {
394 OpenWithCache(kDriRcPath, O_RDONLY); 416 OpenWithCache(kDriRcPath, O_RDONLY);
417 // Accelerated video decode dlopen()'s this shared object
418 // inside the sandbox, so preload it now.
419 // TODO(jorgelo): generalize this to other platforms.
420 if (IsAcceleratedVideoDecodeEnabled()) {
421 const char kI965DrvVideoPath_64[] =
422 "/usr/lib64/va/drivers/i965_drv_video.so";
423 dlopen(kI965DrvVideoPath_64, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE);
424 }
425 }
395 #endif 426 #endif
396 } 427 }
397 428
398 // Is the sandbox fully disabled for this process? 429 // Is the sandbox fully disabled for this process?
399 bool ShouldDisableSandbox(const CommandLine& command_line, 430 bool ShouldDisableSandbox(const CommandLine& command_line,
400 const std::string& process_type) { 431 const std::string& process_type) {
401 if (command_line.HasSwitch(switches::kNoSandbox) || 432 if (command_line.HasSwitch(switches::kNoSandbox) ||
402 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { 433 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) {
403 return true; 434 return true;
404 } 435 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 557
527 namespace content { 558 namespace content {
528 559
529 void InitializeSandbox() { 560 void InitializeSandbox() {
530 #if defined(__i386__) || defined(__x86_64__) 561 #if defined(__i386__) || defined(__x86_64__)
531 InitializeSandbox_x86(); 562 InitializeSandbox_x86();
532 #endif 563 #endif
533 } 564 }
534 565
535 } // namespace content 566 } // 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