Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: components/nacl/browser/nacl_browser.h

Issue 2630443003: Add thread checks to NaClBrowser, and make it leaky (Closed)
Patch Set: Update NaClGdbDebugStubTest Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 static void SetGdbDebugStubPortListenerForTest(
77 76 base::Callback<void(int)> listener);
78 int GetProcessGdbDebugStubPort(int process_id); 77 static void ClearGdbDebugStubPortListenerForTest();
79 78
80 enum ValidationCacheStatus { 79 enum ValidationCacheStatus {
81 CACHE_MISS = 0, 80 CACHE_MISS = 0,
82 CACHE_HIT, 81 CACHE_HIT,
83 CACHE_MAX 82 CACHE_MAX
84 }; 83 };
85 84
86 bool ValidationCacheIsEnabled() const { 85 bool ValidationCacheIsEnabled() const {
87 return validation_cache_is_enabled_; 86 return validation_cache_is_enabled_;
88 } 87 }
89 88
90 const std::string& GetValidationCacheKey() const { 89 const std::string& GetValidationCacheKey() const {
91 return validation_cache_.GetValidationCacheKey(); 90 return validation_cache_.GetValidationCacheKey();
92 } 91 }
93 92
94 // The NaCl singleton keeps information about NaCl executable files opened via 93 // The instance keeps information about NaCl executable files opened via
95 // PPAPI. This allows the NaCl process to get trusted information about the 94 // PPAPI. This allows the NaCl process to get trusted information about the
96 // file directly from the browser process. In theory, a compromised renderer 95 // 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 96 // 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 97 // 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. 98 // modified after validation, allowing an escape from the NaCl sandbox.
100 // Similarly, if we trusted the file path corresponded to the file handle but 99 // 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 100 // it did not, the validation cache could be tricked into bypassing validation
102 // for bad code. 101 // for bad code.
103 // Instead of allowing these attacks, the NaCl process only trusts information 102 // Instead of allowing these attacks, the NaCl process only trusts information
104 // it gets directly from the browser process. Because the information is 103 // it gets directly from the browser process. Because the information is
(...skipping 17 matching lines...) Expand all
122 bool QueryKnownToValidate(const std::string& signature, bool off_the_record); 121 bool QueryKnownToValidate(const std::string& signature, bool off_the_record);
123 void SetKnownToValidate(const std::string& signature, bool off_the_record); 122 void SetKnownToValidate(const std::string& signature, bool off_the_record);
124 void ClearValidationCache(const base::Closure& callback); 123 void ClearValidationCache(const base::Closure& callback);
125 #if defined(OS_WIN) 124 #if defined(OS_WIN)
126 // Get path to NaCl loader on the filesystem if possible. 125 // Get path to NaCl loader on the filesystem if possible.
127 // |exe_path| does not change if the method fails. 126 // |exe_path| does not change if the method fails.
128 bool GetNaCl64ExePath(base::FilePath* exe_path); 127 bool GetNaCl64ExePath(base::FilePath* exe_path);
129 #endif 128 #endif
130 129
131 void EarlyStartup(); 130 void EarlyStartup();
132 static void SetDelegate(NaClBrowserDelegate* delegate); 131
132 // Set/get the NaClBrowserDelegate. The |delegate| must be set at startup,
133 // from the Browser's UI thread. It will be leaked at browser teardown.
134 static void SetDelegate(std::unique_ptr<NaClBrowserDelegate> delegate);
133 static NaClBrowserDelegate* GetDelegate(); 135 static NaClBrowserDelegate* GetDelegate();
136 static void ClearAndDeleteDelegateForTest();
134 137
135 // Each time a NaCl process ends, the browser is notified. 138 // Called whenever a NaCl process exits.
136 void OnProcessEnd(int process_id); 139 void OnProcessEnd(int process_id);
137 // Support for NaCl crash throttling. 140
138 // Each time a NaCl module crashes, the browser is notified. 141 // Called whenever a NaCl process crashes, before OnProcessEnd().
139 void OnProcessCrashed(); 142 void OnProcessCrashed();
143
140 // If "too many" crashes occur within a given time period, NaCl is throttled 144 // If "too many" crashes occur within a given time period, NaCl is throttled
141 // until the rate again drops below the threshold. 145 // until the rate again drops below the threshold.
142 bool IsThrottled(); 146 bool IsThrottled();
143 147
144 private: 148 private:
145 friend struct base::DefaultSingletonTraits<NaClBrowser>;
146
147 enum NaClResourceState { 149 enum NaClResourceState {
148 NaClResourceUninitialized, 150 NaClResourceUninitialized,
149 NaClResourceRequested, 151 NaClResourceRequested,
150 NaClResourceReady 152 NaClResourceReady
151 }; 153 };
152 154
155 static NaClBrowser* GetInstanceInternal();
156
153 NaClBrowser(); 157 NaClBrowser();
154 ~NaClBrowser(); 158 ~NaClBrowser();
155 159
156 void InitIrtFilePath(); 160 void InitIrtFilePath();
157 161
158 void OpenIrtLibraryFile(); 162 void OpenIrtLibraryFile();
159 163
160 void OnIrtOpened(std::unique_ptr<base::FileProxy> file_proxy, 164 void OnIrtOpened(std::unique_ptr<base::FileProxy> file_proxy,
161 base::File::Error error_code); 165 base::File::Error error_code);
162 166
163 void InitValidationCacheFilePath(); 167 void InitValidationCacheFilePath();
164 void EnsureValidationCacheAvailable(); 168 void EnsureValidationCacheAvailable();
165 void OnValidationCacheLoaded(const std::string* data); 169 void OnValidationCacheLoaded(const std::string* data);
166 void RunWithoutValidationCache(); 170 void RunWithoutValidationCache();
167 171
168 // Dispatch waiting tasks if we are ready, or if we know we'll never be ready. 172 // Dispatch waiting tasks if we are ready, or if we know we'll never be ready.
169 void CheckWaiting(); 173 void CheckWaiting();
170 174
171 // Indicate that it is impossible to launch a NaCl process. 175 // Indicate that it is impossible to launch a NaCl process.
172 void MarkAsFailed(); 176 void MarkAsFailed();
173 177
174 void MarkValidationCacheAsModified(); 178 void MarkValidationCacheAsModified();
175 void PersistValidationCache(); 179 void PersistValidationCache();
176 180
177
178 base::File irt_file_; 181 base::File irt_file_;
179 base::FilePath irt_filepath_; 182 base::FilePath irt_filepath_;
180 NaClResourceState irt_state_; 183 NaClResourceState irt_state_;
181 NaClValidationCache validation_cache_; 184 NaClValidationCache validation_cache_;
182 NaClValidationCache off_the_record_validation_cache_; 185 NaClValidationCache off_the_record_validation_cache_;
183 base::FilePath validation_cache_file_path_; 186 base::FilePath validation_cache_file_path_;
184 bool validation_cache_is_enabled_; 187 bool validation_cache_is_enabled_;
185 bool validation_cache_is_modified_; 188 bool validation_cache_is_modified_;
186 NaClResourceState validation_cache_state_; 189 NaClResourceState validation_cache_state_;
187 base::Callback<void(int)> debug_stub_port_listener_; 190 base::Callback<void(int)> debug_stub_port_listener_;
188 191
189 // Map from process id to debug stub port if any. 192 // Map from process id to debug stub port if any.
190 typedef std::map<int, int> GdbDebugStubPortMap; 193 typedef std::map<int, int> GdbDebugStubPortMap;
191 GdbDebugStubPortMap gdb_debug_stub_port_map_; 194 GdbDebugStubPortMap gdb_debug_stub_port_map_;
192 195
193 typedef base::HashingMRUCache<std::string, base::FilePath> PathCacheType; 196 typedef base::HashingMRUCache<std::string, base::FilePath> PathCacheType;
194 PathCacheType path_cache_; 197 PathCacheType path_cache_;
195 198
196 bool ok_; 199 // True if it is no longer possible to launch NaCl processes.
200 bool has_failed_;
197 201
198 // A list of pending tasks to start NaCl processes. 202 // A list of pending tasks to start NaCl processes.
199 std::vector<base::Closure> waiting_; 203 std::vector<base::Closure> waiting_;
200 204
201 std::unique_ptr<NaClBrowserDelegate> browser_delegate_;
202
203 std::deque<base::Time> crash_times_; 205 std::deque<base::Time> crash_times_;
204 206
205 // Singletons get destroyed at shutdown.
206 base::WeakPtrFactory<NaClBrowser> weak_factory_;
207
208 DISALLOW_COPY_AND_ASSIGN(NaClBrowser); 207 DISALLOW_COPY_AND_ASSIGN(NaClBrowser);
209 }; 208 };
210 209
211 } // namespace nacl 210 } // namespace nacl
212 211
213 #endif // COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_ 212 #endif // COMPONENTS_NACL_BROWSER_NACL_BROWSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698