Data write access integrity protection method based on DWT tracking component
Through the DWT tracking component and TrustZone-M environment, a protected data area is built and write access legality is checked, which solves the memory corruption attack problem of control and non-control data in embedded systems, and achieves efficient and accurate data write access integrity protection.
Patent Information
- Application Number
- CN202510244358.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-08-12
AI Technical Summary
The embedded Internet of Things system is vulnerable to memory corruption vulnerabilities and cannot resist memory corruption attacks that control and non-control data in tampered systems at the same time. The existing technology is insufficient in defense.
Use DWT tracking components to monitor write access to embedded systems, build protected data areas through compiler extensions and TrustZone-M trusted execution environments, record a collection of legitimate write instructions, and check the legitimacy of write access in a secure world interrupt handler.
It realizes data write access integrity protection for embedded systems, and can defend against memory corruption attacks of both control and non-control data at the same time, reduces inspection overhead, improves defense accuracy and system scalability.
Smart Images

Figure CN120470595A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to Internet of Things security technology, and in particular relates to a data write access integrity protection method based on a DWT tracking component. Background Art
[0002] With the continuous development of IoT technology, the number of IoT devices is rapidly increasing. Most of these devices are microcontroller-based embedded systems whose software systems are developed in the C language, making them susceptible to memory corruption vulnerabilities. Attackers can exploit memory corruption vulnerabilities to tamper with important system data, hijack system control flow, or achieve other attack objectives, threatening the runtime security of embedded systems.
[0003] Due to the limited hardware resources of embedded systems, defense mechanisms used in general-purpose systems cannot be directly deployed on embedded systems. Therefore, memory corruption defense technologies for embedded systems must be designed based on the specific hardware characteristics. Existing defenses for embedded systems, such as address space layout randomization and control flow integrity protection, primarily protect against memory corruption attacks targeting control data. However, they are insufficient for protecting against memory corruption attacks targeting non-control data, necessitating a more comprehensive defense approach.
[0004] Memory corruption attacks focus on tampering with system data. The tampering achieved by exploiting memory corruption vulnerabilities is to use a write instruction in the program to write data to an address that the program will not access during normal operation. By protecting the system runtime so that the write instructions only access addresses that are in line with the normal intentions of the program, it is possible to defend against attacks on control data and non-control data at the same time, i.e., write access integrity protection. The existing technology monitors the write access of the system through all write instructions of the software instrumentation program, which brings a large overhead. DWT (Data Watchpoint and Trace), as a tracing component of the Arm Coresight debug and tracing architecture on the Arm Cortex-M series microcontroller, can monitor the write access of the embedded system within a certain address range and generate write records of access addresses, instruction addresses and values. The present invention designs and discloses a data write access integrity protection method based on the DWT tracing component to detect that important data in the embedded system is not accessed by illegal write instructions, thereby ensuring the write access integrity of important data in the system. Summary of the Invention
[0005] Purpose of the invention: The present invention is aimed at the problems existing in the prior art and provides a data write access integrity protection method based on the DWT tracking component. It mainly solves the problem that the Internet of Things embedded system is vulnerable to memory corruption vulnerabilities and cannot simultaneously resist memory corruption attacks that tamper with control data and non-control data in the system. With the help of hardware, it non-invasively tracks and records the embedded system's write access to important data, comprehensively detects malicious memory corruption attacks that tamper with important data using illegal write instructions, and ensures the runtime security of the embedded system.
[0006] Technical solution: The data write access integrity protection method based on the DWT tracking component described in the present invention includes the following steps in sequence:
[0007] (1) Construction of protected data area:
[0008] The control data and important non-control data protected by data write access integrity in the program can be divided into global variables, local variables and dynamic memory allocation variables at runtime. New static areas, stack areas and heap areas are opened for them in the linker script, separated from the original data areas; at the same time, an instrumentation access area is opened for the creation and destruction of instrumentation notification variables. The two form a protected data area, and the DWT tracking component will monitor data write access in this area at runtime.
[0009] (2) Compiler function extension:
[0010] On the one hand, the compiler has been enhanced with features that allow for marking instructions, propagating markings, and generating program sections containing the addresses of marked instructions based on the markings. This allows for marking write instructions during static analysis of variable write accesses in the program during the compilation phase, ultimately obtaining the set of legal write instructions for the variable—that is, the addresses of write instructions that legally access the variable. On the other hand, the compiler has been enhanced with processes for protected variable write access analysis, protected variable allocation, and lifecycle instrumentation. The analysis results obtained from the former will be used for runtime comparison checks, while the added code for the latter will allocate protected variables in protected data areas and notify the creation and destruction of variables at runtime, namely, notifying the correspondence between the current variable and the memory address, allowing the data write access integrity protection mechanism to determine the variable and its legal write instruction set through the memory address.
[0011] (3) Post-compilation information processing:
[0012] The TrustZone-M non-secure world executable file that has undergone write access analysis during the compilation phase has information about protected data areas and program sections containing a set of legal write instructions for protected variables. The data structure is defined and this information is extracted, which is compiled into the TrustZone-M secure world program for data write access integrity protection mechanism to check.
[0013] (4) Data write access integrity protection mechanism:
[0014] At system startup, the secure world configures components such as the DWT as secure hardware resources to prevent access from the non-secure world. The DWT is configured to monitor protected data areas in the non-secure world in tracking mode, and the ETB is configured to generate a secure world interrupt when it is full. While a non-secure world program is running, a write access to a protected data area triggers the DWT to generate a data packet containing the access address, instruction address, and other information, which is then stored in the ETB. When the ETB is full, the system enters the secure world interrupt handler. Based on the access address, it either establishes or cancels the correspondence between variables and addresses, or checks whether the instruction address is in the set of valid write instructions for the variable, thereby ensuring the integrity of the system's data write access.
[0015] The step (1) is specifically as follows:
[0016] (11) Through the definition of the linker script, a protected data area is created in the system's free memory area for protected global variables, local variables, dynamically allocated memory variables, and instrumentation, including new static areas, stack areas, heap areas, and instrumentation access areas. The runtime DWT tracking component only monitors data write accesses in the protected data area to avoid unnecessary checking overhead for data write accesses outside the area.
[0017] (12) The protected data area and the original data area as a whole form an arbitrary offset. The protected local variables and dynamic memory allocation variables are allocated and accessed in the protected data area by adding an offset to the original address. Different offsets also provide a certain degree of randomness for the address range of the protected data area.
[0018] The step (11) is specifically as follows:
[0019] (111) Protected global variables, local variables, and dynamically allocated memory variables have new static areas, stack areas, and heap areas. The runtime DWT tracking component monitors write accesses to these areas and generates access address and instruction address data packets for the inspection mechanism to check whether the instruction address accessing this memory address is legal;
[0020] (112) The instrumented access area is used for instrumented code access in the subsequent compilation phase to inform the lifecycle of local variables and dynamically allocated memory variables. It includes four dedicated addresses for local variable creation and destruction, and dynamic memory allocation variable creation and destruction. The runtime DWT tracking component monitors write accesses to this area and generates access address, instruction address, and value data packets for the inspection mechanism to learn about the variables at a certain memory address.
[0021] The step (2) is specifically as follows:
[0022] (21) Expand the PC Sections metadata function in the LLVM compiler to allow multiple PC Sections metadata to be attached to an instruction, meeting the reality that a write instruction in a program may access multiple variables; improve the propagation of PC Sections metadata during compilation and redefine its propagation rules to ensure that the analysis results of write access to protected variables will not be lost during the compilation process after analysis; redesign the program section format based on PC Sections metadata to an absolute instruction address sequence, so that a program section records the legal write instruction set of a variable;
[0023] (22) Add a protected variable write access analysis process to the LLVM compiler. First, based on the target data in the attack analysis, determine that the protected variables are semantically critical variables, pointer type variables and their related variables, and function return addresses in the program. Secondly, determine the location of the protected variable write access analysis process in the compilation process. Add the semantically critical variables, pointer type variables and their related variable analysis process to the end of the semantically rich LLVM IR (Intermediate Representation) instruction representation stage. Add the function return address analysis process to the LLVM MIR instruction representation stage after the compiler adds the function prologue and function epilogue. Then, combine the field-sensitive pointer analysis in the analysis process to identify the write instruction and the written variable, design the unique identifier of the variable and name the PC Sections metadata with the unique identifier, attach the PC Sections metadata of the variables that the write instruction can access to, and record all protected variables for subsequent instrumentation.
[0024] (23) Add a protected variable instrumentation process to the LLVM compiler, assign protected variables to the protected data area, and notify the variable lifecycle. The instrumentation process closely follows the analysis process. Directly assign global variables to the new static area in the protected data area; assign local variables and dynamic memory allocation variables to the stack area and heap area in the protected data area by adding offsets based on the original addresses, and perform subsequent access based on the offsets. Immediately after the creation and destruction of local variables, the instrumentation code is inserted, and the unique identifier and memory address of the variable are written to the instrumentation access area to trigger the DWT to generate two sets of access addresses, instruction addresses, and value data packets; immediately before the allocation and release of dynamic memory allocation variables, the instrumentation code is inserted, and the unique identifier, base address, and size of the variable are written to the instrumentation access area to trigger the DWT to generate three sets of access addresses, instruction addresses, and value data packets. The data write access integrity protection mechanism obtains the corresponding relationship between the current variable and the memory address, so that it can perform checks based on the access address.
[0025] The step (21) is specifically as follows:
[0026] (211) Redefine the data structure and operation method for the instructions of the SelectionDAG and LLVM MIR (Machine Intermediate Representation) representation stages in the LLVM compiler backend, allowing an instruction to attach multiple PC Sections metadata, such as redefining const MachineInstrBuilder&MachineInstrBuilder::setPCSections(std::vector<MDNode*> MD)const adds a set of PC Sections metadata to the instruction;
[0027] (212) Ensure that instructions pass PC Sections metadata when the representation changes, including from LLVM IR to SelectionDAG and from SectionDAG to LLVM MIR. For example, improve void MachineInstr::setExtraInfo(…,std::vector<MDNode*> PCSections,…) pass a set of PCSections metadata during instruction conversion; ensure that instructions pass PC Sections metadata during the optimization process, for example, PC Sections metadata must be passed during the thumb2-reduce-size optimization process under the Arm architecture; ensure that the PC Sections metadata on multiple instructions are also merged into one instruction when instructions are optimized and merged, for example, when multiple consecutive write instructions are merged during the arm-ldst-opt optimization process under the Arm architecture, the PC Sections metadata are also merged; ensure that a group of instructions with a strict sequence of execution relationships pass PC Sections metadata independently when they are optimized simultaneously, for example, redefine voidSelectionDAG::copyExtraInfo(SDNode*From,SDNode*To) to only pass PC Sections metadata between write instructions with the same semantics.
[0028] The step (22) is specifically as follows:
[0029] (221) Design the unique identifier globalId of the global variable as its memory address var_addr, that is, {globalId:var_addr}; design the unique identifier localId of the local variable as the sum of the function address func_addr where it is located and the count count in the function, that is, {localId:func_addr+count}, and count each different domain in the local variable once; design the unique identifier dynamicId of the dynamic memory allocation variable as the sum of the function address func_addr where its allocation point is located and the count count in the function, plus the implicit offset {offset1,offset2…}, that is, {dynamicId:func_addr+count,{offset1,offset2…}}, where offsets offset1, offset2, etc. are the offsets of different domains in the variable. Only the allocation point of the dynamic memory allocation variable is counted once, and different domains in the variable are not counted. Instead, the offsets are implicitly recorded so that one allocation point directly corresponds to multiple domains.
[0030] (222) Manually annotate the semantically critical domains and variables in the data types in the program source code. The analysis process extracts all annotated global variables based on llvm.global.annotations. Perform domain-sensitive pointer analysis on all store instructions on LLVM IR to determine whether the written variable has an annotated global variable. If so, attach PC Sections metadata named after the variable's unique identifier to this store instruction. Determine the addresses of all annotated variables based on llvm.ptr.annotation and llvm.var.annotation, perform domain-sensitive pointer analysis to determine the variables they point to and their domains, and reversely use the results of the pointer analysis to determine all store instructions that access the variable domain, and attach the corresponding PC Sections metadata to them.
[0031] (223) In addition to function pointers, in protected pointer type variables, focus on analyzing data pointers to prevent attackers from using data pointers to expand their attack capabilities from restricted write capabilities to arbitrary write capabilities. The analysis process identifies all store instructions whose written value types are pointer types on LLVM IR for pointer type variables. On the one hand, domain-sensitive pointer analysis is performed on the address written by the store instruction to determine the variable pointed to by the address and its domain. For this store instruction, PC Sections metadata named with the unique identifier of the variable is attached. On the other hand, the value written by the store instruction is traced back to analyze the address of the variable involved in the pointer operation, and domain-sensitive pointer analysis is performed to determine the variable pointed to and its domain. The results of the pointer analysis are then used in reverse to determine all store instructions that write to access this variable domain, and the corresponding PC Sections metadata is attached to them. This completes the write access analysis of all pointer type variables and their related variables.
[0032] (224) The analysis process identifies the push and pop instructions on the LLVM MIR for the function return address, cancels their access to the function return address, and the subsequent insertion process inserts the str instruction before the push instruction to write the return address in the protected stack area, and inserts the ldr instruction after the pop instruction to read the return address.
[0033] The step (3) is specifically as follows:
[0034] (31) Use the extended LLVM compiler to compile non-secure world programs;
[0035] (32) Extract the address range of the protected data area based on the symbol table in the non-secure world executable file, compile it into the secure world program, and set the address range monitored by the DWT accordingly when the system is running;
[0036] (33) Identify the program sections based on PC Sections in the non-secure world executable file. First, determine the unique identifier of the variable from the name of the program section, and then extract the legal instruction set of the variable from the content of the program section. The two are bound together and compiled into the secure world program. The data write access integrity protection mechanism will obtain the address of the variable through the unique identifier of the variable, and then determine the legal write instruction set that should be checked based on the access address.
[0037] The step (4) is specifically as follows:
[0038] (41) When the system starts, the secure world sets the DWT and other components as secure hardware resources to prevent access from the non-secure world, sets the DWT to monitor write access to protected data areas in the non-secure world, and sets the ETB to generate a secure world interrupt when it is full.
[0039] (42) When the system is running in the non-secure world, write access to the protected data area will trigger the DWT to generate a write access record, including the access address, instruction address, and value data. The data is passed through the ITM (Instrumentation Trace Macrocell) component and finally stored in the ETB;
[0040] (43) When the ETB is full, an interrupt signal is generated. This signal is transmitted through the CTI (Cross Trigger Interface) to trigger the system to enter the secure world interrupt handler to check the existing write access records. The secure world interrupt handler reads data from the ETB, parses and assembles the data in units of write access records, and then, based on the access address, either establishes or cancels the correspondence between the variable and the address, or checks whether the instruction address is in the set of legal write instructions for the variable.
[0041] The step (43) is specifically as follows:
[0042] (431) The write access of the non-secure world to the protected global variable will generate a set of access address and instruction address data. The address is used as the unique identifier of the global variable. The secure world interrupt handler directly determines the legal write instruction set to be compared based on the access address and checks whether the instruction address is in the legal write instruction set. If not, it proves that a memory corruption attack has occurred.
[0043] (432) The non-secure world immediately accesses the instrumented access area after the protected local variable is created, and writes the variable unique identifier and address in the instrumented access area, generating two sets of access address, instruction address, and value data. The secure world interrupt handler determines that the data is a local variable creation data based on the access address, determines the legal write instruction set based on the variable unique identifier represented by the value, and associates it with the variable address represented by the value;
[0044] (433) The write access to the protected local variable in the non-secure world will generate a set of access address and instruction address data. The secure world interrupt handler checks whether the instruction address is in the legal write instruction set corresponding to the access address. If not, it proves that a memory corruption attack has occurred.
[0045] (434) The non-secure world accesses the stub access area again before the protected local variable terminates its lifecycle, writes the variable address in the stub access area, and generates a set of access address, instruction address, and value data. The secure world interrupt handler determines that the local variable is destroyed based on the access address, and cancels the association between the memory address represented by the value and the set of legal write instructions;
[0046] (435) The non-secure world immediately accesses the instrumented access area after the protected dynamic memory allocation variable is created, and writes the variable unique identifier, base address, and variable size into the instrumented access area, generating three sets of access address, instruction address, and value data. The secure world interrupt handler determines that the access address is the creation data of the dynamic memory allocation variable, determines a set of legal write instructions based on the variable unique identifier represented by the value, calculates the domain address of the variable based on the variable base address and size represented by the value combined with the offset implied by the unique identifier, and associates it with the corresponding legal write instruction set;
[0047] (436) The write access of the non-secure world to the protected dynamic memory allocation variable will generate a set of access address and instruction address data. The secure world interrupt handler checks whether the instruction address is in the legal write instruction set corresponding to the access address. If not, it proves that a memory corruption attack has occurred.
[0048] (437) Before the protected dynamically allocated memory variable is released, the non-secure world accesses the instrumented access area again and writes the base address to the instrumented access area, generating a set of access address, instruction address, and value data. The secure world interrupt handler determines that the access address is the destruction data of the dynamically allocated memory variable based on the access address and disassociates all related domain addresses from the set of legal write instructions based on the base address represented by the value.
[0049] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method for protecting data write access integrity based on a DWT tracking component is implemented.
[0050] A computer-readable storage medium stores computer instructions, which, when executed by a processor, implement the data write access integrity protection method based on a DWT tracking component.
[0051] Beneficial effects: Compared with the prior art, the present invention has the following advantages:
[0052] (1) The present invention proposes a data write access integrity protection technology based on DWT for embedded systems. By checking the instructions for system write access control data and important non-control data, it can simultaneously defend against memory corruption attacks targeting both system control data and important non-control data. The defense scope is more comprehensive, and the inspection granularity is domain-sensitive, with a finer defense granularity. For function return addresses, compared with the method of relying on the program static control flow graph to check the jump pairs before and after, the defense effect of checking its write instructions is also more accurate.
[0053] (2) The present invention utilizes DWT hardware to monitor system write access in tracing mode and generate tracing data packets. Compared with software instrumentation, all write instructions of the program record system write access, which greatly reduces the need for program code instrumentation. The tracing process is independent of system operation. Compared with the DWT debugging mode, which must interrupt system execution, the tracing data packets can not only be stored in the ETB by the single-core microcontroller and quantitatively processed by interrupts, but can also be processed in parallel without interruption by the dual-core microcontroller or coprocessor to further meet the requirements of high efficiency and high real-time performance, and have stronger system scalability. The present invention only shows the overall design in the single-core microcontroller system.
[0054] (3) The present invention uses only one type of tracking hardware, DWT, to monitor and protect system control data and important non-control data in a unified manner. Compared with using different tracking hardware to monitor system control data and important non-control data separately, there is no need to distinguish different types of data generated by different hardware. The data packet has a simpler format, which reduces the data packet parsing overhead.
[0055] (4) The present invention utilizes the Arm TrustZone-M trusted execution environment to isolate hardware resources such as DWT and runs the data write access integrity protection program in a secure world interrupt manner, ensuring the security of hardware monitoring non-secure world write access, parsing data packets, and checking data write access integrity. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 This is the overall flow chart of the data write access integrity protection method based on the DWT tracking component of the present invention, wherein Figure 1 (a) is the flow chart of the compilation phase, Figure 1 (b) is the flow chart of the operation phase;
[0057] Figure 2 Schematic diagram of the non-secure world memory layout in the embodiment. DETAILED DESCRIPTION
[0058] The technical solution of the present invention is described in detail below, but the protection scope of the present invention is not limited to the embodiments.
[0059] Embodiment: A data write access integrity protection method based on a DWT tracking component comprises the following steps in sequence:
[0060] (1) Construction of protected data area:
[0061] The control data and important non-control data protected by data write access integrity in the program can be divided into global variables, local variables and dynamic memory allocation variables at runtime. New static areas, stack areas and heap areas are opened for them in the linker script, separated from the original data areas; at the same time, an instrumentation access area is opened for the creation and destruction of instrumentation notification variables. The two form a protected data area, and the DWT tracking component will monitor data write access in this area at runtime.
[0062] (2) Compiler function extension:
[0063] On the one hand, the compiler has been enhanced with features that allow for marking instructions, propagating markings, and generating program sections containing the addresses of marked instructions based on the markings. This allows for marking write instructions during static analysis of variable write accesses in the program during the compilation phase, ultimately obtaining the set of legal write instructions for the variable—that is, the addresses of write instructions that legally access the variable. On the other hand, the compiler has been enhanced with processes for protected variable write access analysis, protected variable allocation, and lifecycle instrumentation. The analysis results obtained from the former will be used for runtime comparison checks, while the added code for the latter will allocate protected variables in protected data areas and notify the creation and destruction of variables at runtime, namely, notifying the correspondence between the current variable and the memory address, allowing the data write access integrity protection mechanism to determine the variable and its legal write instruction set through the memory address.
[0064] (3) Post-compilation information processing:
[0065] The TrustZone-M non-secure world executable file that has undergone write access analysis during the compilation phase has information about protected data areas and program sections containing a set of legal write instructions for protected variables. The data structure is defined and this information is extracted, which is compiled into the TrustZone-M secure world program for data write access integrity protection mechanism to check.
[0066] (4) Data write access integrity protection mechanism:
[0067] At system startup, the secure world configures components such as the DWT as secure hardware resources to prevent access from the non-secure world. The DWT is configured to monitor protected data areas in the non-secure world in tracking mode, and the ETB is configured to generate a secure world interrupt when it is full. While a non-secure world program is running, a write access to a protected data area triggers the DWT to generate a data packet containing the access address, instruction address, and other information, which is then stored in the ETB. When the ETB is full, the system enters the secure world interrupt handler. Based on the access address, it either establishes or cancels the correspondence between variables and addresses, or checks whether the instruction address is in the set of valid write instructions for the variable, thereby ensuring the integrity of the system's data write access. Specific embodiment:
[0069] The data write access integrity protection method based on the DWT tracking component in this implementation specifically includes the following steps:
[0070] 1. Construction of protected data area:
[0071] The method proposed in this invention redefines the system memory layout in the linker script, and creates a protected data area for protected global variables, local variables, dynamic memory allocation variables and plug-in needs. A typical memory layout is as follows Figure 2 Specifically, it includes a new static area, stack area, heap area and stub access area, which are offset from the original heap area as a whole. The new stack area and heap area are the same size as the original stack area and heap area. The stub access area consists of four dedicated address areas for notifying the creation and destruction of local variables and the creation and destruction of dynamic memory allocation variables.
[0072] 2. Compiler function extension:
[0073] 2.1 Extending the PC Sections metadata functionality in the LLVM compiler
[0074] (1) Redefine the data structure and operation method of adding PCSections metadata to instructions in the SelectionDAG and LLVM MIR representation stages in the LLVM compiler:
[0075]
[0076] The above data structures allow an instruction to attach multiple PC Sections metadata in the SelectionDAG and LLVM MIR representation stages respectively.
[0077] (2) Improve the propagation of PC Sections metadata by the LLVVM compiler during the Arm architecture compilation process, including processes such as arm-ldst-opt and thumb2-reduce-size.
[0078] (3) Redesign the program section format based on PC Sections metadata:
[0079]
[0080]
[0081] The above format allows the set of legal instructions for write access to a variable to be included directly in the program section.
[0082] 2.2 Add protected variable write access analysis process in LLVM compiler
[0083] (1) For protected semantically critical variables, pointer type variables and their related variables, and function return addresses, domain-sensitive pointer analysis is combined to obtain all their write access instructions. Domain sensitivity means that different domains of access variables have different write instruction sets.
[0084] (2) Attach the PC Sections metadata of the variables that these write access instructions can access, design a unique variable identifier and a PC Sections naming method based on the identifier to distinguish the legal write instruction sets corresponding to different variables. Global variables are directly uniquely identified by their addresses, local variables are uniquely identified by the function address and the count within the function, and dynamic memory allocation variables are uniquely identified by the function address, the count within the function, and the domain offset. Different naming results in different PC Sections metadata. When generating the target file, the compiler generates program sections based on the PC Sections metadata naming and aggregates the instruction addresses with the same PC Sections metadata naming to form a program section containing a legal write instruction set.
[0085] 2.3 Adding protected variable instrumentation to the LLVM compiler
[0086] (1) Locate the alloca allocation instruction and malloc function call instruction for protected local variables and dynamic memory allocation variables. These instructions return the base address of the variable and replace the original addressing by base address with addressing by base address plus offset to reallocate protected local variables and dynamic memory allocation variables to the protected data area.
[0087] (2) Insert code after the alloca instruction of the protected local variable, and write the variable unique identifier and address to the address area used for local variable creation in the insertion access area; insert code before the ret instruction of the function exit, and write the local variable address to the address area used for local variable destruction in the insertion access area.
[0088] (3) Insert the stub code after the malloc function call instruction of the protected dynamic memory allocation variable, and write the variable unique identifier, base address and size to the address area used for dynamic memory allocation variable creation in the stub access area; insert the stub code before the free destruction function call instruction of the dynamic memory allocation variable, and write the variable base address to the address area used for dynamic memory allocation variable destruction in the stub access area.
[0089] 3. Post-compilation information processing:
[0090] The proposed method uses a Python script to extract information from the symbol table and program sections of the non-secure world executable file after compiling it with the extended LLVM compiler. The information is then compiled into the secure world executable file. The address range of the protected data area is extracted from the symbol table, and program sections based on PCSections are identified from the program sections. The unique identifier of the variable is calculated based on the naming, and the set of legal write instructions contained in the variable is extracted. The data structure of the legal write instruction set of the variable is defined as follows:
[0091]
[0092] It can be seen that the set of legal variable write instructions includes the unique identifier of the variable, the instruction index and the number of instructions. The instruction addresses of all legal write instruction sets are expanded and stored in an array.
[0093] 4. Data write access integrity protection mechanism:
[0094] 4.1 System startup phase
[0095] When the system starts, it enters the secure world and sets components such as DWT as secure hardware resources in the secure world to prevent access by attackers from the non-secure world. The range of DWT monitoring write access is set according to the address range of the protected data area extracted from the non-secure world. The ETB is set to generate a secure world interrupt when it is full to enter the data write access integrity check logic.
[0096] 4.2 System operation phase
[0097] After the system enters the non-secure world from the secure world, all write accesses to protected variables in the non-secure world are captured by the DWT to generate write records. At the same time, the write accesses used by the instrumentation code to notify the variable life cycle are also captured by the DWT to generate write records. All write records are arranged in the order of access and passed to the ETB for storage through the ITM.
[0098] 4.3 System Data Write Access Integrity Check Phase
[0099] (1) When the ETB is full of write record data, an interrupt signal is generated. This signal is transmitted through the CTI, and the system enters the secure world interrupt to check the integrity of the data write access. The secure world interrupt handler reads the data from the ETB and assembles the data according to a write access record. When the write access record is assembled, the write record type is determined based on the access address.
[0100] (2) When the access address is the address used to create a local variable, the checking mechanism determines the legal write instruction set based on the unique identifier of the variable being written, and records the variable address being written, associating the two. Subsequently, all instructions that access this variable address will be compared with the legal write instruction set.
[0101] (3) When the access address is an address for local variable destruction, the checking mechanism cancels its association with the legal write instruction set based on the written variable address.
[0102] (4) When the access address is an address used to create a dynamic memory allocation variable, the checking mechanism determines a set of legal write instructions based on the unique identifier of the variable being written, and determines the domain address and legal write instruction set that can be associated within the size range based on the base address and size of the variable being written, associates the two, and records the variable size. Subsequently, all instructions that access this domain address will be compared with the legal write instruction set.
[0103] (5) When the access address is an address for destroying a dynamically allocated memory variable, the checking mechanism disassociates the domain address within the size range from the legal write instruction set based on the written variable base address and the recorded variable size.
[0104] (6) When the access address is another address, the check mechanism checks whether this address is associated with a legal write instruction set. If so, the write access instruction is checked to see if it is in the corresponding legal write instruction set. If not, the write access instruction is ignored.
[0105] It should be noted that the above embodiments are not intended to limit the scope of protection of the present invention, and equivalent changes or substitutions made on the basis of the above technical solutions fall within the scope of protection of the claims of the present invention.
Claims
1. A data write access integrity protection method based on DWT tracking component, characterized in that: The method comprises the following steps in sequence: (1) Construction of protected data area, The control data and important non-control data protected by data write access integrity in the program can be divided into global variables, local variables and dynamic memory allocation variables at runtime. In the link script, new static areas, stack areas and heap areas are opened for them, separated from the original data areas; at the same time, a stub access area is opened for the creation and destruction of stub notification variables. The two form a protected data area. The DWT tracking component will monitor the data write access in this area at runtime. (2) Compiler function extension, On the one hand, the compiler is added with functions such as marking instructions, propagating markings, and generating program sections containing the addresses of marked instructions based on markings, so as to support marking write instructions when statically analyzing write accesses to variables in the program during the compilation phase, and finally obtaining the legal write instruction set of the variable, that is, the set contains the write instruction addresses that legally access the variable. On the other hand, the compiler is added with processes for protected variable write access analysis, protected variable allocation, and lifecycle instrumentation. The analysis results obtained from the former will be used for comparison checks at runtime, and the added code for the latter will allocate protected variables in the protected data area and notify the creation and destruction of variables at runtime, that is, notify the correspondence between the current variable and the memory address, so that the data write access integrity protection mechanism can determine the variable and its legal write instruction set through the memory address. (3) Post-compilation information processing, After the write access analysis in the compilation phase, the TrustZone-M non-secure world executable file has information about the protected data area and a program section containing a set of legal write instructions for protected variables. The data structure is defined and this information is extracted and compiled into the TrustZone-M secure world program for data write access integrity protection mechanism to check. (4) Data write access integrity protection mechanism, At system startup, the secure world configures components such as the DWT as secure hardware resources to prevent access from the non-secure world. The DWT is configured to monitor protected data areas in the non-secure world in tracking mode, and the ETB is configured to generate a secure world interrupt when it is full. While a non-secure world program is running, a write access to a protected data area triggers the DWT to generate a data packet containing the access address, instruction address, and other information, which is then stored in the ETB. When the ETB is full, the system enters the secure world interrupt handler. Based on the access address, it either establishes or cancels the correspondence between variables and addresses, or checks whether the instruction address is in the set of valid write instructions for the variable, thereby ensuring the integrity of the system's data write access.
2. The data write access integrity protection method based on the DWT tracking component according to claim 1 is characterized in that: The step (1) is specifically as follows: (11) Through the definition of the linker script, a protected data area is created in the system's free memory area for protected global variables, local variables, dynamically allocated memory variables, and instrumentation, including new static areas, stack areas, heap areas, and instrumentation access areas. The runtime DWT tracking component only monitors data write accesses in the protected data area to avoid unnecessary checking overhead for data write accesses outside the area. (12) The protected data area and the original data area as a whole form an arbitrary offset. The protected local variables and dynamic memory allocation variables are allocated and accessed in the protected data area by adding an offset to the original address. Different offsets also provide a certain degree of randomness for the address range of the protected data area.
3. The data write access integrity protection method based on the DWT tracking component according to claim 2 is characterized in that: The step (11) is specifically as follows: (111) Protected global variables, local variables, and dynamically allocated memory variables have new static areas, stack areas, and heap areas. The runtime DWT tracking component monitors write accesses to these areas and generates access address and instruction address data packets for the inspection mechanism to check whether the instruction address accessing this memory address is legal; (112) The instrumented access area is used for instrumented code access in the subsequent compilation phase to inform the lifecycle of local variables and dynamically allocated memory variables. It includes four dedicated addresses for local variable creation and destruction, and dynamic memory allocation variable creation and destruction. The runtime DWT tracking component monitors write accesses to this area and generates access address, instruction address, and value data packets for the inspection mechanism to learn about the variables at a certain memory address.
4. The data write access integrity protection method based on the DWT tracking component according to claim 1 is characterized in that: The step (2) is specifically as follows: (21) Expand the PC Sections metadata function in the LLVM compiler to allow multiple PC Sections metadata to be attached to one instruction, meeting the reality that a write instruction in a program may access multiple variables; improve the propagation of PC Sections metadata during compilation and redefine its propagation rules to ensure that the analysis results of protected variable write access are not lost during the compilation process after analysis; redesign the program section format based on PC Sections metadata to an absolute instruction address sequence, so that one program section records the legal write instruction set of one variable; (22) Add a protected variable write access analysis process to the LLVM compiler. First, based on the target data in the attack analysis, determine that the protected variables are semantically critical variables, pointer type variables and their related variables, and function return addresses in the program. Secondly, determine the location of the protected variable write access analysis process in the compilation process. Add the semantically critical variables, pointer type variables and their related variable analysis process to the end of the semantically rich LLVM IR (Intermediate Representation) instruction representation stage. Add the function return address analysis process to the LLVM MIR instruction representation stage after the compiler adds the function prologue and function epilogue. Then, combine the field-sensitive pointer analysis in the analysis process to identify the write instruction and the written variable, design the unique identifier of the variable and name the PC Sections metadata with the unique identifier, attach the PC Sections metadata of the variables that the write instruction can access to, and record all protected variables for subsequent instrumentation. (23) Add a protected variable instrumentation process to the LLVM compiler, assign protected variables to the protected data area, and notify the variable lifecycle. The instrumentation process closely follows the analysis process. Directly assign global variables to the new static area in the protected data area; assign local variables and dynamic memory allocation variables to the stack area and heap area in the protected data area by adding offsets based on the original addresses, and perform subsequent access based on the offsets. Immediately after the creation and destruction of local variables, the instrumentation code is inserted, and the unique identifier and memory address of the variable are written to the instrumentation access area to trigger the DWT to generate two sets of access addresses, instruction addresses, and value data packets; immediately before the allocation and release of dynamic memory allocation variables, the instrumentation code is inserted, and the unique identifier, base address, and size of the variable are written to the instrumentation access area to trigger the DWT to generate three sets of access addresses, instruction addresses, and value data packets. The data write access integrity protection mechanism obtains the corresponding relationship between the current variable and the memory address, so that it can perform checks based on the access address.
5. The data write access integrity protection method based on the DWT tracking component according to claim 4 is characterized in that: The step (21) is specifically as follows: (211) Redefine the data structure and operation method for the instructions of the SelectionDAG and LLVM MIR (Machine Intermediate Representation) representation stages in the LLVM compiler backend, allowing an instruction to attach multiple PC Sections metadata, such as redefining const MachineInstrBuilder&MachineInstrBuilder::setPCSections(std::vector<MDNode*> MD)const adds a set of PC Sections metadata to the instruction; (212) Ensure that instructions pass PC Sections metadata when the representation changes, including from LLVM IR to SelectionDAG and from SectionDAG to LLVM MIR. For example, improve void MachineInstr::setExtraInfo(…,std::vector<MDNode*> PCSections, ...) pass a set of PCSections metadata during instruction conversion; ensure that instructions pass PC Sections metadata during optimization, for example, PC Sections metadata must be passed during thumb2-reduce-size optimization under the Arm architecture; ensure that PC Sections metadata on multiple instructions are also merged into one instruction during instruction optimization merging, for example, PC Sections metadata is also merged when multiple consecutive write instructions are merged during arm-ldst-opt optimization under the Arm architecture; Ensure that a group of instructions with a strict sequential execution relationship independently pass PC Sections metadata when they are optimized simultaneously. For example, redefine voidSelectionDAG::copyExtraInfo(SDNode*From,SDNode*To) to only pass PC Sections metadata between write instructions with the same semantics.
6. The data write access integrity protection method based on the DWT tracking component according to claim 4 is characterized in that: The step (22) is specifically as follows: (221) Design the unique identifier globalId of the global variable as its memory address var_addr, that is, {globalId:var_addr}; design the unique identifier localId of the local variable as the sum of the function address func_addr where it is located and the count count in the function, that is, {localId:func_addr+count}, and count each different domain in the local variable once; design the unique identifier dynamicId of the dynamic memory allocation variable as the sum of the function address func_addr where its allocation point is located and the count count in the function, plus the implicit offset {offset1,offset2…}, that is, {dynamicId:func_addr+count,{offset1,offset2…}}, where offsets offset1, offset2, etc. are the offsets of different domains in the variable. Only the allocation point of the dynamic memory allocation variable is counted once, and different domains in the variable are not counted. Instead, the offsets are implicitly recorded so that one allocation point directly corresponds to multiple domains. (222) Manually annotate the semantically critical domains and variables in the data types in the program source code. The analysis process extracts all annotated global variables based on llvm.global.annotations. Perform domain-sensitive pointer analysis on all store instructions on LLVM IR to determine whether the written variable has an annotated global variable. If so, attach PC Sections metadata named after the variable's unique identifier to this store instruction. Determine the addresses of all annotated variables based on llvm.ptr.annotation and llvm.var.annotation, perform domain-sensitive pointer analysis to determine the variables they point to and their domains, and reversely use the results of the pointer analysis to determine all store instructions that access the variable domain, and attach the corresponding PC Sections metadata to them. (223) In addition to function pointers, in protected pointer type variables, focus on analyzing data pointers to prevent attackers from using data pointers to expand their attack capabilities from restricted write capabilities to arbitrary write capabilities. The analysis process identifies all store instructions whose written value types are pointer types on LLVMIR for pointer type variables. On the one hand, domain-sensitive pointer analysis is performed on the address written by the store instruction to determine the variable pointed to by the address and its domain. For this store instruction, PCSections metadata named with the unique identifier of the variable is attached. On the other hand, the value written by the store instruction is traced back to analyze the address of the variable involved in the pointer operation, and domain-sensitive pointer analysis is performed to determine the variable pointed to and its domain. In reverse, the results of the pointer analysis are used to determine all store instructions that write to access this variable domain, and the corresponding PC Sections metadata is attached to them. This completes the write access analysis of all pointer type variables and their related variables. (224) The analysis process identifies the push and pop instructions on the LLVM MIR for the function return address, cancels their access to the function return address, and the subsequent insertion process inserts the str instruction before the push instruction to write the return address in the protected stack area, and inserts the ldr instruction after the pop instruction to read the return address.
7. The data write access integrity protection method based on the DWT tracking component according to claim 1 is characterized in that: The step (3) is specifically as follows: (31) Use the extended LLVM compiler to compile non-secure world programs; (32) Extract the address range of the protected data area based on the symbol table in the non-secure world executable file, compile it into the secure world program, and set the address range monitored by the DWT accordingly when the system is running; (33) Identify the program sections based on PC Sections in the non-secure world executable file. First, determine the unique identifier of the variable from the name of the program section, and then extract the legal instruction set of the variable from the content of the program section. The two are bound together and compiled into the secure world program. The data write access integrity protection mechanism will obtain the address of the variable through the unique identifier of the variable, and then determine the legal write instruction set that should be checked based on the access address.
8. The data write access integrity protection method based on the DWT tracking component according to claim 1 is characterized in that: The step (4) is specifically as follows: (41) When the system starts, the secure world sets the DWT component as a secure hardware resource to prevent access from the non-secure world, sets the DWT to monitor write access to protected data areas in the non-secure world, and sets the ETB to generate a secure world interrupt when it is full. (42) When the system is running in the non-secure world, write access to the protected data area will trigger the DWT to generate a write access record, including the access address, instruction address, and value data. The data is passed through the ITM (Instrumentation Trace Macrocell) component and finally stored in the ETB; (43) When the ETB is full, an interrupt signal is generated. The trigger system enters the secure world interrupt handler through the CTI (Cross Trigger Interface) to check the existing write access records. The secure world interrupt handler reads data from the ETB, parses and assembles the data in units of one write access record, and then establishes or cancels the correspondence between the variable and the address based on the access address, or checks whether the instruction address is in the set of legal write instructions for the variable. The step (43) is specifically as follows: (431) The write access of the non-secure world to the protected global variable will generate a set of access address and instruction address data. The address is used as the unique identifier of the global variable. The secure world interrupt handler directly determines the legal write instruction set to be compared based on the access address and checks whether the instruction address is in the legal write instruction set. If not, it proves that a memory corruption attack has occurred. (432) The non-secure world immediately accesses the instrumented access area after the protected local variable is created, and writes the variable unique identifier and address in the instrumented access area, generating two sets of access address, instruction address, and value data. The secure world interrupt handler determines that the data is a local variable creation data based on the access address, determines the legal write instruction set based on the variable unique identifier represented by the value, and associates it with the variable address represented by the value; (433) The write access to the protected local variable in the non-secure world will generate a set of access address and instruction address data. The secure world interrupt handler checks whether the instruction address is in the legal write instruction set corresponding to the access address. If not, it proves that a memory corruption attack has occurred. (434) The non-secure world accesses the stub access area again before the protected local variable terminates its lifecycle, writes the variable address in the stub access area, and generates a set of access address, instruction address, and value data. The secure world interrupt handler determines that the local variable is destroyed based on the access address, and cancels the association between the memory address represented by the value and the set of legal write instructions; (435) The non-secure world immediately accesses the instrumented access area after the protected dynamic memory allocation variable is created, and writes the variable unique identifier, base address, and variable size into the instrumented access area, generating three sets of access address, instruction address, and value data. The secure world interrupt handler determines that the access address is the creation data of the dynamic memory allocation variable, determines a set of legal write instructions based on the variable unique identifier represented by the value, calculates the domain address of the variable based on the variable base address and size represented by the value combined with the offset implied by the unique identifier, and associates it with the corresponding legal write instruction set; (436) The write access of the non-secure world to the protected dynamic memory allocation variable will generate a set of access address and instruction address data. The secure world interrupt handler checks whether the instruction address is in the legal write instruction set corresponding to the access address. If not, it proves that a memory corruption attack has occurred. (437) Before the protected dynamically allocated memory variable is released, the non-secure world accesses the instrumented access area again and writes the base address to the instrumented access area, generating a set of access address, instruction address, and value data. The secure world interrupt handler determines that the access address is the destruction data of the dynamically allocated memory variable based on the access address and disassociates all related domain addresses from the set of legal write instructions based on the base address represented by the value.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the data write access integrity protection method based on the DWT tracking component as described in any one of claims 1 to 8 is implemented.
10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the data write access integrity protection method based on the DWT tracking component according to any one of claims 1 to 8 is implemented.
