Memory anomaly detection method for Linux embedded firmware

By combining static analysis and dynamic detection, the problem of silent memory corruption detection in Linux embedded firmware is solved, lightweight memory anomaly detection is achieved, the overhead and false alarm rate are reduced, and it is suitable for IoT devices.

CN118779884APending Publication Date: 2024-10-15NANJING INST OF INFORMATION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410870755.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

Existing technology is difficult to effectively detect silent memory corruption in Linux embedded firmware, resulting in vulnerabilities being missed, and traditional memory detection methods have challenges in performance and false positive rates.

Method used

Adopt a method that combines static analysis and dynamic detection, analyze the firmware through automated analysis tools, locate detection points of sensitive functions, use dynamic instrumentation technology to perform boundary checks, and monitor memory anomalies through static analysis reports and dynamic execution information to reduce redundant detection points and false alarm rate.

Benefits of technology

It implements lightweight memory anomaly detection for Linux embedded firmware, reduces memory and time overhead, improves vulnerability discovery capabilities, has a low false alarm rate, and is suitable for resource-constrained IoT devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779884A_ABST
    Figure CN118779884A_ABST
Patent Text Reader

Abstract

The invention discloses a memory anomaly detection method for Linux embedded firmware. The memory anomaly detection method comprises the steps of firmware analysis, detection point positioning, redundant detection point removal, fuzzy test execution, dynamic boundary check, dynamic boundary updating and memory anomaly reporting. According to the method, security monitoring and vulnerability detection of the lightweight dynamic memory can be realized, a service program in a firmware package is identified and analyzed, a dynamic link library is customized by a supplier, a calling address of a sensitive function is globally positioned to serve as a detection point, and dynamic boundary check is executed at the detection point, so that damage detection of the lightweight silent memory is realized; key variable memory space is detected on the fine granularity level; a forward pollution tracking method is designed to screen redundant detection points so as to further reduce extra overhead; in addition, by dynamically updating the uncertain memory space boundary, false alarms caused by static analysis errors and multi-parameter memory space continuity are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to system security and Internet of Things technology, and in particular to a memory anomaly detection method for Linux embedded firmware. Background Art

[0002] Internet of Things (IoT) devices are becoming more and more important in our lives, especially those embedded devices based on Linux systems. Compared with bare metal devices (running directly on hardware or microcontrollers), Linux embedded IoT devices have advantages in application flexibility, scalability, and multitasking, so they occupy a large market share, which also makes them a target for attackers. Therefore, in order to ensure security, people use techniques such as fuzz testing to discover potential vulnerabilities in Linux embedded devices. However, in practical applications, they still have difficulty in discovering vulnerabilities in firmware. We note that in addition to the limitations of firmware fuzzer capabilities, there is another important reason, namely silent memory corruption in embedded systems.

[0003] Silent memory corruption refers to potential memory errors caused by vulnerabilities, but does not cause externally observable abnormal program behavior, so it is "silent" to both users and fuzzers. The working mechanism of the fuzzer is to provide a large number of test cases for running firmware and rely on the received signals to detect vulnerabilities. These signals can be phenomena such as firmware crashes, unresponsiveness, or system warnings, but they must be observable and "non-silent". Obviously, when silent memory corruption occurs during the fuzzing process, although the reason behind it may be that a vulnerability is triggered, the fuzzer cannot detect it. What's worse, in embedded Linux systems, due to performance limitations and the lack of memory safety mechanisms, the frequency of silent memory corruption is very high, which means that many vulnerabilities in the firmware will be missed by the fuzzer.

