Compiler-based program branch data integrity protection method, system and equipment and medium
Through compiler-based static analysis and runtime verification, combined with Intel MPK hardware protection, the problem of large overhead of non-controlled data attack defense in the existing technology is solved, and efficient data flow integrity protection in large programs is achieved.
Patent Information
- Application Number
- CN202410959146.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-07-17
AI Technical Summary
The prior art has problems such as excessive system overhead and excessive performance overhead when defending against non-controlled data attacks, especially in large programs, it is difficult to effectively protect data flow integrity.
Using the compiler-based program branch data integrity protection method, the branch data to be protected is obtained through static analysis, the static value flow analysis algorithm is used to generate the program data flow chart, and the runtime definition table is protected through Intel MPK hardware when the program is run. Security, verify that the data source point is corrupted.
It realizes efficient and secure protection of data flow integrity in large programs, reduces system overhead, is suitable for a wide range of applications, and has better performance than the existing technology.
Smart Images

Figure CN119089509A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data flow integrity protection (DFI), and in particular relates to a compiler-based program branch data integrity protection method, system, device and medium. Background Art
[0002] Non-control data attacks make it unnecessary for attackers to inject and execute their own code. As long as they identify the exploitable parts in the target program (such as functions that are allowed to run as an administrator), they can access unauthorized functions by changing the values in the program data structure. Some existing methods that are effective against control data attacks cannot detect non-control data attacks. Dynamic taint analysis marks external input data as taints and tracks the propagation path. It performs security checks according to security policies at designated security-sensitive instructions, but because it needs to track external input, the overhead is often high. Data randomization (DSR) randomizes memory data, then assigns different masks to different equivalence classes, and performs XOR operations with the actual values. However, in the calculation of equivalence classes, due to the inaccuracy of the analysis algorithm, the calculated equivalence classes are too large, and attackers can bypass defense measures. Dynamic Information Flow Tracing (DIFT) is similar to dynamic taint analysis. The basic idea is to mark (taint) untrusted external data or sensitive internal data and track their propagation in the system. What is different from dynamic taint analysis is that when the processor detects an instruction operation on untrusted data, a trap will be generated and handed over to the trap processor for processing. Data flow integrity protection (DFI) is currently the mainstream solution for defending against non-control data attacks. Initially, DFI adopted the method of maintaining a runtime definition table (RDT) to protect the integrity of the data flow. Specifically, at runtime, each variable is actually analyzed for definition reachability, and the identifier of its last write instruction is stored in the runtime definition table (RDT); when reading a variable, the identifier in the RDT table is first indexed by the variable address, and then the identifier is checked whether it exists in the static data flow graph (DFG). If it does not exist, the data flow integrity is destroyed and an exception is thrown. However, its security depends on the accuracy of the DFG generated by the static definition reachability analysis, and because it protects all non-control data, there is a problem of excessive system overhead. Selecting some sensitive non-control data in the program for protection is an effective way to solve the system overhead problem, and has been extensively studied by many scholars.
[0003] SCHLESINGER C et al. disclosed Modular protections against non-control data attacks (SCHLESINGER C, PATTABIRAMAN K, SWAMY N, et al. Modular protections against noncontrol data attacks [J]. Journal of Computer Security, 2014, 22 (5): 699-742.), hereinafter referred to as YARRA. YARRA declares key data types and divides these key data types into important data to be protected. These data can only be written by pointers with given static type characteristics, and detects any invalid writes (including possible overwrites due to buffer overflow) during dynamic runtime. However, when the amount of key data is too large or the application is computationally intensive, YARRA has the disadvantage of excessive performance overhead, which exceeds 400%.
[0004] SONG C et al. disclosed HDFI: Hardware-assisted data-flow isolation (SONG C, MOON H, ALAM M, et al. HDFI: Hardware-assisted data-flow isolation [C] / / 2016 IEEE Symposium on Security and Privacy (SP). 2016: 1-17.). Since HDFI protects some non-control data, its performance overhead is low. However, HDFI introduces a new instruction set, which makes it difficult to be widely used. It is also limited by hardware characteristics and the newly introduced instruction set, and has the disadvantage of poor compatibility.
[0005] SONG C et al. published Enforcing Kernel Security Invariants with Data Flow Integrity (SONG C, LEE B, LU K, et al. Enforcing Kernel Security Invariants with Data Flow Integrity. [C / OL] / / Network and Distributed System Security Symposium. 2016. https: / / api.semanticscholar.org / CorpusID:63019167.). KENALI mainly protects some data in the kernel, and its performance overhead is relatively low. However, KENALI requires a lot of hardware support, so it is not universal.
[0006] LIU T et al. published TMDFI: Tagged memory assisted for fine-grained data-flow integrity towards embedded systems against software exploitation (LIU T, SHI G, CHEN L, et al. TMDFI: Tagged memory assisted for fine-grained data-flow integrity towards embedded systems against software exploitation [C] / / 2018 17th IEEE International Conference On Trust, Security And Privacy In Computing And Communications / 12th IEEE International Conference On Big Data Science And Engineering (Trust Com / Big Data SE). 2018: 545-550.). TMDFI adopts an integrity protection scheme based on tag technology, but TMDFI has only 256 tags and is only suitable for small programs, not large programs. Summary of the invention
[0007] In order to overcome the shortcomings of the above-mentioned prior art, the purpose of the present invention is to provide a compiler-based program branch data integrity protection method, system, device and medium, which obtains the branch data to be protected by performing control dependency analysis on the program, and then uses a static value flow analysis algorithm to obtain the branch data source point to form a program data flow graph; when the program is running, it verifies whether the data source point is destroyed, thereby achieving the purpose of protecting the integrity of the program data flow. It has the characteristics of safety, efficiency and high universality, and can be applied to large programs.
[0008] In order to achieve the above object, the technical solution adopted by the present invention is:
[0009] A compiler-based method for protecting program branch data integrity, including static analysis and program runtime verification;
[0010] When the data stream integrity protection is performed on the program, the static analysis is performed, including the following steps:
[0011] Step 1: Input the program intermediate code (LLVM-IR), and perform control dependency analysis on the input program intermediate code (LLVM-IR) to obtain the branch data related to the control flow to be protected in the program;
[0012] Step 2: Pass the branch data obtained in step 1 into the static value flow analysis algorithm to locate the source of the branch data;
[0013] Step 3: Generate a program data flow graph (DFG) based on the branch data source points analyzed in step 2;
[0014] When the program is running, the program runtime verification is performed, including the following steps:
[0015] Step S1: Save the branch data source point obtained by the analysis in step 2 to the Runtime Definitions Table (RDT), then search for the corresponding source point in the Runtime Definitions Table (RDT) according to the data address index, and protect the security of the Runtime Definitions Table (RDT) through Intel MPK hardware;
[0016] Step S2: Determine whether the source point found in step S1 is within the scope of the program data flow graph (DFG) generated in step 3. If it is, continue to execute the program; otherwise, throw an exception.
[0017] The step 1 specifically includes:
[0018] First, the program intermediate code (LLVM-IR) is passed as input to the Pass framework of the LLVM compiler. The Pass framework performs control dependency analysis on the program through a control dependency analysis algorithm. The control dependency analysis includes completeness analysis and the most recent analysis. The completeness analysis is to analyze and obtain all branch data related to the control flow in the program, and the most recent analysis is to analyze and obtain the most recent branch data related to the control flow in the program.
[0019] The control dependency analysis algorithm has the following specific steps:
[0020] Step 1.1: Initialize the branch data set to be protected (Condition_DataSet) and provide two analysis methods, namely the most recent analysis and completeness analysis;
[0021] Step 1.2: Loop through all program instructions in the program and determine whether the current instruction is a control flow instruction. If the current instruction is a control flow instruction, go to step 1.3. If the current instruction is not a control flow instruction, continue with step 1.2.
[0022] Step 1.3: Analyze and obtain all the aforementioned basic blocks (BasicBlock) of the control flow instructions in step 1.2;
[0023] Step 1.3.1: If the most recent analysis is selected in step 1.1, then analyze the termination instructions of the basic blocks obtained in step 1.3 in order from the nearest to the farthest distance from the control flow to see if they are conditional branch instructions, find the conditional branch instruction closest to the control flow, and add the branch data to the set of branch data to be protected, and continue with step 1.2;
[0024] Step 1.3.2: If the completeness analysis is selected in step 1.1, then analyze in turn whether the termination instructions of all the above basic blocks obtained in step 1.3 are conditional branch instructions, and add all the branch data obtained by the analysis to the set of branch data to be protected, and continue with step 1.2;
[0025] Step 1.4: Once all the program instructions in step 1.2 have been traversed, the analysis is complete.
[0026] The step 2 specifically includes:
[0027] The Pass framework of the LLVM compiler passes the branch data as input to the source point-assisted context-sensitive static value flow analysis algorithm to obtain the source point of the branch data, where the source point instruction is defined as the instruction that assigns the data for the last time in the program, and the operand of the instruction is not a function parameter. When the operand of the source point instruction is passed from the function parameter, it is necessary to further trace the source point of the branch data in the program;
[0028] The static value flow analysis algorithm specifically includes the following steps:
[0029] Step 2.1: Initialize the worklists, add the sensitive data instructions to the worklists, and assign the sensitive data to be analyzed to the temporary variable (temp_val);
[0030] Step 2.2: Iterate the worklists in step 2.1 until the definition instruction (Alloca) of sensitive data is found and the loop ends:
[0031] Step 2.2.1: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a function parameter. If it is a function parameter, obtain its callee and enter the callee to continue value flow analysis until its source point is found and the loop is terminated;
[0032] Step 2.2.2: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a phi instruction, and trace back to its source point according to the two branches of the phi instruction respectively, and terminate the program;
[0033] Step 2.2.3: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a select instruction. Different from the analysis of the phi instruction, the select instruction only needs to perform backtracking analysis on one of its operands and terminate the program.
[0034] Step 2.2.4: When the temporary variable (temp_val) after the assignment in step 2.1 is not the case of step 2.2.1 to step 2.2.3, reassign the operand of the temporary variable (temp_val) instruction after the assignment in step 2.1 to the temporary variable (temp_val) instruction itself, and add the instruction to the worklist (worklists), end the judgment, and re-enter the step 2.2.1 loop;
[0035] Step 2.3: Based on the definition instruction (Alloca) of the sensitive data found in step 2.2, traverse the instructions of the entire function, find all write instructions based on the def-use relationship, and write the found write instructions into the source point instruction set (write_insts);
[0036] Step 2.4: Further judge the write instruction obtained in step 2.3 to determine whether the operand (valueOpearnd) of this write instruction is a function parameter. If it is a function parameter, obtain its callee and enter the callee to continue value flow analysis until its source point is found and the loop is terminated.
[0037] The tuple of the program data flow graph (DFG) generated in step 3 is defined as [I i ,I o ,Origin], where I i Represents the branch instruction itself, I o Represents the source instruction itself, and Origin is the source value.
[0038] The step S1 comprises:
[0039] The Pass framework of the LLVM compiler saves the source points located by static value flow analysis into the runtime definition table (RDT) in the form of key-value pairs (key, value), where key is the source point address and value is the source point value. The security of the runtime definition table (RDT) is protected by Intel MPK hardware, which specifically includes the following steps:
[0040] Step S1.1: The Runtime Definition Table (RDT) is a memory area protected by IntelMPK that is requested for context information when the program is running, and the access rights of the memory area are set to inaccessible;
[0041] Step S1.2: When there is context information to be saved, the access permission of the memory area applied for in step S1.1 is set to readable, and the entry to be stored is retrieved;
[0042] Step S1.3: After the relevant entry is retrieved in step 1.2, the access permission of the memory area applied for in step S1.1 is set to writable, and the context information is written;
[0043] Step S1.4: When the writing in step 1.3 is completed, the access permission of the memory area applied for in step S1.1 is immediately set to inaccessible;
[0044] Step S1.5: When the program executes to the module that needs to be verified, the access permission of the memory area applied for in step S1.1 is set to readable, and relevant information is searched for verification;
[0045] Step S1.6: When the verification in step S1.5 is completed, the access permission of the memory area applied for in step S1.1 is set to inaccessible.
[0046] The step S2 comprises:
[0047] The Pass framework of the LLVM compiler generates an executable program after the program is instrumented. When the program is running, when it executes to a sensitive branch instruction, the program searches for the source point value in the runtime definition table (RDT) based on the address of the branch data, and forms a program data flow tuple, and further determines whether the program data flow tuple is in the program data flow graph (DFG). If the program data flow tuple is in the program data flow graph (DFG), the program continues to execute. If the program data flow tuple is not in the program data flow graph (DFG), an exception is thrown.
[0048] A system based on a compiler-based program branch data integrity protection method, comprising:
[0049] Static analysis module: inputs the program intermediate code (LLVM-IR), performs control dependency analysis on the input program intermediate code (LLVM-IR), obtains the branch data related to the control flow to be protected in the program, and then passes the branch data to the static value flow analysis algorithm to locate the source point of the branch data and generate the program data flow graph (DFG);
[0050] Program runtime verification module: Save the branch data source point to the runtime definition table (RDT), then search for the corresponding source point in the runtime definition table (RDT) based on the data address index, and use Intel MPK hardware to protect the security of the runtime definition table (RDT), and determine whether the source point is within the program data flow graph (DFG). If it is, continue to execute the program, otherwise throw an exception.
[0051] A compiler-based program branch data integrity protection device, comprising:
[0052] Memory: used for storing a computer program for implementing a compiler-based program branch data integrity protection method;
[0053] Processor: used to implement the compiler-based program branch data integrity protection method when executing the computer program.
[0054] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a compiler-based program branch data integrity protection method are implemented.
[0055] Compared with the prior art, the beneficial effects of the present invention are:
[0056] 1. The present invention performs static analysis based on the program intermediate code (LLVM-IR), and statically inserts and rewrites the program through the Pass framework. It has the advantage of high universal adaptability and can be applied to large-scale applications.
[0057] 2. The present invention selects this part of non-control data related to the control flow for integrity protection, and innovatively proposes two control dependency analysis algorithms, namely completeness analysis and most recent analysis, which respectively focus on all conditional branch data related to the control flow and the most recent conditional branch data, eliminate some non-sensitive data, and make the system have the characteristics of low overhead.
[0058] 3. The present invention introduces the context concept of source point to realize data flow integrity protection, obtains the source point of sensitive data through static value flow analysis algorithm, and introduces the source point into the tuple definition of program data flow graph, so that the system has the characteristics of high security.
[0059] 4. The present invention uses Intel MPK hardware to perform security protection on the runtime definition table, and converts the memory area between readable, writable and unavailable access rights, so that the memory segment has the characteristics of high security.
[0060] In summary, the present invention has the advantages of low overhead, high security, and high universal adaptability, and can be applied to large-scale applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 It is a schematic diagram of the program structure of the present invention.
[0062] Figure 2 A control dependency analysis algorithm diagram used in an embodiment of the present invention.
[0063] Figure 3 This is a diagram of a static value flow analysis algorithm used in an embodiment of the present invention.
[0064] Figure 4 It is a schematic diagram of the Intel MPK hardware protection runtime definition table (RDT) of the present invention.
[0065] Figure 5 This is a comparison chart of the number of backtracking levels required for the most recent analysis according to an embodiment of the present invention.
[0066] Figure 6 The figure is a comparison of the completeness analysis of the embodiment of the present invention and the amount of protected data in the most recent analysis.
[0067] Figure 7 This is a comparison diagram of system overheads of embodiments of the present invention. DETAILED DESCRIPTION
[0068] The present invention will be described in detail below in conjunction with the accompanying drawings.
[0069] like Figure 1 As shown, a compiler-based program branch data integrity protection method includes static analysis and program runtime verification;
[0070] When the data stream integrity protection is performed on the program, the static analysis is performed, including the following steps:
[0071] Step 1: First, convert the source program into program intermediate code (LLVM-IR) through the LLVM compiler, then input the program intermediate code (LLVM-IR), and perform control dependency analysis on the input program intermediate code (LLVM-IR) to obtain the branch data related to the control flow to be protected in the program. According to the different requirements of the user for the security of the system, you can choose complete analysis or the most recent analysis;
[0072] Step 2: pass the branch data obtained in step 1 into the static value flow analysis algorithm to locate the source of the branch data. In the present invention, it is only necessary to find the last assignment instruction for the sensitive data, and the assignment of the instruction is not a function parameter. The purpose of this is to avoid unnecessary analysis and reduce the complexity of the analysis. At the same time, it is assumed that the attacker has the attack authority for the function stack space, so when the assigned value is a function parameter, it is still untrustworthy;
[0073] Step 3: Generate a program data flow graph (DFG) based on the branch data source points analyzed in step 2, in order to verify whether the data flow integrity is destroyed when the program is running;
[0074] When the program is running, the program runtime verification is performed, including the following steps:
[0075] Step S1: Save the branch data source point obtained by the analysis in step 2 to the Runtime Definitions Table (RDT), then search for the corresponding source point in the Runtime Definitions Table (RDT) according to the data address index, and protect the security of the Runtime Definitions Table (RDT) through Intel MPK hardware;
[0076] Step S2: Determine whether the source point found in step S1 is within the scope of the program data flow graph (DFG) generated in step 3. If it is, continue to execute the program; otherwise, throw an exception.
[0077] The step 1 specifically includes:
[0078] First, the program intermediate code (LLVM-IR) is passed as input to the Pass framework of the LLVM compiler. The Pass framework performs control dependency analysis on the program through a control dependency analysis algorithm. The control dependency analysis includes completeness analysis and the most recent analysis. The completeness analysis is to analyze and obtain all branch data related to the control flow in the program, and the most recent analysis is to analyze and obtain the most recent branch data related to the control flow in the program.
[0079] The control dependency analysis algorithm aims to obtain branch data related to the control flow. The control dependency analysis algorithm identifies sensitive branch data in the instruction set of the program based on IR so as to further analyze and process it. According to the selection judgment condition that the branch data is not empty (Condition_DataSet is not empty) or the current basic block is the initial basic block (isEntryBB(curbb)), the most recent analysis and completeness analysis are performed respectively. The input of the control dependency analysis algorithm is the program IR file, and the output is the branch data related to the control flow. The specific steps are as follows:
[0080] Step 1.1: Initialize the branch data set to be protected (Condition_DataSet) and provide two analysis methods, namely the most recent analysis and completeness analysis;
[0081] Step 1.2: Loop through all program instructions in the program and determine whether the current instruction is a control flow instruction. If the current instruction is a control flow instruction, go to step 1.3. If the current instruction is not a control flow instruction, continue with step 1.2.
[0082] Step 1.3: Analyze and obtain all the aforementioned basic blocks (BasicBlock) of the control flow instructions in step 1.2;
[0083] Step 1.3.1: If the most recent analysis is selected in step 1.1, then analyze the termination instructions of the basic blocks obtained in step 1.3 in order from the nearest to the farthest distance from the control flow to see if they are conditional branch instructions, find the conditional branch instruction closest to the control flow, and add the branch data to the set of branch data to be protected, and continue with step 1.2;
[0084] Step 1.3.2: If the completeness analysis is selected in step 1.1, then analyze in turn whether the termination instructions of all the above basic blocks obtained in step 1.3 are conditional branch instructions, and add all the branch data obtained by the analysis to the set of branch data to be protected, and continue with step 1.2;
[0085] Step 1.4: Once all the program instructions in step 1.2 have been traversed, the analysis is complete.
[0086] Control dependency analysis, the specific implementation of the algorithm is as follows Figure 2 As shown:
[0087] (1) Line 1 initializes the Condition_DataSet collection, and line 16 returns the conditional dependency data set obtained through analysis;
[0088] (2) Lines 2-16 are loops that traverse all instructions in the program until the entire program IR is traversed; Line 4 determines whether the instruction is an indirect call, and Lines 5-12 perform conditional dependency data analysis on the indirect call. Specifically, Line 6 obtains all previous basic blocks of the current basic block;
[0089] (3) Lines 7-10 traverse all basic blocks until the current basic block is the function entry basic block, and the loop ends. Note that here, if the Condition_DataSet collection is not empty, the loop will be exited. This analysis method is suitable for the most recent analysis method. Line 8 determines whether the end instruction of the basic block is a conditional branch instruction. If it is a conditional branch instruction, the branch data is added to the Condition_DataSet collection.
[0090] The step 2 specifically includes:
[0091] The Pass framework of the LLVM compiler passes the branch data as input to the source point-assisted context-sensitive static value flow analysis algorithm to obtain the source point of the branch data, where the source point instruction is defined as the instruction that assigns the data for the last time in the program, and the operand of the instruction is not a function parameter. When the operand of the source point instruction is passed from the function parameter, it is necessary to further trace the source point of the branch data in the program;
[0092] The static value flow analysis algorithm inputs the sensitive data to be analyzed, and outputs the inter-procedural instructions for value flow analysis based on the def-use chain and the write instructions at the source point, which specifically includes the following steps:
[0093] Step 2.1: Initialize the worklists, add the sensitive data instructions to the worklists, and assign the sensitive data to be analyzed to the temporary variable (temp_val);
[0094] Step 2.2: Iterate the worklists in step 2.1 until the definition instruction (Alloca) of sensitive data is found and the loop ends:
[0095] Step 2.2.1: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a function parameter. If it is a function parameter, obtain its callee and enter the callee to continue value flow analysis until its source point is found and the loop is terminated;
[0096] Step 2.2.2: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a phi instruction, and trace back to its source point according to the two branches of the phi instruction respectively, and terminate the program;
[0097] Step 2.2.3: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a select instruction. Different from the analysis of the phi instruction, the select instruction only needs to perform backtracking analysis on one of its operands and terminate the program.
[0098] Step 2.2.4: When the temporary variable (temp_val) after the assignment in step 2.1 is not the case of step 2.2.1 to step 2.2.3, reassign the operand of the temporary variable (temp_val) instruction after the assignment in step 2.1 to the temporary variable (temp_val) instruction itself, and add the instruction to the worklist (worklists), end the judgment, and re-enter the step 2.2.1 loop;
[0099] Step 2.3: Based on the definition instruction (Alloca) of the sensitive data found in step 2.2, traverse the instructions of the entire function, find all write instructions based on the def-use relationship, and write the found write instructions into the source point instruction set (write_insts);
[0100] Step 2.4: Further judge the write instruction obtained in step 2.3 to determine whether the operand (valueOpearnd) of this write instruction is a function parameter. If it is a function parameter, obtain its callee and enter the callee to continue value flow analysis until its source point is found and the loop is terminated.
[0101] The tuple of the program data flow graph (DFG) generated in step 3 is defined as [I i ,I o ,Origin], where I i Represents the branch instruction itself, I o Represents the source instruction itself, and Origin is the source value.
[0102] The specific implementation of the static value flow analysis algorithm is as follows Figure 3 As shown:
[0103] (1) First, lines 1-3 of the algorithm initialize a worklist, add sensitive data instructions to the list, and assign the sensitive data to be analyzed to temp_val;
[0104] (2) Lines 4-19 iterate the work list until the definition (Alloca) instruction of sensitive data is found and the loop ends:
[0105] a) Lines 5-8 determine whether temp_val is a function parameter. If it is a function parameter, its callee is obtained and the value flow analysis is continued in the callee until its source point is found and the loop is terminated;
[0106] b) Lines 9-11 determine whether temp_val is a phi instruction, and trace back to its source point according to the two branches of phi respectively, and terminate the program;
[0107] c) Lines 12-14 determine whether temp_val is a select instruction. Different from the analysis of the phi instruction, select only needs to backtrack one of its operands and terminate the program;
[0108] d) In addition to the above, lines 15-18 reassign the operand of the temp_val instruction to itself, add the instruction to the worklists, end the if judgment, and re-enter the loop;
[0109] (3) Line 20 is based on the Allca instruction obtained from the above analysis. It traverses the instructions of the entire function, finds all write instructions based on the def-use relationship, and writes them into the write_insts set.
[0110] (4) Lines 21-26 further judge the write instruction obtained from the above analysis to determine whether its valueOpearnd is a function parameter. If it is a function parameter, its callee is obtained and the value flow analysis is continued in the callee until its source point is found and the loop is terminated.
[0111] The step S1 comprises:
[0112] like Figure 4 As shown in the figure, the Pass framework of the LLVM compiler saves the source points located by static value flow analysis into the runtime definition table (RDT) in the form of key-value pairs (key, value), where key is the source point address and value is the source point value, and protects the security of the runtime definition table (RDT) through Intel MPK hardware, which specifically includes the following steps:
[0113] Step S1.1: The Runtime Definition Table (RDT) is a memory area protected by IntelMPK that is requested for context information when the program is running, and the access rights of the memory area are set to inaccessible;
[0114] Step S1.2: When there is context information to be saved, the access permission of the memory area applied for in step S1.1 is set to readable, and the entry to be stored is retrieved;
[0115] Step S1.3: After the relevant entry is retrieved in step 1.2, the access permission of the memory area applied for in step S1.1 is set to writable, and the context information is written;
[0116] Step S1.4: When the writing in step 1.3 is completed, the access permission of the memory area applied for in step S1.1 is immediately set to inaccessible;
[0117] Step S1.5: When the program executes to the module that needs to be verified, the access permission of the memory area applied for in step S1.1 is set to readable, and relevant information is searched for verification;
[0118] Step S1.6: When the verification in step S1.5 is completed, the access permission of the memory area applied for in step S1.1 is set to inaccessible.
[0119] The step S2 comprises:
[0120] The Pass framework of the LLVM compiler generates an executable program after the program is instrumented. When the program is running, when it executes to a sensitive branch instruction, the program searches for the source point value in the runtime definition table (RDT) based on the address of the branch data, and forms a program data flow tuple, and further determines whether the program data flow tuple is in the program data flow graph (DFG). If the program data flow tuple is in the program data flow graph (DFG), the program continues to execute. If the program data flow tuple is not in the program data flow graph (DFG), an exception is thrown to determine whether the integrity of the branch data is destroyed.
[0121] A system based on the compiler-based program branch data integrity protection method includes:
[0122] Static analysis module: inputs the program intermediate code (LLVM-IR), performs control dependency analysis on the input program intermediate code (LLVM-IR), obtains the branch data related to the control flow to be protected in the program, and then passes the branch data to the static value flow analysis algorithm to locate the source of the branch data and generate a program data flow graph (DFG) to implement steps 1 to 3 of a compiler-based program branch data integrity protection method;
[0123] Program runtime verification module: saves the branch data source point to the runtime definition table (RDT), then searches for the corresponding source point in the runtime definition table (RDT) based on the data address index, and protects the security of the runtime definition table (RDT) through Intel MPK hardware, determines whether the source point is within the program data flow graph (DFG), continues to execute the program if it is, and throws an exception if it is not, to implement steps S1 to S2 of a compiler-based program branch data integrity protection method.
[0124] A compiler-based program branch data integrity protection device, comprising:
[0125] Memory: used for storing a computer program for implementing a compiler-based program branch data integrity protection method;
[0126] Processor: used to implement the compiler-based program branch data integrity protection method when executing the computer program.
[0127] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a compiler-based program branch data integrity protection method are implemented.
[0128] Figure 5 The number of backtracking layers required for the most recent analysis of the SPEC CPU2006 test case by the present invention, wherein the first column represents the test case, the second column ICTs represents the number of control flow transfer instructions (excluding return instructions, only indirect calls and virtual calls) in the test case, the third column L1 represents the number of most recent conditional branch data related to the control flow that can be found by the control dependency analysis algorithm by backtracking one layer, and the fourth column L2, the fifth column L3 and so on. Therefore, the present invention greatly reduces the time and cost of analysis by backtracking two layers for the most recent analysis.
[0129] Figure 6 This is a comparison of the two analysis methods of the present invention, namely, completeness analysis and the amount of data protected by the most recent analysis. In the figure, Full analysis is the completeness analysis and Last-br analysis is the most recent analysis. It can be seen that the amount of data protected by the most recent analysis is greatly reduced. Since the farther away from the control flow in the program, the higher the cost of tampering by the attacker, the most recent analysis reduces the system overhead as much as possible without sacrificing security, and at the same time meets customized security based on the different security requirements of different users.
[0130] Figure 7 This is the system overhead of the SPEC CPU2006 test suite of the present invention, wherein the average system overhead of the latest analysis is 10.10%, and the average system overhead of the completeness analysis is 50.12%.
[0131] As can be seen from the accompanying drawings and embodiments, compared with the prior art, the performance overhead of the present invention is reduced by 98% compared with YARRA; compared with HDFI, no new instruction set is introduced, so it can be more widely used in large programs; compared with KENALI, which requires the support of many hardware, the present invention only requires the support of Intel MPK, and the current mainstream processors have defaulted to support Intel MPK, so it can be more conveniently applied to the system; compared with TMDFI, the present invention does not use the traditional label technology, but adopts the source point auxiliary context-sensitive technology, which can solve the shortcoming that the number of labels is not enough to protect large programs. After testing all C programs and C++ programs of SPEC CPU 2006, when the last analysis is taken and two layers are traced back, the number of branch data related to indirect calls that can be protected is 84.2%, of which the branch data that can be protected by C type programs accounts for 97.5%, which can greatly make up for the defect that CFI technology cannot guarantee the integrity of non-control data.
Claims
1. A compiler-based program branch data integrity protection method, characterized in that: Includes static analysis and program runtime verification; When the data stream integrity protection is performed on the program, the static analysis is performed, including the following steps: Step 1: Input the program intermediate code (LLVM-IR), and perform control dependency analysis on the input program intermediate code (LLVM-IR) to obtain the branch data related to the control flow to be protected in the program; Step 2: Pass the branch data obtained in step 1 into the static value flow analysis algorithm to locate the source of the branch data; Step 3: Generate a program data flow graph (DFG) based on the branch data source points analyzed in step 2; When the program is running, the program runtime verification is performed, including the following steps: Step S1: Save the branch data source point obtained by the analysis in step 2 to the Runtime Definitions Table (RDT), then search for the corresponding source point in the Runtime Definitions Table (RDT) according to the data address index, and protect the security of the Runtime Definitions Table (RDT) through Intel MPK hardware; Step S2: Determine whether the source point found in step S1 is within the scope of the program data flow graph (DFG) generated in step 3. If it is, continue to execute the program; otherwise, throw an exception.
2. A compiler-based program branch data integrity protection method according to claim 1, characterized in that: The step 1 specifically includes: First, the program intermediate code (LLVM-IR) is passed as input to the Pass framework of the LLVM compiler. The Pass framework performs control dependency analysis on the program through a control dependency analysis algorithm. The control dependency analysis includes completeness analysis and the most recent analysis. The completeness analysis is to analyze and obtain all branch data related to the control flow in the program, and the most recent analysis is to analyze and obtain the most recent branch data related to the control flow in the program. The control dependency analysis algorithm has the following specific steps: Step 1.1: Initialize the branch data set to be protected (Condition_DataSet) and provide two analysis methods, namely the most recent analysis and completeness analysis; Step 1.2: Loop through all program instructions in the program and determine whether the current instruction is a control flow instruction. If the current instruction is a control flow instruction, go to step 1.
3. If the current instruction is not a control flow instruction, continue with step 1.
2. Step 1.3: Analyze and obtain all the aforementioned basic blocks (BasicBlock) of the control flow instructions in step 1.2; Step 1.3.1: If the most recent analysis is selected in step 1.1, then analyze the termination instructions of the basic blocks obtained in step 1.3 in order from the nearest to the farthest distance from the control flow to see if they are conditional branch instructions, find the conditional branch instruction closest to the control flow, and add the branch data to the set of branch data to be protected, and continue with step 1.2; Step 1.3.2: If the completeness analysis is selected in step 1.1, then analyze in turn whether the termination instructions of all the above basic blocks obtained in step 1.3 are conditional branch instructions, and add all the branch data obtained by the analysis to the set of branch data to be protected, and continue with step 1.2; Step 1.4: Once all the program instructions in step 1.2 have been traversed, the analysis is complete.
3. A compiler-based program branch data integrity protection method according to claim 1, characterized in that: The step 2 specifically includes: The Pass framework of the LLVM compiler passes the branch data as input to the source point-assisted context-sensitive static value flow analysis algorithm to obtain the source point of the branch data, where the source point instruction is defined as the instruction that assigns the data for the last time in the program, and the operand of the instruction is not a function parameter. When the operand of the source point instruction is passed from the function parameter, it is necessary to further trace the source point of the branch data in the program; The static value flow analysis algorithm specifically includes the following steps: Step 2.1: Initialize the worklists, add the sensitive data instructions to the worklists, and assign the sensitive data to be analyzed to the temporary variable (temp_val); Step 2.2: Iterate the worklists in step 2.1 until the definition instruction (Alloca) of sensitive data is found and the loop ends: Step 2.2.1: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a function parameter. If it is a function parameter, obtain its callee and enter the callee to continue value flow analysis until its source point is found and the loop is terminated; Step 2.2.2: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a phi instruction, and trace back to its source point according to the two branches of the phi instruction respectively, and terminate the program; Step 2.2.3: Determine whether the temporary variable (temp_val) assigned in step 2.1 is a select instruction. Different from the analysis of the phi instruction, the select instruction only needs to perform backtracking analysis on one of its operands and terminate the program. Step 2.2.4: When the temporary variable (temp_val) after the assignment in step 2.1 is not the case of step 2.2.1 to step 2.2.3, reassign the operand of the temporary variable (temp_val) instruction after the assignment in step 2.1 to the temporary variable (temp_val) instruction itself, and add the instruction to the worklist (worklists), end the judgment, and re-enter the step 2.2.1 loop; Step 2.3: Based on the definition instruction (Alloca) of the sensitive data found in step 2.2, traverse the instructions of the entire function, find all write instructions based on the def-use relationship, and write the found write instructions into the source point instruction set (write_insts); Step 2.4: Further judge the write instruction obtained in step 2.3 to determine whether the operand (valueOpearnd) of this write instruction is a function parameter. If it is a function parameter, obtain its callee and enter the callee to continue value flow analysis until its source point is found and the loop is terminated.
4. The method for protecting program branch data integrity based on a compiler according to claim 1, characterized in that: The tuple of the program data flow graph (DFG) generated in step 3 is defined as [I i ,I o ,Origin], where I i Represents the branch instruction itself, I o Represents the source instruction itself, and Origin is the source value.
5. The method for protecting program branch data integrity based on a compiler according to claim 1, characterized in that: The step S1 comprises: The Pass framework of the LLVM compiler saves the source points located by static value flow analysis into the runtime definition table (RDT) in the form of key-value pairs (key, value), where key is the source point address and value is the source point value. The security of the runtime definition table (RDT) is protected by Intel MPK hardware, which specifically includes the following steps: Step S1.1: The Runtime Definition Table (RDT) is a memory area protected by Intel MPK that is requested for context information when the program is running. The access rights of the memory area are set to inaccessible; Step S1.2: When there is context information to be saved, the access permission of the memory area applied for in step S1.1 is set to readable, and the entry to be stored is retrieved; Step S1.3: After the relevant entry is retrieved in step 1.2, the access permission of the memory area applied for in step S1.1 is set to writable, and the context information is written; Step S1.4: When the writing in step 1.3 is completed, the access permission of the memory area applied for in step S1.1 is immediately set to inaccessible; Step S1.5: When the program executes to the module that needs to be verified, the access permission of the memory area applied for in step S1.1 is set to readable, and relevant information is searched for verification; Step S1.6: When the verification in step S1.5 is completed, the access permission of the memory area applied for in step S1.1 is set to inaccessible.
6. The method for protecting program branch data integrity based on a compiler according to claim 1, characterized in that: The step S2 comprises: The Pass framework of the LLVM compiler generates an executable program after the program is instrumented. When the program is running, when it executes to a sensitive branch instruction, the program searches for the source point value in the runtime definition table (RDT) based on the address of the branch data, and forms a program data flow tuple, and further determines whether the program data flow tuple is in the program data flow graph (DFG). If the program data flow tuple is in the program data flow graph (DFG), the program continues to execute. If the program data flow tuple is not in the program data flow graph (DFG), an exception is thrown.
7. A system based on a compiler-based program branch data integrity protection method according to any one of claims 1 to 6, characterized in that: include: Static analysis module: inputs the program intermediate code (LLVM-IR), performs control dependency analysis on the input program intermediate code (LLVM-IR), obtains the branch data related to the control flow to be protected in the program, and then passes the branch data to the static value flow analysis algorithm to locate the source point of the branch data and generate the program data flow graph (DFG); Program runtime verification module: Save the branch data source point to the runtime definition table (RDT), then search for the corresponding source point in the runtime definition table (RDT) based on the data address index, and use Intel MPK hardware to protect the security of the runtime definition table (RDT), and determine whether the source point is within the program data flow graph (DFG). If it is, continue to execute the program, otherwise throw an exception.
8. A compiler-based program branch data integrity protection device, characterized in that: include: Memory: used for storing a computer program for implementing a compiler-based program branch data integrity protection method as claimed in any one of claims 1 to 6; Processor: used to implement a compiler-based program branch data integrity protection method as described in any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the compiler-based program branch data integrity protection method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
program non-control data attack protection method based on an LLVM compiler
CN109918903A
Intelligent contract code checking method and system for data management and control
CN112115472A
Control flow integrity protection method, system and device and readable storage medium
CN112966258A
A computing device with increased resistance against address probing
EP3667531A1
Method for control-flow integrity protection, apparatus, device and storage medium
EP3866037A2
Cited By
Electronic seal RISC-v processing method for implementing data flow integrity
WO2026148775A1
