| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <sys/epoll.h> | 7 #include <sys/epoll.h> |
| 8 #include <sys/prctl.h> | 8 #include <sys/prctl.h> |
| 9 #include <sys/signal.h> | 9 #include <sys/signal.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 static const int kBrowserDescriptor = 3; | 58 static const int kBrowserDescriptor = 3; |
| 59 static const int kMagicSandboxIPCDescriptor = 5; | 59 static const int kMagicSandboxIPCDescriptor = 5; |
| 60 static const int kZygoteIdDescriptor = 7; | 60 static const int kZygoteIdDescriptor = 7; |
| 61 static bool g_suid_sandbox_active = false; | 61 static bool g_suid_sandbox_active = false; |
| 62 #if defined(SECCOMP_SANDBOX) | 62 #if defined(SECCOMP_SANDBOX) |
| 63 // |g_proc_fd| is used only by the seccomp sandbox. | 63 // |g_proc_fd| is used only by the seccomp sandbox. |
| 64 static int g_proc_fd = -1; | 64 static int g_proc_fd = -1; |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 #if defined(CHROMIUM_SELINUX) |
| 68 static void SELinuxTransitionToTypeOrDie(const char* type) { |
| 69 security_context_t security_context; |
| 70 if (getcon(&security_context)) |
| 71 LOG(FATAL) << "Cannot get SELinux context"; |
| 72 |
| 73 context_t context = context_new(security_context); |
| 74 context_type_set(context, type); |
| 75 const int r = setcon(context_str(context)); |
| 76 context_free(context); |
| 77 freecon(security_context); |
| 78 |
| 79 if (r) { |
| 80 LOG(FATAL) << "dynamic transition to type '" << type << "' failed. " |
| 81 "(this binary has been built with SELinux support, but maybe " |
| 82 "the policies haven't been loaded into the kernel?)"; |
| 83 } |
| 84 } |
| 85 #endif // CHROMIUM_SELINUX |
| 86 |
| 67 // This is the object which implements the zygote. The ZygoteMain function, | 87 // This is the object which implements the zygote. The ZygoteMain function, |
| 68 // which is called from ChromeMain, at the the bottom and simple constructs one | 88 // which is called from ChromeMain, at the the bottom and simple constructs one |
| 69 // of these objects and runs it. | 89 // of these objects and runs it. |
| 70 class Zygote { | 90 class Zygote { |
| 71 public: | 91 public: |
| 72 bool ProcessRequests() { | 92 bool ProcessRequests() { |
| 73 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the | 93 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the |
| 74 // browser on it. | 94 // browser on it. |
| 75 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel. | 95 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel. |
| 76 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC | 96 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 close(g_proc_fd); | 277 close(g_proc_fd); |
| 258 g_proc_fd = -1; | 278 g_proc_fd = -1; |
| 259 } | 279 } |
| 260 #endif | 280 #endif |
| 261 | 281 |
| 262 close(kBrowserDescriptor); // our socket from the browser | 282 close(kBrowserDescriptor); // our socket from the browser |
| 263 if (g_suid_sandbox_active) | 283 if (g_suid_sandbox_active) |
| 264 close(kZygoteIdDescriptor); // another socket from the browser | 284 close(kZygoteIdDescriptor); // another socket from the browser |
| 265 Singleton<base::GlobalDescriptors>()->Reset(mapping); | 285 Singleton<base::GlobalDescriptors>()->Reset(mapping); |
| 266 | 286 |
| 287 #if defined(CHROMIUM_SELINUX) |
| 288 SELinuxTransitionToTypeOrDie("chromium_renderer_t"); |
| 289 #endif |
| 290 |
| 267 // Reset the process-wide command line to our new command line. | 291 // Reset the process-wide command line to our new command line. |
| 268 CommandLine::Reset(); | 292 CommandLine::Reset(); |
| 269 CommandLine::Init(0, NULL); | 293 CommandLine::Init(0, NULL); |
| 270 CommandLine::ForCurrentProcess()->InitFromArgv(args); | 294 CommandLine::ForCurrentProcess()->InitFromArgv(args); |
| 271 CommandLine::SetProcTitle(); | 295 CommandLine::SetProcTitle(); |
| 272 // The fork() request is handled further up the call stack. | 296 // The fork() request is handled further up the call stack. |
| 273 return true; | 297 return true; |
| 274 } else if (child < 0) { | 298 } else if (child < 0) { |
| 275 LOG(ERROR) << "Zygote could not fork"; | 299 LOG(ERROR) << "Zygote could not fork"; |
| 276 goto error; | 300 goto error; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 SkiaFontConfigUseDirectImplementation(); | 597 SkiaFontConfigUseDirectImplementation(); |
| 574 } | 598 } |
| 575 | 599 |
| 576 return true; | 600 return true; |
| 577 } | 601 } |
| 578 #else // CHROMIUM_SELINUX | 602 #else // CHROMIUM_SELINUX |
| 579 | 603 |
| 580 static bool EnterSandbox() { | 604 static bool EnterSandbox() { |
| 581 PreSandboxInit(); | 605 PreSandboxInit(); |
| 582 SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor); | 606 SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor); |
| 583 | |
| 584 security_context_t security_context; | |
| 585 if (getcon(&security_context)) { | |
| 586 LOG(ERROR) << "Cannot get SELinux context"; | |
| 587 return false; | |
| 588 } | |
| 589 | |
| 590 context_t context = context_new(security_context); | |
| 591 context_type_set(context, "chromium_zygote_t"); | |
| 592 const int r = setcon(context_str(context)); | |
| 593 context_free(context); | |
| 594 freecon(security_context); | |
| 595 | |
| 596 if (r) { | |
| 597 LOG(ERROR) << "dynamic transition to type 'chromium_zygote_t' failed. " | |
| 598 "(this binary has been built with SELinux support, but maybe " | |
| 599 "the policies haven't been loaded into the kernel?)"; | |
| 600 return false; | |
| 601 } | |
| 602 | |
| 603 return true; | 607 return true; |
| 604 } | 608 } |
| 605 | 609 |
| 606 #endif // CHROMIUM_SELINUX | 610 #endif // CHROMIUM_SELINUX |
| 607 | 611 |
| 608 bool ZygoteMain(const MainFunctionParams& params) { | 612 bool ZygoteMain(const MainFunctionParams& params) { |
| 609 #if !defined(CHROMIUM_SELINUX) | 613 #if !defined(CHROMIUM_SELINUX) |
| 610 g_am_zygote_or_renderer = true; | 614 g_am_zygote_or_renderer = true; |
| 611 #endif | 615 #endif |
| 612 | 616 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } else { | 653 } else { |
| 650 LOG(INFO) << "Enabling experimental Seccomp sandbox."; | 654 LOG(INFO) << "Enabling experimental Seccomp sandbox."; |
| 651 } | 655 } |
| 652 } | 656 } |
| 653 #endif // SECCOMP_SANDBOX | 657 #endif // SECCOMP_SANDBOX |
| 654 | 658 |
| 655 Zygote zygote; | 659 Zygote zygote; |
| 656 // This function call can return multiple times, once per fork(). | 660 // This function call can return multiple times, once per fork(). |
| 657 return zygote.ProcessRequests(); | 661 return zygote.ProcessRequests(); |
| 658 } | 662 } |
| OLD | NEW |