[0004] An effective way to solve this problem is to introduce a memory anomaly detection mechanism in static firmware or during fuzzing. Memory anomaly detection mechanisms can be divided into static methods and dynamic methods. Static methods detect source code or compiled binary files and insert specific detection code for runtime memory checks. Most traditional static detection methods are designed for C / C++ programs on desktop systems and cannot be applied to firmware with large CPU architecture differences and direct hardware dependence. Although some static detection methods are designed for bare metal firmware, they are not suitable for Linux embedded firmware because such firmware mounts the root file system, which contains multiple service programs, dynamic link libraries (DLLs) and other files. In contrast, dynamic detection methods inject code at runtime through dynamic binary instrumentation (DBI) and monitor the execution of the program to find anomalies instead of directly modifying the program. Dynamic detection methods are compatible with various CPU architectures and can detect anomalies that static methods cannot detect, especially anomalies caused by dynamically loaded code in dynamic link libraries, but they also face the challenge of excessive performance overhead. When used for a single program, this overhead is acceptable. However, for Linux embedded firmware with complex structure and limited resources, the use of traditional dynamic detection methods will greatly reduce the running speed of the fuzzer and even cause it to stagnate.

[0005] In summary, designing memory anomaly detection methods for Linux embedded firmware is still a difficult task, facing the following major challenges:

[0006] (1) Comprehensive firmware testing. Unlike traditional desktop software and bare metal firmware that only focus on a single program, Linux embedded firmware starts multiple service programs when running. Contaminated data may be passed from the main entry point program to other programs and cause memory errors, so all these programs need to be dynamically monitored. In addition, device manufacturers usually introduce many custom DLLs that are not part of the C / C++ standard library into the firmware to implement device personalized functions. Due to improper design, these DLLs may hide many vulnerabilities, so memory exceptions that may be caused by calling DLLs must be monitored.

[0007] (2) Reduce extra overhead. Linux-based firmware runs on the root file system of the device. It is limited by hardware peripherals and system resources. Whether it is a real device or a simulated device, it will face the problem of insufficient testing efficiency. Therefore, the introduction of a memory detection mechanism must avoid excessive memory and time overhead, otherwise it will not meet the basic requirements of fuzz testing.

[0008] (3) Low false alarm rate. The purpose of using memory anomaly detection methods is to help discover memory security defects and vulnerabilities in firmware. Too many false alarms may have a negative impact on the normal operation of the firmware, trigger unnecessary alarms and interfere with the normal firmware development and testing process, and cause security personnel to spend a lot of time and energy to verify and handle. Therefore, careful optimization and adjustment are required to reduce the false alarm rate. Summary of the invention

[0009] Purpose of the invention: The purpose of the present invention is to address the deficiencies in the prior art and to provide a memory anomaly detection method for Linux embedded firmware, so as to achieve fine-grained detection of memory anomalies during firmware fuzz testing, solve the problem that silent memory corruption cannot be monitored, and improve the ability of security personnel to discover firmware vulnerabilities.

[0010] Technical solution: A memory anomaly detection method for Linux embedded firmware of the present invention comprises the following steps:

[0011] Step 1: Firmware analysis

[0012] Use automated analysis tools (such as Binwalk and Firmware Mod Kit) to unpack the firmware, extract the root file system containing the corresponding components and files, and then identify the service programs and manufacturer-customized dynamic link libraries (DLLs) that may hide a large number of vulnerabilities due to the lack of programming specifications, and form the corresponding binary files;

[0013] Step 2: Locate the detection point, that is, analyze the key binary files (service programs and dynamic link libraries DLL), locate the call address of the sensitive function in the disassembled code of the binary file based on the disassembly engine, and analyze the key parameter information related to the memory read and write operations in the sensitive function; the call address of the sensitive function is regarded as the detection point;

[0014] Step 3: Remove redundant detection points. Since sensitive functions are abused in many firmwares, many detection points located in step 2 are irrelevant to external inputs and usually do not lead to exploitable vulnerabilities, but only limit operating efficiency. Therefore, they do not need to be detected. Here, they are all regarded as redundant detection points and removed through the forward pollution tracking method, that is, data flow analysis is performed from the tainted data entry of the program, and only sensitive function calls that may be affected by the tainted data are retained; in addition, an over-pollution strategy is used to retain detection points whose pollution status is difficult to determine, so that tainted variables are widely spread to cover all possible vulnerability points; finally, the detection point information in the screened service program and DLL is integrated (the collected sensitive function name, call address, key parameter address or register, memory size, stack and other data are formatted, and specific markers or keywords are used to mark different information types from different programs or DLLs), and finally a static analysis report that can be reused and subsequently updated is generated according to the template;

