Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: content/zygote/zygote_linux.cc

Issue 10843059: Create a LinuxSandbox class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/zygote/zygote_linux.h ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <sys/wait.h> 11 #include <sys/wait.h>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "ipc/ipc_switches.h" 14 #include "ipc/ipc_switches.h"
15 #include "content/public/common/sandbox_linux.h" 15 #include "content/public/common/sandbox_linux.h"
16 #include "base/process_util.h" 16 #include "base/process_util.h"
17 #include "content/public/common/result_codes.h" 17 #include "content/public/common/result_codes.h"
18 #include "ipc/ipc_channel.h" 18 #include "ipc/ipc_channel.h"
19 #include "base/debug/trace_event.h" 19 #include "base/debug/trace_event.h"
20 #include "base/file_util.h" 20 #include "base/file_util.h"
21 #include "base/linux_util.h" 21 #include "base/linux_util.h"
22 #include "base/eintr_wrapper.h" 22 #include "base/eintr_wrapper.h"
23 #include "base/global_descriptors_posix.h" 23 #include "base/global_descriptors_posix.h"
24 #include "base/logging.h" 24 #include "base/logging.h"
25 #include "base/pickle.h" 25 #include "base/pickle.h"
26 #include "base/posix/unix_domain_socket.h" 26 #include "base/posix/unix_domain_socket.h"
27 #include "content/common/set_process_title.h" 27 #include "content/common/set_process_title.h"
28 #include "content/common/sandbox_methods_linux.h" 28 #include "content/common/sandbox_linux.h"
29 #include "content/common/zygote_commands_linux.h" 29 #include "content/common/zygote_commands_linux.h"
30 #include "content/public/common/content_descriptors.h" 30 #include "content/public/common/content_descriptors.h"
31 #include "content/public/common/zygote_fork_delegate_linux.h" 31 #include "content/public/common/zygote_fork_delegate_linux.h"
32 32
33 #if defined(CHROMIUM_SELINUX) 33 #if defined(CHROMIUM_SELINUX)
34 #include <selinux/selinux.h> 34 #include <selinux/selinux.h>
35 #include <selinux/context.h> 35 #include <selinux/context.h>
36 #endif 36 #endif
37 37
38 // See http://code.google.com/p/chromium/wiki/LinuxZygote 38 // See http://code.google.com/p/chromium/wiki/LinuxZygote
(...skipping 22 matching lines...) Expand all
61 LOG(FATAL) << "dynamic transition to type '" << type << "' failed. " 61 LOG(FATAL) << "dynamic transition to type '" << type << "' failed. "
62 "(this binary has been built with SELinux support, but maybe " 62 "(this binary has been built with SELinux support, but maybe "
63 "the policies haven't been loaded into the kernel?)"; 63 "the policies haven't been loaded into the kernel?)";
64 } 64 }
65 } 65 }
66 #endif // CHROMIUM_SELINUX 66 #endif // CHROMIUM_SELINUX
67 67
68 } // namespace 68 } // namespace
69 69
70 Zygote::Zygote(int sandbox_flags, 70 Zygote::Zygote(int sandbox_flags,
71 ZygoteForkDelegate* helper, 71 ZygoteForkDelegate* helper)
72 int proc_fd_for_seccomp)
73 : sandbox_flags_(sandbox_flags), 72 : sandbox_flags_(sandbox_flags),
74 helper_(helper), 73 helper_(helper),
75 #if defined(SECCOMP_SANDBOX)
76 proc_fd_for_seccomp_(proc_fd_for_seccomp),
77 #endif
78 initial_uma_sample_(0), 74 initial_uma_sample_(0),
79 initial_uma_boundary_value_(0) { 75 initial_uma_boundary_value_(0) {
80 if (helper_) { 76 if (helper_) {
81 helper_->InitialUMA(&initial_uma_name_, 77 helper_->InitialUMA(&initial_uma_name_,
82 &initial_uma_sample_, 78 &initial_uma_sample_,
83 &initial_uma_boundary_value_); 79 &initial_uma_boundary_value_);
84 } 80 }
85 } 81 }
86 82
87 Zygote::~Zygote() { 83 Zygote::~Zygote() {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 412
417 mapping.push_back(std::make_pair( 413 mapping.push_back(std::make_pair(
418 static_cast<uint32_t>(kSandboxIPCChannel), kMagicSandboxIPCDescriptor)); 414 static_cast<uint32_t>(kSandboxIPCChannel), kMagicSandboxIPCDescriptor));
419 415
420 // Returns twice, once per process. 416 // Returns twice, once per process.
421 base::ProcessId child_pid = ForkWithRealPid(process_type, fds, channel_id, 417 base::ProcessId child_pid = ForkWithRealPid(process_type, fds, channel_id,
422 uma_name, uma_sample, 418 uma_name, uma_sample,
423 uma_boundary_value); 419 uma_boundary_value);
424 if (!child_pid) { 420 if (!child_pid) {
425 // This is the child process. 421 // This is the child process.
426 #if defined(SECCOMP_SANDBOX) 422
427 if (proc_fd_for_seccomp_ >= 0) { 423 // At this point, we finally know our process type.
428 if (process_type == switches::kRendererProcess && 424 LinuxSandbox::GetInstance()->PreinitializeSandboxFinish(process_type);
429 SeccompSandboxEnabled()) {
430 SeccompSandboxSetProcFd(proc_fd_for_seccomp_);
431 } else {
432 close(proc_fd_for_seccomp_);
433 }
434 proc_fd_for_seccomp_ = -1;
435 }
436 #endif
437 425
438 close(kBrowserDescriptor); // Our socket from the browser. 426 close(kBrowserDescriptor); // Our socket from the browser.
439 if (UsingSUIDSandbox()) 427 if (UsingSUIDSandbox())
440 close(kZygoteIdFd); // Another socket from the browser. 428 close(kZygoteIdFd); // Another socket from the browser.
441 base::GlobalDescriptors::GetInstance()->Reset(mapping); 429 base::GlobalDescriptors::GetInstance()->Reset(mapping);
442 430
443 #if defined(CHROMIUM_SELINUX) 431 #if defined(CHROMIUM_SELINUX)
444 SELinuxTransitionToTypeOrDie("chromium_renderer_t"); 432 SELinuxTransitionToTypeOrDie("chromium_renderer_t");
445 #endif 433 #endif
446 434
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 PickleIterator iter) { 491 PickleIterator iter) {
504 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != 492 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) !=
505 sizeof(sandbox_flags_)) { 493 sizeof(sandbox_flags_)) {
506 PLOG(ERROR) << "write"; 494 PLOG(ERROR) << "write";
507 } 495 }
508 496
509 return false; 497 return false;
510 } 498 }
511 499
512 } // namespace content 500 } // namespace content
OLDNEW
« no previous file with comments | « content/zygote/zygote_linux.h ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698