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

Side by Side Diff: src/runtime/runtime-compiler.cc

Issue 1393713006: Don't compile functions in a context the caller doesn't have access to (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « src/generator.js ('k') | src/v8natives.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project 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 "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/frames-inl.h" 10 #include "src/frames-inl.h"
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // No callback set and code generation disallowed. 345 // No callback set and code generation disallowed.
346 return false; 346 return false;
347 } else { 347 } else {
348 // Callback set. Let it decide if code generation is allowed. 348 // Callback set. Let it decide if code generation is allowed.
349 VMState<EXTERNAL> state(isolate); 349 VMState<EXTERNAL> state(isolate);
350 return callback(v8::Utils::ToLocal(context)); 350 return callback(v8::Utils::ToLocal(context));
351 } 351 }
352 } 352 }
353 353
354 354
355 // Walk up the stack expecting:
356 // - Runtime_CompileString
357 // - JSFunction callee (eval, Function constructor, etc)
358 // - call() (maybe)
359 // - apply() (maybe)
360 // - bind() (maybe)
361 // - JSFunction caller (maybe)
362 //
363 // return true if the caller has access to the callee or if an exit frame was
364 // hit, in which case allow it through, as it could have come through the api.
365 bool HasAccessToContextForCompileString(Isolate* isolate) {
366 MaybeHandle<JSFunction> callee;
367 bool exit_handled = true;
368 bool has_access = true;
369 bool done = false;
370 for (StackFrameIterator it(isolate); !it.done() && !done; it.Advance()) {
371 StackFrame* raw_frame = it.frame();
372 if (!raw_frame->is_java_script()) {
373 if (raw_frame->is_exit()) exit_handled = false;
374 continue;
375 }
376 JavaScriptFrame* outer_frame = JavaScriptFrame::cast(raw_frame);
377 List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
378 outer_frame->Summarize(&frames);
379 for (int i = frames.length() - 1; i >= 0 && !done; --i) {
380 FrameSummary& frame = frames[i];
381 Handle<JSFunction> fun = frame.function();
382 // Capture the callee function.
383 if (callee.is_null()) {
384 callee = fun;
385 exit_handled = true;
386 continue;
387 }
388 // Exit condition.
389 Handle<JSObject> callee_global_proxy(
390 callee.ToHandleChecked()->context()->global_proxy());
391 if (!isolate->MayAccess(handle(fun->context()), callee_global_proxy)) {
392 has_access = false;
393 done = true;
394 continue;
395 }
396 // Skip bound functions in correct origin.
397 if (fun->shared()->bound()) {
398 exit_handled = true;
399 continue;
400 }
401 done = true;
402 }
403 }
404 return !exit_handled || has_access;
405 }
406
407
355 RUNTIME_FUNCTION(Runtime_CompileString) { 408 RUNTIME_FUNCTION(Runtime_CompileString) {
356 HandleScope scope(isolate); 409 HandleScope scope(isolate);
357 DCHECK(args.length() == 2); 410 DCHECK(args.length() == 2);
358 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); 411 CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
359 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); 412 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1);
360 413
361 // Extract native context. 414 // Extract native context.
362 Handle<Context> context(isolate->native_context()); 415 Handle<Context> context(isolate->native_context());
363 416
417 // Filter cross security context calls.
418 if (!HasAccessToContextForCompileString(isolate)) {
419 return isolate->heap()->undefined_value();
420 }
421
364 // Check if native context allows code generation from 422 // Check if native context allows code generation from
365 // strings. Throw an exception if it doesn't. 423 // strings. Throw an exception if it doesn't.
366 if (context->allow_code_gen_from_strings()->IsFalse() && 424 if (context->allow_code_gen_from_strings()->IsFalse() &&
367 !CodeGenerationFromStringsAllowed(isolate, context)) { 425 !CodeGenerationFromStringsAllowed(isolate, context)) {
368 Handle<Object> error_message = 426 Handle<Object> error_message =
369 context->ErrorMessageForCodeGenerationFromStrings(); 427 context->ErrorMessageForCodeGenerationFromStrings();
370 THROW_NEW_ERROR_RETURN_FAILURE( 428 THROW_NEW_ERROR_RETURN_FAILURE(
371 isolate, 429 isolate,
372 NewEvalError(MessageTemplate::kCodeGenFromStrings, error_message)); 430 NewEvalError(MessageTemplate::kCodeGenFromStrings, error_message));
373 } 431 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 DCHECK(is_valid_language_mode(args.smi_at(3))); 497 DCHECK(is_valid_language_mode(args.smi_at(3)));
440 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); 498 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3));
441 DCHECK(args[4]->IsSmi()); 499 DCHECK(args[4]->IsSmi());
442 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), 500 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(),
443 isolate); 501 isolate);
444 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, 502 return CompileGlobalEval(isolate, args.at<String>(1), outer_info,
445 language_mode, args.smi_at(4)); 503 language_mode, args.smi_at(4));
446 } 504 }
447 } // namespace internal 505 } // namespace internal
448 } // namespace v8 506 } // namespace v8
OLDNEW
« no previous file with comments | « src/generator.js ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698