[0015] Step 4: Perform firmware fuzz testing, that is, perform fuzz testing based on firmware simulation. In the firmware initialization stage, the boundary check function and the information of the static analysis report are inserted into the free memory space through dynamic stub technology, so as to collect dynamic execution information at runtime and provide for the dynamic boundary check call in step 5.

[0016] Step 5: Dynamic Bounds Check

[0017] When the firmware runs to a sensitive function call point, it determines whether the address is a detection point based on the static analysis results. For detection points, two boundary check functions will be called before and after the sensitive function call. Before calling a sensitive function, the memory address and boundary of the sensitive parameter are determined by combining static analysis information and dynamic execution information (which is the result of dynamic collection when running to each detection point). Then, 2 to 4 bytes of memory data are read outside the memory boundary of each sensitive parameter and recorded as check_bytes. After calling the sensitive function, the check_bytes memory data is re-read and compared with the previous record.

[0018] If it is detected that the check_bytes data has changed, it means that an out-of-bounds data modification has occurred, and go to step 6; if the test result is normal, continue to execute the test until the firmware runs to the end, at which time you can choose to end the test or return to step 4 to continue the next round of testing; (There will be multiple dynamic detection points during a test process. If the detection is normal, continue to run until the next detection point, which is equivalent to returning to the beginning of step 5);

[0019] Step 6: Dynamic boundary update

[0020] Since the dynamic bounds check result in step 5 does not directly prove the existence of memory corruption, two important issues that may cause false positives must be addressed: bounds inference errors and continuous memory space impact.

[0021] For stack variable destination parameters that may have boundary inference errors, perform boundary extension: use the closest determined boundary as the new boundary of the current sensitive variable; if the check_bytes of the new boundary can still be detected to change in subsequent fuzz testing, it means that the data modification has passed the stack variable or function call stack frame boundary, and the influence of boundary inference errors can be ruled out at this time;

[0022] For multiple destination parameter variables in continuous memory space, their boundaries are "merged" and the "merged" memory space boundaries are used as the new boundaries of all adjacent variables, and a check_bytes is shared. In the subsequent fuzz test, when any variable overflows and causes the check_bytes to change, the influence of the continuous memory space can be excluded; if a certain check point has been dynamically updated, any memory corruption at the location of the check point in the subsequent fuzz process will be considered deterministic;

[0023] Step 7: Report memory exceptions:

[0024] For deterministic memory corruption, directly report the memory exception and provide suspected vulnerability information; for non-deterministic memory corruption, send a special process signal (NON_DET_SIGNAL) when the program exits; after receiving the process signal NON_DET_SIGNAL, the fuzzy engine will add the current test case to the priority queue and return to step 4; in the subsequent fuzz testing process, this test case will undergo more mutations, and only when a real vulnerability occurs will a deterministic memory exception report be triggered to ensure that a single detection point has at most one false positive.

[0025] Furthermore, the specific method of parsing the firmware in step 1 is:

[0026] Analyze the system initialization script to find the startup instructions of each service, and traverse the executable files in the system directory, and identify the program that provides interactive services in the IoT device by combining the special naming of the file. Then, by checking the program's dependency list, searching the library load path, and parsing the library's symbol table, determine the DLL linked to the program and its source, and based on the firmware manufacturer's characteristics, such as specific file headers, function naming rules, or data structure naming, identify the manufacturer's customized DLL linked to the service program, and then add it to the analysis queue.

[0027] Furthermore, the method for locating the detection point in step 2 is:

[0028] First, data flow analysis is performed in combination with the function prototype to identify the register or offset address corresponding to the key parameters, so that the real address of the parameter can be read and calculated during the subsequent firmware operation;

[0029] Next, to determine the memory space size of the key parameter, it is necessary to consider the different situations when the target parameter is a heap variable, a global stack variable, or a local stack variable. If it is a heap variable, since heap variables are usually explicitly allocated, the memory space size is also determined, so no additional analysis is required. If it is a stack variable, the reasoning result provided by the IDA Pro reverse engine is called. In order to solve the error caused by this approach, the present invention introduces step 6 in the dynamic detection stage.

