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

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: Enable PID namespace per process for nonsfi newlib NaCl as well. 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 19 matching lines...) Expand all
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 static const int kDefaultExitCode = 1;
41
42 #if !defined(OS_NACL_NONSFI) 40 #if !defined(OS_NACL_NONSFI)
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);
(...skipping 12 matching lines...) Expand all
64 // processes ignore such signals unless they have an explicit handler set. 62 // processes ignore such signals unless they have an explicit handler set.
65 // 63 //
66 // This function requries CAP_SYS_ADMIN. If |drop_capabilities_in_child| is 64 // This function requries CAP_SYS_ADMIN. If |drop_capabilities_in_child| is
67 // true, then capabilities are dropped in the child. 65 // true, then capabilities are dropped in the child.
68 static pid_t ForkInNewPidNamespace(bool drop_capabilities_in_child); 66 static pid_t ForkInNewPidNamespace(bool drop_capabilities_in_child);
69 67
70 // Installs a signal handler for: 68 // Installs a signal handler for:
71 // 69 //
72 // SIGHUP, SIGINT, SIGABRT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2 70 // SIGHUP, SIGINT, SIGABRT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
73 // 71 //
74 // that exits with kDefaultExitCode. These are signals whose default action is 72 // that exits with SignalExitCode(sig). These are signals whose default action
75 // to terminate the program (apart from SIGILL, SIGFPE, and SIGSEGV, which 73 // is to terminate the program (apart from SIGILL, SIGFPE, and SIGSEGV, which
76 // will still terminate the process if e.g. an illegal instruction is 74 // will still terminate the process if e.g. an illegal instruction is
77 // encountered, etc.). 75 // encountered, etc.).
78 // 76 //
79 // If any of these already had a signal handler installed, this function will 77 // If any of these already had a signal handler installed, this function will
80 // not override them. 78 // not override them.
81 static void InstallDefaultTerminationSignalHandlers(); 79 static void InstallDefaultTerminationSignalHandlers();
82 80
83 // Installs a signal handler for |sig| which exits with |exit_code|. If a 81 // Installs a signal handler for |sig| which exits with |exit_code|. If a
84 // signal handler was already present for |sig|, does nothing and returns 82 // signal handler was already present for |sig|, does nothing and returns
85 // false. 83 // false.
86 static bool InstallTerminationSignalHandler(int sig, int exit_code); 84 static bool InstallTerminationSignalHandler(int sig, int exit_code);
87 85
86 // Returns an exit code corresponding to the process being killed by sig. This
87 // is the same as exit code that NaCl's default signal handler uses.
88 static int SignalExitCode(int sig) { return -sig & 0xff; }
89
88 // Returns whether the namespace sandbox created a new user, PID, and network 90 // Returns whether the namespace sandbox created a new user, PID, and network
89 // namespace. In particular, InNewUserNamespace should return true iff the 91 // namespace. In particular, InNewUserNamespace should return true iff the
90 // process was started via this class. 92 // process was started via this class.
91 static bool InNewUserNamespace(); 93 static bool InNewUserNamespace();
92 static bool InNewPidNamespace(); 94 static bool InNewPidNamespace();
93 static bool InNewNetNamespace(); 95 static bool InNewNetNamespace();
94 96
95 private: 97 private:
96 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox); 98 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox);
97 }; 99 };
98 100
99 } // namespace sandbox 101 } // namespace sandbox
100 102
101 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ 103 #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