OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ | 5 #ifndef COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ |
6 #define COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ | 6 #define COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/containers/mru_cache.h" | 14 #include "base/containers/mru_cache.h" |
15 #include "base/files/file.h" | 15 #include "base/files/file.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/singleton.h" | |
18 #include "base/memory/weak_ptr.h" | |
19 #include "base/time/time.h" | 17 #include "base/time/time.h" |
20 #include "build/build_config.h" | 18 #include "build/build_config.h" |
21 #include "components/nacl/browser/nacl_browser_delegate.h" | 19 #include "components/nacl/browser/nacl_browser_delegate.h" |
22 #include "components/nacl/browser/nacl_validation_cache.h" | 20 #include "components/nacl/browser/nacl_validation_cache.h" |
23 | 21 |
24 namespace base { | 22 namespace base { |
25 class FileProxy; | 23 class FileProxy; |
26 } | 24 } |
27 | 25 |
28 namespace nacl { | 26 namespace nacl { |
(...skipping 30 matching lines...) Expand all Loading... |
59 // the public interface, however, so the IRT can be explicitly opened as | 57 // the public interface, however, so the IRT can be explicitly opened as |
60 // early as possible to prevent autoupdate issues. | 58 // early as possible to prevent autoupdate issues. |
61 void EnsureIrtAvailable(); | 59 void EnsureIrtAvailable(); |
62 | 60 |
63 // Path to IRT. Available even before IRT is loaded. | 61 // Path to IRT. Available even before IRT is loaded. |
64 const base::FilePath& GetIrtFilePath(); | 62 const base::FilePath& GetIrtFilePath(); |
65 | 63 |
66 // IRT file handle, only available when IsReady(). | 64 // IRT file handle, only available when IsReady(). |
67 const base::File& IrtFile() const; | 65 const base::File& IrtFile() const; |
68 | 66 |
69 // Methods for testing GDB debug stub in browser. If test adds debug stub | 67 // Methods for tracking the GDB debug stub port associated with each NaCl |
70 // port listener, Chrome will allocate a currently-unused TCP port number for | 68 // process. |
71 // debug stub server instead of a fixed one. | 69 void SetProcessGdbDebugStubPort(int process_id, int port); |
| 70 int GetProcessGdbDebugStubPort(int process_id); |
72 | 71 |
73 // Notify listener that new debug stub TCP port is allocated. | 72 // While a test has a GDB debug port callback set, Chrome will allocate a |
74 void SetProcessGdbDebugStubPort(int process_id, int port); | 73 // currently-unused TCP port to the debug stub server, instead of a fixed |
75 void SetGdbDebugStubPortListener(base::Callback<void(int)> listener); | 74 // one. |
76 void ClearGdbDebugStubPortListener(); | 75 void SetGdbDebugStubPortListenerForTest(base::Callback<void(int)> listener); |
77 | 76 void ClearGdbDebugStubPortListenerForTest(); |
78 int GetProcessGdbDebugStubPort(int process_id); | |
79 | 77 |
80 enum ValidationCacheStatus { | 78 enum ValidationCacheStatus { |
81 CACHE_MISS = 0, | 79 CACHE_MISS = 0, |
82 CACHE_HIT, | 80 CACHE_HIT, |
83 CACHE_MAX | 81 CACHE_MAX |
84 }; | 82 }; |
85 | 83 |
86 bool ValidationCacheIsEnabled() const { | 84 bool ValidationCacheIsEnabled() const { |
87 return validation_cache_is_enabled_; | 85 return validation_cache_is_enabled_; |
88 } | 86 } |
89 | 87 |
90 const std::string& GetValidationCacheKey() const { | 88 const std::string& GetValidationCacheKey() const { |
91 return validation_cache_.GetValidationCacheKey(); | 89 return validation_cache_.GetValidationCacheKey(); |
92 } | 90 } |
93 | 91 |
94 // The NaCl singleton keeps information about NaCl executable files opened via | 92 // The instance keeps information about NaCl executable files opened via |
95 // PPAPI. This allows the NaCl process to get trusted information about the | 93 // PPAPI. This allows the NaCl process to get trusted information about the |
96 // file directly from the browser process. In theory, a compromised renderer | 94 // file directly from the browser process. In theory, a compromised renderer |
97 // could provide a writable file handle or lie about the file's path. If we | 95 // could provide a writable file handle or lie about the file's path. If we |
98 // trusted the handle was read only but it was not, an mmapped file could be | 96 // trusted the handle was read only but it was not, an mmapped file could be |
99 // modified after validation, allowing an escape from the NaCl sandbox. | 97 // modified after validation, allowing an escape from the NaCl sandbox. |
100 // Similarly, if we trusted the file path corresponded to the file handle but | 98 // Similarly, if we trusted the file path corresponded to the file handle but |
101 // it did not, the validation cache could be tricked into bypassing validation | 99 // it did not, the validation cache could be tricked into bypassing validation |
102 // for bad code. | 100 // for bad code. |
103 // Instead of allowing these attacks, the NaCl process only trusts information | 101 // Instead of allowing these attacks, the NaCl process only trusts information |
104 // it gets directly from the browser process. Because the information is | 102 // it gets directly from the browser process. Because the information is |
(...skipping 17 matching lines...) Expand all Loading... |
122 bool QueryKnownToValidate(const std::string& signature, bool off_the_record); | 120 bool QueryKnownToValidate(const std::string& signature, bool off_the_record); |
123 void SetKnownToValidate(const std::string& signature, bool off_the_record); | 121 void SetKnownToValidate(const std::string& signature, bool off_the_record); |
124 void ClearValidationCache(const base::Closure& callback); | 122 void ClearValidationCache(const base::Closure& callback); |
125 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
126 // Get path to NaCl loader on the filesystem if possible. | 124 // Get path to NaCl loader on the filesystem if possible. |
127 // |exe_path| does not change if the method fails. | 125 // |exe_path| does not change if the method fails. |
128 bool GetNaCl64ExePath(base::FilePath* exe_path); | 126 bool GetNaCl64ExePath(base::FilePath* exe_path); |
129 #endif | 127 #endif |
130 | 128 |
131 void EarlyStartup(); | 129 void EarlyStartup(); |
132 static void SetDelegate(NaClBrowserDelegate* delegate); | 130 |
| 131 // Set/get the NaClBrowserDelegate. The |delegate| must be set at startup, |
| 132 // from the Browser's UI thread. It will be leaked at browser teardown. |
| 133 static void SetDelegate(std::unique_ptr<NaClBrowserDelegate> delegate); |
133 static NaClBrowserDelegate* GetDelegate(); | 134 static NaClBrowserDelegate* GetDelegate(); |
| 135 static void ClearAndDeleteDelegateForTest(); |
134 | 136 |
135 // Each time a NaCl process ends, the browser is notified. | 137 // Called whenever a NaCl process exits. |
136 void OnProcessEnd(int process_id); | 138 void OnProcessEnd(int process_id); |
137 // Support for NaCl crash throttling. | 139 |
138 // Each time a NaCl module crashes, the browser is notified. | 140 // Called whenever a NaCl process crashes, before OnProcessEnd(). |
139 void OnProcessCrashed(); | 141 void OnProcessCrashed(); |
| 142 |
140 // If "too many" crashes occur within a given time period, NaCl is throttled | 143 // If "too many" crashes occur within a given time period, NaCl is throttled |
141 // until the rate again drops below the threshold. | 144 // until the rate again drops below the threshold. |
142 bool IsThrottled(); | 145 bool IsThrottled(); |
143 | 146 |
144 private: | 147 private: |
145 friend struct base::DefaultSingletonTraits<NaClBrowser>; | |
146 | |
147 enum NaClResourceState { | 148 enum NaClResourceState { |
148 NaClResourceUninitialized, | 149 NaClResourceUninitialized, |
149 NaClResourceRequested, | 150 NaClResourceRequested, |
150 NaClResourceReady | 151 NaClResourceReady |
151 }; | 152 }; |
152 | 153 |
153 NaClBrowser(); | 154 NaClBrowser(); |
154 ~NaClBrowser(); | 155 ~NaClBrowser(); |
155 | 156 |
156 void InitIrtFilePath(); | 157 void InitIrtFilePath(); |
(...skipping 10 matching lines...) Expand all Loading... |
167 | 168 |
168 // Dispatch waiting tasks if we are ready, or if we know we'll never be ready. | 169 // Dispatch waiting tasks if we are ready, or if we know we'll never be ready. |
169 void CheckWaiting(); | 170 void CheckWaiting(); |
170 | 171 |
171 // Indicate that it is impossible to launch a NaCl process. | 172 // Indicate that it is impossible to launch a NaCl process. |
172 void MarkAsFailed(); | 173 void MarkAsFailed(); |
173 | 174 |
174 void MarkValidationCacheAsModified(); | 175 void MarkValidationCacheAsModified(); |
175 void PersistValidationCache(); | 176 void PersistValidationCache(); |
176 | 177 |
177 | |
178 base::File irt_file_; | 178 base::File irt_file_; |
179 base::FilePath irt_filepath_; | 179 base::FilePath irt_filepath_; |
180 NaClResourceState irt_state_; | 180 NaClResourceState irt_state_; |
181 NaClValidationCache validation_cache_; | 181 NaClValidationCache validation_cache_; |
182 NaClValidationCache off_the_record_validation_cache_; | 182 NaClValidationCache off_the_record_validation_cache_; |
183 base::FilePath validation_cache_file_path_; | 183 base::FilePath validation_cache_file_path_; |
184 bool validation_cache_is_enabled_; | 184 bool validation_cache_is_enabled_; |
185 bool validation_cache_is_modified_; | 185 bool validation_cache_is_modified_; |
186 NaClResourceState validation_cache_state_; | 186 NaClResourceState validation_cache_state_; |
187 base::Callback<void(int)> debug_stub_port_listener_; | 187 base::Callback<void(int)> debug_stub_port_listener_; |
188 | 188 |
189 // Map from process id to debug stub port if any. | 189 // Map from process id to debug stub port if any. |
190 typedef std::map<int, int> GdbDebugStubPortMap; | 190 typedef std::map<int, int> GdbDebugStubPortMap; |
191 GdbDebugStubPortMap gdb_debug_stub_port_map_; | 191 GdbDebugStubPortMap gdb_debug_stub_port_map_; |
192 | 192 |
193 typedef base::HashingMRUCache<std::string, base::FilePath> PathCacheType; | 193 typedef base::HashingMRUCache<std::string, base::FilePath> PathCacheType; |
194 PathCacheType path_cache_; | 194 PathCacheType path_cache_; |
195 | 195 |
196 bool ok_; | 196 // True if it is no longer possible to launch NaCl processes. |
| 197 bool has_failed_; |
197 | 198 |
198 // A list of pending tasks to start NaCl processes. | 199 // A list of pending tasks to start NaCl processes. |
199 std::vector<base::Closure> waiting_; | 200 std::vector<base::Closure> waiting_; |
200 | 201 |
201 std::unique_ptr<NaClBrowserDelegate> browser_delegate_; | |
202 | |
203 std::deque<base::Time> crash_times_; | 202 std::deque<base::Time> crash_times_; |
204 | 203 |
205 // Singletons get destroyed at shutdown. | |
206 base::WeakPtrFactory<NaClBrowser> weak_factory_; | |
207 | |
208 DISALLOW_COPY_AND_ASSIGN(NaClBrowser); | 204 DISALLOW_COPY_AND_ASSIGN(NaClBrowser); |
209 }; | 205 }; |
210 | 206 |
211 } // namespace nacl | 207 } // namespace nacl |
212 | 208 |
213 #endif // COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ | 209 #endif // COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ |
OLD | NEW |