[0030] Beneficial effects: The present invention realizes lightweight memory anomaly detection during Linux embedded firmware fuzz testing. By performing static sensitive information analysis and dynamic memory inspection on the firmware, the memory is monitored with less overhead, helping to discover memory security defects and vulnerabilities. Compared with the prior art, the present invention has the following advantages:

[0031] (1) Firmware Applicability

[0032] The present invention solves the challenge that traditional memory detection technology cannot be applied to the firmware of IoT devices. By performing lightweight dynamic memory detection on all service programs and dynamic link libraries in the firmware, the static plug-in problem caused by multiple architectures is avoided. In addition, memory vulnerabilities caused by multi-process interactions and in manufacturer-customized dynamic link libraries can be discovered. The present invention is more suitable for embedded firmware of IoT systems that lack memory safety mechanisms.

[0033] (2) Low overhead

[0034] The present invention locates memory detection points based on sensitive function calls and monitors related sensitive variables, rather than monitoring the memory space of all variables, and further screens out redundant detection points through static pollution analysis, thereby achieving fine-grained memory monitoring, greatly reducing additional memory overhead and time overhead, and is more suitable for resource-constrained IoT device firmware. After the present invention is introduced into the firmware running process, the average memory overhead accounts for only 36%, and the time overhead accounts for only 13.96%.

[0035] (3) Low false alarm rate

[0036] The present invention avoids boundary reasoning errors in the static analysis process by dynamically updating the boundary of non-deterministic memory corruption at the detection point, and eliminates the boundary influence effect of the continuous memory space of multiple sensitive variables, which can ensure that each detection point will only trigger a non-deterministic memory corruption report once at most, so as to achieve a low false alarm rate of memory anomaly detection. The false alarm rate of abnormal state of the present invention can be as low as 0.32%. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 It is a system structure diagram of the present invention.

[0038] Figure 2 It is a basic flow chart of the memory anomaly detection method for firmware fuzzy testing of the present invention.

[0039] Figure 3 It is an illustration of the sensitive function pollution analysis of the present invention.

[0040] Figure 4 It is an illustration of the dynamic boundary merging of the present invention. DETAILED DESCRIPTION

[0041] 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.

[0042] The memory anomaly detection method for Linux embedded firmware of the present invention can realize lightweight memory anomaly detection in the process of Linux embedded firmware fuzz testing, monitor the memory with less overhead by performing static sensitive information analysis and dynamic memory inspection on the firmware, and help discover memory security defects and vulnerabilities. Figure 2 As shown, the specific steps include:

[0043] Step 1: Firmware parsing, that is, first use an automated analysis tool to unpack the firmware, then extract the root file system containing the corresponding components and files, and then identify the service programs containing vulnerabilities and the dynamic link library DLL customized by the manufacturer in the firmware to form the corresponding binary file.

[0044] Since Linux embedded firmware is not a complete executable file, but a root file system directory, which contains the basic files and directories required for the device to start and work. IoT devices provide specific services to users, such as managing the network configuration of routers, reading the images captured by cameras, etc. These interactive services may be attacked when receiving user input; typical service programs include Web servers, Telnet / SSH, FTP, SNMP, etc. This embodiment identifies them by analyzing the system initialization script and its special file naming. Then, identify the manufacturer-customized DLLs related to the service program. They are not strictly designed like standard libraries, and due to the lack of specifications, they may hide a large number of vulnerabilities. Use the ELF viewing tool readelf and the binary analysis tool objdump to extract all DLLs that the service program depends on, and automatically identify the manufacturer-customized DLLs based on manufacturer characteristics, such as specific function naming rules, specific data structures or algorithms, and then add them to the analysis queue.

[0045] Step 2: Locate the detection point, that is, analyze the key binary files of the service program and the dynamic link library DLL, locate the call address of the sensitive function in the disassembled code of the binary file based on the disassembly engine, and analyze the key parameter information involved in the memory read and write operations in the sensitive function; here, the call address of the sensitive function is regarded as the detection point.

