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

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

Issue 868233011: Start all children in their own PID namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to some comments. Created 5 years, 9 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
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>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/process/launch.h" 15 #include "base/process/launch.h"
14 #include "base/process/process.h" 16 #include "base/process/process.h"
15 #include "sandbox/sandbox_export.h" 17 #include "sandbox/sandbox_export.h"
16 18
17 namespace sandbox { 19 namespace sandbox {
(...skipping 22 matching lines...) Expand all
40 // supported (use Credentials::CanCreateProcessInNewUserNS to check this). 42 // supported (use Credentials::CanCreateProcessInNewUserNS to check this).
41 // 43 //
42 // pre_exec_delegate and clone_flags fields of LaunchOptions should be nullptr 44 // pre_exec_delegate and clone_flags fields of LaunchOptions should be nullptr
43 // and 0, respectively, since this function makes a copy of options and 45 // and 0, respectively, since this function makes a copy of options and
44 // overrides them. 46 // overrides them.
45 static base::Process LaunchProcess(const base::CommandLine& cmdline, 47 static base::Process LaunchProcess(const base::CommandLine& cmdline,
46 const base::LaunchOptions& options); 48 const base::LaunchOptions& options);
47 static base::Process LaunchProcess(const std::vector<std::string>& argv, 49 static base::Process LaunchProcess(const std::vector<std::string>& argv,
48 const base::LaunchOptions& options); 50 const base::LaunchOptions& options);
49 51
52 // Forks a process in its own PID namespace. The child process is the init
53 // process inside of the PID namespace, so if the child needs to fork further,
54 // it should call CreateInitProcessReaper, which turns the init process into a
55 // reaper process.
56 //
57 // If the child does not call CreateInitProcessReaper, then there are some
58 // special considerations to be made for the fact that it is an init process
59 // in a PID namespace.
60 //
61 // Aside from SIGKILL and SIGSTOP, the init process in a PID namespace ignores
62 // signals for which it does not have an explicit signal handler. The child
63 // may call InstallTerminationSignalHandler to setup handlers for these
64 // signals that exit with a specific exit code. For most purposes, handlers
65 // should be installed for at least these signals:
66 //
67 // SIGHUP, SIGINT, SIGABRT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
68 //
69 // This function requries CAP_SYS_ADMIN. Callers are responsible for dropping
70 // capabilities in the child if desired.
71 static pid_t ForkInNewPidNamespace();
72
73 // Installs a signal handler for |sig| which exits with |exit_code|.
74 static void InstallTerminationSignalHandler(int sig, int exit_code);
jln (very slow on Chromium) 2015/03/24 22:03:34 I would like to make this API really easy to use f
jln (very slow on Chromium) 2015/03/24 22:57:40 Meh: we still need to support a separate InstallTe
rickyz (no longer on Chrome) 2015/03/25 22:47:46 Any opinions on whether this should take a map or
jln (very slow on Chromium) 2015/03/25 23:47:50 I was thinking this should take two arguments: a d
75
50 // Returns whether the namespace sandbox created a new user, PID, and network 76 // Returns whether the namespace sandbox created a new user, PID, and network
51 // namespace. In particular, InNewUserNamespace should return true iff the 77 // namespace. In particular, InNewUserNamespace should return true iff the
52 // process was started via this class. 78 // process was started via this class.
53 static bool InNewUserNamespace(); 79 static bool InNewUserNamespace();
54 static bool InNewPidNamespace(); 80 static bool InNewPidNamespace();
55 static bool InNewNetNamespace(); 81 static bool InNewNetNamespace();
56 82
57 private: 83 private:
58 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox); 84 DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox);
59 }; 85 };
60 86
61 } // namespace sandbox 87 } // namespace sandbox
62 88
63 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ 89 #endif // SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698