Operating system-oriented cross-control flow kernel vulnerability mining method
By building control flow diagrams and key variable control flow diagrams in the operating system kernel, combined with error processing mode analysis, the problem of cross-control flow data propagation detection in the existing technology is solved, and comprehensive vulnerability detection of the Linux kernel is achieved, which improves the Detection accuracy and coverage, ability to identify serious vulnerabilities.
Patent Information
- Application Number
- CN202410914017.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2044-07-09
Smart Images

Figure CN118940271A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a cross-control flow kernel vulnerability mining method for an operating system, belonging to the technical field of vulnerability detection. Background Art
[0002] Vulnerability detection is an integral part of network security. Through vulnerability detection, you can quickly discover security risks in systems, applications, or networks, and help assess and mitigate risks that may lead to data leaks or service interruptions. Regular vulnerability detection can prevent hackers from exploiting unpatched security flaws to attack.
[0003] Operating system kernel vulnerability mining can play an important role in many fields. These application areas cover network security, enterprise management, government supervision and many other aspects.
[0004] The limitations of existing technologies include being difficult to apply to the entire operating system kernel, not considering cross-control flow data propagation, and being unable to identify some vulnerabilities with complex characteristics, which are specifically reflected in:
[0005] Static methods usually require complex calculations. This type of method can complete the calculation within a certain period of time when analyzing relatively simple open source projects, but for projects with a large amount of code such as operating system kernels, the time overhead of static methods is unacceptable. Software error injection methods are difficult to trigger more complex kernel code execution paths, so it is difficult to discover vulnerabilities in these codes.
[0006] Existing static methods and taint analysis methods do not consider the situation where data propagates across control flows when analyzing problems in code. When these methods encounter such situations, they usually interrupt the analysis process, resulting in missed reports or false positives, which greatly reduces the accuracy.
[0007] Existing static methods and taint analysis methods usually only focus on the characteristics of specific types of vulnerabilities, so they have considerable limitations when analyzing problems, resulting in them only being able to discover specific types of vulnerabilities. Summary of the invention
[0008] A brief overview of the present invention is provided below in order to provide a basic understanding of certain aspects of the present invention. It should be understood that this overview is not an exhaustive overview of the present invention. It is not intended to identify key or important parts of the present invention, nor is it intended to limit the scope of the present invention. Its purpose is merely to present certain concepts in a simplified form as a prelude to a more detailed description discussed later.
[0009] In view of this, in order to solve the technical problems existing in the prior art, the present invention provides a cross-control flow kernel vulnerability mining method for an operating system.
[0010] Solution 1: A cross-control flow kernel vulnerability mining method for operating systems, including:
[0011] S1. Compile the Linux kernel code and generate LLVMIR. Call the LLVM API to read the content of the LLVMIR bytecode file and parse it to obtain the LLVMIR in the form of a memory object.
[0012] S2, build the control flow graph of each function and identify the error code;
[0013] S3, identifying the return error code function, the target function and the code error variable;
[0014] S4, traverse the control flow graph of each function and identify the memory pointer;
[0015] S5, construct key variable control flow graph;
[0016] S6, identify security checks and memory release;
[0017] S7. Make a vulnerability report.
[0018] Preferably, the steps of constructing the control flow graph of each function and identifying the error code include:
[0019] S21. According to the LLVMIR in the form of memory objects, construct the control flow graph of each function in the Linux kernel code, and describe the control flow graph as Gf=V,E,f∈F, where F is the set of functions in the kernel, f is the function in the set, G is the control flow graph corresponding to the function, V is the set of nodes, the node is the basic block in the function, E is the set of directed edges, and the directed edges are the control flow transfer relationship between basic blocks;
[0020] S22, collecting functions that may be used for indirect calls according to the LLVMIR in the form of memory objects, and saving them to set I;
[0021] S23, traverse the control flow graph of each function, check the function call instructions in the basic block, collect all indirect call points, find matching functions in the set I according to the number and type of parameters used in the function call as potential indirect call objects, build a mapping Ind, and the key of the mapping Ind is the indirect call point;
[0022] S24. Collect error codes defined in the Linux source code and save them to the Err collection.
[0023] 3. The method for cross-control flow kernel vulnerability mining for an operating system according to claim 1, wherein the step of identifying the return error code function, the target function and the code error variable comprises:
[0024] S31, traverse each node in the control flow graph, check the operands used by each instruction in the basic block, if they are equal to the negative of a certain error code, mark them as error codes, and save the operands marked as error codes to the set ErrSrc; if the operand is a null pointer, save the operand of the null pointer to the set NullSrc;
[0025] S32, starting the tracing propagation process with one of the operands ErrSrc and NullSrc as the starting point; if an instruction uses the traced operand, the value generated by the instruction is marked; if the operand of an instruction is a marked value, the value generated by the instruction is also marked; if the operand of a return instruction is a marked value, the function where the instruction is located is saved in the set ErrRetFunc; if a storage instruction saves the marked value to the memory area pointed to by a parameter pointer of the function, the function where the instruction is located is also saved in the set ErrRetFunc;
[0026] S33. Traverse the control flow graph of each function and check the function call instructions therein. If the called object exists in the set ErrRetFunc, add the function to the set TargetFunc; add the variable that stores the error code to the set ErrRetVar.
[0027] Preferably, the step of traversing the control flow graph of each function and identifying the memory pointer includes:
[0028] S41, traverse the control flow graph of each function, check whether there is a call instruction for calling the Linux memory allocation related function in the function call instruction, and skip if not; if there is, track the propagation process of the memory pointer returned by the function; if there is a return instruction that uses the memory pointer, add the current function to the set MemAllocFunc; if there is a storage instruction that saves the memory pointer to the memory pointed to by the function pointer parameter, also add the current function to the set MemAllocFunc;
[0029] S42, traverse the control flow graph of each function, if the function is in the set MemAllocFunc, skip it, if not check whether there is a call to the function in MemAllocFunc in the function call instruction, according to the memory pointer returned by the callee, track how the corresponding variable that saves the memory pointer is propagated; if there is a return instruction that uses the saved memory pointer, add the current function to the set MemAllocFunc; if there is a store instruction that saves the saved memory pointer to the memory pointed to by the function pointer parameter, also add the current function to the set MemAllocFunc;
[0030] S43, repeat S42 until there is no new function in the set MemAllocFunc;
[0031] S44, traverse the control flow graph of each function, check whether there is a call to the function in MemAllocFunc in the function call instruction; if there is a called object in the set MemAllocFunc, add the current function to the set TargetFunc; save the variable that saves the memory pointer to the set MemRetVar.
[0032] Preferably, the steps of constructing a key variable control flow graph include:
[0033] Merge the sets ErrRetVar and MemRetVar into KeyVar, where the variables are key variables; for each function, construct the key variable control flow graph KGf = Var, Acc, f∈F according to the control flow graph, where F is the set of functions in the kernel, f is the function in the set, Var is the set of key variables, and Acc is the set of access relations between key variables;
[0034] In a control flow graph G of function f, a variable is in KeyVar, add the variable to the set Var;
[0035] Add the parameter variables of function f to the set Var;
[0036] If a function instruction uses variable A in the set Var, add the function instruction to the set Var; if the function instruction saves the return value to another variable B, or saves A to another variable C, add B or C to the set Var, and add a directed edge in Acc from A to B or C; repeat this process until KGf no longer changes.
[0037] Preferably, the steps of identifying security check and memory release include:
[0038] For each key variable in KeyVar, start from the variable control flow graph KGf of the function f where the key variable is located and track its propagation process;
[0039] If there is a point in Var that accesses a key variable, it is marked; if other points in Var access the marked point, they are also marked; if the marked point is a function call instruction, enter the key variable control flow graph corresponding to the called function, mark the corresponding parameters, and continue to track the propagation of the parameters;
[0040] For the function call instructions in Ind, enter the key variable control flow graph corresponding to each potential call object respectively to continue tracking; if the marked point is a return instruction, and it is entered from the previous function to the current function, return to the previous function and mark its return value variable; if it is found that the storage instruction saves the marked value to the function parameter, and it is entered from the previous function to the current function, return to the previous function and mark its corresponding parameter variable; if it is found that the storage instruction saves the marked value to a field of the global variable, mark the global variable and field, and find all places where the global variable and field are used, and continue to track its propagation; during the tracking process, if it is found that the marked point is a comparison instruction, and the comparison object is the negative of the integer value in Err, stop tracking and record the tracking path as successful; if the comparison object is a null pointer, add one Verified pointer marks are found and tracing continues; if the marked point is found to be a function call instruction, and the callee name contains "release", "free", "put" and "destroy", or the function name is kfree(), kmem_cache_free(), kvfree() and vfree(), tracing is stopped and the tracing path is recorded as successful; if a storage instruction is found to save an unmarked value to a marked variable, tracing is stopped and the path is recorded as failed; if it is found that it is not accessed by other points during the tracing process, tracing is stopped and the path is recorded as failed; for key variables of memory pointer type, if it is found that they are used to calculate related instructions or load instructions during the tracing process, but the tracing path does not have a verified pointer mark, tracing is stopped and the path is recorded as failed.
[0041] Preferably, the steps of making a vulnerability report include:
[0042] For trace paths recorded as failed, the report may have a hole;
[0043] For the case where the key variable is an error code, if it fails because it is not accessed by other points, an error code unhandled vulnerability is reported;
[0044] If it fails because it is overwritten during the propagation process, an error code propagation failure vulnerability is reported;
[0045] For cases where the critical variable is a memory pointer, if it fails because it is not accessed by other points, a resource leak vulnerability is reported;
[0046] If it fails because a pointer is used without validation, a NULL pointer dereference vulnerability is reported;
[0047] For reported error code unhandled vulnerabilities, check how the return value of the error return function corresponding to the key variables is handled in the code;
[0048] For the reported unhandled error code vulnerability, check the return value of the error return function corresponding to the key variable in the code; if for an error code return function, after analyzing all the calling instructions that call it, it is found that the return value is checked after more than 70% of the calling points, while the return value is not checked after the remaining calling points, then the unhandled error code vulnerability related to the error code return function will be reported as a severe unhandled error code vulnerability.
[0049] Solution 2: An electronic device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of a cross-control flow kernel vulnerability mining method for an operating system described in Solution 1 are implemented.
[0050] Solution three: A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for mining cross-control flow kernel vulnerabilities for an operating system described in Solution one is implemented.
[0051] The beneficial effects of the present invention are as follows:
[0052] 1. The present invention detects the entire Linux kernel method based on the common features of error handling vulnerabilities, and customizes analysis rules specifically for Linux. These rules cover various common error handling modes, so that the system can systematically identify and report vulnerabilities in error handling codes; by capturing the common features of error handling codes, vulnerabilities caused by improper error handling can be effectively detected, providing more comprehensive coverage than traditional methods.
[0053] 2. The present invention can associate the control flows analyzed in the Linux kernel for joint analysis. This method can associate the separated control flows in the Linux kernel for joint analysis, so that the taint propagation between different control flows can be accurately tracked, thereby significantly improving the accuracy and coverage of vulnerability detection.
[0054] 3. The present invention can identify serious error handling vulnerabilities from ordinary vulnerability reports. By analyzing the processing of error codes in different callers, the system can identify those vulnerabilities that may cause major security risks. Through this in-depth analysis method, ordinary vulnerabilities and critical vulnerabilities that may cause serious consequences can be effectively distinguished, thereby improving the practicality and credibility of the detection results. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0056] Figure 1 This is a flow chart of a cross-control flow kernel vulnerability mining method for operating systems. DETAILED DESCRIPTION
[0057] In order to make the technical solutions and advantages of the embodiments of the present invention more clearly understood, the exemplary embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict.
[0058] Example 1: Reference Figure 1 This embodiment describes a cross-control flow kernel vulnerability mining method for an operating system, including:
[0059] S1. Compile the Linux kernel code and generate LLVMIR. Call the LLVM API to read the content of the LLVMIR bytecode file and parse it to obtain the LLVMIR in the form of a memory object.
[0060] S2, build the control flow graph of each function and identify the error code;
[0061] S21. According to the LLVMIR in the form of memory objects, construct the control flow graph of each function in the Linux kernel code, and describe the control flow graph as Gf=V,E,f∈F, where F is a set of functions, f is a function in the kernel, G is the control flow graph corresponding to the function, V is a set of nodes, a node is a basic block in the function, and E is a set of directed edges, which are control flow transfer relationships between basic blocks;
[0062] S22. Collect functions that may be used for indirect calls according to LLVMIR in the form of memory objects and save them into set I; function pointers of functions in the set are either saved into global variables or local variables, or used as parameters of function call instructions.
[0063] S23, traverse the control flow graph of each function, check the function call instructions in the basic block, collect all indirect call points, find matching functions in the set I according to the number and type of parameters used in the function call as potential indirect call objects, build a mapping Ind, and the key of the mapping Ind is the indirect call point;
[0064] An indirect call site is a function call instruction, but this type of function call instruction uses a variable value to make a function call;
[0065] If the number and type of parameters of the function call instruction match the number and type of parameters of a function in set I, the match is considered successful;
[0066] The key of the mapping Ind is the indirect call point, and the value is a set containing all the functions that successfully match the indirect call point in the set I.
[0067] S24, collect error codes defined in the Linux source code and save them to the set Err;
[0068] S3, identifying the return error code function, the target function and the code error variable;
[0069] S31, traverse each node in the control flow graph, check the operands used by each instruction in the basic block, if they are equal to the negative of a certain error code, mark them as error codes, and save the operands marked as error codes to the set ErrSrc; if the operand is a null pointer, save the operand of the null pointer to the set NullSrc;
[0070] S32, starting the tracing propagation process with one of the operands ErrSrc and NullSrc as the starting point; if an instruction uses the traced operand, the value generated by the instruction is marked; if the operand of an instruction is a marked value, the value generated by the instruction is also marked; if the operand of a return instruction is a marked value, the function where the instruction is located is saved in the set ErrRetFunc; if a storage instruction saves the marked value to the memory area pointed to by a parameter pointer of the function, the function where the instruction is located is also saved in the set ErrRetFunc;
[0071] S33, traverse the control flow graph of each function, check the function call instructions therein, if there is a called object in the set ErrRetFunc, add the function to the set TargetFunc; add the variable that stores the error code to the set ErrRetVar;
[0072] The error code function is: the error code is a series of positive integers representing different error messages. The positive integers are negated and then used as the return value of the error code function.
[0073] The objective function is a function for further determining whether there is a vulnerability;
[0074] The variable of the error code is the variable storing the return value or the pointer parameter variable.
[0075] S4, traverse the control flow graph of each function and identify the memory pointer;
[0076] S41, traverse the control flow graph of each function, check whether there is a call instruction for calling the Linux memory allocation related function in the function call instruction, and skip if not; if there is, track the propagation process of the memory pointer returned by the function; if there is a return instruction that uses the memory pointer, add the current function to the set MemAllocFunc; if there is a storage instruction that saves the memory pointer to the memory pointed to by the function pointer parameter, also add the current function to the set MemAllocFunc;
[0077] S42, traverse the control flow graph of each function, if the function is in the set MemAllocFunc, skip it, if not check whether there is a call to the function in MemAllocFunc in the function call instruction, according to the memory pointer returned by the callee, track how the corresponding variable that saves the memory pointer is propagated; if there is a return instruction that uses the saved memory pointer, add the current function to the set MemAllocFunc; if there is a store instruction that saves the saved memory pointer to the memory pointed to by the function pointer parameter, also add the current function to the set MemAllocFunc;
[0078] The variable storing the memory pointer may be a variable storing the return value of a function call instruction, or may be a pointer parameter of a function call instruction.
[0079] S43, repeat S42 until there is no new function in the set MemAllocFunc;
[0080] S44, traverse the control flow graph of each function, check whether there is a call to the function in MemAllocFunc in the function call instruction; if there is a called object in the set MemAllocFunc, add the current function to the set TargetFunc; save the variable that saves the memory pointer to the set MemRetVar;
[0081] Among them, the variable of the memory pointer is the variable of the return value of the calling instruction or a pointer parameter variable.
[0082] S5, construct key variable control flow graph;
[0083] Merge the sets ErrRetVar and MemRetVar into KeyVar, where the variables are key variables; for each function, construct the key variable control flow graph KGf = Var, Acc, f∈F according to the control flow graph, where F is the set of functions in the kernel, f is the function in the set, Var is the set of key variables, and Acc is the set of access relations between key variables;
[0084] In a control flow graph G of function f, a variable is in KeyVar, add the variable to the set Var;
[0085] Add the parameter variables of function f to the set Var;
[0086] If a function instruction uses variable A in the set Var, add the function instruction to the set Var; if the function instruction saves the return value to another variable B, or saves A to another variable C, add B or C to the set Var, and add a directed edge in Acc from A to B or C; repeat this process until KGf no longer changes;
[0087] S6, identify security checks and memory release;
[0088] For each key variable in KeyVar, start from the variable control flow graph KGf of the function f where the key variable is located and track its propagation process;
[0089] If there is a point in Var that accesses a key variable, it is marked; if other points in Var access the marked point, they are also marked; if the marked point is a function call instruction, enter the key variable control flow graph corresponding to the called function, mark the corresponding parameters, and continue to track the propagation of the parameters;
[0090] For the function call instructions in Ind, enter the key variable control flow graph corresponding to each potential call object respectively to continue tracking; if the marked point is a return instruction, and it is entered from the previous function to the current function, return to the previous function and mark its return value variable; if it is found that the storage instruction saves the marked value to the function parameter, and it is entered from the previous function to the current function, return to the previous function and mark its corresponding parameter variable; if it is found that the storage instruction saves the marked value to a field of the global variable, mark the global variable and field, and find all places where the global variable and field are used, and continue to track its propagation; during the tracking process, if it is found that the marked point is a comparison instruction, and the comparison object is the negative of the integer value in Err, stop tracking and record the tracking path as successful; if the comparison object is a null pointer, add one Verified pointer marks are found and the tracing continues; if the marked point is found to be a function call instruction, and the callee name contains "release", "free", "put" and "destroy", or the function name is kfree(), kmem_cache_free(), kvfree() and vfree(), the tracing is stopped and the tracing path is recorded as successful; if a storage instruction is found to save an unmarked value to a marked variable, the tracing is stopped and the path is recorded as failed; if it is found that it is not accessed by other points during the tracing process, the tracing is stopped and the path is recorded as failed; for key variables of memory pointer type, if it is found that they are used to calculate related instructions or load instructions during the tracing process, but the tracing path does not have a verified pointer mark, the tracing is stopped and the path is recorded as failed;
[0091] S7. Make a vulnerability report.
[0092] For trace paths recorded as failed, the report may have a hole;
[0093] For the case where the key variable is an error code, if it fails because it is not accessed by other points, an error code unhandled vulnerability is reported;
[0094] If it fails because it is overwritten during the propagation process, an error code propagation failure vulnerability is reported;
[0095] For cases where the critical variable is a memory pointer, if it fails because it is not accessed by other points, a resource leak vulnerability is reported;
[0096] If it fails because a pointer is used without validation, a NULL pointer dereference vulnerability is reported;
[0097] For reported error code unhandled vulnerabilities, check how the return value of the error return function corresponding to the key variables is handled in the code;
[0098] For the reported unhandled error code vulnerability, check the return value of the error return function corresponding to the key variable in the code; if for an error code return function, after analyzing all the calling instructions that call it, it is found that the return value is checked after more than 70% of the calling points, while the return value is not checked after the remaining calling points, then the unhandled error code vulnerability related to the error code return function will be reported as a severe unhandled error code vulnerability.
[0099] In the process of analyzing multiple versions of Linux kernels, this embodiment confirmed 34 error handling vulnerabilities, 25 of which were already in the CVE list. After reporting the new vulnerabilities to the Linux kernel maintainers, at least 4 were confirmed.
[0100] Embodiment 2: The computer device of the present invention may be a device including a processor and a memory, such as a single-chip microcomputer including a central processing unit, etc. Moreover, the processor is used to implement the steps of the above-mentioned cross-control flow kernel vulnerability mining method for operating systems when executing a computer program stored in the memory.
[0101] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0102] The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SmartMediaCard, SMC), a secure digital (SecureDigital, SD) card, a flash card (FlashCard), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0103] Embodiment 3: Computer readable storage medium embodiment.
[0104] The computer-readable storage medium of the present invention can be any form of storage medium that can be read by a processor of a computer device, including but not limited to non-volatile memory, volatile memory, ferroelectric memory, etc. A computer program is stored on the computer-readable storage medium. When the processor of the computer device reads and executes the computer program stored in the memory, the steps of the above-mentioned cross-control flow kernel vulnerability mining method for an operating system can be implemented.
[0105] The computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer readable media do not include electric carrier signals and telecommunication signals.
[0106] Although the present invention has been described according to a limited number of embodiments, it will be apparent to those skilled in the art, with the benefit of the above description, that other embodiments may be envisioned within the scope of the invention thus described. In addition, it should be noted that the language used in this specification is selected primarily for readability and teaching purposes, rather than for explaining or defining the subject matter of the present invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is illustrative, not restrictive, with respect to the scope of the present invention, which is defined by the appended claims.
Claims
1. A cross-control flow kernel vulnerability mining method for an operating system, characterized in that: include: S1. Compile the Linux kernel code and generate LLVM IR. Call the LLVM API to read the content of the LLVM IR bytecode file and parse it to obtain the LLVM IR in the form of a memory object. S2, build the control flow graph of each function and identify the error code; S3, identifying the return error code function, the target function and the code error variable; S4, traverse the control flow graph of each function and identify the memory pointer; S5, construct key variable control flow graph; S6, identify security checks and memory release; S7. Make a vulnerability report.
2. The method for cross-control flow kernel vulnerability mining for operating systems according to claim 1, characterized in that: The steps to construct the control flow graph of each function and identify the error code include: S21. According to the LLVM IR in the form of memory objects, construct the control flow graph of each function in the Linux kernel code, and describe the control flow graph as G(f) = (V, E0, f∈F, where F is the set of functions in the kernel, f is a function in the set, G is the control flow graph corresponding to the function, V is the set of nodes, nodes are basic blocks in the function, E is the set of directed edges, and directed edges are the control flow transfer relationships between basic blocks; S22. Collect functions that may be used for indirect calls according to the LLVM IR in the form of memory objects and save them into set I. S23, traverse the control flow graph of each function, check the function call instructions in the basic block, collect all indirect call points, find matching functions in the set I according to the number and type of parameters used in the function call as potential indirect call objects, build a mapping Ind, and the key of the mapping Ind is the indirect call point; S24. Collect error codes defined in the Linux source code and save them to the Err collection.
3. The method for cross-control flow kernel vulnerability mining for operating systems according to claim 1, characterized in that: The steps to identify the function that returns the error code, the target function, and the code error variable include: S31, traverse each node in the control flow graph, check the operands used by each instruction in the basic block, if they are equal to the negative of a certain error code, mark them as error codes, and save the operands marked as error codes to the set ErrSrc; if the operand is a null pointer, save the operand of the null pointer to the set NullSrc; S32, starting the tracing propagation process with one of the operands ErrSrc and NullSrc as the starting point; if an instruction uses the traced operand, the value generated by the instruction is marked; if the operand of an instruction is a marked value, the value generated by the instruction is also marked; if the operand of a return instruction is a marked value, the function where the instruction is located is saved in the set ErrRetFunc; if a storage instruction saves the marked value to the memory area pointed to by a parameter pointer of the function, the function where the instruction is located is also saved in the set ErrRetFunc; S33. Traverse the control flow graph of each function and check the function call instructions therein. If the called object exists in the set ErrRetFunc, add the function to the set TargetFunc; add the variable that stores the error code to the set ErrRetVar.
4. The method for cross-control flow kernel vulnerability mining for operating systems according to claim 1, characterized in that: Traversing the control flow graph of each function, the steps to identify the memory pointer include: S41, traverse the control flow graph of each function, check whether there is a call instruction for calling the Linux memory allocation related function in the function call instruction, and skip if not; if there is, track the propagation process of the memory pointer returned by the function; if there is a return instruction that uses the memory pointer, add the current function to the set MemAllocFunc; if there is a storage instruction that saves the memory pointer to the memory pointed to by the function pointer parameter, also add the current function to the set MemAllocFunc; S42, traverse the control flow graph of each function, if the function is in the set MemAllocFunc, skip it, if not check whether there is a call to the function in MemAllocFunc in the function call instruction, according to the memory pointer returned by the callee, track how the corresponding variable that saves the memory pointer is propagated; if there is a return instruction that uses the saved memory pointer, add the current function to the set MemAllocFunc; if there is a store instruction that saves the saved memory pointer to the memory pointed to by the function pointer parameter, also add the current function to the set MemAllocFunc; S43, repeat S42 until there is no new function in the set MemAllocFunc; S44, traverse the control flow graph of each function, check whether there is a call to the function in MemAllocFunc in the function call instruction; if there is a called object in the set MemAllocFunc, add the current function to the set TargetFunc; save the variable that saves the memory pointer to the set MemRetVar.
5. The method for cross-control flow kernel vulnerability mining for operating systems according to claim 1, characterized in that: The steps to construct the key variable control flow graph include: Merge the sets ErrRetVar and MemRetVar into KeyVar, where the variables are key variables; for each function, construct the key variable control flow graph KG(f0=(Var,Acc),f∈F) according to the control flow graph, where F is the set of functions in the kernel, f is the function in the set, Var is the set of key variables, and Acc is the set of access relations between key variables; In a control flow graph G of function f, a variable is in KeyVar, add the variable to the set Var; Add the parameter variables of function f to the set Var; If a function instruction uses variable A in the set Var, add the function instruction to the set Var; if the function instruction saves the return value to another variable B, or saves A to another variable C, add B or C to the set Var, and add a directed edge in Acc from A to B or C; repeat this process until KG(f) no longer changes.
6. The method for cross-control flow kernel vulnerability mining for operating systems according to claim 1, characterized in that: The steps to identify safety checks and memory releases include: For each key variable in KeyVar, start from the variable control flow graph KG(f) of the function f where the key variable is located and track its propagation process; If there is a point in Var that accesses a key variable, it is marked; if other points in Var access the marked point, they are also marked; if the marked point is a function call instruction, enter the key variable control flow graph corresponding to the called function, mark the corresponding parameters, and continue to track the propagation of the parameters; For the function call instructions in Ind, enter the key variable control flow graph corresponding to each potential call object respectively to continue tracking; if the marked point is a return instruction, and it is entered from the previous function to the current function, return to the previous function and mark its return value variable; if it is found that the storage instruction saves the marked value to the function parameter, and it is entered from the previous function to the current function, return to the previous function and mark its corresponding parameter variable; if it is found that the storage instruction saves the marked value to a field of the global variable, mark the global variable and field, and find all places where the global variable and field are used, and continue to track its propagation; during the tracking process, if it is found that the marked point is a comparison instruction, and the comparison object is the negative of the integer value in Err, stop tracking and record the tracking path as successful; if the comparison object is a null pointer, add one Verified pointer marks are found and tracing continues; if the marked point is found to be a function call instruction, and the callee name contains "release", "free", "put" and "destroy", or the function name is kfree(), kmem_cache_free(), kvfree() and vfree(), tracing is stopped and the tracing path is recorded as successful; if a storage instruction is found to save an unmarked value to a marked variable, tracing is stopped and the path is recorded as failed; if it is found that it is not accessed by other points during the tracing process, tracing is stopped and the path is recorded as failed; for key variables of memory pointer type, if it is found that they are used to calculate related instructions or load instructions during the tracing process, but the tracing path does not have a verified pointer mark, tracing is stopped and the path is recorded as failed.
7. The method for mining cross-control flow kernel vulnerabilities for an operating system according to claim 1, characterized in that: The steps to report a vulnerability include: For trace paths recorded as failed, the report may have a hole; For the case where the key variable is an error code, if it fails because it is not accessed by other points, an error code unhandled vulnerability is reported; If it fails because it is overwritten during the propagation process, an error code propagation failure vulnerability is reported; For cases where the critical variable is a memory pointer, if it fails because it is not accessed by other points, a resource leak vulnerability is reported; If it fails because a pointer is used without validation, a NULL pointer dereference vulnerability is reported; For reported error code unhandled vulnerabilities, check how the return value of the error return function corresponding to the key variables is handled in the code; For the reported unhandled error code vulnerability, check the return value of the error return function corresponding to the key variable in the code; if for an error code return function, after analyzing all the calling instructions that call it, it is found that the return value is checked after more than 70% of the calling points, while the return value is not checked after the remaining calling points, then the unhandled error code vulnerability related to the error code return function will be reported as a severe unhandled error code vulnerability.
8. An electronic device, characterized in that: The invention comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of a cross-control flow kernel vulnerability mining method for an operating system as described in any one of claims 1 to 7 when executing the computer program.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the method for mining cross-control flow kernel vulnerabilities for an operating system as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Shaping vulnerability detection method based on dynamic and static analysis
CN110909358A
Method for detecting kernel information leakage vulnerability of operating system under binary file
CN114417343A
Object-driven Linux kernel crash classification method and device
CN116150760A
Defect detection method, device, system and computer readable medium
US20190108003A1