[0046] Step 3, remove redundant detection points, that is, for the detection points located in step 2, the detection points without copper leakage are regarded as redundant detection points, and the redundant detection points are first removed by the forward contamination tracking method; then the over-contamination strategy is adopted to retain the detection points whose contamination status is difficult to determine; finally, the detection point information in the screened service program and DLL is integrated to generate a static analysis report that can be reused and subsequently updated.

[0047] Step 4: Perform firmware fuzz testing, that is, perform fuzz testing based on firmware simulation (for example, using gemu). During the firmware initialization phase, the boundary check function and static analysis report information are inserted into the free memory space through dynamic insertion technology, so as to collect dynamic execution information at runtime and provide for the dynamic boundary check call in step 5.

[0048] Step 5: Dynamic Bounds Check

[0049] When the firmware runs to the call address of a sensitive function, it determines whether the call address is a detection point based on the static analysis report; for the detection point, two boundary check functions will be called before and after the sensitive function call;

[0050] Before calling a sensitive function, first combine static analysis information and dynamic execution information to determine the memory address and boundary of the sensitive parameter. At runtime, the actual address or pointer of the parameter can be obtained according to the stack offset or register data, and the memory boundary can be calculated using the memory space size. Since the offset address of the detection point in the DLL can only be obtained through static analysis, additional calculations are required. During the firmware fuzzing process, the base address libcaddr of the library loaded into the memory is usually unchanged, so the real address mem_addr = libcaddr + offsetfunc_i can be determined and calculated in the initialization run phase. Then, 2 to 4 bytes of memory data are read outside the memory boundary of each sensitive parameter and recorded as check_bytes;

[0051] After calling the sensitive function, re-read the check_bytes memory data and compare it with the previous record; under normal circumstances, the execution result of calling the sensitive function will only affect the data in the target parameter memory space. If the check_bytes data is detected to have changed, it means that out-of-bounds data modification has occurred, and execute step 6; if the detection result is normal, continue to execute the test until the firmware runs to the end, at which time you can choose to end the test or return to step 4 to continue the next round of testing.

[0052] Step 6: Dynamic boundary update, that is, correct the boundary inference errors and continuous memory space impact that may exist in the dynamic boundary check results of step 5. The specific method is:

[0053] For stack variable destination parameters that may have boundary inference errors, perform boundary extension and use the closest determined boundary as the new boundary of the current sensitive variable; if the check_bytes of the new boundary can still be detected to change in subsequent fuzz testing, it means that the data modification has passed the stack variable or function call stack frame boundary, and the influence of boundary inference errors is eliminated at this time;

[0054] For multiple destination parameter variables in continuous memory space, their boundaries are merged, and the merged memory space boundaries are used as the new boundaries of all adjacent variables, and a check_bytes is shared. In the subsequent fuzz test, when any variable overflows and causes the check_bytes to change, the influence of the continuous memory space can be excluded; if a detection point has been dynamically updated, any memory corruption occurring at the detection point position in the subsequent fuzz process will be considered deterministic.

[0055] Step 7: Report memory exceptions. For deterministic memory corruption, directly report memory exceptions and provide suspected vulnerability information. For non-deterministic memory corruption, a special process signal NON_DET_SIGNAL is sent when the program exits. After receiving the process signal NON_DET_SIGNAL, the fuzzy engine adds the current test case to the priority queue and returns to step 4.

[0056] like Figure 1 As shown, the memory anomaly detection method for Linux embedded firmware in this embodiment mainly involves a static analysis module and a dynamic detection module.

[0057] In the static analysis module, the firmware is globally statically analyzed, sensitive information is extracted for dynamic detection, and stored as a static analysis report. In order to focus on vulnerability discovery and reduce the overhead of dynamic detection, we only analyze the service programs and manufacturer-customized DLLs in the firmware root file system, and locate the overall call address of sensitive functions as vulnerability detection points. Since not all of these detection points are valuable, we designed a forward taint tracking method to perform coarse-grained data pollution analysis starting from the binary taint data entry, filtering out detection points that are not affected by external input.

