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_SANDBOX_LINUX_H_ | 5 #ifndef CONTENT_COMMON_SANDBOX_LINUX_SANDBOX_LINUX_H_ |
6 #define CONTENT_COMMON_SANDBOX_LINUX_SANDBOX_LINUX_H_ | 6 #define CONTENT_COMMON_SANDBOX_LINUX_SANDBOX_LINUX_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "content/public/common/sandbox_linux.h" | 12 #include "content/public/common/sandbox_linux.h" |
13 | 13 |
14 template <typename T> struct DefaultSingletonTraits; | 14 template <typename T> struct DefaultSingletonTraits; |
| 15 namespace base { |
| 16 class Thread; |
| 17 } |
15 namespace sandbox { class SetuidSandboxClient; } | 18 namespace sandbox { class SetuidSandboxClient; } |
16 | 19 |
17 namespace content { | 20 namespace content { |
18 | 21 |
19 // A singleton class to represent and change our sandboxing state for the | 22 // A singleton class to represent and change our sandboxing state for the |
20 // three main Linux sandboxes. | 23 // three main Linux sandboxes. |
21 class LinuxSandbox { | 24 class LinuxSandbox { |
22 public: | 25 public: |
23 // This is a list of sandbox IPC methods which the renderer may send to the | 26 // This is a list of sandbox IPC methods which the renderer may send to the |
24 // sandbox host. See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC | 27 // sandbox host. See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC |
(...skipping 13 matching lines...) Expand all Loading... |
38 | 41 |
39 // Do some initialization that can only be done before any of the sandboxes | 42 // Do some initialization that can only be done before any of the sandboxes |
40 // are enabled. If using the setuid sandbox, this should be called manually | 43 // are enabled. If using the setuid sandbox, this should be called manually |
41 // before the setuid sandbox is engaged. | 44 // before the setuid sandbox is engaged. |
42 void PreinitializeSandbox(); | 45 void PreinitializeSandbox(); |
43 | 46 |
44 // Initialize the sandbox with the given pre-built configuration. Currently | 47 // Initialize the sandbox with the given pre-built configuration. Currently |
45 // seccomp-bpf and address space limitations (the setuid sandbox works | 48 // seccomp-bpf and address space limitations (the setuid sandbox works |
46 // differently and is set-up in the Zygote). This will instantiate the | 49 // differently and is set-up in the Zygote). This will instantiate the |
47 // LinuxSandbox singleton if it doesn't already exist. | 50 // LinuxSandbox singleton if it doesn't already exist. |
| 51 // This function should only be called without any thread running. |
48 static bool InitializeSandbox(); | 52 static bool InitializeSandbox(); |
49 | 53 |
| 54 // Stop |thread| in a way that can be trusted by the sandbox. |
| 55 static void StopThread(base::Thread* thread); |
| 56 |
50 // Returns the status of the renderer, worker and ppapi sandbox. Can only | 57 // Returns the status of the renderer, worker and ppapi sandbox. Can only |
51 // be queried after going through PreinitializeSandbox(). This is a bitmask | 58 // be queried after going through PreinitializeSandbox(). This is a bitmask |
52 // and uses the constants defined in "enum LinuxSandboxStatus". Since the | 59 // and uses the constants defined in "enum LinuxSandboxStatus". Since the |
53 // status needs to be provided before the sandboxes are actually started, | 60 // status needs to be provided before the sandboxes are actually started, |
54 // this returns what will actually happen once InitializeSandbox() | 61 // this returns what will actually happen once InitializeSandbox() |
55 // is called from inside these processes. | 62 // is called from inside these processes. |
56 int GetStatus(); | 63 int GetStatus(); |
57 // Returns true if the current process is single-threaded or if the number | 64 // Returns true if the current process is single-threaded or if the number |
58 // of threads cannot be determined. | 65 // of threads cannot be determined. |
59 bool IsSingleThreaded() const; | 66 bool IsSingleThreaded() const; |
(...skipping 11 matching lines...) Expand all Loading... |
71 // started we will crash. | 78 // started we will crash. |
72 bool StartSeccompBPF(const std::string& process_type); | 79 bool StartSeccompBPF(const std::string& process_type); |
73 | 80 |
74 // Limit the address space of the current process (and its children). | 81 // Limit the address space of the current process (and its children). |
75 // to make some vulnerabilities harder to exploit. | 82 // to make some vulnerabilities harder to exploit. |
76 bool LimitAddressSpace(const std::string& process_type); | 83 bool LimitAddressSpace(const std::string& process_type); |
77 | 84 |
78 private: | 85 private: |
79 friend struct DefaultSingletonTraits<LinuxSandbox>; | 86 friend struct DefaultSingletonTraits<LinuxSandbox>; |
80 | 87 |
81 // InitializeSandbox() is static and gets an instance of the Singleton. This | 88 // Some methods are static and get an instance of the Singleton. These |
82 // is the non-static implementation. | 89 // are the non-static implementations. |
83 bool InitializeSandboxImpl(); | 90 bool InitializeSandboxImpl(); |
| 91 void StopThreadImpl(base::Thread* thread); |
84 // We must have been pre_initialized_ before using this. | 92 // We must have been pre_initialized_ before using this. |
85 bool seccomp_bpf_supported() const; | 93 bool seccomp_bpf_supported() const; |
86 // Returns true if it can be determined that the current process has open | 94 // Returns true if it can be determined that the current process has open |
87 // directories that are not managed by the LinuxSandbox class. This would | 95 // directories that are not managed by the LinuxSandbox class. This would |
88 // be a vulnerability as it would allow to bypass the setuid sandbox. | 96 // be a vulnerability as it would allow to bypass the setuid sandbox. |
89 bool HasOpenDirectories(); | 97 bool HasOpenDirectories() const; |
90 // The last part of the initialization is to make sure any temporary "hole" | 98 // The last part of the initialization is to make sure any temporary "hole" |
91 // in the sandbox is closed. For now, this consists of closing proc_fd_. | 99 // in the sandbox is closed. For now, this consists of closing proc_fd_. |
92 void SealSandbox(); | 100 void SealSandbox(); |
93 // GetStatus() makes promises as to how the sandbox will behave. This | 101 // GetStatus() makes promises as to how the sandbox will behave. This |
94 // checks that no promises have been broken. | 102 // checks that no promises have been broken. |
95 void CheckForBrokenPromises(const std::string& process_type); | 103 void CheckForBrokenPromises(const std::string& process_type); |
| 104 // Stop |thread| and make sure it does not appear in /proc/self/tasks/ |
| 105 // anymore. |
| 106 void StopThreadAndEnsureNotCounted(base::Thread* thread) const; |
96 | 107 |
97 // A file descriptor to /proc. It's dangerous to have it around as it could | 108 // A file descriptor to /proc. It's dangerous to have it around as it could |
98 // allow for sandbox bypasses. It needs to be closed before we consider | 109 // allow for sandbox bypasses. It needs to be closed before we consider |
99 // ourselves sandboxed. | 110 // ourselves sandboxed. |
100 int proc_fd_; | 111 int proc_fd_; |
101 bool seccomp_bpf_started_; | 112 bool seccomp_bpf_started_; |
102 // The value returned by GetStatus(). Gets computed once and then cached. | 113 // The value returned by GetStatus(). Gets computed once and then cached. |
103 int sandbox_status_flags_; | 114 int sandbox_status_flags_; |
104 // Did PreinitializeSandbox() run? | 115 // Did PreinitializeSandbox() run? |
105 bool pre_initialized_; | 116 bool pre_initialized_; |
106 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. | 117 bool seccomp_bpf_supported_; // Accurate if pre_initialized_. |
107 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; | 118 scoped_ptr<sandbox::SetuidSandboxClient> setuid_sandbox_client_; |
108 | 119 |
109 ~LinuxSandbox(); | 120 ~LinuxSandbox(); |
110 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); | 121 DISALLOW_IMPLICIT_CONSTRUCTORS(LinuxSandbox); |
111 }; | 122 }; |
112 | 123 |
113 } // namespace content | 124 } // namespace content |
114 | 125 |
115 #endif // CONTENT_COMMON_SANDBOX_LINUX_SANDBOX_LINUX_H_ | 126 #endif // CONTENT_COMMON_SANDBOX_LINUX_SANDBOX_LINUX_H_ |
OLD | NEW |