GeezerVison is showing github.com — src: remove code cache integrity check · nodejs/node@fd913fe
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_code_cache_stub.cc -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,9 +11,5 @@ namespace native_module { | 11 | 11 | // into native_module_loader.code_cache_. | 12 | 12 | void NativeModuleLoader::LoadCodeCache() {} | 13 | 13 |
| 14 | | -// The generated source code would instert <std::string, std::string> pairs | 15 | | -// into native_module_loader.code_cache_hash_. | 16 | | -void NativeModuleLoader::LoadCodeCacheHash() {} | 17 | | - | 18 | 14 | } // namespace native_module | 19 | 15 | } // namespace node |
Collapse file Copy file name to clipboardExpand all lines: src/node_native_module.cc -41Lines changed: 0 additions & 41 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -105,9 +105,7 @@ Local<String> NativeModuleLoader::GetSource(Isolate* isolate, | 105 | 105 |
| 106 | 106 | NativeModuleLoader::NativeModuleLoader() : config_(GetConfig()) { | 107 | 107 | LoadJavaScriptSource(); | 108 | | - LoadJavaScriptHash(); | 109 | 108 | LoadCodeCache(); | 110 | | - LoadCodeCacheHash(); | 111 | 109 | } | 112 | 110 |
| 113 | 111 | void NativeModuleLoader::CompileCodeCache( | @@ -168,29 +166,6 @@ MaybeLocal<Value> NativeModuleLoader::CompileAsModule( | 168 | 166 | env->context(), id, ¶meters, result, env); | 169 | 167 | } | 170 | 168 |
| 171 | | -// Currently V8 only checks that the length of the source code is the | 172 | | -// same as the code used to generate the hash, so we add an additional | 173 | | -// check here: | 174 | | -// 1. During compile time, when generating node_javascript.cc and | 175 | | -// node_code_cache.cc, we compute and include the hash of the | 176 | | -// JavaScript source in both. | 177 | | -// 2. At runtime, we check that the hash of the code being compiled | 178 | | -// and the hash of the code used to generate the cache | 179 | | -// (without the parameters) is the same. | 180 | | -// This is based on the assumptions: | 181 | | -// 1. `code_cache_hash` must be in sync with `code_cache` | 182 | | -// (both defined in node_code_cache.cc) | 183 | | -// 2. `source_hash` must be in sync with `source` | 184 | | -// (both defined in node_javascript.cc) | 185 | | -// 3. If `source_hash` is in sync with `code_cache_hash`, | 186 | | -// then the source code used to generate `code_cache` | 187 | | -// should be in sync with the source code in `source` | 188 | | -// The only variable left, then, are the parameters passed to the | 189 | | -// CompileFunctionInContext. If the parameters used generate the cache | 190 | | -// is different from the one used to compile modules at run time, then | 191 | | -// there could be false postivies, but that should be rare and should fail | 192 | | -// early in the bootstrap process so it should be easy to detect and fix. | 193 | | - | 194 | 169 | // Returns nullptr if there is no code cache corresponding to the id | 195 | 170 | ScriptCompiler::CachedData* NativeModuleLoader::GetCachedData( | 196 | 171 | const char* id) const { | @@ -204,22 +179,6 @@ ScriptCompiler::CachedData* NativeModuleLoader::GetCachedData( | 204 | 179 | const uint8_t* code_cache_value = it->second.one_bytes_data(); | 205 | 180 | size_t code_cache_length = it->second.length(); | 206 | 181 |
| 207 | | - const auto it2 = code_cache_hash_.find(id); | 208 | | - CHECK_NE(it2, code_cache_hash_.end()); | 209 | | - const std::string& code_cache_hash_value = it2->second; | 210 | | - | 211 | | - const auto it3 = source_hash_.find(id); | 212 | | - CHECK_NE(it3, source_hash_.end()); | 213 | | - const std::string& source_hash_value = it3->second; | 214 | | - | 215 | | - // It may fail when any of the inputs of the `node_js2c` target in | 216 | | - // node.gyp is modified but the tools/generate_code_cache.js | 217 | | - // is not re run. | 218 | | - // FIXME(joyeecheung): Figure out how to resolve the dependency issue. | 219 | | - // When the code cache was introduced we were at a point where refactoring | 220 | | - // node.gyp may not be worth the effort. | 221 | | - CHECK_EQ(code_cache_hash_value, source_hash_value); | 222 | | - | 223 | 182 | return new ScriptCompiler::CachedData(code_cache_value, code_cache_length); | 224 | 183 | } | 225 | 184 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_native_module.h -5Lines changed: 0 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,14 +75,12 @@ class NativeModuleLoader { | 75 | 75 |
| 76 | 76 | // Generated by tools/js2c.py as node_javascript.cc | 77 | 77 | void LoadJavaScriptSource(); // Loads data into source_ | 78 | | - void LoadJavaScriptHash(); // Loads data into source_hash_ | 79 | 78 | UnionBytes GetConfig(); // Return data for config.gypi | 80 | 79 |
| 81 | 80 | // Generated by tools/generate_code_cache.js as node_code_cache.cc when | 82 | 81 | // the build is configured with --code-cache-path=.... They are noops | 83 | 82 | // in node_code_cache_stub.cc | 84 | 83 | void LoadCodeCache(); // Loads data into code_cache_ | 85 | | - void LoadCodeCacheHash(); // Loads data into code_cache_hash_ | 86 | 84 |
| 87 | 85 | v8::ScriptCompiler::CachedData* GetCachedData(const char* id) const; | 88 | 86 |
| @@ -105,9 +103,6 @@ class NativeModuleLoader { | 105 | 103 | NativeModuleRecordMap source_; | 106 | 104 | NativeModuleRecordMap code_cache_; | 107 | 105 | UnionBytes config_; | 108 | | - | 109 | | - NativeModuleHashMap source_hash_; | 110 | | - NativeModuleHashMap code_cache_hash_; | 111 | 106 | }; | 112 | 107 |
| 113 | 108 | } // namespace native_module | |
Collapse file Copy file name to clipboardExpand all lines: test/code-cache/test-code-cache-generator.js -6Lines changed: 0 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,6 @@ if (child.status !== 0) { | 31 | 31 |
| 32 | 32 | // Verifies that: | 33 | 33 | // - node::LoadCodeCache() | 34 | | -// - node::LoadCodeCacheHash() | 35 | 34 | // are defined in the generated code. | 36 | 35 | // See src/node_native_module.h for explanations. | 37 | 36 |
| @@ -41,18 +40,13 @@ const rl = readline.createInterface({ | 41 | 40 | }); | 42 | 41 |
| 43 | 42 | let hasCacheDef = false; | 44 | | -let hasHashDef = false; | 45 | 43 |
| 46 | 44 | rl.on('line', common.mustCallAtLeast((line) => { | 47 | 45 | if (line.includes('LoadCodeCache(')) { | 48 | 46 | hasCacheDef = true; | 49 | 47 | } | 50 | | - if (line.includes('LoadCodeCacheHash(')) { | 51 | | - hasHashDef = true; | 52 | | - } | 53 | 48 | }, 2)); | 54 | 49 |
| 55 | 50 | rl.on('close', common.mustCall(() => { | 56 | 51 | assert.ok(hasCacheDef); | 57 | | - assert.ok(hasHashDef); | 58 | 52 | })); |
Collapse file Copy file name to clipboardExpand all lines: tools/generate_code_cache.js +3-24Lines changed: 3 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | // of `configure`. | 9 | 9 |
| 10 | 10 | const { | 11 | | - getSource, | 12 | 11 | getCodeCache, | 13 | 12 | cachableBuiltins | 14 | 13 | } = require('internal/bootstrap/cache'); | @@ -19,13 +18,6 @@ const { | 19 | 18 | } | 20 | 19 | } = require('util'); | 21 | 20 |
| 22 | | -function hash(str) { | 23 | | - if (process.versions.openssl) { | 24 | | - return require('crypto').createHash('sha256').update(str).digest('hex'); | 25 | | - } | 26 | | - return ''; | 27 | | -} | 28 | | - | 29 | 21 | const fs = require('fs'); | 30 | 22 |
| 31 | 23 | const resultPath = process.argv[2]; | @@ -65,26 +57,18 @@ function getInitalizer(key, cache) { | 65 | 57 | const defName = `${key.replace(/\//g, '_').replace(/-/g, '_')}_raw`; | 66 | 58 | const definition = `static const uint8_t ${defName}[] = {\n` + | 67 | 59 | `${cache.join(',')}\n};`; | 68 | | - const source = getSource(key); | 69 | | - const sourceHash = hash(source); | 70 | 60 | const initializer = | 71 | 61 | 'code_cache_.emplace(\n' + | 72 | 62 | ` "${key}",\n` + | 73 | 63 | ` UnionBytes(${defName}, arraysize(${defName}))\n` + | 74 | 64 | ');'; | 75 | | - const hashIntializer = | 76 | | - 'code_cache_hash_.emplace(\n' + | 77 | | - ` "${key}",\n` + | 78 | | - ` "${sourceHash}"\n` + | 79 | | - ');'; | 80 | 65 | return { | 81 | | - definition, initializer, hashIntializer, sourceHash | | 66 | + definition, initializer | 82 | 67 | }; | 83 | 68 | } | 84 | 69 |
| 85 | 70 | const cacheDefinitions = []; | 86 | 71 | const cacheInitializers = []; | 87 | | -const cacheHashInitializers = []; | 88 | 72 | let totalCacheSize = 0; | 89 | 73 |
| 90 | 74 | function lexical(a, b) { | @@ -107,13 +91,12 @@ for (const key of cachableBuiltins.sort(lexical)) { | 107 | 91 | const size = cachedData.byteLength; | 108 | 92 | totalCacheSize += size; | 109 | 93 | const { | 110 | | - definition, initializer, hashIntializer, sourceHash | | 94 | + definition, initializer, | 111 | 95 | } = getInitalizer(key, cachedData); | 112 | 96 | cacheDefinitions.push(definition); | 113 | 97 | cacheInitializers.push(initializer); | 114 | | - cacheHashInitializers.push(hashIntializer); | 115 | 98 | console.log(`Generated cache for '${key}', size = ${formatSize(size)}` + | 116 | | - `, hash = ${sourceHash}, total = ${formatSize(totalCacheSize)}`); | | 99 | + `, total = ${formatSize(totalCacheSize)}`); | 117 | 100 | } | 118 | 101 |
| 119 | 102 | const result = `#include "node_native_module.h" | @@ -131,10 +114,6 @@ void NativeModuleLoader::LoadCodeCache() { | 131 | 114 | ${cacheInitializers.join('\n ')} | 132 | 115 | } | 133 | 116 |
| 134 | | -void NativeModuleLoader::LoadCodeCacheHash() { | 135 | | - ${cacheHashInitializers.join('\n ')} | 136 | | -} | 137 | | -
| 138 | 117 | } // namespace native_module | 139 | 118 | } // namespace node | 140 | 119 | `; | |
Collapse file Copy file name to clipboardExpand all lines: tools/js2c.py +1-20Lines changed: 1 addition & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -189,10 +189,6 @@ def ReadMacros(lines): | 189 | 189 | {initializers} | 190 | 190 | }} | 191 | 191 |
| 192 | | -void NativeModuleLoader::LoadJavaScriptHash() {{ | 193 | | - {hash_initializers} | 194 | | -}} | 195 | | -
| 196 | 192 | UnionBytes NativeModuleLoader::GetConfig() {{ | 197 | 193 | return UnionBytes(config_raw, arraysize(config_raw)); // config.gypi | 198 | 194 | }} | @@ -218,13 +214,6 @@ def ReadMacros(lines): | 218 | 214 | ); | 219 | 215 | """ | 220 | 216 |
| 221 | | -HASH_INITIALIZER = """\ | 222 | | -source_hash_.emplace( | 223 | | - "{module}", | 224 | | - "{hash_value}" | 225 | | -); | 226 | | -""" | 227 | | - | 228 | 217 | DEPRECATED_DEPS = """\ | 229 | 218 | 'use strict'; | 230 | 219 | process.emitWarning( | @@ -251,8 +240,6 @@ def JS2C(source, target): | 251 | 240 | # Build source code lines | 252 | 241 | definitions = [] | 253 | 242 | initializers = [] | 254 | | - hash_initializers = [] | 255 | | - config_initializers = [] | 256 | 243 |
| 257 | 244 | def GetDefinition(var, source): | 258 | 245 | # Treat non-ASCII as UTF-8 and convert it to UTF-16. | @@ -267,15 +254,11 @@ def GetDefinition(var, source): | 267 | 254 |
| 268 | 255 | def AddModule(module, source): | 269 | 256 | var = '%s_raw' % (module.replace('-', '_').replace('/', '_')) | 270 | | - source_hash = hashlib.sha256(source).hexdigest() | 271 | 257 | definition = GetDefinition(var, source) | 272 | 258 | initializer = INITIALIZER.format(module=module, | 273 | 259 | var=var) | 274 | | - hash_initializer = HASH_INITIALIZER.format(module=module, | 275 | | - hash_value=source_hash) | 276 | 260 | definitions.append(definition) | 277 | 261 | initializers.append(initializer) | 278 | | - hash_initializers.append(hash_initializer) | 279 | 262 |
| 280 | 263 | for name in modules: | 281 | 264 | lines = ReadFile(str(name)) | @@ -320,9 +303,7 @@ def AddModule(module, source): | 320 | 303 | output = open(str(target[0]), "w") | 321 | 304 | output.write( | 322 | 305 | TEMPLATE.format(definitions=''.join(definitions), | 323 | | - initializers=''.join(initializers), | 324 | | - hash_initializers=''.join(hash_initializers), | 325 | | - config_initializers=''.join(config_initializers))) | | 306 | + initializers=''.join(initializers))) | 326 | 307 | output.close() | 327 | 308 |
| 328 | 309 | def main(): | |
|