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> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 // Skia. | 26 // Skia. |
27 enum LinuxSandboxIPCMethods { | 27 enum LinuxSandboxIPCMethods { |
28 METHOD_GET_FONT_FAMILY_FOR_CHARS = 32, | 28 METHOD_GET_FONT_FAMILY_FOR_CHARS = 32, |
29 METHOD_LOCALTIME = 33, | 29 METHOD_LOCALTIME = 33, |
30 METHOD_GET_CHILD_WITH_INODE = 34, | 30 METHOD_GET_CHILD_WITH_INODE = 34, |
31 METHOD_GET_STYLE_FOR_STRIKE = 35, | 31 METHOD_GET_STYLE_FOR_STRIKE = 35, |
32 METHOD_MAKE_SHARED_MEMORY_SEGMENT = 36, | 32 METHOD_MAKE_SHARED_MEMORY_SEGMENT = 36, |
33 METHOD_MATCH_WITH_FALLBACK = 37, | 33 METHOD_MATCH_WITH_FALLBACK = 37, |
34 }; | 34 }; |
35 | 35 |
36 // A list of sandbox configuration for content's process types. | |
37 enum SandboxConfig { | |
38 SANDBOX_CONFIG_INVALID = 0, | |
39 SANDBOX_CONFIG_GENERIC, // Exact sandbox unspecified, useful for pre-init. | |
40 SANDBOX_CONFIG_RENDERER, | |
41 SANDBOX_CONFIG_WORKER, | |
42 SANDBOX_CONFIG_GPU, | |
43 SANDBOX_CONFIG_PPAPI, | |
44 SANDBOX_CONFIG_UTILITY, | |
45 }; | |
46 | |
36 // Get our singleton instance. | 47 // Get our singleton instance. |
37 static LinuxSandbox* GetInstance(); | 48 static LinuxSandbox* GetInstance(); |
38 | 49 |
39 // Do some initialization that can only be done before any of the sandboxes | 50 // Do some initialization that can only be done before any of the sandboxes |
40 // is enabled. | 51 // is enabled. |
41 // | 52 // |
42 // There are two versions of this function. One takes a process_type | 53 // There are two versions of this function. One takes a process_type |
43 // as an argument, the other doesn't. | 54 // as an argument, the other doesn't. |
44 // It may be necessary to call PreinitializeSandboxBegin before knowing the | 55 // It may be necessary to call PreinitializeSandboxBegin before knowing the |
45 // process type (this is for instance the case with the Zygote). | 56 // process type (this is for instance the case with the Zygote). |
46 // In that case, it is crucial that PreinitializeSandboxFinish() gets | 57 // In that case, it is crucial that PreinitializeSandboxFinish() gets |
47 // called for every child process. | 58 // called for every child process. |
48 // TODO(markus, jln) we know this is not always done at the moment | 59 // TODO(markus, jln) we know this is not always done at the moment |
49 // (crbug.com/139877). | 60 // (crbug.com/139877). |
50 void PreinitializeSandbox(const std::string& process_type); | 61 // These functions can accept SANDBOX_CONFIG_GENERIC as a parameter if the |
62 // full type of the sandbox isn't known yet. | |
63 void PreinitializeSandbox(LinuxSandbox::SandboxConfig sandbox_config); | |
51 // These should be called together. | 64 // These should be called together. |
52 void PreinitializeSandboxBegin(); | 65 void PreinitializeSandboxBegin(); |
53 void PreinitializeSandboxFinish(const std::string& process_type); | 66 void PreinitializeSandboxFinish(LinuxSandbox::SandboxConfig sandbox_config); |
54 | 67 |
55 // Returns the Status of the sandbox. Can only be queried if we went through | 68 // Initialize the sandbox with the given pre-built configuration. Currently |
56 // PreinitializeSandbox() or PreinitializeSandboxBegin(). This is a bitmask | 69 // seccomp-legacy, seccomp-bpf, address space limitations (the setuid sandbox |
57 // and uses the constants defined in "enum LinuxSandboxStatus". | 70 // works differently and is set-up in the Zygote). This will instanciate the |
Markus (顧孟勤)
2013/04/10 23:39:50
s/instanciate/instantiate/
| |
71 // LinuxSandbox singleton if it doesn't already exist. | |
72 static bool InitializeSandbox(LinuxSandbox::SandboxConfig sandbox_config); | |
73 | |
74 // Returns the Status of the renderers' sandbox. Can only be queried if we | |
75 // went through PreinitializeSandbox() or PreinitializeSandboxBegin(). This | |
76 // is a bitmask and uses the constants defined in "enum LinuxSandboxStatus". | |
58 // Since we need to provide the status before the sandboxes are actually | 77 // Since we need to provide the status before the sandboxes are actually |
59 // started, this returns what will actually happen once the various Start* | 78 // started, this returns what will actually happen once the various Start* |
60 // functions are called from inside a renderer. | 79 // functions are called from inside a renderer. |
61 int GetStatus() const; | 80 int GetStatus() const; |
62 // Is the current process single threaded? | 81 // Is the current process single threaded? |
63 bool IsSingleThreaded() const; | 82 bool IsSingleThreaded() const; |
64 // Did we start Seccomp BPF? | 83 // Did we start Seccomp BPF? |
65 bool seccomp_bpf_started() const; | 84 bool seccomp_bpf_started() const; |
66 | 85 |
67 // Simple accessor for our instance of the setuid sandbox. Will never return | 86 // Simple accessor for our instance of the setuid sandbox. Will never return |
68 // NULL. | 87 // NULL. |
69 // There is no StartSetuidSandbox(), the SetuidSandboxClient instance should | 88 // There is no StartSetuidSandbox(), the SetuidSandboxClient instance should |
70 // be used directly. | 89 // be used directly. |
71 sandbox::SetuidSandboxClient* setuid_sandbox_client() const; | 90 sandbox::SetuidSandboxClient* setuid_sandbox_client() const; |
72 | 91 |
73 // Check the policy and eventually start the seccomp-legacy sandbox. | 92 // Check the policy and eventually start the seccomp-legacy sandbox. |
74 bool StartSeccompLegacy(const std::string& process_type); | 93 bool StartSeccompLegacy(LinuxSandbox::SandboxConfig sandbox_config); |
75 // Check the policy and eventually start the seccomp-bpf sandbox. This should | 94 // Check the policy and eventually start the seccomp-bpf sandbox. This should |
76 // never be called with threads started. If we detect that thread have | 95 // never be called with threads started. If we detect that thread have |
77 // started we will crash. | 96 // started we will crash. |
78 bool StartSeccompBpf(const std::string& process_type); | 97 bool StartSeccompBpf(LinuxSandbox::SandboxConfig sandbox_config); |
79 | 98 |
80 // Limit the address space of the current process (and its children). | 99 // Limit the address space of the current process (and its children). |
81 // to make some vulnerabilities harder to exploit. | 100 // to make some vulnerabilities harder to exploit. |
82 bool LimitAddressSpace(const std::string& process_type); | 101 bool LimitAddressSpace(LinuxSandbox::SandboxConfig sandbox_config); |
83 | 102 |
84 private: | 103 private: |
85 friend struct DefaultSingletonTraits<LinuxSandbox>; | 104 friend struct DefaultSingletonTraits<LinuxSandbox>; |
86 | 105 |
87 // We must have been pre_initialized_ before using either of these. | 106 // We must have been pre_initialized_ before using either of these. |
88 bool seccomp_legacy_supported() const; | 107 bool seccomp_legacy_supported() const; |
89 bool seccomp_bpf_supported() const; | 108 bool seccomp_bpf_supported() const; |
90 | 109 |
91 int proc_fd_; | 110 int proc_fd_; |
92 bool seccomp_bpf_started_; | 111 bool seccomp_bpf_started_; |
93 // Have we been through PreinitializeSandbox or PreinitializeSandboxBegin? | 112 // Have we been through PreinitializeSandbox or PreinitializeSandboxBegin? |
94 bool pre_initialized_; | 113 bool pre_initialized_; |
95 bool seccomp_legacy_supported_; // Accurate if pre_initialized_. | 114 bool seccomp_legacy_supported_; // Accurate if pre_initialized_. |
96 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. | 115 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. |
97 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; | 116 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; |
98 | 117 |
99 ~LinuxSandbox(); | 118 ~LinuxSandbox(); |
100 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); | 119 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); |
101 }; | 120 }; |
102 | 121 |
103 } // namespace content | 122 } // namespace content |
104 | 123 |
105 #endif // CONTENT_COMMON_SANDBOX_LINUX_H_ | 124 #endif // CONTENT_COMMON_SANDBOX_LINUX_H_ |
106 | 125 |
OLD | NEW |