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 <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <pthread.h> | 10 #include <pthread.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <sys/socket.h> | 12 #include <sys/socket.h> |
13 #include <sys/stat.h> | 13 #include <sys/stat.h> |
14 #include <sys/types.h> | 14 #include <sys/types.h> |
15 #include <sys/wait.h> | 15 #include <sys/wait.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
20 #include "base/callback.h" | 20 #include "base/callback.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
23 #include "base/linux_util.h" | 23 #include "base/linux_util.h" |
| 24 #include "base/memory/scoped_vector.h" |
24 #include "base/native_library.h" | 25 #include "base/native_library.h" |
25 #include "base/pickle.h" | 26 #include "base/pickle.h" |
26 #include "base/posix/eintr_wrapper.h" | 27 #include "base/posix/eintr_wrapper.h" |
27 #include "base/posix/unix_domain_socket_linux.h" | 28 #include "base/posix/unix_domain_socket_linux.h" |
28 #include "base/rand_util.h" | 29 #include "base/rand_util.h" |
29 #include "base/sys_info.h" | 30 #include "base/sys_info.h" |
30 #include "build/build_config.h" | 31 #include "build/build_config.h" |
31 #include "content/common/child_process_sandbox_support_impl_linux.h" | 32 #include "content/common/child_process_sandbox_support_impl_linux.h" |
32 #include "content/common/font_config_ipc_linux.h" | 33 #include "content/common/font_config_ipc_linux.h" |
33 #include "content/common/pepper_plugin_list.h" | 34 #include "content/common/pepper_plugin_list.h" |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 436 |
436 sandbox::SetuidSandboxClient* setuid_sandbox = | 437 sandbox::SetuidSandboxClient* setuid_sandbox = |
437 linux_sandbox->setuid_sandbox_client(); | 438 linux_sandbox->setuid_sandbox_client(); |
438 | 439 |
439 if (is_suid_sandbox_child) { | 440 if (is_suid_sandbox_child) { |
440 CHECK(EnterSuidSandbox(setuid_sandbox)) << "Failed to enter setuid sandbox"; | 441 CHECK(EnterSuidSandbox(setuid_sandbox)) << "Failed to enter setuid sandbox"; |
441 } | 442 } |
442 } | 443 } |
443 | 444 |
444 bool ZygoteMain(const MainFunctionParams& params, | 445 bool ZygoteMain(const MainFunctionParams& params, |
445 ZygoteForkDelegate* forkdelegate) { | 446 ScopedVector<ZygoteForkDelegate> fork_delegates) { |
446 g_am_zygote_or_renderer = true; | 447 g_am_zygote_or_renderer = true; |
447 sandbox::InitLibcUrandomOverrides(); | 448 sandbox::InitLibcUrandomOverrides(); |
448 | 449 |
449 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); | 450 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); |
450 // This will pre-initialize the various sandboxes that need it. | 451 // This will pre-initialize the various sandboxes that need it. |
451 linux_sandbox->PreinitializeSandbox(); | 452 linux_sandbox->PreinitializeSandbox(); |
452 | 453 |
453 const bool must_enable_setuid_sandbox = | 454 const bool must_enable_setuid_sandbox = |
454 linux_sandbox->setuid_sandbox_client()->IsSuidSandboxChild(); | 455 linux_sandbox->setuid_sandbox_client()->IsSuidSandboxChild(); |
455 if (must_enable_setuid_sandbox) { | 456 if (must_enable_setuid_sandbox) { |
456 linux_sandbox->setuid_sandbox_client()->CloseDummyFile(); | 457 linux_sandbox->setuid_sandbox_client()->CloseDummyFile(); |
457 | 458 |
458 // Let the ZygoteHost know we're booting up. | 459 // Let the ZygoteHost know we're booting up. |
459 CHECK(UnixDomainSocket::SendMsg(kZygoteSocketPairFd, | 460 CHECK(UnixDomainSocket::SendMsg(kZygoteSocketPairFd, |
460 kZygoteBootMessage, | 461 kZygoteBootMessage, |
461 sizeof(kZygoteBootMessage), | 462 sizeof(kZygoteBootMessage), |
462 std::vector<int>())); | 463 std::vector<int>())); |
463 } | 464 } |
464 | 465 |
465 if (forkdelegate != NULL) { | 466 VLOG(1) << "ZygoteMain: initializing " << fork_delegates.size() |
466 VLOG(1) << "ZygoteMain: initializing fork delegate"; | 467 << " fork delegates"; |
467 forkdelegate->Init(GetSandboxFD(), must_enable_setuid_sandbox); | 468 for (ScopedVector<ZygoteForkDelegate>::iterator i = fork_delegates.begin(); |
468 } else { | 469 i != fork_delegates.end(); |
469 VLOG(1) << "ZygoteMain: fork delegate is NULL"; | 470 ++i) { |
| 471 (*i)->Init(GetSandboxFD(), must_enable_setuid_sandbox); |
470 } | 472 } |
471 | 473 |
472 // Turn on the first layer of the sandbox if the configuration warrants it. | 474 // Turn on the first layer of the sandbox if the configuration warrants it. |
473 EnterLayerOneSandbox(linux_sandbox, must_enable_setuid_sandbox); | 475 EnterLayerOneSandbox(linux_sandbox, must_enable_setuid_sandbox); |
474 | 476 |
475 int sandbox_flags = linux_sandbox->GetStatus(); | 477 int sandbox_flags = linux_sandbox->GetStatus(); |
476 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID; | 478 bool setuid_sandbox_engaged = sandbox_flags & kSandboxLinuxSUID; |
477 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); | 479 CHECK_EQ(must_enable_setuid_sandbox, setuid_sandbox_engaged); |
478 | 480 |
479 Zygote zygote(sandbox_flags, forkdelegate); | 481 Zygote zygote(sandbox_flags, fork_delegates.Pass()); |
480 // This function call can return multiple times, once per fork(). | 482 // This function call can return multiple times, once per fork(). |
481 return zygote.ProcessRequests(); | 483 return zygote.ProcessRequests(); |
482 } | 484 } |
483 | 485 |
484 } // namespace content | 486 } // namespace content |
OLD | NEW |