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 const int chroot_ret = chroot("/"); |
| 77 |
| 78 char kSecondMessage[100]; |
| 79 const ssize_t printed = |
| 80 base::strings::SafeSPrintf(kSecondMessage, |
| 81 "chroot() returned %d. Errno is %d.\n", |
| 82 chroot_ret, |
| 83 errno); |
| 84 if (printed > 0 && printed < static_cast<ssize_t>(sizeof(kSecondMessage))) { |
| 85 ignore_result(write(STDERR_FILENO, kSecondMessage, printed)); |
| 86 } |
| 87 errno = old_errno; |
| 88 } |
| 89 |
| 90 // This is a quick hack to allow testing sandbox crash reports in production |
| 91 // binaries. |
| 92 // This installs a signal handler for SIGUSR2 that performs a chroot(). |
| 93 // In most of our BPF policies, it is a "watched" system call which will |
| 94 // trigger a SIGSYS signal whose handler will crash. |
| 95 // This has been added during the investigation of https://crbug.com/415842. |
| 96 void InstallSandboxCrashTestHandler() { |
| 97 struct sigaction act = {}; |
| 98 act.sa_handler = DoChrootSignalHandler; |
| 99 CHECK_EQ(0, sigemptyset(&act.sa_mask)); |
| 100 act.sa_flags = 0; |
| 101 |
| 102 PCHECK(0 == sigaction(SIGUSR2, &act, NULL)); |
| 103 } |
| 104 } // namespace |
| 105 |
67 // See http://code.google.com/p/chromium/wiki/LinuxZygote | 106 // See http://code.google.com/p/chromium/wiki/LinuxZygote |
68 | 107 |
69 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, | 108 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, |
70 char* timezone_out, | 109 char* timezone_out, |
71 size_t timezone_out_len) { | 110 size_t timezone_out_len) { |
72 Pickle request; | 111 Pickle request; |
73 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); | 112 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); |
74 request.WriteString( | 113 request.WriteString( |
75 std::string(reinterpret_cast<char*>(&input), sizeof(input))); | 114 std::string(reinterpret_cast<char*>(&input), sizeof(input))); |
76 | 115 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // Note: a non-dumpable process can't be debugged. To debug sandbox-related | 442 // Note: a non-dumpable process can't be debugged. To debug sandbox-related |
404 // issues, one can specify --allow-sandbox-debugging to let the process be | 443 // issues, one can specify --allow-sandbox-debugging to let the process be |
405 // dumpable. | 444 // dumpable. |
406 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 445 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
407 if (!command_line.HasSwitch(switches::kAllowSandboxDebugging)) { | 446 if (!command_line.HasSwitch(switches::kAllowSandboxDebugging)) { |
408 prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); | 447 prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); |
409 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { | 448 if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0)) { |
410 LOG(ERROR) << "Failed to set non-dumpable flag"; | 449 LOG(ERROR) << "Failed to set non-dumpable flag"; |
411 return false; | 450 return false; |
412 } | 451 } |
| 452 } else { |
| 453 // If sandbox debugging is allowed, install a handler for sandbox-related |
| 454 // crash testing. |
| 455 InstallSandboxCrashTestHandler(); |
413 } | 456 } |
| 457 |
414 #endif | 458 #endif |
415 | 459 |
416 return true; | 460 return true; |
417 } | 461 } |
418 | 462 |
419 #if defined(ADDRESS_SANITIZER) | 463 #if defined(ADDRESS_SANITIZER) |
420 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; | 464 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; |
421 | 465 |
422 // A helper process which collects code coverage data from the renderers over a | 466 // 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. | 467 // 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; | 615 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID; |
572 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); | 616 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); |
573 | 617 |
574 Zygote zygote(sandbox_flags, fork_delegates.Pass(), extra_children, | 618 Zygote zygote(sandbox_flags, fork_delegates.Pass(), extra_children, |
575 extra_fds); | 619 extra_fds); |
576 // This function call can return multiple times, once per fork(). | 620 // This function call can return multiple times, once per fork(). |
577 return zygote.ProcessRequests(); | 621 return zygote.ProcessRequests(); |
578 } | 622 } |
579 | 623 |
580 } // namespace content | 624 } // namespace content |
OLD | NEW |