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 <signal.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/common/font_config_ipc_linux.h" | 33 #include "content/common/font_config_ipc_linux.h" |
34 #include "content/common/sandbox_linux/sandbox_debug_handling_linux.h" | 34 #include "content/common/sandbox_linux/sandbox_debug_handling_linux.h" |
35 #include "content/common/sandbox_linux/sandbox_linux.h" | 35 #include "content/common/sandbox_linux/sandbox_linux.h" |
36 #include "content/common/zygote_commands_linux.h" | 36 #include "content/common/zygote_commands_linux.h" |
37 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
38 #include "content/public/common/main_function_params.h" | 38 #include "content/public/common/main_function_params.h" |
39 #include "content/public/common/sandbox_linux.h" | 39 #include "content/public/common/sandbox_linux.h" |
40 #include "content/public/common/zygote_fork_delegate_linux.h" | 40 #include "content/public/common/zygote_fork_delegate_linux.h" |
41 #include "content/zygote/zygote_linux.h" | 41 #include "content/zygote/zygote_linux.h" |
42 #include "crypto/nss_util.h" | 42 #include "crypto/nss_util.h" |
| 43 #include "sandbox/linux/services/credentials.h" |
43 #include "sandbox/linux/services/init_process_reaper.h" | 44 #include "sandbox/linux/services/init_process_reaper.h" |
44 #include "sandbox/linux/services/libc_urandom_override.h" | 45 #include "sandbox/linux/services/libc_urandom_override.h" |
45 #include "sandbox/linux/services/namespace_sandbox.h" | 46 #include "sandbox/linux/services/namespace_sandbox.h" |
46 #include "sandbox/linux/services/thread_helpers.h" | 47 #include "sandbox/linux/services/thread_helpers.h" |
47 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" | 48 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" |
48 #include "third_party/icu/source/i18n/unicode/timezone.h" | 49 #include "third_party/icu/source/i18n/unicode/timezone.h" |
49 #include "third_party/skia/include/ports/SkFontConfigInterface.h" | 50 #include "third_party/skia/include/ports/SkFontConfigInterface.h" |
50 | 51 |
51 #if defined(OS_LINUX) | 52 #if defined(OS_LINUX) |
52 #include <sys/prctl.h> | 53 #include <sys/prctl.h> |
(...skipping 20 matching lines...) Expand all Loading... |
73 namespace content { | 74 namespace content { |
74 | 75 |
75 namespace { | 76 namespace { |
76 | 77 |
77 void CloseFds(const std::vector<int>& fds) { | 78 void CloseFds(const std::vector<int>& fds) { |
78 for (const auto& it : fds) { | 79 for (const auto& it : fds) { |
79 PCHECK(0 == IGNORE_EINTR(close(it))); | 80 PCHECK(0 == IGNORE_EINTR(close(it))); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
| 84 void RunTwoClosures(const base::Closure* first, const base::Closure* second) { |
| 85 first->Run(); |
| 86 second->Run(); |
| 87 } |
| 88 |
83 } // namespace | 89 } // namespace |
84 | 90 |
85 // See http://code.google.com/p/chromium/wiki/LinuxZygote | 91 // See http://code.google.com/p/chromium/wiki/LinuxZygote |
86 | 92 |
87 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, | 93 static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output, |
88 char* timezone_out, | 94 char* timezone_out, |
89 size_t timezone_out_len) { | 95 size_t timezone_out_len) { |
90 Pickle request; | 96 Pickle request; |
91 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); | 97 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); |
92 request.WriteString( | 98 request.WriteString( |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 if (getpid() == 1) { | 406 if (getpid() == 1) { |
401 // The setuid sandbox has created a new PID namespace and we need | 407 // The setuid sandbox has created a new PID namespace and we need |
402 // to assume the role of init. | 408 // to assume the role of init. |
403 CHECK(CreateInitProcessReaper(post_fork_parent_callback)); | 409 CHECK(CreateInitProcessReaper(post_fork_parent_callback)); |
404 } | 410 } |
405 | 411 |
406 CHECK(SandboxDebugHandling::SetDumpableStatusAndHandlers()); | 412 CHECK(SandboxDebugHandling::SetDumpableStatusAndHandlers()); |
407 return true; | 413 return true; |
408 } | 414 } |
409 | 415 |
| 416 static void DropAllCapabilities(int proc_fd) { |
| 417 CHECK(sandbox::Credentials::DropAllCapabilities(proc_fd)); |
| 418 } |
| 419 |
410 static void EnterNamespaceSandbox(LinuxSandbox* linux_sandbox, | 420 static void EnterNamespaceSandbox(LinuxSandbox* linux_sandbox, |
411 base::Closure* post_fork_parent_callback) { | 421 base::Closure* post_fork_parent_callback) { |
412 linux_sandbox->EngageNamespaceSandbox(); | 422 linux_sandbox->EngageNamespaceSandbox(); |
413 | 423 |
414 if (getpid() == 1) { | 424 if (getpid() == 1) { |
415 CHECK(CreateInitProcessReaper(post_fork_parent_callback)); | 425 base::Closure drop_all_caps_callback = |
| 426 base::Bind(&DropAllCapabilities, linux_sandbox->proc_fd()); |
| 427 base::Closure callback = base::Bind( |
| 428 &RunTwoClosures, &drop_all_caps_callback, post_fork_parent_callback); |
| 429 CHECK(CreateInitProcessReaper(&callback)); |
416 } | 430 } |
417 } | 431 } |
418 | 432 |
419 #if defined(SANITIZER_COVERAGE) | 433 #if defined(SANITIZER_COVERAGE) |
420 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; | 434 const size_t kSanitizerMaxMessageLength = 1 * 1024 * 1024; |
421 | 435 |
422 // A helper process which collects code coverage data from the renderers over a | 436 // 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. | 437 // socket and dumps it to a file. See http://crbug.com/336212 for discussion. |
424 static void SanitizerCoverageHelper(int socket_fd, int file_fd) { | 438 static void SanitizerCoverageHelper(int socket_fd, int file_fd) { |
425 scoped_ptr<char[]> buffer(new char[kSanitizerMaxMessageLength]); | 439 scoped_ptr<char[]> buffer(new char[kSanitizerMaxMessageLength]); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; | 610 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; |
597 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); | 611 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); |
598 | 612 |
599 Zygote zygote(sandbox_flags, fork_delegates.Pass(), extra_children, | 613 Zygote zygote(sandbox_flags, fork_delegates.Pass(), extra_children, |
600 extra_fds); | 614 extra_fds); |
601 // This function call can return multiple times, once per fork(). | 615 // This function call can return multiple times, once per fork(). |
602 return zygote.ProcessRequests(); | 616 return zygote.ProcessRequests(); |
603 } | 617 } |
604 | 618 |
605 } // namespace content | 619 } // namespace content |
OLD | NEW |