Chromium Code Reviews| 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/zygote/zygote_main.h" | 5 #include "content/zygote/zygote_main.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include <signal.h> | |
| 10 #include <string.h> | 11 #include <string.h> |
| 11 #include <sys/socket.h> | 12 #include <sys/socket.h> |
| 12 #include <sys/types.h> | 13 #include <sys/types.h> |
| 13 #include <unistd.h> | 14 #include <unistd.h> |
| 14 | 15 |
| 15 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 16 #include "base/bind.h" | 17 #include "base/bind.h" |
| 17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 18 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 19 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
| 20 #include "base/native_library.h" | 21 #include "base/native_library.h" |
| 21 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 22 #include "base/posix/eintr_wrapper.h" | 23 #include "base/posix/eintr_wrapper.h" |
| 23 #include "base/posix/unix_domain_socket_linux.h" | 24 #include "base/posix/unix_domain_socket_linux.h" |
| 24 #include "base/rand_util.h" | 25 #include "base/rand_util.h" |
| 26 #include "base/strings/safe_sprintf.h" | |
| 25 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
| 27 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 28 #include "content/common/child_process_sandbox_support_impl_linux.h" | 30 #include "content/common/child_process_sandbox_support_impl_linux.h" |
| 29 #include "content/common/font_config_ipc_linux.h" | 31 #include "content/common/font_config_ipc_linux.h" |
| 30 #include "content/common/sandbox_linux/sandbox_linux.h" | 32 #include "content/common/sandbox_linux/sandbox_linux.h" |
| 31 #include "content/common/zygote_commands_linux.h" | 33 #include "content/common/zygote_commands_linux.h" |
| 32 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 33 #include "content/public/common/main_function_params.h" | 35 #include "content/public/common/main_function_params.h" |
| 34 #include "content/public/common/sandbox_linux.h" | 36 #include "content/public/common/sandbox_linux.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 57 #if defined(ENABLE_WEBRTC) | 59 #if defined(ENABLE_WEBRTC) |
| 58 #include "third_party/libjingle/overrides/init_webrtc.h" | 60 #include "third_party/libjingle/overrides/init_webrtc.h" |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 #if defined(ADDRESS_SANITIZER) | 63 #if defined(ADDRESS_SANITIZER) |
| 62 #include <sanitizer/asan_interface.h> | 64 #include <sanitizer/asan_interface.h> |
| 63 #endif | 65 #endif |
| 64 | 66 |
| 65 namespace content { | 67 namespace content { |
| 66 | 68 |
| 69 namespace { | |
| 70 | |
| 71 void DoChrootSignalHandler(int) { | |
| 72 const int old_errno = errno; | |
| 73 const char kFirstMessage[] = "Chroot signal handler called.\n"; | |
| 74 ignore_result(write(STDERR_FILENO, kFirstMessage, sizeof(kFirstMessage) - 1)); | |
| 75 | |
| 76 ignore_result(chroot("/")); | |
| 77 | |
| 78 char kSecondMessage[100]; | |
| 79 const ssize_t printed = base::strings::SafeSPrintf( | |
| 80 kSecondMessage, "chroot() returned. Errno is %d.\n", errno); | |
|
mdempsky
2014/09/19 23:35:40
Maybe go ahead and include chroot()'s return value
jln (very slow on Chromium)
2014/09/19 23:42:30
Done
| |
| 81 if (printed > 0 && printed < static_cast<ssize_t>(sizeof(kSecondMessage))) { | |
| 82 ignore_result(write(STDERR_FILENO, kSecondMessage, printed)); | |
| 83 } | |
| 84 errno = old_errno; | |
| 85 } | |
| 86 | |
| 87 // This is a quick hack to allow testing sandbox crash reports in production | |
| 88 // binaries. | |
| 89 // This installs a signal handler for SIGUSR2 that performs a chroot(). | |
| 90 // In most of our BPF policies, it is a "watched" system call which will | |
| 91 // trigger a SIGSYS signal whose handler will crash. | |
| 92 // This has been added during the investigation of https://crbug.com/415842. | |
| 93 void InstallSandboxCrashTestHandler() { | |
| 94 struct sigaction act = {}; | |
| 95 act.sa_handler = DoChrootSignalHandler; | |
| 96 CHECK_EQ(0, sigemptyset(&act.sa_mask)); | |
| 97 act.sa_flags = 0; | |
| 98 | |
| 99 PCHECK(0 == sigaction(SIGUSR2, &act, NULL)); | |
| 100 } | |
| 101 } | |
|
mdempsky
2014/09/19 23:35:40
(Should have a "// namespace" comment, I think?)
jln (very slow on Chromium)
2014/09/19 23:42:30
Done.
| |
| 102 | |
| 67 // See http://code.google.com/p/chromium/wiki/LinuxZygote | 103 // See http://code.google.com/p/chromium/wiki/LinuxZygote |
| 68 | 104 |
| 69 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, | 105 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, |
| 70 char* timezone_out, | 106 char* timezone_out, |
| 71 size_t timezone_out_len) { | 107 size_t timezone_out_len) { |
| 72 Pickle request; | 108 Pickle request; |
| 73 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); | 109 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); |
| 74 request.WriteString( | 110 request.WriteString( |
| 75 std::string(reinterpret_cast<char*>(&input), sizeof(input))); | 111 std::string(reinterpret_cast<char*>(&input), sizeof(input))); |
| 76 | 112 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 // issues, one can specify --allow-sandbox-debugging to let the process be | 440 // issues, one can specify --allow-sandbox-debugging to let the process be |
| 405 // dumpable. | 441 // dumpable. |
| 406 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 442 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 407 if (!command_line.HasSwitch(switches::kAllowSandboxDebugging)) { | 443 if (!command_line.HasSwitch(switches::kAllowSandboxDebugging)) { |
| 408 prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); | 444 prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); |
| 409 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { | 445 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { |
| 410 LOG(ERROR) << "Failed to set non-dumpable flag"; | 446 LOG(ERROR) << "Failed to set non-dumpable flag"; |
| 411 return false; | 447 return false; |
| 412 } | 448 } |
| 413 } | 449 } |
| 450 | |
| 451 InstallSandboxCrashTestHandler(); | |
| 414 #endif | 452 #endif |
| 415 | 453 |
| 416 return true; | 454 return true; |
| 417 } | 455 } |
| 418 | 456 |
| 419 #if defined(ADDRESS_SANITIZER) | 457 #if defined(ADDRESS_SANITIZER) |
| 420 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; | 458 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; |
| 421 | 459 |
| 422 // A helper process which collects code coverage data from the renderers over a | 460 // A helper process which collects code coverage data from the renderers over a |
| 423 // socket and dumps it to a file. See http://crbug.com/336212 for discussion. | 461 // socket and dumps it to a file. See http://crbug.com/336212 for discussion. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID; | 609 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID; |
| 572 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); | 610 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); |
| 573 | 611 |
| 574 Zygote zygote(sandbox_flags, fork_delegates.Pass(), extra_children, | 612 Zygote zygote(sandbox_flags, fork_delegates.Pass(), extra_children, |
| 575 extra_fds); | 613 extra_fds); |
| 576 // This function call can return multiple times, once per fork(). | 614 // This function call can return multiple times, once per fork(). |
| 577 return zygote.ProcessRequests(); | 615 return zygote.ProcessRequests(); |
| 578 } | 616 } |
| 579 | 617 |
| 580 } // namespace content | 618 } // namespace content |
| OLD | NEW |