Skip to content

Commit

Permalink
Break dependence of zygote_linux.cc on common_sandbox_support_linux.h
Browse files Browse the repository at this point in the history
Content's zygote_main should be responsible for communicating an
additional argument as required to keep zygote_linux.h ignorant.

Change-Id: I475f0eee5c200f536154c4f847b39d731d0e77f1
Reviewed-on: https://chromium-review.googlesource.com/862612
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#529929}
  • Loading branch information
tsepez authored and Commit Bot committed Jan 17, 2018
1 parent 7b59d47 commit 0c58331
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
13 changes: 6 additions & 7 deletions content/zygote/zygote_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "content/common/zygote_commands_linux.h"
#include "content/public/common/common_sandbox_support_linux.h"
#include "content/public/common/content_descriptors.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/mojo_channel_switches.h"
Expand Down Expand Up @@ -95,16 +94,17 @@ void KillAndReap(pid_t pid, ZygoteForkDelegate* helper) {
Zygote::Zygote(int sandbox_flags,
std::vector<std::unique_ptr<ZygoteForkDelegate>> helpers,
const std::vector<base::ProcessHandle>& extra_children,
const std::vector<int>& extra_fds)
const std::vector<int>& extra_fds,
const base::GlobalDescriptors::Descriptor& ipc_backchannel)
: sandbox_flags_(sandbox_flags),
helpers_(std::move(helpers)),
initial_uma_index_(0),
extra_children_(extra_children),
extra_fds_(extra_fds),
to_reap_() {}
to_reap_(),
ipc_backchannel_(ipc_backchannel) {}

Zygote::~Zygote() {
}
Zygote::~Zygote() {}

bool Zygote::ProcessRequests() {
// A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the
Expand Down Expand Up @@ -610,8 +610,7 @@ base::ProcessId Zygote::ReadArgsAndFork(base::PickleIterator iter,
mapping.push_back(base::GlobalDescriptors::Descriptor(key, fds[i].get()));
}

mapping.push_back(base::GlobalDescriptors::Descriptor(
static_cast<uint32_t>(kSandboxIPCChannel), GetSandboxFD()));
mapping.push_back(ipc_backchannel_);

// Returns twice, once per process.
base::ProcessId child_pid =
Expand Down
7 changes: 6 additions & 1 deletion content/zygote/zygote_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Zygote {
Zygote(int sandbox_flags,
std::vector<std::unique_ptr<ZygoteForkDelegate>> helpers,
const std::vector<base::ProcessHandle>& extra_children,
const std::vector<int>& extra_fds);
const std::vector<int>& extra_fds,
const base::GlobalDescriptors::Descriptor& ipc_backchannel);
~Zygote();

bool ProcessRequests();
Expand Down Expand Up @@ -153,6 +154,10 @@ class Zygote {

// The vector contains the child processes that need to be reaped.
std::vector<ZygoteProcessInfo> to_reap_;

// Sandbox IPC channel for renderers to invoke services from the browser. See
// https://chromium.googlesource.com/chromium/src/+/master/docs/linux_sandbox_ipc.md
base::GlobalDescriptors::Descriptor ipc_backchannel_;
};

} // namespace content
Expand Down
6 changes: 5 additions & 1 deletion content/zygote/zygote_main_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "content/common/font_config_ipc_linux.h"
#include "content/common/zygote_commands_linux.h"
#include "content/public/common/common_sandbox_support_linux.h"
#include "content/public/common/content_descriptors.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/zygote_fork_delegate_linux.h"
Expand Down Expand Up @@ -633,7 +634,10 @@ bool ZygoteMain(
CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged);

Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children,
extra_fds);
extra_fds,
base::GlobalDescriptors::Descriptor(
static_cast<uint32_t>(kSandboxIPCChannel), GetSandboxFD()));

// This function call can return multiple times, once per fork().
return zygote.ProcessRequests();
}
Expand Down

0 comments on commit 0c58331

Please sign in to comment.