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. |
| 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 CONTENT_COMMON_SANDBOX_LINUX_H_ | 5 #ifndef CONTENT_COMMON_SANDBOX_LINUX_H_ |
| 6 #define CONTENT_COMMON_SANDBOX_LINUX_H_ | 6 #define CONTENT_COMMON_SANDBOX_LINUX_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 8 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/public/common/sandbox_linux.h" | 12 #include "content/public/common/sandbox_linux.h" |
| 10 | 13 |
| 11 // TODO(jln) move this somewhere else. | |
| 12 #if defined(__i386__) || defined(__x86_64__) | |
| 13 #define SECCOMP_BPF_SANDBOX | |
| 14 #endif | |
| 15 | |
| 16 template <typename T> struct DefaultSingletonTraits; | 14 template <typename T> struct DefaultSingletonTraits; |
| 17 namespace sandbox { class SetuidSandboxClient; } | 15 namespace sandbox { class SetuidSandboxClient; } |
| 18 | 16 |
| 19 namespace content { | 17 namespace content { |
| 20 | 18 |
| 21 // A singleton class to represent and change our sandboxing state for the | 19 // A singleton class to represent and change our sandboxing state for the |
| 22 // three main Linux sandboxes. | 20 // three main Linux sandboxes. |
| 23 class LinuxSandbox { | 21 class LinuxSandbox { |
| 24 public: | 22 public: |
| 25 // This is a list of sandbox IPC methods which the renderer may send to the | 23 // This is a list of sandbox IPC methods which the renderer may send to the |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 53 // These should be called together. | 51 // These should be called together. |
| 54 void PreinitializeSandboxBegin(); | 52 void PreinitializeSandboxBegin(); |
| 55 void PreinitializeSandboxFinish(const std::string& process_type); | 53 void PreinitializeSandboxFinish(const std::string& process_type); |
| 56 | 54 |
| 57 // Returns the Status of the sandbox. Can only be queried if we went through | 55 // Returns the Status of the sandbox. Can only be queried if we went through |
| 58 // PreinitializeSandbox() or PreinitializeSandboxBegin(). This is a bitmask | 56 // PreinitializeSandbox() or PreinitializeSandboxBegin(). This is a bitmask |
| 59 // and uses the constants defined in "enum LinuxSandboxStatus". | 57 // and uses the constants defined in "enum LinuxSandboxStatus". |
| 60 // Since we need to provide the status before the sandboxes are actually | 58 // Since we need to provide the status before the sandboxes are actually |
| 61 // started, this returns what will actually happen once the various Start* | 59 // started, this returns what will actually happen once the various Start* |
| 62 // functions are called from inside a renderer. | 60 // functions are called from inside a renderer. |
| 63 int GetStatus(); | 61 int GetStatus() const; |
| 62 // Is the current process single threaded ? | |
| 63 bool IsSingleThreaded() const; | |
| 64 | 64 |
| 65 // Simple accessor for our instance of the setuid sandbox. Will never return | 65 // Simple accessor for our instance of the setuid sandbox. Will never return |
| 66 // NULL. | 66 // NULL. |
| 67 // There is no StartSetuidSandbox(), the SetuidSandboxClient instance should | 67 // There is no StartSetuidSandbox(), the SetuidSandboxClient instance should |
| 68 // be used directly. | 68 // be used directly. |
| 69 sandbox::SetuidSandboxClient* setuid_sandbox_client() const; | 69 sandbox::SetuidSandboxClient* setuid_sandbox_client() const; |
| 70 | 70 |
| 71 // Check the policy and eventually start the seccomp-legacy sandbox. | 71 // Check the policy and eventually start the seccomp-legacy sandbox. |
| 72 bool StartSeccompLegacy(const std::string& process_type); | 72 bool StartSeccompLegacy(const std::string& process_type); |
| 73 // Check the policy and eventually start the seccomp-bpf sandbox. | 73 // Check the policy and eventually start the seccomp-bpf sandbox. |
| 74 // TODO(jln): not implemented at the moment. | |
| 75 bool StartSeccompBpf(const std::string& process_type); | 74 bool StartSeccompBpf(const std::string& process_type); |
| 76 | 75 |
| 77 private: | 76 private: |
| 78 friend struct DefaultSingletonTraits<LinuxSandbox>; | 77 friend struct DefaultSingletonTraits<LinuxSandbox>; |
| 79 bool ShouldEnableSeccompLegacy(const std::string& process_type); | 78 |
| 79 // We must have be pre_initialized_ before using either of these. | |
|
Markus (顧孟勤)
2012/08/02 20:39:13
s/be/been/
jln (very slow on Chromium)
2012/08/02 20:50:40
Done.
| |
| 80 bool seccomp_legacy_supported() const; | |
| 81 bool seccomp_bpf_supported() const; | |
| 80 | 82 |
| 81 int proc_fd_; | 83 int proc_fd_; |
| 82 // Have we been through PreinitializeSandbox or PreinitializeSandboxBegin ? | 84 // Have we been through PreinitializeSandbox or PreinitializeSandboxBegin ? |
| 83 bool pre_initialized_; | 85 bool pre_initialized_; |
| 84 bool seccomp_legacy_supported_; // Accurate if pre_initialized_. | 86 bool seccomp_legacy_supported_; // Accurate if pre_initialized_. |
| 87 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. | |
| 85 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; | 88 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; |
| 86 LinuxSandbox(); | 89 |
| 87 ~LinuxSandbox(); | 90 ~LinuxSandbox(); |
| 88 DISALLOW_COPY_AND_ASSIGN(LinuxSandbox); | 91 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); |
| 89 }; | 92 }; |
| 90 | 93 |
| 91 } // namespace content | 94 } // namespace content |
| 92 | 95 |
| 93 #endif // CONTENT_COMMON_SANDBOX_LINUX_H_ | 96 #endif // CONTENT_COMMON_SANDBOX_LINUX_H_ |
| 94 | 97 |
| OLD | NEW |