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

Side by Side Diff: chrome/nacl/nacl_validation_query.cc

Issue 14750007: NaCl: enable meta-based validation for shared libraries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/nacl/nacl_validation_query.h" 5 #include "chrome/nacl/nacl_validation_query.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "crypto/nss_util.h" 8 #include "crypto/nss_util.h"
9 #include "chrome/nacl/nacl_validation_db.h" 9 #include "chrome/nacl/nacl_validation_db.h"
10 #include "native_client/src/trusted/validator/nacl_file_info.h"
10 #include "native_client/src/trusted/validator/validation_cache.h" 11 #include "native_client/src/trusted/validator/validation_cache.h"
11 12
12 NaClValidationQueryContext::NaClValidationQueryContext( 13 NaClValidationQueryContext::NaClValidationQueryContext(
13 NaClValidationDB* db, 14 NaClValidationDB* db,
14 const std::string& profile_key, 15 const std::string& profile_key,
15 const std::string& nacl_version) 16 const std::string& nacl_version)
16 : db_(db), 17 : db_(db),
17 profile_key_(profile_key), 18 profile_key_(profile_key),
18 nacl_version_(nacl_version) { 19 nacl_version_(nacl_version) {
19 20
20 // Sanity checks. 21 // Sanity checks.
21 CHECK(profile_key.length() >= 8); 22 CHECK(profile_key.length() >= 8);
22 CHECK(nacl_version.length() >= 4); 23 CHECK(nacl_version.length() >= 4);
23 } 24 }
24 25
25 NaClValidationQuery* NaClValidationQueryContext::CreateQuery() { 26 NaClValidationQuery* NaClValidationQueryContext::CreateQuery() {
26 NaClValidationQuery* query = new NaClValidationQuery(db_, profile_key_); 27 NaClValidationQuery* query = new NaClValidationQuery(db_, profile_key_);
27 // Changing the version effectively invalidates existing hashes. 28 // Changing the version effectively invalidates existing hashes.
28 query->AddData(nacl_version_); 29 query->AddData(nacl_version_);
29 return query; 30 return query;
30 } 31 }
31 32
33 bool NaClValidationQueryContext::ResolveFileToken(
34 struct NaClFileToken *file_token,
Mark Seaborn 2013/05/24 20:21:58 Fix "*" spacing style
Nick Bray (chromium) 2013/05/24 21:35:24 Done.
35 int32* fd,
36 std::string* path) {
37 return db_->ResolveFileToken(file_token, fd, path);
38 }
39
32 NaClValidationQuery::NaClValidationQuery(NaClValidationDB* db, 40 NaClValidationQuery::NaClValidationQuery(NaClValidationDB* db,
33 const std::string& profile_key) 41 const std::string& profile_key)
34 : state_(READY), 42 : state_(READY),
35 hasher_(crypto::HMAC::SHA256), 43 hasher_(crypto::HMAC::SHA256),
36 db_(db), 44 db_(db),
37 buffer_length_(0) { 45 buffer_length_(0) {
38 // Without this line on Linux, HMAC::Init will instantiate a singleton that 46 // Without this line on Linux, HMAC::Init will instantiate a singleton that
39 // in turn attempts to open a file. Disabling this behavior avoids a ~70 ms 47 // in turn attempts to open a file. Disabling this behavior avoids a ~70 ms
40 // stall the first time HMAC is used. 48 // stall the first time HMAC is used.
41 // This function is also called in nacl_helper_linux.cc, but nacl_helper may 49 // This function is also called in nacl_helper_linux.cc, but nacl_helper may
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 128 }
121 129
122 static void SetKnownToValidate(void* query) { 130 static void SetKnownToValidate(void* query) {
123 static_cast<NaClValidationQuery*>(query)->SetKnownToValidate(); 131 static_cast<NaClValidationQuery*>(query)->SetKnownToValidate();
124 } 132 }
125 133
126 static void DestroyQuery(void* query) { 134 static void DestroyQuery(void* query) {
127 delete static_cast<NaClValidationQuery*>(query); 135 delete static_cast<NaClValidationQuery*>(query);
128 } 136 }
129 137
138 static int ResolveFileToken(void* handle, struct NaClFileToken* file_token,
139 int32* fd, char** file_path,
140 uint32 *file_path_length) {
Mark Seaborn 2013/05/24 20:21:58 Fix "*" spacing style
Nick Bray (chromium) 2013/05/24 21:35:24 Done.
141 std::string path;
142 *file_path = NULL;
143 *file_path_length = 0;
144 bool ok = static_cast<NaClValidationQueryContext*>(handle)->
145 ResolveFileToken(file_token, fd, &path);
146 if (ok) {
147 *file_path = static_cast<char *>(malloc(path.length() + 1));
Mark Seaborn 2013/05/24 20:21:58 Style is "char*"
Nick Bray (chromium) 2013/05/24 21:35:24 Done.
148 CHECK(*file_path);
149 memcpy(*file_path, path.data(), path.length());
150 (*file_path)[path.length()] = 0;
151 *file_path_length = static_cast<uint32>(path.length());
152 }
153 return ok;
154 }
155
130 struct NaClValidationCache* CreateValidationCache( 156 struct NaClValidationCache* CreateValidationCache(
131 NaClValidationDB* db, const std::string& profile_key, 157 NaClValidationDB* db, const std::string& profile_key,
132 const std::string& nacl_version) { 158 const std::string& nacl_version) {
133 NaClValidationCache* cache = 159 NaClValidationCache* cache =
134 static_cast<NaClValidationCache*>(malloc(sizeof(NaClValidationCache))); 160 static_cast<NaClValidationCache*>(malloc(sizeof(NaClValidationCache)));
135 // Make sure any fields introduced in a cross-repo change are zeroed. 161 // Make sure any fields introduced in a cross-repo change are zeroed.
136 memset(cache, 0, sizeof(*cache)); 162 memset(cache, 0, sizeof(*cache));
137 cache->handle = new NaClValidationQueryContext(db, profile_key, nacl_version); 163 cache->handle = new NaClValidationQueryContext(db, profile_key, nacl_version);
138 cache->CreateQuery = CreateQuery; 164 cache->CreateQuery = CreateQuery;
139 cache->AddData = AddData; 165 cache->AddData = AddData;
140 cache->QueryKnownToValidate = QueryKnownToValidate; 166 cache->QueryKnownToValidate = QueryKnownToValidate;
141 cache->SetKnownToValidate = SetKnownToValidate; 167 cache->SetKnownToValidate = SetKnownToValidate;
142 cache->DestroyQuery = DestroyQuery; 168 cache->DestroyQuery = DestroyQuery;
169 cache->ResolveFileToken = ResolveFileToken;
143 return cache; 170 return cache;
144 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698