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(OS_LINUX) && defined(__x86_64__) | 7 #if defined(OS_LINUX) && defined(__x86_64__) |
8 | 8 |
9 #include <asm/unistd.h> | 9 #include <asm/unistd.h> |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <linux/audit.h> | 11 #include <linux/audit.h> |
12 #include <linux/filter.h> | 12 #include <linux/filter.h> |
13 #include <signal.h> | 13 #include <signal.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <sys/prctl.h> | 15 #include <sys/prctl.h> |
16 #include <ucontext.h> | 16 #include <ucontext.h> |
17 #include <unistd.h> | 17 #include <unistd.h> |
18 | 18 |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/file_util.h" | 22 #include "base/file_util.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "content/gpu/gpu_info_collector.h" | |
Chris Evans
2012/06/07 23:11:34
I'm not 100% sure, but isn't it considered a layer
Jorge Lucangeli Obes
2012/06/08 00:15:24
GPU info logic moved to gpu_main.cc, but cmdline f
| |
25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
26 | 27 |
27 #ifndef PR_SET_NO_NEW_PRIVS | 28 #ifndef PR_SET_NO_NEW_PRIVS |
28 #define PR_SET_NO_NEW_PRIVS 38 | 29 #define PR_SET_NO_NEW_PRIVS 38 |
29 #endif | 30 #endif |
30 | 31 |
31 #ifndef SYS_SECCOMP | 32 #ifndef SYS_SECCOMP |
32 #define SYS_SECCOMP 1 | 33 #define SYS_SECCOMP 1 |
33 #endif | 34 #endif |
34 | 35 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 PLOG_IF(FATAL, ret != 0) << "prctl(PR_SET_NO_NEW_PRIVS) failed"; | 382 PLOG_IF(FATAL, ret != 0) << "prctl(PR_SET_NO_NEW_PRIVS) failed"; |
382 | 383 |
383 struct sock_fprog fprog; | 384 struct sock_fprog fprog; |
384 fprog.len = program.size(); | 385 fprog.len = program.size(); |
385 fprog.filter = const_cast<struct sock_filter*>(&program[0]); | 386 fprog.filter = const_cast<struct sock_filter*>(&program[0]); |
386 | 387 |
387 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &fprog, 0, 0); | 388 ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &fprog, 0, 0); |
388 PLOG_IF(FATAL, ret != 0) << "Failed to install filter."; | 389 PLOG_IF(FATAL, ret != 0) << "Failed to install filter."; |
389 } | 390 } |
390 | 391 |
392 static bool ShouldEnableGPUSandbox() { | |
393 #if defined(OS_CHROMEOS) | |
394 content::GPUInfo gpu_info; | |
395 | |
396 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info)) | |
397 return false; | |
398 | |
399 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
400 | |
401 return command_line.HasSwitch(switches::kEnableChromeOSGPUSandbox) && | |
402 gpu_info.gpu.vendor_id == 0x8086; // Intel GPU | |
403 #else | |
404 return true; | |
405 #endif | |
406 } | |
407 | |
391 } // anonymous namespace | 408 } // anonymous namespace |
392 | 409 |
393 namespace content { | 410 namespace content { |
394 | 411 |
395 void InitializeSandbox() { | 412 void InitializeSandbox() { |
396 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 413 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
397 if (command_line.HasSwitch(switches::kNoSandbox) || | 414 if (command_line.HasSwitch(switches::kNoSandbox) || |
398 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) | 415 command_line.HasSwitch(switches::kDisableSeccompFilterSandbox)) |
399 return; | 416 return; |
400 | 417 |
401 std::string process_type = | 418 std::string process_type = |
402 command_line.GetSwitchValueASCII(switches::kProcessType); | 419 command_line.GetSwitchValueASCII(switches::kProcessType); |
403 if (process_type == switches::kGpuProcess && | 420 if (process_type == switches::kGpuProcess && |
404 command_line.HasSwitch(switches::kDisableGpuSandbox)) | 421 command_line.HasSwitch(switches::kDisableGpuSandbox)) |
405 return; | 422 return; |
406 | 423 |
407 if (!CanUseSeccompFilters()) | 424 if (!CanUseSeccompFilters()) |
408 return; | 425 return; |
409 | 426 |
410 CheckSingleThreaded(); | 427 CheckSingleThreaded(); |
411 | 428 |
412 std::vector<struct sock_filter> program; | 429 std::vector<struct sock_filter> program; |
413 EmitPreamble(&program); | 430 EmitPreamble(&program); |
414 | 431 |
415 if (process_type == switches::kGpuProcess) { | 432 if (process_type == switches::kGpuProcess && |
433 ShouldEnableGPUSandbox()) { | |
416 ApplyGPUPolicy(&program); | 434 ApplyGPUPolicy(&program); |
417 EmitTrap(&program); // Default deny. | 435 EmitTrap(&program); // Default deny. |
418 } else if (process_type == switches::kPpapiPluginProcess) { | 436 } else if (process_type == switches::kPpapiPluginProcess) { |
419 ApplyFlashPolicy(&program); | 437 ApplyFlashPolicy(&program); |
420 EmitTrap(&program); // Default deny. | 438 EmitTrap(&program); // Default deny. |
421 } else if (process_type == switches::kRendererProcess || | 439 } else if (process_type == switches::kRendererProcess || |
422 process_type == switches::kWorkerProcess) { | 440 process_type == switches::kWorkerProcess) { |
423 ApplyNoPtracePolicy(&program); | 441 ApplyNoPtracePolicy(&program); |
424 EmitAllow(&program); // Default permit. | 442 EmitAllow(&program); // Default permit. |
425 } else { | 443 } else { |
426 NOTREACHED(); | 444 NOTREACHED(); |
427 } | 445 } |
428 | 446 |
429 InstallSIGSYSHandler(); | 447 InstallSIGSYSHandler(); |
430 InstallFilter(program); | 448 InstallFilter(program); |
431 } | 449 } |
432 | 450 |
433 } // namespace content | 451 } // namespace content |
434 | 452 |
435 #else | 453 #else |
436 | 454 |
437 namespace content { | 455 namespace content { |
438 | 456 |
439 void InitializeSandbox() { | 457 void InitializeSandbox() { |
440 } | 458 } |
441 | 459 |
442 } // namespace content | 460 } // namespace content |
443 | 461 |
444 #endif | 462 #endif |
445 | |
OLD | NEW |