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 #include "chrome/browser/nacl_host/nacl_browser.h" | 5 #include "chrome/browser/nacl_host/nacl_browser.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 12 #include "base/rand_util.h" |
12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
13 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_paths_internal.h" | 17 #include "chrome/common/chrome_paths_internal.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "extensions/common/url_pattern.h" | 20 #include "extensions/common/url_pattern.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 | 22 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Query", status, CACHE_MAX); | 99 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Query", status, CACHE_MAX); |
99 } | 100 } |
100 | 101 |
101 void LogCacheSet(ValidationCacheStatus status) { | 102 void LogCacheSet(ValidationCacheStatus status) { |
102 // Bucket zero is reserved for future use. | 103 // Bucket zero is reserved for future use. |
103 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, CACHE_MAX); | 104 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, CACHE_MAX); |
104 } | 105 } |
105 | 106 |
106 } // namespace | 107 } // namespace |
107 | 108 |
| 109 namespace nacl { |
| 110 |
| 111 void OpenNaClExecutableImpl(const base::FilePath& file_path, |
| 112 base::PlatformFile* file) { |
| 113 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to |
| 114 // memory map the executable. |
| 115 // IMPORTANT: This file descriptor must not have write access - that could |
| 116 // allow a sandbox escape. |
| 117 base::PlatformFileError error_code; |
| 118 *file = base::CreatePlatformFile( |
| 119 file_path, |
| 120 base::PLATFORM_FILE_OPEN | |
| 121 base::PLATFORM_FILE_READ | |
| 122 base::PLATFORM_FILE_EXECUTE, // Windows only flag. |
| 123 NULL, |
| 124 &error_code); |
| 125 if (error_code != base::PLATFORM_FILE_OK) { |
| 126 *file = base::kInvalidPlatformFileValue; |
| 127 return; |
| 128 } |
| 129 // Check that the file does not reference a directory. Returning a descriptor |
| 130 // to an extension directory could allow a sandbox escape. |
| 131 base::PlatformFileInfo file_info; |
| 132 if (!base::GetPlatformFileInfo(*file, &file_info) || file_info.is_directory) |
| 133 { |
| 134 base::ClosePlatformFile(*file); |
| 135 *file = base::kInvalidPlatformFileValue; |
| 136 return; |
| 137 } |
| 138 } |
| 139 |
| 140 } |
| 141 |
108 NaClBrowser::NaClBrowser() | 142 NaClBrowser::NaClBrowser() |
109 : weak_factory_(this), | 143 : weak_factory_(this), |
110 irt_platform_file_(base::kInvalidPlatformFileValue), | 144 irt_platform_file_(base::kInvalidPlatformFileValue), |
111 irt_filepath_(), | 145 irt_filepath_(), |
112 irt_state_(NaClResourceUninitialized), | 146 irt_state_(NaClResourceUninitialized), |
113 debug_patterns_(), | 147 debug_patterns_(), |
114 inverse_debug_patterns_(false), | 148 inverse_debug_patterns_(false), |
115 validation_cache_file_path_(), | 149 validation_cache_file_path_(), |
116 validation_cache_is_enabled_( | 150 validation_cache_is_enabled_( |
117 CheckEnvVar("NACL_VALIDATION_CACHE", | 151 CheckEnvVar("NACL_VALIDATION_CACHE", |
118 kValidationCacheEnabledByDefault)), | 152 kValidationCacheEnabledByDefault)), |
119 validation_cache_is_modified_(false), | 153 validation_cache_is_modified_(false), |
120 validation_cache_state_(NaClResourceUninitialized), | 154 validation_cache_state_(NaClResourceUninitialized), |
| 155 path_cache_(10), |
121 ok_(true) { | 156 ok_(true) { |
122 InitIrtFilePath(); | 157 InitIrtFilePath(); |
123 InitValidationCacheFilePath(); | 158 InitValidationCacheFilePath(); |
124 } | 159 } |
125 | 160 |
126 NaClBrowser::~NaClBrowser() { | 161 NaClBrowser::~NaClBrowser() { |
127 if (irt_platform_file_ != base::kInvalidPlatformFileValue) | 162 if (irt_platform_file_ != base::kInvalidPlatformFileValue) |
128 base::ClosePlatformFile(irt_platform_file_); | 163 base::ClosePlatformFile(irt_platform_file_); |
129 } | 164 } |
130 | 165 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 void NaClBrowser::WaitForResources(const base::Closure& reply) { | 399 void NaClBrowser::WaitForResources(const base::Closure& reply) { |
365 waiting_.push_back(reply); | 400 waiting_.push_back(reply); |
366 EnsureAllResourcesAvailable(); | 401 EnsureAllResourcesAvailable(); |
367 CheckWaiting(); | 402 CheckWaiting(); |
368 } | 403 } |
369 | 404 |
370 const base::FilePath& NaClBrowser::GetIrtFilePath() { | 405 const base::FilePath& NaClBrowser::GetIrtFilePath() { |
371 return irt_filepath_; | 406 return irt_filepath_; |
372 } | 407 } |
373 | 408 |
| 409 uint64 NaClBrowser::PutFilePath(const base::FilePath& path) { |
| 410 uint64 nonce; |
| 411 while (true) { |
| 412 nonce = base::RandUint64(); |
| 413 // A zero nonce indicates there is no nonce, if we get zero, ask for another |
| 414 // number. |
| 415 if (nonce != 0) { |
| 416 // If the nonce is in use, ask for another number. |
| 417 PathCacheType::iterator iter = path_cache_.Peek(nonce); |
| 418 if (iter == path_cache_.end()) { |
| 419 path_cache_.Put(nonce, path); |
| 420 break; |
| 421 } |
| 422 } |
| 423 } |
| 424 return nonce; |
| 425 } |
| 426 |
| 427 bool NaClBrowser::GetFilePath(uint64 nonce, base::FilePath* path) { |
| 428 PathCacheType::iterator iter = path_cache_.Peek(nonce); |
| 429 if (iter == path_cache_.end()) { |
| 430 *path = base::FilePath(FILE_PATH_LITERAL("")); |
| 431 return false; |
| 432 } |
| 433 *path = iter->second; |
| 434 path_cache_.Erase(iter); |
| 435 return true; |
| 436 } |
| 437 |
| 438 |
374 bool NaClBrowser::QueryKnownToValidate(const std::string& signature, | 439 bool NaClBrowser::QueryKnownToValidate(const std::string& signature, |
375 bool off_the_record) { | 440 bool off_the_record) { |
376 if (off_the_record) { | 441 if (off_the_record) { |
377 // If we're off the record, don't reorder the main cache. | 442 // If we're off the record, don't reorder the main cache. |
378 return validation_cache_.QueryKnownToValidate(signature, false) || | 443 return validation_cache_.QueryKnownToValidate(signature, false) || |
379 off_the_record_validation_cache_.QueryKnownToValidate(signature, true); | 444 off_the_record_validation_cache_.QueryKnownToValidate(signature, true); |
380 } else { | 445 } else { |
381 bool result = validation_cache_.QueryKnownToValidate(signature, true); | 446 bool result = validation_cache_.QueryKnownToValidate(signature, true); |
382 LogCacheQuery(result ? CACHE_HIT : CACHE_MISS); | 447 LogCacheQuery(result ? CACHE_HIT : CACHE_MISS); |
383 // Queries can modify the MRU order of the cache. | 448 // Queries can modify the MRU order of the cache. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 // because it can degrade the responsiveness of the browser. | 529 // because it can degrade the responsiveness of the browser. |
465 // The task is sequenced so that multiple writes happen in order. | 530 // The task is sequenced so that multiple writes happen in order. |
466 content::BrowserThread::PostBlockingPoolSequencedTask( | 531 content::BrowserThread::PostBlockingPoolSequencedTask( |
467 kValidationCacheSequenceName, | 532 kValidationCacheSequenceName, |
468 FROM_HERE, | 533 FROM_HERE, |
469 base::Bind(WriteCache, validation_cache_file_path_, | 534 base::Bind(WriteCache, validation_cache_file_path_, |
470 base::Owned(pickle))); | 535 base::Owned(pickle))); |
471 } | 536 } |
472 validation_cache_is_modified_ = false; | 537 validation_cache_is_modified_ = false; |
473 } | 538 } |
OLD | NEW |