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

Unified Diff: chrome/browser/nacl_host/nacl_browser.cc

Issue 14750007: NaCl: enable meta-based validation for shared libraries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/nacl_host/nacl_browser.cc
diff --git a/chrome/browser/nacl_host/nacl_browser.cc b/chrome/browser/nacl_host/nacl_browser.cc
index fa733c6036462a91cc1d341659d93eaf94bc4b44..15cb0c3ce474c30b6b9af75754f7ff9bd80628b3 100644
--- a/chrome/browser/nacl_host/nacl_browser.cc
+++ b/chrome/browser/nacl_host/nacl_browser.cc
@@ -9,6 +9,7 @@
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/pickle.h"
+#include "base/rand_util.h"
#include "base/strings/string_split.h"
#include "base/win/windows_version.h"
#include "build/build_config.h"
@@ -105,6 +106,39 @@ void LogCacheSet(ValidationCacheStatus status) {
} // namespace
+namespace nacl {
+
+void OpenNaClExecutableImpl(const base::FilePath& file_path,
+ base::PlatformFile* file) {
+ // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to
+ // memory map the executable.
+ // IMPORTANT: This file descriptor must not have write access - that could
+ // allow a sandbox escape.
+ base::PlatformFileError error_code;
+ *file = base::CreatePlatformFile(
+ file_path,
+ base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_EXECUTE, // Windows only flag.
+ NULL,
+ &error_code);
+ if (error_code != base::PLATFORM_FILE_OK) {
+ *file = base::kInvalidPlatformFileValue;
+ return;
+ }
+ // Check that the file does not reference a directory. Returning a descriptor
+ // to an extension directory could allow a sandbox escape.
+ base::PlatformFileInfo file_info;
+ if (!base::GetPlatformFileInfo(*file, &file_info) || file_info.is_directory)
+ {
+ base::ClosePlatformFile(*file);
+ *file = base::kInvalidPlatformFileValue;
+ return;
+ }
+}
+
+}
+
NaClBrowser::NaClBrowser()
: weak_factory_(this),
irt_platform_file_(base::kInvalidPlatformFileValue),
@@ -118,6 +152,7 @@ NaClBrowser::NaClBrowser()
kValidationCacheEnabledByDefault)),
validation_cache_is_modified_(false),
validation_cache_state_(NaClResourceUninitialized),
+ path_cache_(10),
ok_(true) {
InitIrtFilePath();
InitValidationCacheFilePath();
@@ -371,6 +406,36 @@ const base::FilePath& NaClBrowser::GetIrtFilePath() {
return irt_filepath_;
}
+uint64 NaClBrowser::PutFilePath(const base::FilePath& path) {
+ uint64 nonce;
+ while (true) {
+ nonce = base::RandUint64();
+ // A zero nonce indicates there is no nonce, if we get zero, ask for another
+ // number.
+ if (nonce != 0) {
+ // If the nonce is in use, ask for another number.
+ PathCacheType::iterator iter = path_cache_.Peek(nonce);
+ if (iter == path_cache_.end()) {
+ path_cache_.Put(nonce, path);
+ break;
+ }
+ }
+ }
+ return nonce;
+}
+
+bool NaClBrowser::GetFilePath(uint64 nonce, base::FilePath* path) {
+ PathCacheType::iterator iter = path_cache_.Peek(nonce);
+ if (iter == path_cache_.end()) {
+ *path = base::FilePath(FILE_PATH_LITERAL(""));
+ return false;
+ }
+ *path = iter->second;
+ path_cache_.Erase(iter);
+ return true;
+}
+
+
bool NaClBrowser::QueryKnownToValidate(const std::string& signature,
bool off_the_record) {
if (off_the_record) {

Powered by Google App Engine
This is Rietveld 408576698