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

Unified Diff: gin/isolate_holder.cc

Issue 832393003: [gin] Fingerprint the V8 snapshot files on Windows and verify before loading the snapshot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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: gin/isolate_holder.cc
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index 2b6d64b35c042b2e183e6cc0c963c2f2ab96d392..d3858b58e7302125a60e35137a708c77193e944e 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -12,6 +12,8 @@
#include "base/message_loop/message_loop.h"
#include "base/rand_util.h"
#include "base/sys_info.h"
+#include "crypto/secure_hash.h"
+#include "crypto/sha2.h"
#include "gin/array_buffer.h"
#include "gin/debug_impl.h"
#include "gin/function_template.h"
@@ -72,6 +74,20 @@ bool MapV8Files(base::FilePath* natives_path, base::FilePath* snapshot_path,
return true;
}
+bool VerifyV8SnapshotFile(base::MemoryMappedFile* snapshot_file,
+ const unsigned char* fingerprint) {
+ scoped_ptr<crypto::SecureHash> hash(
grt (UTC plus 2) 2015/01/07 19:27:19 can you use crypto::SHA256HashString(base::StringP
rmcilroy 2015/01/08 15:05:35 Done.
+ crypto::SecureHash::Create(crypto::SecureHash::SHA256));
+ hash->Update(snapshot_file->data(), snapshot_file->length());
+ unsigned char output[crypto::kSHA256Length];
+ hash->Finish(output, sizeof(output));
+ for (size_t i = 0; i < crypto::kSHA256Length; i++) {
grt (UTC plus 2) 2015/01/07 19:27:19 ? return !memcmp(fingerprint, output, sizeof(out
rmcilroy 2015/01/08 15:05:35 Done.
+ if (fingerprint[i] != output[i])
+ return false;
+ }
+ return true;
+}
+
#if !defined(OS_MACOSX)
const int v8_snapshot_dir =
#if defined(OS_ANDROID)
@@ -87,6 +103,11 @@ const int v8_snapshot_dir =
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+
+// Declared in gen/gin/v8_snapshot_fingerprint.cc
grt (UTC plus 2) 2015/01/07 19:27:19 Declared -> Defined (these are declarations here)
rmcilroy 2015/01/08 15:05:35 Done.
+extern const unsigned char g_natives_fingerprint[];
+extern const unsigned char g_snapshot_fingerprint[];
+
// static
bool IsolateHolder::LoadV8Snapshot() {
if (g_mapped_natives && g_mapped_snapshot)
@@ -118,6 +139,15 @@ bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) {
return MapV8Files(NULL, NULL, natives_fd, snapshot_fd);
}
+
+// static
+bool IsolateHolder::LoadAndVerifyV8Snapshot() {
+ if (!LoadV8Snapshot())
+ return false;
+ return VerifyV8SnapshotFile(g_mapped_natives, g_natives_fingerprint) &&
+ VerifyV8SnapshotFile(g_mapped_snapshot, g_snapshot_fingerprint);
+}
+
#endif // V8_USE_EXTERNAL_STARTUP_DATA
//static

Powered by Google App Engine
This is Rietveld 408576698