Embedded software stack usage dynamic analysis method and system based on data breakpoints
By setting data breakpoints in embedded software and dynamically analyzing stack usage, the problem of stack overflow risks and dynamic analysis dependence on emulators in the existing technology is solved, and high-security and high-reliability embedded software stack analysis is achieved. , suitable for embedded software evaluation in high-end fields.
Patent Information
- Application Number
- CN202111501263.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-09
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-12-09
AI Technical Summary
When analyzing the usage of embedded software stacks, existing technologies have security risks, such as stack overflow problems, and dynamic analysis methods rely on emulators or periodic detection, lacking high security and high reliability dynamic analysis during actual operation. means.
Using a dynamic analysis method of embedded software stack usage based on data breakpoints, by setting data breakpoints at preset locations, recording target addresses, and analyzing instruction operations during exception handling, it is possible to achieve this without instrumenting source code and without resorting to simulation. Dynamic analysis of stack usage of embedded programs in case of processor.
It realizes dynamic analysis during the running process of embedded programs, improves the accuracy and safety of analysis results, and has application value in high-end fields such as aviation and military control.
Smart Images

Figure CN114238098B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded software, and in particular to a method and system for dynamically analyzing usage of an embedded software stack based on data breakpoints. Background Art
[0002] There are two general usage scenarios for embedded software stacks:
[0003] Static analysis: Analyze the stack usage of embedded software in a static way by analyzing the source code or disassembly code of the embedded software;
[0004] Dynamic analysis: By starting the system timer and other methods, the stack usage of the embedded software is periodically and dynamically detected.
[0005] Patent document CN110096888B (application number: CN201910311605.5) discloses a method and system for accelerating the verification and analysis of SMM security risks. The method includes: deploying a basic environment, obtaining and recording host environment information, obtaining a visualized BIOS source code call relationship diagram and a module composition diagram of a BIOS image; obtaining a GUID identifier related to SMM, matching the SMM-related GUID in the BIOS source code with the corresponding GUID in the bin image generated by source code compilation; obtaining the environment information of the virtual machine, setting breakpoints to capture the call stack information during runtime; verifying and analyzing SMM security risks.
[0006] With the rapid development of computer technology, embedded systems are not only used more and more widely in people's daily lives, but also play an increasingly critical role in some high-end fields such as aviation and military-related control fields. The security and stability requirements of embedded software in related fields are also constantly increasing. C language, as the most widely used programming language in embedded software, has many security risks, especially stack overflow risks. Summary of the invention
[0007] In view of the defects in the prior art, the object of the present invention is to provide a method and system for dynamically analyzing the usage of an embedded software stack based on data breakpoints.
[0008] The method for dynamic analysis of embedded software stack usage based on data breakpoints provided by the present invention comprises:
[0009] Step 1: Compile the program to be analyzed and call the analysis start interface at the preset location;
[0010] Step 2: Obtain the preset stack space of the current embedded program through the preset analysis module, set a data breakpoint for the preset stack space, and enable the data breakpoint exception of the embedded target board;
[0011] Step 3: In the exception handling of the data breakpoint, analyze the target address read or modified by the current instruction and record the target address;
[0012] Step 4: When the analyzed program runs to the preset position, the analysis end interface is called to close the data breakpoint exception of the target board and output the stack analysis result.
[0013] Preferably, the source code of the analyzed program is modified, and the analysis start function and analysis end function of the preset analysis module are called at the start point and end point of the analysis range of the analyzed program respectively, and then the modified embedded program is compiled according to its original compilation method to generate an executable embedded program.
[0014] Preferably, downloading and curing the recompiled embedded program, and running the analyzed embedded program;
[0015] When the analyzed embedded program runs to the analysis start function, the preset stack space of the analyzed program is obtained according to the stack start label and stack end label in the compilation link script of the program, and a data breakpoint is set for the preset stack space of the analyzed program, and the data breakpoint exception is enabled. When the analyzed program performs a stack push or pop operation during operation, the data breakpoint exception is triggered, and at the same time, the interrupt handling function of the data breakpoint exception in the preset analysis module is mounted into the analyzed embedded program.
[0016] Preferably, after the analyzed embedded program generates a data breakpoint exception, the operation target address of the current instruction is analyzed in the exception handling function of the data breakpoint exception, and the target address is the operation address of the current stack pointer, and the target address is recorded at the same time.
[0017] Preferably, when the analyzed embedded program executes to the analysis end function, the data breakpoint exception is closed by a preset analysis module, and the actual usage of the stack space is output after analyzing the recorded results.
[0018] The embedded software stack usage dynamic analysis system based on data breakpoints provided by the present invention comprises:
[0019] Module M1: compiles the analyzed program and calls the analysis start interface at the preset position;
[0020] Module M2: obtains the preset stack space of the current embedded program through the preset analysis module, sets data breakpoints for the preset stack space, and enables data breakpoint exceptions of the embedded target board;
[0021] Module M3: In the exception handling of data breakpoints, analyze the target address read or modified by the current instruction and record the target address;
[0022] Module M4: When the analyzed program runs to the preset position, the analysis end interface is called to close the data breakpoint exception of the target board and output the stack analysis result.
[0023] Preferably, the source code of the analyzed program is modified, and the analysis start function and analysis end function of the preset analysis module are called at the start point and end point of the analysis range of the analyzed program respectively, and then the modified embedded program is compiled according to its original compilation method to generate an executable embedded program.
[0024] Preferably, downloading and curing the recompiled embedded program, and running the analyzed embedded program;
[0025] When the analyzed embedded program runs to the analysis start function, the preset stack space of the analyzed program is obtained according to the stack start label and stack end label in the compilation link script of the program, and a data breakpoint is set for the preset stack space of the analyzed program, and the data breakpoint exception is enabled. When the analyzed program performs a stack push or pop operation during operation, the data breakpoint exception is triggered, and at the same time, the interrupt handling function of the data breakpoint exception in the preset analysis module is mounted into the analyzed embedded program.
[0026] Preferably, after the analyzed embedded program generates a data breakpoint exception, the operation target address of the current instruction is analyzed in the exception handling function of the data breakpoint exception, and the target address is the operation address of the current stack pointer, and the target address is recorded at the same time.
[0027] Preferably, when the analyzed embedded program executes to the analysis end function, the data breakpoint exception is closed by a preset analysis module, and the actual usage of the stack space is output after analyzing the recorded results.
[0028] Compared with the prior art, the present invention has the following beneficial effects:
[0029] The present invention realizes dynamic analysis of the stack usage of the embedded program during the operation of the embedded program without inserting source code and without the help of an emulator, and has certain practical application value in embedded software evaluation in the field of high security and high reliability; each time the stack space is modified, a record analysis is performed, and the analysis result is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0031] Figure 1 The relationship between the analyzed program and the analysis module and the program execution flow chart;
[0032] Figure 2Compilation flow chart for the analysis module and the analyzed program. DETAILED DESCRIPTION
[0033] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0034] Example:
[0035] like Figure 1 and Figure 2 The present invention provides a method for dynamically analyzing the usage of an embedded software stack based on data breakpoints, comprising:
[0036] The analysis module is compiled together with the analyzed program, and the analysis start interface is called at the location specified by the analyzed program. The analysis module obtains the preset stack space of the current embedded program, sets data breakpoints for the preset stack space of the program, and enables the data breakpoint exception of the embedded target board. In the exception handling of the data breakpoint, the target address to be accessed (read or modified) by the current instruction is analyzed and the target address is recorded. When the analyzed program runs to the analysis end interface, the data breakpoint exception of the target board is closed and the stack analysis result is output.
[0037] This method can dynamically analyze the stack usage of embedded software without inserting source code and without using an emulator. Because it is dynamically analyzed during the actual operation of the embedded program, its analysis results are more reliable than static analysis based on data flow graphs. It includes the following steps:
[0038] 1. First, modify the source code of the analyzed program, and call the analysis start function and analysis end function of the analysis module at the start and end points of the analysis range of the analyzed program, respectively. Figure 1 , and then compile the modified embedded program according to its original compilation method to generate an executable embedded program.
[0039] 2. Download or solidify the recompiled embedded program, and run the analyzed embedded program.
[0040] 3. When the analyzed embedded program runs to the analysis start function, the analysis start function obtains the preset stack space of the analyzed program according to the program compilation link information (stack start label and stack end label in the link script), and sets a data breakpoint for the preset stack space of the analyzed program (according to the definition of data breakpoint, data breakpoint can set a range of addresses, and any access of the processor to the address range will trigger a data breakpoint exception), and enables the data breakpoint exception, so that when the analyzed program performs stack push or stack pop operations during operation, the data breakpoint exception will be triggered. At the same time, the analysis start function mounts the interrupt processing function of the data breakpoint exception in the analysis module to the interrupt processing module of the analyzed embedded program.
[0041] 4. After the analyzed embedded program generates a data breakpoint exception, the operation target address of the current instruction is analyzed in the exception handling function of the data breakpoint exception (the interrupt handling function of the analysis module. Because the interrupt handling function has been mounted to the interrupt handling module of the analyzed embedded program in the analysis start function, the processor will automatically execute the interrupt handling function when a data breakpoint exception occurs). The target address is the operation address of the current stack pointer, and the target address is recorded at the same time.
[0042] 5. When the analyzed embedded program executes to the analysis end function, the analysis module closes the data breakpoint exception, analyzes the recorded results of step 4, and outputs the actual usage of the stack space.
[0043] The embedded software stack usage dynamic analysis system based on data breakpoints provided by the present invention comprises: module M1: compiling the analyzed program and calling the analysis start interface at a preset position; module M2: obtaining the preset stack space of the current embedded program through the preset analysis module, setting data breakpoints for the preset stack space, and enabling the data breakpoint exception of the embedded target board; module M3: in the data breakpoint exception processing, analyzing the target address read or modified by the current instruction, and recording the target address; module M4: calling the analysis end interface when the analyzed program runs to the preset position, closing the data breakpoint exception of the target board and outputting the stack analysis result.
[0044] Modify the source code of the analyzed program, call the analysis start function and analysis end function of the preset analysis module at the start and end points of the analysis range of the analyzed program respectively, and then compile the modified embedded program according to its original compilation method to generate an executable embedded program. Download and solidify the recompiled embedded program, and run the analyzed embedded program; when the analyzed embedded program runs to the analysis start function, obtain the preset stack space of the analyzed program according to the stack start label and stack end label in the program's compilation link script, and set data breakpoints for the preset stack space of the analyzed program, enable data breakpoint exceptions, and trigger data breakpoint exceptions when the analyzed program performs stack push or pop operations during operation. At the same time, the interrupt processing function of the data breakpoint exception in the preset analysis module is mounted to the analyzed embedded program. After the analyzed embedded program generates a data breakpoint exception, analyze the operation target address of the current instruction in the exception processing function of the data breakpoint exception. The target address is the operation address of the current stack pointer, and the target address is recorded at the same time. When the analyzed embedded program executes to the analysis end function, the data breakpoint exception is closed through the preset analysis module, and the actual usage of the stack space is output after analyzing the recorded results.
[0045] Those skilled in the art know that, in addition to implementing the system, device and its various modules provided by the present invention in a purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Therefore, the system, device and its various modules provided by the present invention can be considered as a hardware component, and the modules included therein for implementing various programs can also be considered as structures within the hardware component; the modules for implementing various functions can also be considered as both software programs for implementing the method and structures within the hardware component.
[0046] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A dynamic analysis method for embedded software stack usage based on data breakpoints, It is characterized in that include: Step 1: Compile the program to be analyzed and call the analysis start interface at the preset location; Step 2: Obtain the preset stack space of the current embedded program through the preset analysis module, set a data breakpoint for the preset stack space, and enable the data breakpoint exception of the embedded target board; Step 3: In the exception handling of the data breakpoint, analyze the target address read or modified by the current instruction and record the target address; Step 4: When the analyzed program runs to the preset position, the analysis end interface is called to close the data breakpoint exception of the target board and output the stack analysis result; Modify the source code of the analyzed program, call the analysis start function and analysis end function of the preset analysis module at the start point and end point of the analysis range of the analyzed program respectively, and then compile the modified embedded program according to its original compilation method to generate an executable embedded program; Download and solidify the recompiled embedded program, and run the analyzed embedded program; When the analyzed embedded program runs to the analysis start function, the preset stack space of the analyzed program is obtained according to the stack start label and the stack end label in the compilation link script of the program, and a data breakpoint is set for the preset stack space of the analyzed program, and a data breakpoint exception is enabled. When the analyzed program performs a stack push or pop operation during operation, a data breakpoint exception is triggered, and at the same time, an interrupt processing function of the data breakpoint exception in the preset analysis module is mounted to the analyzed embedded program; After the analyzed embedded program generates a data breakpoint exception, the operation target address of the current instruction is analyzed in the exception handling function of the data breakpoint exception, the target address is the operation address of the current stack pointer, and the target address is recorded at the same time; When the analyzed embedded program executes to the analysis end function, the data breakpoint exception is closed through the preset analysis module, and the actual usage of the stack space is output after analyzing the recorded results.
2. A dynamic analysis system for embedded software stack usage based on data breakpoints, It is characterized in that include: Module M1: compiles the analyzed program and calls the analysis start interface at the preset position; Module M2: obtains the preset stack space of the current embedded program through the preset analysis module, sets data breakpoints for the preset stack space, and enables data breakpoint exceptions of the embedded target board; Module M3: In the exception handling of data breakpoints, analyze the target address read or modified by the current instruction and record the target address; Module M4: When the analyzed program runs to the preset position, the analysis end interface is called to close the data breakpoint exception of the target board and output the stack analysis result; Modify the source code of the analyzed program, call the analysis start function and analysis end function of the preset analysis module at the start point and end point of the analysis range of the analyzed program respectively, and then compile the modified embedded program according to its original compilation method to generate an executable embedded program; Download and solidify the recompiled embedded program, and run the analyzed embedded program; When the analyzed embedded program runs to the analysis start function, the preset stack space of the analyzed program is obtained according to the stack start label and the stack end label in the compilation link script of the program, and a data breakpoint is set for the preset stack space of the analyzed program, and a data breakpoint exception is enabled. When the analyzed program performs a stack push or pop operation during operation, a data breakpoint exception is triggered, and at the same time, an interrupt processing function of the data breakpoint exception in the preset analysis module is mounted to the analyzed embedded program; After the analyzed embedded program generates a data breakpoint exception, the operation target address of the current instruction is analyzed in the exception handling function of the data breakpoint exception, the target address is the operation address of the current stack pointer, and the target address is recorded at the same time; When the analyzed embedded program executes to the analysis end function, the data breakpoint exception is closed through the preset analysis module, and the actual usage of the stack space is output after analyzing the recorded results.
