| 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 <stdio.h> | 10 #include <stdio.h> |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 13 #include <sys/types.h> | 13 #include <sys/types.h> |
| 14 #include <sys/wait.h> | 14 #include <sys/wait.h> |
| 15 #include <unistd.h> | 15 #include <unistd.h> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/containers/hash_tables.h" | |
| 20 #include "base/files/file_path.h" | |
| 21 #include "base/linux_util.h" | 19 #include "base/linux_util.h" |
| 22 #include "base/memory/scoped_ptr.h" | |
| 23 #include "base/native_library.h" | 20 #include "base/native_library.h" |
| 24 #include "base/pickle.h" | 21 #include "base/pickle.h" |
| 25 #include "base/posix/eintr_wrapper.h" | 22 #include "base/posix/eintr_wrapper.h" |
| 26 #include "base/posix/unix_domain_socket_linux.h" | 23 #include "base/posix/unix_domain_socket_linux.h" |
| 27 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
| 28 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 29 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 30 #include "content/common/font_config_ipc_linux.h" | 27 #include "content/common/font_config_ipc_linux.h" |
| 31 #include "content/common/pepper_plugin_list.h" | 28 #include "content/common/pepper_plugin_list.h" |
| 32 #include "content/common/sandbox_linux.h" | 29 #include "content/common/sandbox_linux.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // pre-sandbox init, but more likely this is just a build configuration error. | 294 // pre-sandbox init, but more likely this is just a build configuration error. |
| 298 #error Which SSL library are you using? | 295 #error Which SSL library are you using? |
| 299 #endif | 296 #endif |
| 300 #if defined(ENABLE_PLUGINS) | 297 #if defined(ENABLE_PLUGINS) |
| 301 // Ensure access to the Pepper plugins before the sandbox is turned on. | 298 // Ensure access to the Pepper plugins before the sandbox is turned on. |
| 302 PreloadPepperPlugins(); | 299 PreloadPepperPlugins(); |
| 303 #endif | 300 #endif |
| 304 #if defined(ENABLE_WEBRTC) | 301 #if defined(ENABLE_WEBRTC) |
| 305 InitializeWebRtcModule(); | 302 InitializeWebRtcModule(); |
| 306 #endif | 303 #endif |
| 304 SkFontConfigInterface::SetGlobal( |
| 305 new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor))->unref(); |
| 307 } | 306 } |
| 308 | 307 |
| 309 // Do nothing here | 308 // Do nothing here |
| 310 static void SIGCHLDHandler(int signal) { | 309 static void SIGCHLDHandler(int signal) { |
| 311 } | 310 } |
| 312 | 311 |
| 313 // The current process will become a process reaper like init. | 312 // The current process will become a process reaper like init. |
| 314 // We fork a child that will continue normally, when it dies, we can safely | 313 // We fork a child that will continue normally, when it dies, we can safely |
| 315 // exit. | 314 // exit. |
| 316 // We need to be careful we close the magic kZygoteIdFd properly in the parent | 315 // We need to be careful we close the magic kZygoteIdFd properly in the parent |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 (void) HANDLE_EINTR(close(sync_fds[0])); | 376 (void) HANDLE_EINTR(close(sync_fds[0])); |
| 378 if (read_ret == 1) | 377 if (read_ret == 1) |
| 379 return true; | 378 return true; |
| 380 else | 379 else |
| 381 return false; | 380 return false; |
| 382 } | 381 } |
| 383 } | 382 } |
| 384 | 383 |
| 385 // This will set the *using_suid_sandbox variable to true if the SUID sandbox | 384 // This will set the *using_suid_sandbox variable to true if the SUID sandbox |
| 386 // is enabled. This does not necessarily exclude other types of sandboxing. | 385 // is enabled. This does not necessarily exclude other types of sandboxing. |
| 387 static bool EnterSandbox(sandbox::SetuidSandboxClient* setuid_sandbox, | 386 static bool EnterSuidSandbox(LinuxSandbox* linux_sandbox, |
| 388 bool* using_suid_sandbox, bool* has_started_new_init) { | 387 bool* using_suid_sandbox, |
| 388 bool* has_started_new_init) { |
| 389 *using_suid_sandbox = false; | 389 *using_suid_sandbox = false; |
| 390 *has_started_new_init = false; | 390 *has_started_new_init = false; |
| 391 |
| 392 sandbox::SetuidSandboxClient* setuid_sandbox = |
| 393 linux_sandbox->setuid_sandbox_client(); |
| 394 |
| 391 if (!setuid_sandbox) | 395 if (!setuid_sandbox) |
| 392 return false; | 396 return false; |
| 393 | 397 |
| 394 PreSandboxInit(); | 398 PreSandboxInit(); |
| 395 SkFontConfigInterface::SetGlobal( | 399 |
| 396 new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor))->unref(); | 400 // Check that the pre-sandbox initialization didn't spawn threads. |
| 401 DCHECK(linux_sandbox->IsSingleThreaded()); |
| 397 | 402 |
| 398 if (setuid_sandbox->IsSuidSandboxChild()) { | 403 if (setuid_sandbox->IsSuidSandboxChild()) { |
| 399 // Use the SUID sandbox. This still allows the seccomp sandbox to | 404 // Use the SUID sandbox. This still allows the seccomp sandbox to |
| 400 // be enabled by the process later. | 405 // be enabled by the process later. |
| 401 *using_suid_sandbox = true; | 406 *using_suid_sandbox = true; |
| 402 | 407 |
| 403 if (!setuid_sandbox->IsSuidSandboxUpToDate()) { | 408 if (!setuid_sandbox->IsSuidSandboxUpToDate()) { |
| 404 LOG(WARNING) << "You are using a wrong version of the setuid binary!\n" | 409 LOG(WARNING) << "You are using a wrong version of the setuid binary!\n" |
| 405 "Please read " | 410 "Please read " |
| 406 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment." | 411 "https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment." |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 459 |
| 455 bool ZygoteMain(const MainFunctionParams& params, | 460 bool ZygoteMain(const MainFunctionParams& params, |
| 456 ZygoteForkDelegate* forkdelegate) { | 461 ZygoteForkDelegate* forkdelegate) { |
| 457 g_am_zygote_or_renderer = true; | 462 g_am_zygote_or_renderer = true; |
| 458 sandbox::InitLibcUrandomOverrides(); | 463 sandbox::InitLibcUrandomOverrides(); |
| 459 | 464 |
| 460 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); | 465 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); |
| 461 // This will pre-initialize the various sandboxes that need it. | 466 // This will pre-initialize the various sandboxes that need it. |
| 462 linux_sandbox->PreinitializeSandbox(); | 467 linux_sandbox->PreinitializeSandbox(); |
| 463 | 468 |
| 464 sandbox::SetuidSandboxClient* setuid_sandbox = | |
| 465 linux_sandbox->setuid_sandbox_client(); | |
| 466 | |
| 467 if (forkdelegate != NULL) { | 469 if (forkdelegate != NULL) { |
| 468 VLOG(1) << "ZygoteMain: initializing fork delegate"; | 470 VLOG(1) << "ZygoteMain: initializing fork delegate"; |
| 469 forkdelegate->Init(Zygote::kMagicSandboxIPCDescriptor); | 471 forkdelegate->Init(Zygote::kMagicSandboxIPCDescriptor); |
| 470 } else { | 472 } else { |
| 471 VLOG(1) << "ZygoteMain: fork delegate is NULL"; | 473 VLOG(1) << "ZygoteMain: fork delegate is NULL"; |
| 472 } | 474 } |
| 473 | 475 |
| 474 // Turn on the sandbox. | 476 // Turn on the sandbox. |
| 475 bool using_suid_sandbox = false; | 477 bool using_suid_sandbox = false; |
| 476 bool has_started_new_init = false; | 478 bool has_started_new_init = false; |
| 477 | 479 |
| 478 if (!EnterSandbox(setuid_sandbox, | 480 if (!EnterSuidSandbox(linux_sandbox, |
| 479 &using_suid_sandbox, | 481 &using_suid_sandbox, |
| 480 &has_started_new_init)) { | 482 &has_started_new_init)) { |
| 481 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " | 483 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " |
| 482 << errno << ")"; | 484 << errno << ")"; |
| 483 return false; | 485 return false; |
| 484 } | 486 } |
| 485 | 487 |
| 488 sandbox::SetuidSandboxClient* setuid_sandbox = |
| 489 linux_sandbox->setuid_sandbox_client(); |
| 490 |
| 486 if (setuid_sandbox->IsInNewPIDNamespace() && !has_started_new_init) { | 491 if (setuid_sandbox->IsInNewPIDNamespace() && !has_started_new_init) { |
| 487 LOG(ERROR) << "The SUID sandbox created a new PID namespace but Zygote " | 492 LOG(ERROR) << "The SUID sandbox created a new PID namespace but Zygote " |
| 488 "is not the init process. Please, make sure the SUID " | 493 "is not the init process. Please, make sure the SUID " |
| 489 "binary is up to date."; | 494 "binary is up to date."; |
| 490 } | 495 } |
| 491 | 496 |
| 492 int sandbox_flags = linux_sandbox->GetStatus(); | 497 int sandbox_flags = linux_sandbox->GetStatus(); |
| 493 | 498 |
| 494 Zygote zygote(sandbox_flags, forkdelegate); | 499 Zygote zygote(sandbox_flags, forkdelegate); |
| 495 // This function call can return multiple times, once per fork(). | 500 // This function call can return multiple times, once per fork(). |
| 496 return zygote.ProcessRequests(); | 501 return zygote.ProcessRequests(); |
| 497 } | 502 } |
| 498 | 503 |
| 499 } // namespace content | 504 } // namespace content |
| OLD | NEW |