[0058] Sensitive information in the static analysis report is read in the dynamic detection module, and a dynamic boundary check is performed on the running firmware. The detection code is introduced into the firmware through dynamic instrumentation. When running to the vulnerability detection point, the memory boundary address of the key variable is calculated based on the sensitive information and dynamic execution information. The out-of-bounds data is compared before and after the sensitive function call to detect memory anomalies. In order to reduce the false alarm rate, the present invention considers three types of non-deterministic memory anomalies caused by memory boundary positioning errors, updates the boundaries of the corresponding key variables by extension or merging, and synchronizes the static analysis report. Subsequently, a specific signal is sent to the fuzzy engine to add the current seed to the priority mutation queue.

[0059] The specific method of parsing the firmware in step 1 of this embodiment is:

[0060] Analyze the system initialization script to find the startup instructions of each service, and traverse the executable files in the system directory, and identify the program that provides interactive services in the IoT device based on the special naming of the files; then determine the DLL linked to the program and its source by checking the program's dependency list, searching the library loading path and parsing the library's symbol table, and identify the manufacturer's customized dynamic link library DLL linked to the service program based on the firmware manufacturer's characteristics, such as specific file headers, function naming rules or data structure naming, and then add it to the analysis queue.

[0061] The method for locating the detection point in step 2 of this embodiment is:

[0062] First, data flow analysis is performed in combination with sensitive function prototypes to identify the registers or offset addresses corresponding to key parameters, so that the real addresses of the parameters can be read and calculated during the subsequent firmware operation. Here, in order to identify and analyze various sensitive function calls in the firmware, they are divided into two types: Type I sensitive functions write multiple data sources to a target address, format multiple data sources into a string, and store it in the specified target address; Type II sensitive functions parse a source data into multiple target addresses, read the formatted data from the string, and store it in the specified target address. If a sensitive function is called when the source data is contaminated by external input, and the memory space of the destination parameter does not have strict boundary management, it will directly lead to memory security vulnerabilities, including out-of-bounds writes, buffer overflows, etc.

[0063] Next, to determine the memory size of the key parameter, consider the different situations when the target parameter is a heap variable, a global stack variable, or a local stack variable; if it is a heap variable, no additional analysis is required; if it is a stack variable, call the inference result provided by the IDA Pro reverse engine. In addition, when the stack variable is passed as a pointer parameter, the call of the sensitive function may have multiple parameter sources, such as Figure 3 As shown in the Func4 node of , the memory space size of the corresponding sensitive variable may be different. The present invention only updates and records the maximum memory space size, because if there is indeed a memory vulnerability, the data of the small sensitive variable can also overflow beyond the boundary of the large sensitive variable. This makes it slightly difficult for the fuzzer to trigger a crash, but this is acceptable compared to the difficulty in finding vulnerabilities.

[0064] Since too many detection points in the firmware limit the operating efficiency, many sensitive functions in the firmware are abused, and many of these detection points are irrelevant to external inputs, and they usually do not lead to exploitable vulnerabilities, so there is no need to detect them, and the present invention regards them as redundant detection points. In step 3 of this embodiment, when removing redundant detection points, the redundant detection points are first removed by forward taint tracking technology, that is, data flow analysis is performed from the taint data entry of the program, and only sensitive function calls that may be affected by the taint data are retained.

[0065] Tainted data entry in firmware is the function of receiving external input in the program, which can be divided into three types:

[0066] (1) Network sockets, using the recv() function to receive data from a connected socket, commonly seen in network service programs, where tainted data is saved to the receive buffer;

[0067] (2) Binary entry, including the execution entry point of the program and the functions for external calls. Other programs can directly pass tainted data through their parameters;

[0068] (3) Implicit reception: data is read from a file or a specified global variable through a function designed by the developer. The tainted data enters the program through a parameter pointer or return value.

