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_linux.h" | 5 #include "content/zygote/zygote_linux.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/common/sandbox_linux.h" | 23 #include "content/common/sandbox_linux.h" |
24 #include "content/common/set_process_title.h" | 24 #include "content/common/set_process_title.h" |
25 #include "content/common/zygote_commands_linux.h" | 25 #include "content/common/zygote_commands_linux.h" |
26 #include "content/public/common/content_descriptors.h" | 26 #include "content/public/common/content_descriptors.h" |
27 #include "content/public/common/result_codes.h" | 27 #include "content/public/common/result_codes.h" |
28 #include "content/public/common/sandbox_linux.h" | 28 #include "content/public/common/sandbox_linux.h" |
29 #include "content/public/common/zygote_fork_delegate_linux.h" | 29 #include "content/public/common/zygote_fork_delegate_linux.h" |
30 #include "ipc/ipc_channel.h" | 30 #include "ipc/ipc_channel.h" |
31 #include "ipc/ipc_switches.h" | 31 #include "ipc/ipc_switches.h" |
32 | 32 |
33 #if defined(CHROMIUM_SELINUX) | |
34 #include <selinux/context.h> | |
35 #include <selinux/selinux.h> | |
36 #endif | |
37 | |
38 // See http://code.google.com/p/chromium/wiki/LinuxZygote | 33 // See http://code.google.com/p/chromium/wiki/LinuxZygote |
39 | 34 |
40 namespace content { | 35 namespace content { |
41 | 36 |
42 namespace { | 37 namespace { |
43 | 38 |
44 // NOP function. See below where this handler is installed. | 39 // NOP function. See below where this handler is installed. |
45 void SIGCHLDHandler(int signal) { | 40 void SIGCHLDHandler(int signal) { |
46 } | 41 } |
47 | 42 |
48 #if defined(CHROMIUM_SELINUX) | |
49 void SELinuxTransitionToTypeOrDie(const char* type) { | |
50 security_context_t security_context; | |
51 if (getcon(&security_context)) | |
52 LOG(FATAL) << "Cannot get SELinux context"; | |
53 | |
54 context_t context = context_new(security_context); | |
55 context_type_set(context, type); | |
56 const int r = setcon(context_str(context)); | |
57 context_free(context); | |
58 freecon(security_context); | |
59 | |
60 if (r) { | |
61 LOG(FATAL) << "dynamic transition to type '" << type << "' failed. " | |
62 "(this binary has been built with SELinux support, but maybe " | |
63 "the policies haven't been loaded into the kernel?)"; | |
64 } | |
65 } | |
66 #endif // CHROMIUM_SELINUX | |
67 | |
68 } // namespace | 43 } // namespace |
69 | 44 |
70 const int Zygote::kMagicSandboxIPCDescriptor; | 45 const int Zygote::kMagicSandboxIPCDescriptor; |
71 | 46 |
72 Zygote::Zygote(int sandbox_flags, | 47 Zygote::Zygote(int sandbox_flags, |
73 ZygoteForkDelegate* helper) | 48 ZygoteForkDelegate* helper) |
74 : sandbox_flags_(sandbox_flags), | 49 : sandbox_flags_(sandbox_flags), |
75 helper_(helper), | 50 helper_(helper), |
76 initial_uma_sample_(0), | 51 initial_uma_sample_(0), |
77 initial_uma_boundary_value_(0) { | 52 initial_uma_boundary_value_(0) { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 uma_name, uma_sample, | 409 uma_name, uma_sample, |
435 uma_boundary_value); | 410 uma_boundary_value); |
436 if (!child_pid) { | 411 if (!child_pid) { |
437 // This is the child process. | 412 // This is the child process. |
438 | 413 |
439 close(kBrowserDescriptor); // Our socket from the browser. | 414 close(kBrowserDescriptor); // Our socket from the browser. |
440 if (UsingSUIDSandbox()) | 415 if (UsingSUIDSandbox()) |
441 close(kZygoteIdFd); // Another socket from the browser. | 416 close(kZygoteIdFd); // Another socket from the browser. |
442 base::GlobalDescriptors::GetInstance()->Reset(mapping); | 417 base::GlobalDescriptors::GetInstance()->Reset(mapping); |
443 | 418 |
444 #if defined(CHROMIUM_SELINUX) | |
445 SELinuxTransitionToTypeOrDie("chromium_renderer_t"); | |
446 #endif | |
447 | |
448 // Reset the process-wide command line to our new command line. | 419 // Reset the process-wide command line to our new command line. |
449 CommandLine::Reset(); | 420 CommandLine::Reset(); |
450 CommandLine::Init(0, NULL); | 421 CommandLine::Init(0, NULL); |
451 CommandLine::ForCurrentProcess()->InitFromArgv(args); | 422 CommandLine::ForCurrentProcess()->InitFromArgv(args); |
452 | 423 |
453 // Update the process title. The argv was already cached by the call to | 424 // Update the process title. The argv was already cached by the call to |
454 // SetProcessTitleFromCommandLine in ChromeMain, so we can pass NULL here | 425 // SetProcessTitleFromCommandLine in ChromeMain, so we can pass NULL here |
455 // (we don't have the original argv at this point). | 426 // (we don't have the original argv at this point). |
456 SetProcessTitleFromCommandLine(NULL); | 427 SetProcessTitleFromCommandLine(NULL); |
457 } else if (child_pid < 0) { | 428 } else if (child_pid < 0) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 PickleIterator iter) { | 475 PickleIterator iter) { |
505 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != | 476 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != |
506 sizeof(sandbox_flags_)) { | 477 sizeof(sandbox_flags_)) { |
507 PLOG(ERROR) << "write"; | 478 PLOG(ERROR) << "write"; |
508 } | 479 } |
509 | 480 |
510 return false; | 481 return false; |
511 } | 482 } |
512 | 483 |
513 } // namespace content | 484 } // namespace content |
OLD | NEW |