OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ | 5 #ifndef SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
6 #define SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ | 6 #define SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
7 | 7 |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 19 matching lines...) Expand all Loading... |
30 // not have an explicit signal handler registered. | 30 // not have an explicit signal handler registered. |
31 // If B dies, all the processes in the namespace will die. | 31 // If B dies, all the processes in the namespace will die. |
32 // B can fork() and the parent can assume the role of init(1), by using | 32 // B can fork() and the parent can assume the role of init(1), by using |
33 // CreateInitProcessReaper(). | 33 // CreateInitProcessReaper(). |
34 // 4. B chroots using Credentials::MoveToNewUserNS() and | 34 // 4. B chroots using Credentials::MoveToNewUserNS() and |
35 // Credentials::DropFileSystemAccess() | 35 // Credentials::DropFileSystemAccess() |
36 // 5. B drops capabilities gained by entering the new user namespace with | 36 // 5. B drops capabilities gained by entering the new user namespace with |
37 // Credentials::DropAllCapabilities(). | 37 // Credentials::DropAllCapabilities(). |
38 class SANDBOX_EXPORT NamespaceSandbox { | 38 class SANDBOX_EXPORT NamespaceSandbox { |
39 public: | 39 public: |
40 #if !defined(OS_NACL_NONSFI) | |
41 static const int kDefaultExitCode = 1; | 40 static const int kDefaultExitCode = 1; |
42 | 41 |
| 42 #if !defined(OS_NACL_NONSFI) |
43 // Launch a new process inside its own user/PID/network namespaces (depending | 43 // Launch a new process inside its own user/PID/network namespaces (depending |
44 // on kernel support). Requires at a minimum that user namespaces are | 44 // on kernel support). Requires at a minimum that user namespaces are |
45 // supported (use Credentials::CanCreateProcessInNewUserNS to check this). | 45 // supported (use Credentials::CanCreateProcessInNewUserNS to check this). |
46 // | 46 // |
47 // pre_exec_delegate and clone_flags fields of LaunchOptions should be nullptr | 47 // pre_exec_delegate and clone_flags fields of LaunchOptions should be nullptr |
48 // and 0, respectively, since this function makes a copy of options and | 48 // and 0, respectively, since this function makes a copy of options and |
49 // overrides them. | 49 // overrides them. |
50 static base::Process LaunchProcess(const base::CommandLine& cmdline, | 50 static base::Process LaunchProcess(const base::CommandLine& cmdline, |
51 const base::LaunchOptions& options); | 51 const base::LaunchOptions& options); |
52 static base::Process LaunchProcess(const std::vector<std::string>& argv, | 52 static base::Process LaunchProcess(const std::vector<std::string>& argv, |
53 const base::LaunchOptions& options); | 53 const base::LaunchOptions& options); |
| 54 #endif // !defined(OS_NACL_NONSFI) |
54 | 55 |
55 // Forks a process in its own PID namespace. The child process is the init | 56 // Forks a process in its own PID namespace. The child process is the init |
56 // process inside of the PID namespace, so if the child needs to fork further, | 57 // process inside of the PID namespace, so if the child needs to fork further, |
57 // it should call CreateInitProcessReaper, which turns the init process into a | 58 // it should call CreateInitProcessReaper, which turns the init process into a |
58 // reaper process. | 59 // reaper process. |
59 // | 60 // |
60 // Otherwise, the child should setup handlers for signals which should | 61 // Otherwise, the child should setup handlers for signals which should |
61 // terminate the process using InstallDefaultTerminationSignalHandlers or | 62 // terminate the process using InstallDefaultTerminationSignalHandlers or |
62 // InstallTerminationSignalHandler. This works around the fact that init | 63 // InstallTerminationSignalHandler. This works around the fact that init |
63 // processes ignore such signals unless they have an explicit handler set. | 64 // processes ignore such signals unless they have an explicit handler set. |
(...skipping 12 matching lines...) Expand all Loading... |
76 // encountered, etc.). | 77 // encountered, etc.). |
77 // | 78 // |
78 // If any of these already had a signal handler installed, this function will | 79 // If any of these already had a signal handler installed, this function will |
79 // not override them. | 80 // not override them. |
80 static void InstallDefaultTerminationSignalHandlers(); | 81 static void InstallDefaultTerminationSignalHandlers(); |
81 | 82 |
82 // Installs a signal handler for |sig| which exits with |exit_code|. If a | 83 // Installs a signal handler for |sig| which exits with |exit_code|. If a |
83 // signal handler was already present for |sig|, does nothing and returns | 84 // signal handler was already present for |sig|, does nothing and returns |
84 // false. | 85 // false. |
85 static bool InstallTerminationSignalHandler(int sig, int exit_code); | 86 static bool InstallTerminationSignalHandler(int sig, int exit_code); |
86 #endif // !defined(OS_NACL_NONSFI) | |
87 | 87 |
88 // Returns whether the namespace sandbox created a new user, PID, and network | 88 // Returns whether the namespace sandbox created a new user, PID, and network |
89 // namespace. In particular, InNewUserNamespace should return true iff the | 89 // namespace. In particular, InNewUserNamespace should return true iff the |
90 // process was started via this class. | 90 // process was started via this class. |
91 static bool InNewUserNamespace(); | 91 static bool InNewUserNamespace(); |
92 static bool InNewPidNamespace(); | 92 static bool InNewPidNamespace(); |
93 static bool InNewNetNamespace(); | 93 static bool InNewNetNamespace(); |
94 | 94 |
95 private: | 95 private: |
96 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox); | 96 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox); |
97 }; | 97 }; |
98 | 98 |
99 } // namespace sandbox | 99 } // namespace sandbox |
100 | 100 |
101 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ | 101 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
OLD | NEW |