[0069] Perform tainted data flow analysis starting from the tainted data entry. Since the fuzzer will try to cover all execution edges, there is no need to analyze whether tainted data is passed between basic blocks during the static analysis phase. Instead, a coarse-grained analysis that ignores jump conditions and possible harmless processing and focuses on the taint propagation of function calls can be performed to implement taint analysis of paths within the program. For external function calls of the program, if they come from a manufacturer's customized DLL, the corresponding DLL file is analyzed to understand the propagation of tainted data; if they come from a standard library or open source library, the function parameters and return values ​​are determined based on the collected function prototypes to determine whether they are tainted. In this process, function call points that are not on the tainted path or whose source parameters are not tainted will be filtered out, for example Figure 3 The Func5 node in the code.

[0070] In addition, the present invention adopts an over-pollution strategy to retain detection points whose pollution status is difficult to determine, so as to cover all possible vulnerability points. Since static analysis methods generally have problems such as complex data structure and lack of runtime semantics, and the coarse-grained pollution tracking process is insensitive to the execution path, when the jump branch and the caller are different, some detection points cannot accurately determine whether sensitive parameters are polluted. Figure 3 Func4 in the example receives uncontaminated data when called by Func1, but passes contaminated data when called by Func2. Since the data passed by Func4 to the sensitive function sscanf may be contaminated, this call location is considered an over-contamination detection point. The over-contamination strategy is a trade-off between detection overhead and vulnerability discovery capabilities. Although this will have a slight impact on operating efficiency, the vulnerabilities that may be discovered at the over-contamination detection point are obviously more valuable.

[0071] Finally, the detection point information in the filtered service programs and DLLs is integrated and saved into a reusable static analysis report.

[0072] Since the dynamic bounds check result in step 5 cannot directly prove the existence of memory corruption, two important issues that may cause false positives must be resolved: boundary inference errors and continuous memory space impact. The root cause of the boundary inference error is that the size of the stack variable memory space obtained by the reverse analysis engine during the static analysis phase is incorrect, resulting in inaccurate calculation of the memory boundary address. At this time, the location of check_bytes is still in the memory space of the target parameter, and the data change is completely normal. In addition, the source of the continuous memory space impact is that for type II sensitive functions, if there are multiple destination parameters in a continuous memory space, the corresponding check_bytes location may be located in the memory space of other parameters, and their normal memory modifications may cause the check byte data to change. In more general cases, if these destination parameters are member variables of a class object, their memory space is usually continuous. When these problems occur, non-deterministic memory corruption (Non-Det-Corr) may be detected, resulting in false positives. There are three situations that may lead to NonDet-Corr: a) the stack variable destination parameter boundary inference error of type I sensitive function; b) the adjacent memory space of multiple heap variable destination parameters of type II sensitive function is affected; c) the stack variable destination parameter boundary inference error of type II sensitive function or the adjacent memory space is affected. If any of these situations occurs at the detection point, the memory anomaly detection result is non-deterministic.

[0073] Therefore, to solve the above problems, this embodiment provides a dynamic boundary update method to transform the non-deterministic boundary into a deterministic boundary to reduce the false alarm rate. Case a and case b can be solved by boundary expansion and boundary merging respectively, while the solution to case c requires boundary expansion based on boundary merging. These updates will be written into the static analysis report after the single test is completed, and return to step 4, such as Figure 4 shown.

[0074] In this embodiment, two advanced Linux-based firmware vulnerability mining tools are used to test the firmware of IoT devices from 10 well-known manufacturers. The test results are shown in Table 1.

[0075] Table 1 Firmware vulnerability mining tool test results

[0076]

[0077] From the test data in Table 1, it can be seen that although all known vulnerabilities cannot be discovered due to the limitations of the vulnerability mining tool itself, 76 and 12 more memory vulnerabilities were discovered respectively after the anomaly detection mechanism of the present invention was introduced, proving the effectiveness of the present invention.

Claims

