OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
| 6 #define SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
| 7 |
| 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/process/launch.h" |
| 11 #include "base/process/process.h" |
| 12 #include "sandbox/sandbox_export.h" |
| 13 |
| 14 namespace sandbox { |
| 15 |
| 16 // Helper class for starting a process inside a new user, PID, and network |
| 17 // namespace. Before using a namespace sandbox, check for namespaces support |
| 18 // using Credentials::CanCreateProcessInNewUserNS. |
| 19 // |
| 20 // A typical use for "A" launching a sandboxed process "B" would be: |
| 21 // 1. A sets up a command line and launch options for process B. |
| 22 // 2. A launches B with LaunchProcess. |
| 23 // 3. B should be prepared to assume the role of init(1). In particular, apart |
| 24 // from SIGKILL and SIGSTOP, B cannot receive any signal for which it does |
| 25 // not have an explicit signal handler registered. |
| 26 // If B dies, all the processes in the namespace will die. |
| 27 // B can fork() and the parent can assume the role of init(1), by using |
| 28 // CreateInitProcessReaper(). |
| 29 // 4. B chroots using Credentials::MoveToNewUserNS() and |
| 30 // Credentials::DropFileSystemAccess() |
| 31 // 5. B drops capabilities gained by entering the new user namespace with |
| 32 // Credentials::DropAllCapabilities(). |
| 33 class SANDBOX_EXPORT NamespaceSandbox { |
| 34 public: |
| 35 // Launch a new process inside its own user/PID/network namespaces (depending |
| 36 // on kernel support). Requires at a minimum that user namespaces are |
| 37 // supported (use Credentials::CanCreateProcessInNewUserNS to check this). |
| 38 // |
| 39 // pre_exec_delegate and clone_flags fields of LaunchOptions should be nullptr |
| 40 // and 0, respectively, since this function makes a copy of options and |
| 41 // overrides them. |
| 42 static base::Process LaunchProcess(const base::CommandLine& cmdline, |
| 43 const base::LaunchOptions& options); |
| 44 |
| 45 // Returns whether the namespace sandbox created a new user, PID, and network |
| 46 // namespace. In particular, InNewUserNamespace should return true iff the |
| 47 // process was started via this class. |
| 48 static bool InNewUserNamespace(); |
| 49 static bool InNewPidNamespace(); |
| 50 static bool InNewNetNamespace(); |
| 51 |
| 52 private: |
| 53 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox); |
| 54 }; |
| 55 |
| 56 } // namespace sandbox |
| 57 |
| 58 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
OLD | NEW |