| Index: sandbox/linux/services/namespace_sandbox.h
|
| diff --git a/sandbox/linux/services/namespace_sandbox.h b/sandbox/linux/services/namespace_sandbox.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d08ac1149e4d795127e3a4da8a86dfb8f858cb34
|
| --- /dev/null
|
| +++ b/sandbox/linux/services/namespace_sandbox.h
|
| @@ -0,0 +1,77 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_
|
| +#define SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_
|
| +
|
| +#include "base/files/scoped_file.h"
|
| +#include "base/process/launch.h"
|
| +#include "base/process/process_handle.h"
|
| +#include "sandbox/sandbox_export.h"
|
| +
|
| +namespace sandbox {
|
| +
|
| +// Helper class for starting a process inside a new user, PID, and network
|
| +// namespace. The expected usage looks like:
|
| +//
|
| +// A typical use for "A" launching a sandboxed process "B" would be:
|
| +// 1. A sets up a command line for process B.
|
| +// 2. A calls SetupLaunchOptions which sets up the a pipe for communicating with
|
| +// the child.
|
| +// 3. A launches B with base::LaunchProcess.
|
| +// 4. A calls PrepareSandboxedProcess, at which point B begins running.
|
| +// 5. B should be prepared to assume the role of init(1). In particular, apart
|
| +// from SIGKILL and SIGSTOP, B cannot receive any signal for which it does
|
| +// not have an explicit signal handler registered.
|
| +// If B dies, all the processes in the namespace will die.
|
| +// B can fork() and the parent can assume the role of init(1), by using
|
| +// CreateInitProcessReaper().
|
| +// 6. B chroots using Credentials::MoveToNewUserNS() and
|
| +// Credentials::DropFileSystemAccess().
|
| +//
|
| +// An instance of this class may only be used once.
|
| +class SANDBOX_EXPORT NamespaceSandbox {
|
| + public:
|
| + NamespaceSandbox();
|
| + ~NamespaceSandbox();
|
| +
|
| + // Setup the launch options for the sandboxed process. The caller is
|
| + // responsible for setting options->fds_to_remap = fds_to_remap.
|
| + void SetupLaunchOptions(base::LaunchOptions* options,
|
| + base::FileHandleMappingVector* fds_to_remap);
|
| +
|
| + // Prepares the child process before it execs the new program. This adds an
|
| + // identity mapping for the uid and gid inside the user namespace, then
|
| + // signals the child to exec the new program.
|
| + void PrepareSandboxedProcess(base::ProcessId pid);
|
| +
|
| + // Returns whether the namespace sandbox created a new user, PID, and network
|
| + // namespace. In particular, InNewUserNamespace should return true iff the
|
| + // process was started via this class.
|
| + static bool InNewUserNamespace();
|
| + static bool InNewPidNamespace();
|
| + static bool InNewNetNamespace();
|
| +
|
| + private:
|
| + class ReadFromPipeDelegate : public base::LaunchOptions::PreExecDelegate {
|
| + public:
|
| + ReadFromPipeDelegate();
|
| + ~ReadFromPipeDelegate() override;
|
| + void RunAsyncSafe() override;
|
| + void set_fd(int fd);
|
| +
|
| + private:
|
| + int fd_;
|
| + DISALLOW_COPY_AND_ASSIGN(ReadFromPipeDelegate);
|
| + };
|
| + // Pipe fds used to communicate with the child process.
|
| + base::ScopedFD read_fd_;
|
| + base::ScopedFD write_fd_;
|
| +
|
| + ReadFromPipeDelegate read_from_pipe_delegate_;
|
| +};
|
| +
|
| +} // namespace sandbox
|
| +
|
| +#endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_
|
|
|