1. A memory anomaly detection method for Linux embedded firmware, characterized in that: The following steps are involved: Step 1: Firmware parsing, that is, first use an automated analysis tool to unpack the firmware, then extract the root file system containing the corresponding components and files, and then identify the service program containing the vulnerability and the dynamic link library DLL customized by the manufacturer to form the corresponding binary file; Step 2: Locate the detection point, that is, analyze the key binary files of the service program and the dynamic link library DLL, locate the call address of the sensitive function in the disassembled code of the binary file based on the disassembly engine, and analyze the key parameter information related to the memory read and write operation in the sensitive function; the call address of the sensitive function is regarded as the detection point; Step 3, removing redundant detection points, that is, for the detection points located in step 2, the detection points without copper leakage are regarded as redundant detection points, and the redundant detection points are first removed by the forward contamination tracking method; then the over-contamination strategy is adopted to retain the detection points whose contamination status is difficult to determine; finally, the detection point information in the screened service program and DLL is integrated to generate a static analysis report that can be reused and subsequently updated; Step 4: Perform firmware fuzz testing, that is, perform fuzz testing based on firmware simulation. In the firmware initialization stage, the boundary check function and the information of the static analysis report are inserted into the free memory space through dynamic stub technology, so as to collect dynamic execution information at runtime and provide for the dynamic boundary check call in step 5. Step 5: Dynamic Bounds Check When the firmware runs to the call address of a sensitive function, it determines whether the call address is a detection point based on the static analysis report; For the detection point, two bounds checking functions will be called before and after the sensitive function call; Before calling a sensitive function, first combine static analysis information and dynamic execution information to determine the memory address and boundary of sensitive parameters, then read 2 to 4 bytes of memory data outside the memory boundary of each sensitive parameter and record it as check_bytes; After calling the sensitive function, re-read the check_bytes memory data and compare it with the previous record; if the check_bytes data is detected to have changed, it means that out-of-bounds data modification has occurred, and execute step 6; if the test result is normal, continue to execute the test until the firmware runs to the end, at which time you can choose to end the test or return to step 4 to continue the next round of testing; Step 6: Dynamic boundary update, that is, correct the boundary inference errors and continuous memory space impact that may exist in the dynamic boundary check results of step 5. The specific method is: For stack variable destination parameters that may have boundary inference errors, perform boundary extension and use the closest determined boundary as the new boundary of the current sensitive variable; if the check_bytes of the new boundary can still be detected to change in subsequent fuzz testing, it means that the data modification has passed the stack variable or function call stack frame boundary, and the influence of boundary inference errors is eliminated at this time; For multiple destination parameter variables in continuous memory space, their boundaries are merged and the merged memory space boundary is used as the new boundary of all adjacent variables, and a check_bytes is shared. In the subsequent fuzz test, when any variable overflows and causes the check_bytes to change, the influence of the continuous memory space can be excluded; if a checkpoint has been dynamically updated, any memory corruption at the checkpoint position in the subsequent fuzz process will be considered deterministic; Step 7: Report memory exceptions. For deterministic memory corruption, directly report memory exceptions and provide suspected vulnerability information. For non-deterministic memory corruption, a special process signal NON_DET_SIGNAL is sent when the program exits. After receiving the process signal NON_DET_SIGNAL, the fuzzy engine adds the current test case to the priority queue and returns to step 4.

2. The memory anomaly detection method for Linux embedded firmware according to claim 1, characterized in that: The specific method of parsing the firmware in step 1 is: Analyze the system initialization script to find the startup instructions of each service, and traverse the executable files in the system directory, and identify the program that provides interactive services in the IoT device based on the special naming of the files; then determine the DLL linked to the program and its source by checking the program's dependency list, searching the library loading path and parsing the library's symbol table, and identify the manufacturer-customized dynamic link library DLL linked to the service program based on the firmware manufacturer's characteristics, and then add it to the analysis queue.

3. The memory anomaly detection method for Linux embedded firmware according to claim 1, characterized in that: The method for locating the detection point in step 2 is: First, data flow analysis is performed in combination with sensitive function prototypes to identify the registers or offset addresses corresponding to key parameters, so that the real addresses of the parameters can be read and calculated during the subsequent firmware operation; Next, to determine the memory space size of the key parameters, consider different situations when the target parameter is a heap variable, a global stack variable, or a local stack variable; if it is a heap variable, no additional analysis is required; if it is a stack variable, call the inference results provided by the IDA Pro reverse engine.