Fuzzy testing method and device for JIT compiler in JavaScript engine
By building test samples containing JIT compiler error-exposed elements and capturing the execution results of JIT compiler optimization functions, the problem that existing fuzz testing tools are difficult to detect JIT compiler vulnerabilities is solved, and efficient use of JIT compiler vulnerabilities in the JavaScript engine JIT compiler vulnerabilities is achieved Mining and accurate detection.
Patent Information
- Application Number
- CN202410911579.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-22
AI Technical Summary
Existing fuzz testing tools are difficult to efficiently tap the JIT compiler vulnerabilities in the JavaScript engine, especially those subtle errors that do not cause crashes, which are often ignored.
By building test samples containing elements that reveal JIT compiler errors, using the opt function to trigger the JIT compiler optimization function, and capturing the execution results before and after optimization, using precise test oracle to detect JIT compiler errors, including reconfiguring activation thresholds and generating Targeted sample mutation strategy.
It realizes efficient mining of JavaScript engine JIT compiler vulnerabilities, captures hidden and crash errors, and improves testing efficiency and accuracy.
Smart Images

Figure CN119003331A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software security technology, and in particular to a fuzz testing method and device for a JIT compiler in a JavaScript engine. Background Art
[0002] Browsers provide great convenience for our lives, and the role of JavaScript language and its engine cannot be underestimated. JavaScript language allows web pages to be updated in real time and interact dynamically with users. The JavaScript engine is responsible for the execution of JavaScript language. In recent years, the response speed of web pages has become the main factor in the competition for browser market share. In order to improve the response speed of web pages, JavaScript engines will perform complex optimizations when executing JavaScript code in web pages, and the JIT compiler is the module responsible for optimization.
[0003] Fuzz testing is a software testing technique. The core idea is to automatically or semi-automatically generate random data input into a program and monitor program anomalies, such as crashes and assertion failures, to find possible program errors, such as memory leaks. Fuzz testing is widely used to detect security vulnerabilities in software or computer systems. However, no one has yet designed an effective fuzz testing tool specifically for testing JIT compilers. Studies have found that bugs in JIT compilers often cause extremely subtle errors at the beginning, and require the activation of the JIT compiler, and sometimes the prerequisites for application-specific defect optimizations. Such bugs usually do not crash the JavaScript engine, so fuzzers that use crashes as the only result reference (hereinafter referred to as oracle) can easily miss these bugs (only capture samples that cause the target program to crash), but most existing fuzzers do this. Summary of the invention
[0004] (1) Technical issues to be solved
[0005] The present application provides a fuzz testing method and device for a JIT compiler in a JavaScript engine, which solves the current problem that it is difficult to efficiently mine JIT compiler vulnerabilities in JavaScript engines.
[0006] (2) Technical solution
[0007] In a first aspect, the present application provides a fuzz testing method for a JIT compiler in a JavaScript engine, comprising:
[0008] Constructing a test sample that includes a JIT compiler error disclosure element and can trigger a JIT compiler optimization function, wherein the test sample uses an opt function;
[0009] The JIT compiler optimization function is triggered by the test sample, and JIT compiler errors are captured according to the execution results of the test sample before and after the optimization.
[0010] Furthermore, the construction includes a test sample containing JIT compiler error disclosure elements and capable of triggering JIT compiler optimization functions, including:
[0011] Develop targeted sample mutation and generation strategies based on program elements and optimization behaviors that cause JIT compiler errors;
[0012] A JIT compiler error disclosure element is generated through the sample mutation and generation strategy, and a test sample is constructed according to the JIT compiler error disclosure element.
[0013] Furthermore, the program elements include arrays, objects, sub-expressions and special numbers, and the optimization behaviors include boundary check elimination, redundancy elimination and common sub-expression elimination.
[0014] Furthermore, the sample mutation and generation strategies include five heuristic mutation strategies: array, object, sub-expression, special number and conditional variable reallocation.
[0015] Furthermore, the construction includes a test sample containing JIT compiler error disclosure elements and capable of triggering JIT compiler optimization functions, and further includes:
[0016] reconfiguring the activation threshold of each JIT compiler layer according to the original threshold configuration of each JIT compiler layer;
[0017] Set the number of calls to each JIT compiler layer opt function to twice the activation threshold of the JIT compiler layer.
[0018] Furthermore, triggering a JIT compiler optimization function through the test sample and capturing JIT compiler errors according to the execution results of the test sample before and after the optimization include:
[0019] The test sample is first completely executed by the interpreter and then by the JIT compiler, and two final states before and after optimization are returned;
[0020] Check whether the two final states before and after the optimization are the same. If they are not the same, it is considered that an error has occurred in the JIT compiler, and the JIT compiler error is captured.
[0021] Furthermore, triggering a JIT compiler optimization function through the test sample and capturing JIT compiler errors according to the execution results of the test sample before and after the optimization also includes:
[0022] Execute multiple test samples in succession to pre-check the existence of factors that may falsely produce different execution results;
[0023] Test samples that pass the precheck are forwarded to the JIT compiler to see if there are any differences in the final state.
[0024] In a second aspect, the present application provides a fuzz testing device for a JIT compiler in a JavaScript engine, comprising:
[0025] A sample construction module, used to construct a test sample that includes a JIT compiler error disclosure element and can trigger a JIT compiler optimization function, wherein the test sample uses an opt function;
[0026] The optimization trigger module is used to trigger the JIT compiler optimization function through the test sample and capture JIT compiler errors according to the execution results of the test sample before and after the optimization.
[0027] In a third aspect, the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the fuzz testing method for the JIT compiler in the JavaScript engine as described above is implemented.
[0028] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the fuzz testing method for the JIT compiler in the JavaScript engine as described above.
[0029] (3) Beneficial effects
[0030] The above technical solution of the present application has the following advantages:
[0031] The first aspect of the present application provides a fuzz testing method for the JIT compiler in the JavaScript engine. By constructing a test sample that includes a JIT compiler error disclosure element and can trigger the JIT compiler optimization function, and triggering the JIT compiler optimization function through the test sample, the JIT compiler errors are captured according to the execution results of the test sample before and after the optimization, and the vulnerabilities in the JavaScript engine JIT compiler can be efficiently discovered.
[0032] It can be understood that the beneficial effects of the second, third and fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0034] Figure 1 A flowchart of a fuzz testing method for a JIT compiler in a JavaScript engine provided by this application;
[0035] Figure 2 Architecture diagram of the four JavaScript engines provided for this application;
[0036] Figure 3 Schematic diagram of the test sample provided for this application;
[0037] Figure 4 The workflow diagram of FuzzJIT provided for this application;
[0038] Figure 5 A schematic diagram of the structure of a fuzzy testing device for a JIT compiler in a JavaScript engine provided by this application;
[0039] Figure 6 A schematic diagram of the structure of the electronic device provided in this application. DETAILED DESCRIPTION
[0040] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0041] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0042] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0043] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. "Multiple" means "two or more".
[0044] Since JavaScript is a weakly typed language, developers do not need to specify the type of variables, and the type of variables can be dynamically converted during operation. Therefore, the JavaScript engine needs to perform tedious judgments on the type of variables during execution and take corresponding actions. The optimization of the JavaScript language is based on a rule: if a variable is observed to belong to a certain variable type in multiple previous executions, then it is very likely to be the same data type in the next operation. Based on this assumption, the JavaScript engine can simplify the judgment process, thereby saving the number of instructions that need to be executed. Or if the JavaScript engine infers that the type or value range of a variable will not be affected by certain operations, then there is no need to judge before and after the operation, thereby saving the number of instructions executed.
[0045] However, in practice, the types of variables are complex and changeable, and the side effects of complex operations such as callbacks are difficult to model, making it difficult to implement optimization. If the necessary checks are mistakenly removed, serious security errors will result. Due to the complexity of the implementation of JavaScript engine optimization functions, vulnerabilities are inevitable in this part. In security competitions, JIT compiler vulnerabilities are widely exploited to obtain remote code execution. In the past three years of Pwn2Own competitions, 6 of the 8 successful attacks used incorrect optimization vulnerabilities. From the analysis of the JavaScript engine bugs reported by Google Project Zero from 2016 to 2021, it can be found that in recent years, more attention and efforts have been invested in the discovery of JIT compiler errors, and the number is about four times that of parser / interpreter errors in the past four years. Therefore, detecting security vulnerabilities in JavaScript optimization is a very important task.
[0046] The present application provides a fuzz testing method for the JIT compiler in the JavaScript engine, and proposes FuzzJIT, a fuzz testing technology for the JIT compiler, which uses a more accurate test oracle. The core idea of the new oracle is that a piece of JavaScript code should produce consistent execution results before and after JIT compilation, otherwise it is considered that an error has occurred in the JIT compiler. The characteristics of FuzzJIT are that it can actively activate the JIT compiler, purposefully generate promising inputs that may cause the JIT compiler to fail, and keenly capture those hidden and non-crash JIT compiler errors and crash errors. The design of FuzzJIT targets the JIT compiler while retaining the high efficiency of fuzz testing, and can efficiently mine vulnerabilities in the JIT compiler of the JavaScript engine.
[0047] The specific implementation methods of the present application are further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present application but are not intended to limit the scope of the present application.
[0048] like Figure 1 As shown, the fuzz testing method for the JIT compiler in the JavaScript engine provided in this embodiment specifically includes the following steps:
[0049] S100, constructing a test sample that includes a JIT compiler error disclosure element and can trigger a JIT compiler optimization function, wherein the test sample uses an opt function.
[0050] In some embodiments, the construction contains a test sample that includes a JIT compiler error disclosure element and can trigger the JIT compiler optimization function, including: formulating a targeted sample mutation and generation strategy based on the program elements and optimization behaviors that cause the JIT compiler error; generating a JIT compiler error disclosure element through the sample mutation and generation strategy, and constructing a test sample based on the JIT compiler error disclosure element.
[0051] In some embodiments, the program elements include arrays, objects, sub-expressions, and special numbers, and the optimization behaviors include bounds check elimination, redundancy elimination, and common sub-expression elimination.
[0052] In some embodiments, the sample mutation and generation strategies include five heuristic mutation strategies: array, object, sub-expression, special number, and conditional variable reallocation.
[0053] In some embodiments, the construction contains a test sample that includes a JIT compiler error disclosure element and can trigger the JIT compiler optimization function, and also includes: reconfiguring the activation threshold of each JIT compiler layer according to the original threshold configuration of each JIT compiler layer; setting the number of calls to the opt function of each JIT compiler layer to twice the activation threshold of the JIT compiler layer.
[0054] In applications, in order to specifically discover JIT compiler errors during fuzz testing, it is necessary to ensure that the generated samples trigger the optimization function. After the optimization function is triggered, the possibility of triggering the optimization error is maximized as much as possible. After the optimization error is triggered, it is accurately captured.
[0055] Different JavaScript engines have slightly different optimization triggering conditions. In this application, four mainstream JavaScript engines are studied: JavaScriptCore, V8, SpiderMonkey, and ChakraCore. They are widely adopted by end users and intensively apply JIT compilation to pursue faster execution speed. Their architectures are as follows: Figure 2 As shown. Each engine contains a parser, an interpreter, and one or more JIT compiler layers. When there are multiple layers of JIT compilers, they will be gradually activated as the code becomes hotter and hotter (hot here means that the code is executed repeatedly, and the more times the same line of code is executed, the hotter it is). Each layer is related to a specific execution number threshold for activation. The later layers tend to have higher thresholds than the previous ones and generate assembly code with a higher degree of optimization. There are many optimization methods in each layer, and when the JIT layer is triggered, they will be selectively activated and interleaved based on the profiling information. Vulnerabilities may exist in any layer, so the overall testing approach should be able to penetrate into every layer.
[0056] In different engines, the activation threshold of each JIT compiler layer is usually configurable. It is worth mentioning that the threshold cannot be set too small, because some optimizations need to consider the minimum number of executions when making decisions. Too small thresholds may cause false positives that cannot be reproduced under the default settings of the engine, while larger thresholds sacrifice more testing efficiency. Next, this application summarizes the original threshold configurations of each engine and how to reconfigure them based on experiments and some industry experience. These configurations worked well in the experiments and did not cause false positives.
[0057] In JavaScriptCore, there are three layers of JIT compilers. If a function is called more than 6 and 66 times, the Baseline JIT compiler and the DFG (Data Flow Graph) JIT compiler will be activated respectively. If any function takes more than 10 milliseconds to run on a modern CPU, the FTL (Faster Than Light) JIT compiler is activated. In the experiment, the thresholds are uniformly defined as 10, 50, and 100 function calls. By default, in SpiderMonkey, the JIT compiler requires 1,000 function calls to trigger, and this application is configured to 50. By default, in ChakraCore, Simple JIT and Full JIT require 25 and 20,000 iterations to trigger, respectively. This application experimentally configures them to 10 and 100 times, respectively.
[0058] This application triggers the JIT module by packaging test cases. When packaging a test case to trigger a single-layer JIT compiler module, you can directly use Figure 3 If there is more than one layer, the trigger structure of each layer (similar to Figure 3 21 to 28 in ), from front to back, will be pipelined under the true branch of the if statement in line 20. To ensure that the JIT compiler layer is triggered 100% of the time during fuzzing, the opt function will be called (exceeded) twice its threshold. That is, if the threshold is τ, Figure 3 In line 22 of , N will be set to 2τ.
[0059] The activation mechanism of the V8 Turbofan JIT compiler is different from the other three. Instead of monitoring the number of times a function is called, it tries to estimate the time it takes to execute the unoptimized version and guess how many times it will be executed in the future to prejudge the benefit of optimizing a function. To facilitate testing, V8 provides a built-in local syntax to force JIT compilation and optimization by calling %OptimizeFunctionOnNextCall on the function to be compiled. The V8 maintenance team acknowledges bugs discovered in this way regardless of whether they can be reproduced under the original activation settings. Therefore, this application sets N to 1 when exploring V8 and explicitly calls %OptimizeFunctionOnNextCall(opt) after the for loop on line 22.
[0060] In order to make the fuzzing process more effective and expose more errors, the goal of this application is to generate test samples that can substantially challenge the correctness of the compilation and optimization of the JIT compiler. According to the error type, a targeted sample mutation and generation strategy should be formulated. Here, we focus on the program elements that cause errors (arrays, objects, subexpressions, special numbers) and the three most common optimization behaviors that cause errors (bounds check elimination, redundancy elimination, and common subexpression elimination).
[0061] This application proposes five heuristic mutation strategies for arrays, objects, subexpressions, special numbers, and conditional variable reallocation, as they are the main analysis objects of these three elimination methods. In order to confirm this connection, especially for arrays, objects, and special numbers, a small empirical study of known JIT bugs and their exploits was conducted. 164 different JIT compiler errors and their PoCs were collected from the Google Project Zero bug report list and GitHub's repository on JavaScript engine CVEs, and the existence of these three categories of elements was analyzed. Among these 164 error PoCs, 112 appeared arrays, 115 appeared objects, and 50 appeared special numbers. It is worth mentioning that multiple factors may be required to trigger a bug.
[0062] Next, this application will introduce in detail how each code generation strategy is inspired and designed.
[0063] Arrays: Bounds checks on array indexing operations are incorrectly eliminated if array indices are incorrectly assumed to always be within the array bounds. This happens when the range of the index or the size of the array is incorrectly estimated during range analysis. Range analysis is more prone to errors in some corner cases that can be exploited by special numbers. The size of an array is affected by the APIs that operate on it, so it is important to model and propagate the impact of different APIs on the range analysis of array sizes. There are 12 types of arrays in JavaScript, including Int8Array, Uint8Array, Int16Array, etc. For each array, there are more than 24 APIs, such as Array.concat(), Array.copy(), Array.reverse(), some of which require complex range calculations. For example, when analyzing the array concatenation operation Array.concat(), range addition should be performed correctly. Among the 164 bugs collected, 6 bugs, including CVE-2014-3176, CVE-2016-1646, and CVE-2017-5030, were mainly caused by the unified modeling of Array.concat().
[0064] Objects: In the process of eliminating redundancy, type checks for a variable are removed when the type of the variable is considered to have never changed since its last type check. However, the modification of variable types can be done in extremely hidden ways, especially for JavaScript objects, which is a major factor in type confusion errors. The type of a JavaScript object is determined by the number and type of its properties. Adding, removing, or changing the properties of an object will change its type. JavaScript allows all object properties to be changed, even magic properties such as __proto__, constructor, and prototype. Changing these magic properties can override or pollute the prototype of its base object. If the base object is also inherited by other objects, the pollution will propagate through the prototype chain. With such hidden means to modify object types, type verification algorithms are prone to errors.
[0065] Subexpressions: The existence of common subexpressions is a necessary condition for common subexpression elimination optimization. However, this is difficult or rarely achieved in the process of random mutation. Here, the application intentionally allows some subexpressions to recur in the test samples, and tries to complicate them by mixing different operations, such as multiplication, division, power, root, etc. By scattering these subexpressions in different locations of the program, the ability of the JIT compiler to analyze the operations between any two common subexpressions is tested in the hope that it will make mistakes. If the value of the latter subexpression is changed under the table and ignored by the optimizer, it will be incorrectly replaced with an outdated value and lead to inconsistent execution results.
[0066] Special numbers: Special numbers are very effective in testing corner cases where the JIT compiler is prone to errors, especially during range analysis and type checking. For example, 2.3023e-320 is a special floating point number that was found in CVE-2017-11802, CVE-2018-0840, CVE-2018-8556, CVE-2018-0835, CVE-2018-0953, CVE-2018-8466, and CVE-2018-8542 to be incorrectly treated as a pointer to an object and trigger a type confusion error. In addition, -5.3049894784e-314, equivalent to 0x8000000280000002, is a constant of JavascriptNativeFloatArray::MissingItem and is used to cause type confusion in CVE-2018-0953.
[0067] Conditional variable reassignment: In order to test whether the JIT compiler correctly generates type and bounds checks, never mistakenly removes them during optimization, and correctly verifies them at runtime, this application designs a novel program semantics to conditionally change the type and value of certain variables. Turn off the change when the JIT compiler is triggered, and test whether the correct check can be generated. In this way, the compiler cannot see the type and value of the runtime variable on the change path during profiling, and if the variable is used for sensitive operations, it can survive optimization. This design is in Figure 3 The opt function takes a parameter that controls whether the body of the if statement on line 9 is executed. Within its body, some variables are changed to different types and values. In this example, v0 is changed from an array to an object. When the JIT optimization is triggered, the parameter passed to opt is carefully controlled to be false (see Figure 3Line 23), so the changed type of v0 is never observed at runtime. There is an array indexing operation on v0 on line 13, for which the JIT compiler should generate bounds checks and type checks and not remove them during optimization because the side effects of the if body can flow to line 13. If the type check is mistakenly removed and the type is changed when opt is called (see line 25), indexing an object will cause a type confusion error.
[0068] The elements generated by the above five code generation strategies are called JIT error disclosure elements.
[0069] This application takes measures to control grammatical complexity. When generating the opt function body in mutation, variable declarations and assignment statements are tended to be generated, as well as JavaScript built-in API call statements associated with various data types. In particular, the chances of generating arrays and their related built-in API calls, as well as generating objects and their type change operations are increased. In order to generate recurring subexpressions, a pool of existing subexpressions is maintained and allowed to be inserted repeatedly during mutation. In addition, a set of interesting numbers is extracted from the 164 PoCs collected, allowing the fuzzer to choose from them instead of generating random numbers when needed. For conditional variable reallocation, an if statement with the opt parameter as the condition is inserted, and its body is randomly generated. In order to further improve the density of JIT error-revealing elements in the sample, the generation of complex statements, such as function declarations, class declarations, try / catch statements, switch / case statements, is disabled. It is also avoided to generate loop structures in the function body of opt, because it is embedded in the loop itself, and too many loop structures will also hinder the execution efficiency during fuzz testing. By keeping the syntax simple and pure, the semantic correctness of the generated test input can also be improved.
[0070] S200 , triggering a JIT compiler optimization function through the test sample, and capturing JIT compiler errors according to the execution results of the test sample before and after the optimization.
[0071] In some embodiments, the JIT compiler optimization function is triggered by the test sample, and the JIT compiler error is captured according to the execution result of the test sample before and after the optimization, including: the test sample is first completely executed by the interpreter, and then executed by the JIT compiler, and two final states before and after the optimization are returned; checking whether the two final states before and after the optimization are the same, if not the same, it is considered that an error has occurred in the JIT compiler, and this JIT compiler error is captured.
[0072] In some embodiments, triggering the JIT compiler optimization function through the test sample and capturing JIT compiler errors according to the execution results of the test sample before and after the optimization also includes: executing multiple test samples in succession to pre-check the existence of factors that may mistakenly produce different execution results; checking whether there are any differences in the final state, and forwarding the test samples that pass the pre-check to the JIT compiler.
[0073] In the application, by returning the final execution status of the opt function (see Figure 3 Line 15), its behavior can be observed from the outside and ensure that any related code is not removed as dead code during the optimization process. Because every statement is important during testing, and any tiny error in execution will trigger an alert. For capturing JIT compiler errors, you can execute the code snippet and its JIT version separately, record their final states and compare them, just like a typical differential test. This ensures that their calling contexts are the same, so any differences that arise are due to the differences between interpretation and JIT compilation / optimization. But if you do this, you will start the JavaScript engine twice, which is very time-consuming and will cause serious lags in the fuzz testing process.
[0074] Here, this application proposes a novel idea to make the test case self-aware of the consistency of the execution before and after optimization by integrating the two executions into a single run and including the comparison logic in itself. The test code (i.e., the opt function) is first executed completely by the interpreter and then by the JIT compiler (see Figure 3 Lines 21 to 25), and further compare their final states (see Figure 3 Lines 26 to 28). This application has carefully designed the code packaging, and as long as the opt function has no syntax and semantic errors, the packaged test sample can be successfully executed.
[0075] Now, this application explains how to check whether the two final states returned before and after optimization, that is, whether the two arrays are the same. There are 8 built-in data types in JavaScript, undefined, null, bigint, symbol, boolean, string, number and object. Except for object, the others are primitive types, and the "===" operator can be used to check whether they are strictly equal. For a variable of object type, it is a reference / pointer to an object, which is usually associated with a set of properties (in the form of key-value pairs) and a list of methods. Here, the key is of primitive type, while the value can be of any type, whether primitive or non-primitive. It is cumbersome to thoroughly compare two objects. Given that the comparison is included in the test case, complex calculations will also slow down the fuzzy processing. Here, this application focuses on comparing key-value pairs because they are the main characters that need to be operated in the program.
[0076] deepEquals() function (see Figure 3 Line 1) recursively compares two variables of any type in depth. Variables of different types are never the same. Two variables are the same only if every comparison encountered during the recursive execution returns true. The rules for basic types are all basic cases and do not require recursive calls. In particular, the present application considers two special cases of numeric types, one is that "===" cannot distinguish between 0 and -0, and the other is that "===" considers any comparison involving NaN (Not-A-Number) to be unequal. It is important to distinguish between 0 and -0 in some mathematical calculations, such as division and atan2, and there are several JIT compiler errors caused by their misuse. Object.is() is able to distinguish them. NaN indicates a failure in mathematical calculation, and its comparison rule with "===" will result in a false positive, that is, an unnecessary inconsistency, which is corrected by the present application as equal. For object types, the present application considers commonly used classes and groups them according to whether they can be compared with the same rules. Classes that mainly wrap primitive type variables, such as Date and String, can be compared based on their toString() values. Here, the application uses the valueOf() function to accurately convert Number objects to their corresponding primitive types and delegates comparison to the rules of primitive numbers. Otherwise, if two objects share the same property list (returned by Object.keys()), they are identical and the value of each property is exactly the same. To balance performance, the deepEquals() function considers most common errors instead of catching all possible inconsistencies before handling them.
[0077] Sometimes, executing the same function twice in a single run does produce different results, even on the same arguments, since their calling contexts may differ due to some execution side effects, for example, changing global variables used by the function. Other factors that may lead to different execution results include generating random numbers (such as Math.random()), reading the current time (such as date.now()), and concurrency. Such inconsistencies should not be counted when testing the correctness of the JIT compiler. This application eliminates the impact of these factors to avoid false positives. Concurrency features can be disabled using command symbols of various JavaScript engines. For other factors, this application proposes a two-pronged approach to effectively address them. This application creates an API blacklist to filter some special APIs and blocks their generation during the mutation process. On the other hand, the existence of these factors is pre-checked by executing the function several times in succession and seeing if there are any differences in the final state (see Figure 3 Only test cases that pass the pre-check are forwarded to test the JIT compiler. The blacklist increases the probability of obtaining valid test samples and ensures fuzzing efficiency. It is not easy to have a complete blacklist, and the pre-check is to effectively cut off unqualified test cases. The application also carefully controls the execution iteration to make it small and avoid unexpected activation of the JIT compiler.
[0078] Finally, this application summarizes the workflow of FuzzJIT and draws a diagram, see Figure 4 .
[0079] The embodiment of the present application provides a fuzz testing method for the JIT compiler in the JavaScript engine. By improving the oracle, the crash errors and non-crash errors in the Javascript engine are detected. A code packaging template is designed to ensure that all test cases will trigger the JIT compiler module. Any unexpected execution differences caused by the JIT compiler will be captured. A set of mutation strategies are also designed to guide the generation of samples, so that the mutator focuses on generating samples that are prone to contain optimization error characteristics, which can efficiently mine vulnerabilities in the JavaScript engine JIT compiler.
[0080] Corresponding to the fuzz testing method for the JIT compiler in the JavaScript engine described in the above embodiment, as Figure 5 As shown, this embodiment provides a fuzzy testing device for a JIT compiler in a JavaScript engine. The fuzzy testing device 500 for a JIT compiler in a JavaScript engine includes:
[0081] A sample construction module 501 is used to construct a test sample that includes a JIT compiler error disclosure element and can trigger a JIT compiler optimization function, wherein the test sample uses an opt function;
[0082] The optimization triggering module 502 is used to trigger the JIT compiler optimization function through the test sample and capture JIT compiler errors according to the execution results of the test sample before and after the optimization.
[0083] It should be noted that the information interaction, execution process, etc. between the above-mentioned modules / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0084] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0085] The present application embodiment also provides an electronic device 600, such as Figure 6 As shown, it includes a memory 601, a processor 602, and a computer program 603 stored in the memory 601 and executable on the processor 602. When the processor 602 executes the computer program 603, the steps of the fuzz testing method for the JIT compiler in the JavaScript engine provided in the first aspect are implemented.
[0086] In applications, the electronic device may include, but is not limited to, a processor and a memory. Figure 6 This is only an example of an electronic device and does not constitute a limitation on the electronic device. It may include more or fewer components than shown in the figure, or combine certain components, or different components, such as input and output devices, network access devices, etc. Input and output devices may include cameras, audio acquisition / playback devices, display screens, etc. Network access devices may include a network module for wirelessly communicating with external devices.
[0087] In applications, the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0088] In application, the memory may be an internal storage unit of an electronic device in some embodiments, such as a hard disk or memory of the electronic device. The memory may also be an external storage device of the electronic device in other embodiments, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. The memory may also include both an internal storage unit and an external storage device of the electronic device. The memory is used to store operating systems, applications, boot loaders (BootLoader), data, and other programs, such as program codes of computer programs, etc. The memory may also be used to temporarily store data that has been output or is to be output.
[0089] The embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0090] The present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to an electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.
[0091] Those of ordinary skill in the art will appreciate that the devices and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0092] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interface, indirect coupling or communication connection of devices, which can be electrical, mechanical or other forms.
[0093] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A fuzz testing method for a JIT compiler in a JavaScript engine, characterized in that: include: Constructing a test sample that includes a JIT compiler error disclosure element and can trigger a JIT compiler optimization function, wherein the test sample uses an opt function; The JIT compiler optimization function is triggered by the test sample, and JIT compiler errors are captured according to the execution results of the test sample before and after the optimization.
2. The fuzz testing method for the JIT compiler in the JavaScript engine according to claim 1, characterized in that: The build contains JIT compiler error disclosure elements and test samples that can trigger JIT compiler optimization functions, including: Develop targeted sample mutation and generation strategies based on program elements and optimization behaviors that cause JIT compiler errors; A JIT compiler error disclosure element is generated through the sample mutation and generation strategy, and a test sample is constructed according to the JIT compiler error disclosure element.
3. The fuzz testing method for the JIT compiler in the JavaScript engine as claimed in claim 2, characterized in that: The program elements include arrays, objects, sub-expressions and special numbers, and the optimization behaviors include bounds check elimination, redundancy elimination and common sub-expression elimination.
4. The fuzz testing method for the JIT compiler in the JavaScript engine according to claim 2, characterized in that: The sample mutation and generation strategies include five heuristic mutation strategies: array, object, sub-expression, special number and conditional variable reallocation.
5. The fuzz testing method for the JIT compiler in the JavaScript engine according to claim 1, characterized in that: The build contains a test sample that contains JIT compiler error disclosure elements and can trigger JIT compiler optimization functions, and also includes: reconfiguring the activation threshold of each JIT compiler layer according to the original threshold configuration of each JIT compiler layer; Set the number of calls to each JIT compiler layer opt function to twice the activation threshold of the JIT compiler layer.
6. The fuzz testing method for the JIT compiler in the JavaScript engine according to claim 1, characterized in that: The triggering of the JIT compiler optimization function by the test sample and capturing the JIT compiler errors according to the execution results of the test sample before and after the optimization include: The test sample is first completely executed by the interpreter and then by the JIT compiler, and two final states before and after optimization are returned; Check whether the two final states before and after the optimization are the same. If they are not the same, it is considered that an error has occurred in the JIT compiler, and the JIT compiler error is captured.
7. The fuzz testing method for a JIT compiler in a JavaScript engine as claimed in claim 1, characterized in that: The method of triggering the JIT compiler optimization function by using the test sample and capturing JIT compiler errors according to the execution results of the test sample before and after the optimization further includes: Execute multiple test samples in succession to pre-check the existence of factors that may falsely produce different execution results; Test samples that pass the precheck are forwarded to the JIT compiler to see if there are any differences in the final state.
8. A fuzz testing device for a JIT compiler in a JavaScript engine, characterized in that: include: A sample construction module, used to construct a test sample that includes a JIT compiler error disclosure element and can trigger a JIT compiler optimization function, wherein the test sample uses an opt function; The optimization trigger module is used to trigger the JIT compiler optimization function through the test sample and capture JIT compiler errors according to the execution results of the test sample before and after the optimization.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the fuzz testing method for the JIT compiler in the JavaScript engine is implemented as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the fuzz testing method for a JIT compiler in a JavaScript engine is implemented as described in any one of claims 1 to 7.
