Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
hidehiko
2015/02/04 15:40:05
nit: 2015 for added files?
mdempsky
2015/02/05 03:02:08
Done.
| |
| 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_SUID_SETUID_SANDBOX_CLIENT_H_ | 5 #ifndef SANDBOX_LINUX_SUID_SETUID_SANDBOX_HOST_H_ |
| 6 #define SANDBOX_LINUX_SUID_SETUID_SANDBOX_CLIENT_H_ | 6 #define SANDBOX_LINUX_SUID_SETUID_SANDBOX_HOST_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "base/environment.h" | |
| 11 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
| 13 #include "base/process/launch.h" | 11 #include "base/process/launch.h" |
| 14 #include "sandbox/sandbox_export.h" | 12 #include "sandbox/sandbox_export.h" |
| 15 | 13 |
| 16 namespace sandbox { | 14 namespace sandbox { |
| 17 | 15 |
| 18 // Helper class to use the setuid sandbox. This class is to be used both | 16 // Helper class to use the setuid sandbox. This class is to be used |
| 19 // before launching the setuid helper and after being executed through the | 17 // before launching the setuid helper. |
| 20 // setuid helper. | |
| 21 // This class is difficult to use. It has been created by refactoring very old | 18 // This class is difficult to use. It has been created by refactoring very old |
| 22 // code scathered through the Chromium code base. | 19 // code scathered through the Chromium code base. |
| 23 // | 20 // |
| 24 // A typical use for "A" launching a sandboxed process "B" would be: | 21 // A typical use for "A" launching a sandboxed process "B" would be: |
| 25 // 1. A calls SetupLaunchEnvironment() | 22 // 1. A calls SetupLaunchEnvironment() |
| 26 // 2. A sets up a CommandLine and then amends it with | 23 // 2. A sets up a CommandLine and then amends it with |
| 27 // PrependWrapper() (or manually, by relying on GetSandboxBinaryPath()). | 24 // PrependWrapper() (or manually, by relying on GetSandboxBinaryPath()). |
| 28 // 3. A uses SetupLaunchOptions() to arrange for a dummy descriptor for the | 25 // 3. A uses SetupLaunchOptions() to arrange for a dummy descriptor for the |
| 29 // setuid sandbox ABI. | 26 // setuid sandbox ABI. |
| 30 // 4. A launches B with base::LaunchProcess, using the amended CommandLine. | 27 // 4. A launches B with base::LaunchProcess, using the amended CommandLine. |
|
hidehiko
2015/02/04 15:40:05
nit: maybe base::CommandLine, to be consistent wit
mdempsky
2015/02/05 03:02:08
Done.
| |
| 31 // 5. B uses CloseDummyFile() to close the dummy file descriptor. | 28 // (The remaining steps are described within setuid_sandbox_client.h.) |
| 32 // 6. B performs various initializations that require access to the file | 29 class SANDBOX_EXPORT SetuidSandboxHost { |
| 33 // system. | |
| 34 // 6.b (optional) B uses sandbox::Credentials::HasOpenDirectory() to verify | |
| 35 // that no directory is kept open (which would allow bypassing the setuid | |
| 36 // sandbox). | |
| 37 // 7. B should be prepared to assume the role of init(1). In particular, B | |
| 38 // cannot receive any signal from any other process, excluding SIGKILL. | |
| 39 // If B dies, all the processes in the namespace will die. | |
| 40 // B can fork() and the parent can assume the role of init(1), by using | |
| 41 // CreateInitProcessReaper(). | |
| 42 // 8. B requests being chroot-ed through ChrootMe() and | |
| 43 // requests other sandboxing status via the status functions. | |
| 44 class SANDBOX_EXPORT SetuidSandboxClient { | |
| 45 public: | 30 public: |
| 46 // All instantation should go through this factory method. | 31 // All instantation should go through this factory method. |
| 47 static class SetuidSandboxClient* Create(); | 32 static SetuidSandboxHost* Create(); |
| 48 ~SetuidSandboxClient(); | 33 ~SetuidSandboxHost(); |
| 49 | |
| 50 // Close the dummy file descriptor leftover from the sandbox ABI. | |
| 51 void CloseDummyFile(); | |
| 52 // Ask the setuid helper over the setuid sandbox IPC channel to chroot() us | |
| 53 // to an empty directory. | |
| 54 // Will only work if we have been launched through the setuid helper. | |
| 55 bool ChrootMe(); | |
| 56 | |
| 57 // Did we get launched through an up to date setuid binary ? | |
| 58 bool IsSuidSandboxUpToDate() const; | |
| 59 // Did we get launched through the setuid helper ? | |
| 60 bool IsSuidSandboxChild() const; | |
| 61 // Did the setuid helper create a new PID namespace ? | |
| 62 bool IsInNewPIDNamespace() const; | |
| 63 // Did the setuid helper create a new network namespace ? | |
| 64 bool IsInNewNETNamespace() const; | |
| 65 // Are we done and fully sandboxed ? | |
| 66 bool IsSandboxed() const; | |
| 67 | 34 |
| 68 // The setuid sandbox may still be disabled via the environment. | 35 // The setuid sandbox may still be disabled via the environment. |
| 69 // This is tracked in crbug.com/245376. | 36 // This is tracked in crbug.com/245376. |
| 70 bool IsDisabledViaEnvironment(); | 37 bool IsDisabledViaEnvironment(); |
| 71 // Get the sandbox binary path. This method knows about the | 38 // Get the sandbox binary path. This method knows about the |
| 72 // CHROME_DEVEL_SANDBOX environment variable used for user-managed builds. If | 39 // CHROME_DEVEL_SANDBOX environment variable used for user-managed builds. If |
| 73 // the sandbox binary cannot be found, it will return an empty FilePath. | 40 // the sandbox binary cannot be found, it will return an empty FilePath. |
| 74 base::FilePath GetSandboxBinaryPath(); | 41 base::FilePath GetSandboxBinaryPath(); |
| 75 // Modify |cmd_line| to launch via the setuid sandbox. Crash if the setuid | 42 // Modify |cmd_line| to launch via the setuid sandbox. Crash if the setuid |
| 76 // sandbox binary cannot be found. |cmd_line| must not be NULL. | 43 // sandbox binary cannot be found. |cmd_line| must not be NULL. |
| 77 void PrependWrapper(base::CommandLine* cmd_line); | 44 void PrependWrapper(base::CommandLine* cmd_line); |
| 78 // Set-up the launch options for launching via the setuid sandbox. Caller is | 45 // Set-up the launch options for launching via the setuid sandbox. Caller is |
| 79 // responsible for keeping |dummy_fd| alive until LaunchProcess() completes. | 46 // responsible for keeping |dummy_fd| alive until LaunchProcess() completes. |
| 80 // |options| and |fds_to_remap| must not be NULL. | 47 // |options| and |fds_to_remap| must not be NULL. |
| 81 // (Keeping |dummy_fd| alive is an unfortunate historical artifact of the | 48 // (Keeping |dummy_fd| alive is an unfortunate historical artifact of the |
| 82 // chrome-sandbox ABI.) | 49 // chrome-sandbox ABI.) |
| 83 void SetupLaunchOptions(base::LaunchOptions* options, | 50 void SetupLaunchOptions(base::LaunchOptions* options, |
| 84 base::FileHandleMappingVector* fds_to_remap, | 51 base::FileHandleMappingVector* fds_to_remap, |
| 85 base::ScopedFD* dummy_fd); | 52 base::ScopedFD* dummy_fd); |
| 86 // Set-up the environment. This should be done prior to launching the setuid | 53 // Set-up the environment. This should be done prior to launching the setuid |
| 87 // helper. | 54 // helper. |
| 88 void SetupLaunchEnvironment(); | 55 void SetupLaunchEnvironment(); |
| 89 | 56 |
| 90 private: | 57 private: |
| 91 SetuidSandboxClient(); | 58 SetuidSandboxHost(); |
| 92 | 59 |
| 93 // Holds the environment. Will never be NULL. | 60 // Holds the environment. Will never be NULL. |
| 94 base::Environment* env_; | 61 base::Environment* env_; |
| 95 bool sandboxed_; | |
| 96 | 62 |
| 97 DISALLOW_COPY_AND_ASSIGN(SetuidSandboxClient); | 63 DISALLOW_COPY_AND_ASSIGN(SetuidSandboxHost); |
| 98 }; | 64 }; |
| 99 | 65 |
| 100 } // namespace sandbox | 66 } // namespace sandbox |
| 101 | 67 |
| 102 #endif // SANDBOX_LINUX_SUID_SETUID_SANDBOX_CLIENT_H_ | 68 #endif // SANDBOX_LINUX_SUID_SETUID_SANDBOX_HOST_H_ |
| OLD | NEW |