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

Side by Side Diff: sandbox/linux/services/namespace_sandbox.h

Issue 1158793003: Enable one PID namespace per process for NaCl processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 5 years, 6 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
« no previous file with comments | « sandbox/linux/services/credentials.cc ('k') | sandbox/linux/services/namespace_sandbox.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 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 20 matching lines...) Expand all
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) 40 #if !defined(OS_NACL_NONSFI)
41 static const int kDefaultExitCode = 1;
42
43 // Launch a new process inside its own user/PID/network namespaces (depending 41 // Launch a new process inside its own user/PID/network namespaces (depending
44 // on kernel support). Requires at a minimum that user namespaces are 42 // on kernel support). Requires at a minimum that user namespaces are
45 // supported (use Credentials::CanCreateProcessInNewUserNS to check this). 43 // supported (use Credentials::CanCreateProcessInNewUserNS to check this).
46 // 44 //
47 // pre_exec_delegate and clone_flags fields of LaunchOptions should be nullptr 45 // 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 46 // and 0, respectively, since this function makes a copy of options and
49 // overrides them. 47 // overrides them.
50 static base::Process LaunchProcess(const base::CommandLine& cmdline, 48 static base::Process LaunchProcess(const base::CommandLine& cmdline,
51 const base::LaunchOptions& options); 49 const base::LaunchOptions& options);
52 static base::Process LaunchProcess(const std::vector<std::string>& argv, 50 static base::Process LaunchProcess(const std::vector<std::string>& argv,
(...skipping 10 matching lines...) Expand all
63 // processes ignore such signals unless they have an explicit handler set. 61 // processes ignore such signals unless they have an explicit handler set.
64 // 62 //
65 // This function requries CAP_SYS_ADMIN. If |drop_capabilities_in_child| is 63 // This function requries CAP_SYS_ADMIN. If |drop_capabilities_in_child| is
66 // true, then capabilities are dropped in the child. 64 // true, then capabilities are dropped in the child.
67 static pid_t ForkInNewPidNamespace(bool drop_capabilities_in_child); 65 static pid_t ForkInNewPidNamespace(bool drop_capabilities_in_child);
68 66
69 // Installs a signal handler for: 67 // Installs a signal handler for:
70 // 68 //
71 // SIGHUP, SIGINT, SIGABRT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2 69 // SIGHUP, SIGINT, SIGABRT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
72 // 70 //
73 // that exits with kDefaultExitCode. These are signals whose default action is 71 // that exits with SignalExitCode(sig). These are signals whose default action
74 // to terminate the program (apart from SIGILL, SIGFPE, and SIGSEGV, which 72 // is to terminate the program (apart from SIGILL, SIGFPE, and SIGSEGV, which
75 // will still terminate the process if e.g. an illegal instruction is 73 // will still terminate the process if e.g. an illegal instruction is
76 // encountered, etc.). 74 // encountered, etc.).
77 // 75 //
78 // If any of these already had a signal handler installed, this function will 76 // If any of these already had a signal handler installed, this function will
79 // not override them. 77 // not override them.
80 static void InstallDefaultTerminationSignalHandlers(); 78 static void InstallDefaultTerminationSignalHandlers();
81 79
82 // Installs a signal handler for |sig| which exits with |exit_code|. If a 80 // 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 81 // signal handler was already present for |sig|, does nothing and returns
84 // false. 82 // false.
85 static bool InstallTerminationSignalHandler(int sig, int exit_code); 83 static bool InstallTerminationSignalHandler(int sig, int exit_code);
86 #endif // !defined(OS_NACL_NONSFI) 84 #endif // !defined(OS_NACL_NONSFI)
87 85
86 static inline int SignalExitCode(int sig) { return -sig & 0xff; }
jln (very slow on Chromium) 2015/06/09 21:18:10 Let's add a comment to describe this. Mention that
rickyz (no longer on Chrome) 2015/06/09 22:55:25 Done.
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_
OLDNEW
« no previous file with comments | « sandbox/linux/services/credentials.cc ('k') | sandbox/linux/services/namespace_sandbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698