Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS 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 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #ifndef DEBUGD_SRC_SANDBOXED_PROCESS_H_ |
| 6 | #define DEBUGD_SRC_SANDBOXED_PROCESS_H_ |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
Ricky Liang | 1ef73e5 | 2016-05-24 16:32:34 +0800 | [diff] [blame] | 9 | #include <vector> |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 10 | |
Alex Vakulenko | e769653 | 2015-10-16 16:27:29 -0700 | [diff] [blame] | 11 | #include <brillo/process.h> |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 12 | |
| 13 | namespace debugd { |
| 14 | |
Alex Vakulenko | e769653 | 2015-10-16 16:27:29 -0700 | [diff] [blame] | 15 | class SandboxedProcess : public brillo::ProcessImpl { |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 16 | public: |
| 17 | SandboxedProcess(); |
Eric Caruso | a6f1adb | 2017-05-24 14:19:46 -0700 | [diff] [blame] | 18 | ~SandboxedProcess() override = default; |
Ben Chan | 297c3c2 | 2013-07-17 17:34:12 -0700 | [diff] [blame] | 19 | |
| 20 | // Get the full path of a helper executable located at the |relative_path| |
| 21 | // relative to the debugd helpers directory. Return false if the full path |
| 22 | // is too long. |
| 23 | static bool GetHelperPath(const std::string& relative_path, |
| 24 | std::string* full_path); |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 25 | |
| 26 | virtual bool Init(); |
| 27 | |
Jorge Lucangeli Obes | c99a12a | 2014-09-17 16:43:40 -0700 | [diff] [blame] | 28 | // Disable the default sandboxing for this process. |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 29 | virtual void DisableSandbox(); |
| 30 | |
Jorge Lucangeli Obes | c99a12a | 2014-09-17 16:43:40 -0700 | [diff] [blame] | 31 | // Change the default sandboxing for this process. |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 32 | virtual void SandboxAs(const std::string& user, const std::string& group); |
| 33 | |
Justin Carlson | 73310fb | 2016-10-11 16:13:26 -0700 | [diff] [blame] | 34 | // Set a file to be used as the seccomp bpf file for this process. See |
| 35 | // minijail0 -S for details of what can be in this file. |
| 36 | virtual void SetSeccompFilterPolicyFile(const std::string& path); |
| 37 | |
Jorge Lucangeli Obes | c99a12a | 2014-09-17 16:43:40 -0700 | [diff] [blame] | 38 | // Allow this process to access the root mount namespace. |
| 39 | virtual void AllowAccessRootMountNamespace(); |
| 40 | |
Jorge Lucangeli Obes | 389a9ee | 2015-05-14 17:37:01 -0700 | [diff] [blame] | 41 | // Kill the sandboxed process' process group. |
| 42 | virtual bool KillProcessGroup(); |
| 43 | |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 44 | static const char kDefaultUser[]; |
| 45 | static const char kDefaultGroup[]; |
Elly Fong-Jones | 215b562 | 2013-03-20 14:32:18 -0400 | [diff] [blame] | 46 | |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 47 | private: |
| 48 | bool sandboxing_; |
Jorge Lucangeli Obes | c99a12a | 2014-09-17 16:43:40 -0700 | [diff] [blame] | 49 | bool access_root_mount_ns_; |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 50 | std::string user_; |
| 51 | std::string group_; |
Justin Carlson | 73310fb | 2016-10-11 16:13:26 -0700 | [diff] [blame] | 52 | std::string seccomp_filter_policy_file_; |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 55 | } // namespace debugd |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 56 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 57 | #endif // DEBUGD_SRC_SANDBOXED_PROCESS_H_ |