OLD | NEW |
---|---|
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 Loading... | |
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 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 Loading... | |
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 (IsAcceleratedVideoDecodeEnabled()) { |
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 file descriptor does not work. |
283 // Allow open() even though it severely weakens the sandbox, | |
284 // to test the sandboxing mechanism in general. | |
285 // TODO(jorgelo): remove this once we fix libva. | |
286 return playground2::Sandbox::SB_ALLOWED; | |
287 } else { | |
288 // Hook open() in the GPU process to allow opening /etc/drirc, | |
289 // needed by Mesa. | |
290 // The hook needs dup(), lseek(), and close() to be allowed. | |
291 return playground2::Sandbox::ErrorCode(GpuOpenSIGSYS_Handler, NULL); | |
292 } | |
277 default: | 293 default: |
278 if (IsGettimeSyscall(sysno) || | 294 if (IsGettimeSyscall(sysno) || |
279 IsKillSyscall(sysno)) { // GPU watchdog. | 295 IsKillSyscall(sysno)) { // GPU watchdog. |
280 return playground2::Sandbox::SB_ALLOWED; | 296 return playground2::Sandbox::SB_ALLOWED; |
281 } | 297 } |
282 // Generally, filename-based syscalls will fail with ENOENT to behave | 298 // Generally, filename-based syscalls will fail with ENOENT to behave |
283 // similarly to a possible future setuid sandbox. | 299 // similarly to a possible future setuid sandbox. |
284 if (IsFileSystemSyscall(sysno)) { | 300 if (IsFileSystemSyscall(sysno)) { |
285 return ENOENT; | 301 return ENOENT; |
286 } | 302 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 // TODO(jln) we should not have to do that in a trivial policy. | 399 // TODO(jln) we should not have to do that in a trivial policy. |
384 return ENOSYS; | 400 return ENOSYS; |
385 } else { | 401 } else { |
386 return playground2::Sandbox::SB_ALLOWED; | 402 return playground2::Sandbox::SB_ALLOWED; |
387 } | 403 } |
388 } | 404 } |
389 | 405 |
390 // Warms up/preloads resources needed by the policies. | 406 // Warms up/preloads resources needed by the policies. |
391 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) { | 407 void WarmupPolicy(playground2::Sandbox::EvaluateSyscall policy) { |
392 #if defined(__x86_64__) | 408 #if defined(__x86_64__) |
393 if (policy == GpuProcessPolicy_x86_64) | 409 if (policy == GpuProcessPolicy_x86_64) { |
394 OpenWithCache(kDriRcPath, O_RDONLY); | 410 OpenWithCache(kDriRcPath, O_RDONLY); |
411 // Accelerated video decode dlopen()'s this shared object | |
412 // inside the sandbox, so preload it now. | |
413 if (IsAcceleratedVideoDecodeEnabled()) { | |
414 const char kI965DrvVideoPath_64[] = | |
415 "/usr/lib64/va/drivers/i965_drv_video.so"; | |
piman
2012/07/26 01:09:52
What about i915 (Alex, etc.)?
piman
2012/07/26 01:13:05
Mmh, we're still whipping it as x86 for now, so ma
| |
416 dlopen(kI965DrvVideoPath_64, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); | |
417 } | |
418 } | |
395 #endif | 419 #endif |
396 } | 420 } |
397 | 421 |
398 // Is the sandbox fully disabled for this process? | 422 // Is the sandbox fully disabled for this process? |
399 bool ShouldDisableSandbox(const CommandLine& command_line, | 423 bool ShouldDisableSandbox(const CommandLine& command_line, |
400 const std::string& process_type) { | 424 const std::string& process_type) { |
401 if (command_line.HasSwitch(switches::kNoSandbox) || | 425 if (command_line.HasSwitch(switches::kNoSandbox) || |
402 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { | 426 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) { |
403 return true; | 427 return true; |
404 } | 428 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 | 550 |
527 namespace content { | 551 namespace content { |
528 | 552 |
529 void InitializeSandbox() { | 553 void InitializeSandbox() { |
530 #if defined(__i386__) || defined(__x86_64__) | 554 #if defined(__i386__) || defined(__x86_64__) |
531 InitializeSandbox_x86(); | 555 InitializeSandbox_x86(); |
532 #endif | 556 #endif |
533 } | 557 } |
534 | 558 |
535 } // namespace content | 559 } // namespace content |
OLD | NEW |