Kernel data race detection method based on patch and concurrent behavior pattern analysis
Through the patch-based concurrency behavior pattern analysis method, concurrent functions and shared variables are identified, which solves the problems of high false alarm rate and low efficiency in kernel data competition detection, and achieves efficient and accurate data competition detection.
Patent Information
- Application Number
- CN202410367119.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-28
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-03-28
AI Technical Summary
Existing kernel data contention detection methods have problems such as high false alarm rates and low analysis efficiency. Especially in operating system kernels, static analysis methods have low accuracy and dynamic analysis methods are time-consuming.
Using a method based on patch and concurrent behavior pattern analysis, kernel patches are screened through vulnerability repair patch identification tools and natural language processing, concurrent functions and shared variables are extracted, and alias analysis and concurrent behavior pattern comparison are performed. If the patterns are the same and are not subject to kernel synchronization, Language restrictions, output data competition detection report.
It effectively reduces the number of data competition analysis objects, improves the accuracy and efficiency of detection, avoids false positives, and achieves efficient data competition detection.
Smart Images

Figure CN118171284B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software security technology, and in particular to a kernel data competition detection method based on patch and concurrent behavior pattern analysis. Background Art
[0002] As the core component of the computer system, the operating system kernel is responsible for managing the computer's resources and performing core tasks, playing a vital role in various fields. Data competition is a common concurrency problem in the kernel. If the competing data affects the critical data flow or critical control flow of the program, it may lead to serious security issues such as memory corruption and permission bypass. Attackers can exploit the above vulnerabilities to carry out various malicious behaviors, including unauthorized access, information theft, and system crashes. These attacks may lead to the exposure of personal privacy, the leakage of critical data, and even cause serious damage to the country's critical infrastructure.
[0003] In current computer systems, data competition detection is an important means to ensure stable kernel operation and data security. At present, the data competition detection methods proposed by researchers can be divided into two categories: static analysis and dynamic analysis. Among static analysis methods, static analysis based on data flow has a large number of false positives and low detection result accuracy; while symbolic execution methods can accurately detect potential data competition, but the analysis efficiency is low and there is a problem of path explosion. In contrast, dynamic analysis methods based on lock set analysis, occurrence order relationship, sampling, and fuzz testing can better capture data competition that may occur during runtime by monitoring the code running status in real time, provide more accurate test results, and effectively reduce false positives. However, due to the large amount of kernel code, dynamic analysis usually takes a lot of time and also faces efficiency issues. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a kernel data contention detection method based on patch and concurrent behavior pattern analysis, which can perform efficient data contention detection on the operating system kernel.
[0005] According to a first aspect of an embodiment of the present application, a kernel data race detection method based on patch and concurrent behavior pattern analysis is provided, comprising:
[0006] Collect kernel patches, and use vulnerability repair patch identification tools and natural language processing methods to screen the kernel patches to obtain kernel patches that repair concurrent vulnerabilities;
[0007] For the kernel patch for fixing the concurrent vulnerability, extract the concurrent functions and shared variables in the patch;
[0008] Performing alias analysis on the concurrent function in the patch to obtain an alias pointer in the concurrent function, wherein the alias pointer is a potential shared variable, and the function where the alias pointer is located is a potential concurrent function;
[0009] For the concurrent functions in the patch, the shared variables in the patch, the potential shared variables and the potential concurrent functions, a concurrent behavior pattern analysis is performed through variable access operation types, control flow graphs, data flow graphs and kernel synchronization primitives;
[0010] According to the concurrent behavior pattern analysis result, a concurrent behavior pattern comparison is performed, including: (1) comparing the potential shared variables and the shared variables in the patch according to the concurrent behavior patterns of the functions in which they are located; (2) comparing the potential concurrent functions and the concurrent functions in the patch according to the concurrent behavior patterns of the shared variables in the functions;
[0011] If the concurrent behavior patterns are the same and the two are not restricted by the same kernel synchronization primitives, data competition is considered to exist and a data competition detection report is output.
[0012] According to a second aspect of an embodiment of the present application, a kernel data competition detection device based on patch and concurrent behavior pattern analysis is provided, characterized in that it includes:
[0013] The collection and processing module is used to collect kernel patches, screen the kernel patches using vulnerability patch identification tools and natural language processing methods, and obtain kernel patches that repair concurrent vulnerabilities;
[0014] The extraction module is used to extract concurrent functions and shared variables fixed by kernel patches that fix concurrent vulnerabilities;
[0015] The alias analysis module is used to perform alias analysis on the concurrent function in the patch, obtain the alias pointer in the concurrent function, and consider the alias pointer to be a potential shared variable, and the function in which it is located is a potential concurrent function;
[0016] Pattern analysis module, used to analyze concurrent behavior patterns of potential shared variables and potential concurrent functions through variable access operation types, control flow graphs, data flow graphs, and kernel synchronization primitives;
[0017] A pattern comparison module is used to compare concurrent behavior patterns according to the concurrent behavior pattern analysis result, including: (1) comparing the potential shared variables and the shared variables in the patch according to the concurrent behavior patterns of the functions in which they are located; (2) comparing the potential concurrent functions and the concurrent functions in the patch according to the concurrent behavior patterns of the shared variables in the functions;
[0018] The output module is used to output a data competition detection report if the concurrent behavior patterns are the same and the two are not restricted by the same kernel synchronization primitives.
[0019] According to a third aspect of an embodiment of the present application, there is provided an electronic device, characterized in that it includes:
[0020] one or more processors;
[0021] A memory for storing one or more programs;
[0022] When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in the first aspect.
[0023] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer instructions are stored, characterized in that when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.
[0024] The technical solution provided by the embodiments of the present application may have the following beneficial effects:
[0025] It can be seen from the above embodiments that the present invention extracts known concurrent functions and known shared variables from concurrency-related patches, and identifies potential shared variables and potential concurrent functions according to the characteristics of the known concurrent functions and shared variables, so that the identification is more targeted, thereby achieving the effect of effectively reducing the number of data contention analysis objects.
[0026] The present invention adopts a concurrent behavior pattern analysis method that considers the security impact of potential shared variables and potential concurrent functions on the kernel, overcomes the problem of high false alarm rate of static data competition detection methods, and thus achieves the effect of accurately identifying harmful data competition.
[0027] The present invention adopts a static detection method for analyzing files modified by patches and performing data competition detection based on concurrent behavior pattern comparison. It does not need to test all codes, overcomes the problem of data competition analysis efficiency, and achieves the effect of high detection efficiency and low resource consumption.
[0028] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0030] Figure 1The present invention is a flowchart of a kernel data contention detection method based on patch and concurrent behavior pattern analysis according to an exemplary embodiment.
[0031] Figure 2 The figure is a flowchart of extracting concurrent functions and shared variables within a patch according to an exemplary embodiment.
[0032] Figure 3 The figure is a schematic diagram of a function stain analysis method according to an exemplary embodiment.
[0033] Figure 4 It is a schematic diagram of a concurrent behavior pattern analysis method according to an exemplary embodiment.
[0034] Figure 5 The figure is a schematic diagram of a method for comparing concurrent behavior patterns of potential shared variables and shared variables within a patch according to an exemplary embodiment.
[0035] Figure 6 The invention is a block diagram showing a kernel data contention detection device based on patch and concurrent behavior pattern analysis according to an exemplary embodiment. DETAILED DESCRIPTION
[0036] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0037] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0038] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0039] Figure 1 is a flowchart of a kernel data competition detection method based on patch and concurrent behavior pattern analysis according to an exemplary embodiment. Figure 1 As shown, the method may include the following steps:
[0040] S1: Collect kernel patches, use vulnerability patch identification tools and natural language processing methods to screen the kernel patches, and obtain kernel patches that repair concurrent vulnerabilities; this step may include the following sub-steps:
[0041] S11: Collect kernel patches using distributed version control tools;
[0042] Specifically, by using the Git distributed version control tool, pull the kernel-related code base from the remote code repository (such as GitHub, GitLab, etc.). Use the git clone or git pull command to download or update the latest kernel patch.
[0043] S12: Analyze the kernel patch using a vulnerability repair patch identification tool and a keyword matching method to obtain a kernel patch that repairs the vulnerability;
[0044] Specifically, the PatchNet vulnerability patch identification tool is used to analyze the collected kernel patches and identify the kernel patches that fix the vulnerabilities. For the patches that the PatchNet vulnerability patch identification tool fails to identify, the keyword matching method is used to further identify the kernel patches related to the vulnerability repair by searching for keywords such as "repair", "vulnerability", "security", etc. By combining the two methods, on the one hand, the recognition accuracy of the kernel patches that fix the vulnerabilities can be improved, and on the other hand, the recognition scope can be expanded to collect more kernel patches that fix the vulnerabilities.
[0045] S13: Apply natural language processing technology to analyze the natural language description part of the kernel patch for repairing the vulnerability, identify patches related to concurrent repair, and obtain the kernel patch for repairing the concurrent vulnerability.
[0046] Specifically, we first use the git log --pretty=format:"%b" command of the distributed version control tool to extract the natural language description part from the submission history of the kernel patch. Then, we input the natural language description part of the patch into a large language model (such as ChatGPT) as a prompt word, and use the large language model to identify patches related to concurrency repairs, and obtain kernel patches that repair concurrency vulnerabilities. The application of natural language processing technology, especially large language models, can more accurately and conveniently identify patches related to concurrency repairs, providing a guarantee for the subsequent accurate analysis of kernel patches that repair concurrency vulnerabilities.
[0047] S2: extracting concurrent functions and shared variables in the kernel patch for fixing the concurrent vulnerability; this step may include the following sub-steps:
[0048] S21: Extract the modified files in the patch through distributed version control tools and regular expression matching;
[0049] Specifically, the git log-name-only instruction of the distributed version control tool is used to obtain a list of files modified in the patch.
[0050] S22: for all functions in the file modified by the patch, determining one by one whether there are pointer type parameters in the function or whether there are access operations to global variables; if so, the function is considered to be a potential concurrent function in the file;
[0051] Specifically, use ClangAST Matcher to analyze all functions in the file modified in the patch one by one, matching the pointer type parameters and global variables in the function. If there are pointer type parameters or global variables in the function, mark the function as a potential concurrent function in the file.
[0052] S23: Perform taint analysis on the potential concurrent functions in the file to obtain potential shared variables in the file; this step may include the following sub-steps:
[0053] S231: Initializing a potential shared variable set in the file as a set of pointer type parameters and global variables of potential concurrent functions in the file, and marking variables in the potential shared variable set in the file as tainted information;
[0054] Specifically, ClangAST Matcher is used to analyze the potential concurrent functions in the file, StatementMatcher and DeclarationMatcher are used to extract pointer type parameters and global variables in the potential concurrent functions in the file, and save them in a potential shared variable set in the file.
[0055] S232: Obtain the variables accessed by each instruction in the potential concurrent function in the file and the access operation type. If the accessed variable is in the potential shared variable set in the file, the instruction is considered to be a potential concurrent instruction, and other variables written by the instruction are contaminated variables and potential shared variables in the file, and the other variables written by the instruction are added to the potential shared variable set in the file.
[0056] Specifically, the ClangAST Matcher is used to analyze the assignment operation in the potential concurrent function in the file. When the left operand and the right operand of the assignment operation are both pointer types, and the left operand is not in the potential shared variable set in the file, but the right operand is in the potential shared variable set in the file, it is considered that this is a taint propagation, and the left operand is saved in the potential shared variable set in the file. At the same time, the left operand is marked as a write access operation, and the right operand is marked as a read access operation, and the assignment operation is marked as a potential concurrent instruction.
[0057] S233: When all code paths of the potential concurrent functions in the file are analyzed, the taint analysis is terminated, and the potential shared variables in the file identified by the taint analysis, the access operation types of the potential shared variables, and the potential concurrent instructions are saved in the potential shared variable information set in the file.
[0058] Specifically, after all code paths of potential concurrent functions in the file are analyzed, the taint analysis is terminated, and the potential shared variables in the potential shared variable set, the access operation types of the potential shared variables, and the potential concurrent instructions are saved to the local file of the shared variable information set in the file for use in subsequent further analysis.
[0059] S24: matching the potential concurrent functions in the file and the potential shared variables in the file with the natural language description part and the code modification part of the patch. If the match is successful, the potential concurrent functions in the file or the potential shared variables in the file are considered to be concurrent functions in the patch or shared variables in the patch.
[0060] Specifically, use git log--pretty=format:"%b" to extract the natural language description part of the patch, and delete the commit information extracted by the git log--pretty=format:"%(trailers)" command in the natural language description part. Use git log--pretty=format:""-p--unified=0 command to extract the modified code block. Use regular expressions to match the potential concurrent functions in the file and the potential shared variables in the file with the natural language description part and the code modification part of the patch. If the match is successful, the potential concurrent function in the file or the potential shared variable in the file is considered to be a concurrent function in the patch or a shared variable in the patch.
[0061] S3: Perform alias analysis on the concurrent function in the patch to obtain an alias pointer in the concurrent function, where the alias pointer is a potential shared variable and the function where the alias pointer is located is a potential concurrent function;
[0062] Specifically, the concurrent functions in the patch are input into the SVF tool, and the SVF tool is used to perform alias analysis to obtain the alias pointers and the call graph of the alias pointers marked by the SVF tool. Through the call graph of the alias pointer, the functions in which the alias pointers are accessed or modified are tracked, and the functions that access or modify the alias pointers, that is, the functions where the alias pointers are located, are obtained, and these functions are considered to be the functions where the alias pointers are located.
[0063] S4: Analyze the concurrent behavior patterns of the concurrent functions, shared variables, potential shared variables and potential concurrent functions in the patch through variable access operation types, control flow graphs, data flow graphs and kernel synchronization primitives; this step may include the following sub-steps:
[0064] S41: acquiring access operation types of potential shared variables and shared variables in patches from the potential shared variable information set in the file;
[0065] Specifically, the local file storing the shared variable information set in the file is read to obtain the access operation types of the potential shared variables to be analyzed and the shared variables in the patch.
[0066] S42: Generate a control flow graph and a data flow graph of concurrent functions and potential concurrent functions in the patch;
[0067] Specifically, the code analysis tool joern is used to apply the instruction cpg.method.name("<function name>").cfg to generate the control flow graph and data flow graph of the concurrent functions and potential concurrent functions in the patch.
[0068] S43: Determine the positions of the shared variables and potential shared variables in the patch in the control flow graph;
[0069] Specifically, the code analysis tool joern is used to apply the instruction cpg.method.name("<function name>").cfg.filter{it.code.contains("variable name")} to query the nodes where the shared variables and potential shared variables in the patch are located in the control flow graph, that is, the positions of the shared variables and potential shared variables in the patch in the control flow graph.
[0070] S44: Calculating the relative positions of the potential shared variables and the shared variables in the patch in the control flow graph according to the positions of the shared variables in the patch and the potential shared variables in the control flow graph;
[0071] Specifically, according to the control flow graph, the shortest path from the function entry to the node where the shared variable in the patch and the potential shared variable are located is calculated, and the lengths of the two shortest paths are subtracted to obtain the relative positions of the potential shared variable and the shared variable in the patch in the control flow graph.
[0072] S45: Security impact analysis: Determine whether the shared variables and potential shared variables in the patch are used in conditional judgment statements. If they are used in conditional judgment statements, the variables used for conditional judgment are considered to be security-related variables. Determine whether there is a release operation on the potential shared variables. If there is a release operation, the potential shared variables are considered to be security-related variables;
[0073] Specifically, the conditional judgment statements (e.g., if, for, while, etc.) and the related variables used for conditional judgment in the code are extracted through ClangAST Matcher. If the conditional judgment related variables are shared variables or potential shared variables in the patch, the variables used for conditional judgment are considered to be security-related variables. Release operation related variables are extracted through release operation related functions summarized based on experience (e.g., kfree(), vfree(), free_pages(), free_irq(), etc.). If the release operation related variables are shared variables or potential shared variables in the patch, the release operation related variables are considered to be security-related variables. When performing concurrent behavior pattern analysis, security impact consistency analysis is performed to consider the impact of different shared variables on kernel security, which can exclude benign data competition and achieve the effect of accurately identifying harmful data competition.
[0074] S46: Analyze, according to the data flow graph, whether the shared variables and potential shared variables in the patch are restricted by the same kernel synchronization primitives.
[0075] Specifically, all relevant nodes involving shared variables and potential shared variables in the patch are identified through a data flow graph. Retrieve whether the relevant nodes include kernel synchronization primitives, such as mutex locks, semaphores, spin locks, READ_ONCE(), WRITE_ONCE(), etc. If the node contains relevant kernel synchronization primitives, mark the kernel synchronization primitives, and find all paths from the kernel synchronization primitives to the shared variables or potential shared variables in the patch through path analysis. If the above path exists, it is considered that the shared variables or potential shared variables in the patch are restricted by the marked kernel synchronization primitives. After the above analysis is completed, compare the kernel synchronization primitives that restrict the shared variables and potential shared variables in the patch. If the two are consistent, it is considered that the shared variables in the patch and the potential shared variables are restricted by the same kernel synchronization primitives.
[0076] S5: performing a concurrent behavior pattern comparison based on the concurrent behavior pattern analysis result, including: (1) comparing the potential shared variables and the shared variables in the patch based on the concurrent behavior patterns of the functions in which they are located; (2) comparing the potential concurrent functions and the concurrent functions in the patch based on the concurrent behavior patterns of the shared variables in the functions; this step may include the following sub-steps:
[0077] The potential shared variables and the shared variables in the patch are compared according to the concurrent behavior mode of the function in which they are located, including:
[0078] A1: Compare the access operation types of the potential shared variables and the shared variables in the patch to determine whether they are all write access operations or all read access operations;
[0079] Specifically, according to the access operation types of the potential shared variable and the shared variable in the patch obtained from the analysis result of S41, if the access operation types of the potential shared variable and the shared variable in the patch are both write access operations or read access operations, it is considered that the access operation types of the potential shared variable and the shared variable in the patch are the same.
[0080] A2: Compare the relative positions of the potential shared variable and the shared variable in the patch in the control flow graph to see whether they are less than a given threshold;
[0081] Specifically, given a threshold value (e.g., a distance of 10), based on the relative positions of the potential shared variables and the shared variables in the patch in the control flow graph obtained by S44, the relative positions are compared to see whether they are less than the given threshold value. By comparing the relative positions of the potential shared variables and the shared variables in the patch in the control flow graph, the potential impact of the potential shared variables and the shared variables in the patch on the program behavior can be evaluated.
[0082] A3: Comparison of security impact consistency: If the shared variable in the patch is a security-related variable, compare whether the potential shared variable is a security-related variable. If both are or neither is a security-related variable, the potential shared variable is considered to have the same security impact as the shared variable in the patch.
[0083] Specifically, according to the result of the security impact analysis of the shared variables and potential shared variables in the patch in S45, if both the shared variables in the patch and the potential shared variables are security-related variables, or both the shared variables in the patch and the potential shared variables are not security-related variables, then it is considered that the security impact of the potential shared variables is consistent with that of the shared variables in the patch.
[0084] A4: If the access operation type of the potential shared variable and the shared variable in the patch is the same, the relative position is less than a given threshold and the security impact is consistent, then the concurrent behavior patterns of the two are considered to be the same.
[0085] Specifically, the analysis results of A1, A2, and A3 are combined to make a judgment. If all conditions are met, that is, the access operation type is the same, the relative position is within the threshold, and the security impact is consistent, then the potential shared variables and the shared variables in the patch are considered to have the same concurrent behavior pattern.
[0086] The potential concurrent function and the concurrent function in the patch are compared according to the concurrent behavior patterns of the shared variables in the functions, including:
[0087] B1: Compare the access operation types of the shared variables in the patch in the potential concurrent function and the concurrent function in the patch to determine whether they are all write access operations or all read access operations;
[0088] Specifically, according to the access operation types of the shared variables in the patch in the potential concurrent function and the concurrent function in the patch obtained from the analysis result of S41, if the access operation types of the shared variables in the patch in the potential concurrent function and the concurrent function in the patch are both write access operations or read access operations, then it is considered that the access operation types of the shared variables in the patch in the potential concurrent function and the concurrent function in the patch are the same.
[0089] B2: Comparison of security impact consistency: If the shared variable in the patch is a security-related variable in the concurrent function in the patch, compare whether the shared variable in the patch is a security-related variable in the potential concurrent function; if the shared variable in the patch is a security-related variable in both or neither, the security impact of the shared variable in the patch in the potential concurrent function is considered to be consistent with that in the concurrent function in the patch;
[0090] Specifically, according to the result of the security impact analysis of the shared variables in the patch in S45, if the shared variables in the patch are security-related variables in both the concurrent functions in the patch and the potential concurrent functions, or the shared variables in the patch are not security-related variables in both the concurrent functions in the patch and the potential concurrent functions, it is considered that the security impact of the shared variables in the patch is consistent in the concurrent functions in the patch and in the potential concurrent functions.
[0091] B3: If the access operation type of the shared variable in the patch in the potential concurrent function is the same as that in the concurrent function in the patch, and the security impact is consistent, then the concurrent behavior patterns of the two are considered to be the same.
[0092] Specifically, the analysis results of B1 and B2 are combined to make a judgment. If all conditions are met, that is, the access operation type is the same and the security impact is consistent, then it is considered that the potential concurrent function has the same concurrent behavior pattern as the concurrent function in the patch.
[0093] S6: If the concurrent behavior patterns are the same and the two are not restricted by the same kernel synchronization primitives, it is considered that data competition exists and a data competition detection report is output.
[0094] Specifically, when the concurrent behavior mode of the potential shared variable is the same as that of the shared variable in the patch, and according to the analysis result of S46, the access of the potential shared variable and the shared variable in the patch is not constrained by the same type of kernel synchronization primitive (such as mutex, semaphore, etc.), it is considered that there is data competition in the function where the potential shared variable is located, and a data competition detection report is generated; when the concurrent behavior mode of the shared variable in the patch is the same in the potential concurrent function and the concurrent function in the patch, and the access of the potential concurrent function and the concurrent function in the patch to the shared variable in the patch is not constrained by the same type of kernel synchronization primitive, it is considered that there is data competition between the potential concurrent function and the concurrent function in the patch, and a data competition detection report is generated. Among them, the data competition detection report includes: the function name and code position involved in the data competition, the shared variables involved in the data competition and their types and positions, and the names and types of kernel synchronization primitives that are not used. Through a detailed data competition report, developers can locate the problem more accurately and take corresponding solutions, thereby improving the robustness and reliability of the code. Data competition detection is performed using a static analysis method based on concurrent behavior pattern analysis, which does not require the consumption of a large amount of computing resources and has high detection efficiency and low resource consumption.
[0095] It can be seen from the above embodiments that the present application achieves the effect of reducing the number of data contention analysis objects by identifying potential shared variables and potential concurrent functions based on patches. By analyzing the security impact of potential shared variables and potential concurrent functions on the kernel, the effect of accurately identifying harmful data contention is achieved. By comparing with the concurrent behavior pattern in the patch, the effect of high analysis efficiency and low resource consumption is achieved.
[0096] Corresponding to the aforementioned embodiment of the kernel data contention detection method based on patch and concurrent behavior pattern analysis, the present application also provides an embodiment of the kernel data contention detection device based on patch and concurrent behavior pattern analysis.
[0097] Figure 6 1 is a block diagram of a kernel data contention detection device based on patch and concurrent behavior pattern analysis according to an exemplary embodiment. Figure 6 , the device comprises:
[0098] The collection and processing module 1 is used to collect kernel patches, screen the kernel patches using vulnerability repair patch identification tools and natural language processing methods, and obtain kernel patches that repair concurrent vulnerabilities;
[0099] Extraction module 2, used for extracting concurrent functions and shared variables fixed by the kernel patch for fixing concurrent vulnerabilities;
[0100] Alias analysis module 3, used to perform alias analysis on concurrent functions in the patch, obtain the alias pointer in the concurrent function, and consider the alias pointer to be a potential shared variable, and the function in which the alias pointer is located to be a potential concurrent function;
[0101] A pattern analysis module 4 is used to analyze concurrent behavior patterns of potential shared variables and potential concurrent functions through variable access operation types, control flow graphs, data flow graphs, and kernel synchronization primitives;
[0102] The mode comparison module 5 is used to compare the concurrent behavior modes according to the concurrent behavior mode analysis result, including: (1) comparing the potential shared variables and the shared variables in the patch according to the concurrent behavior modes of the functions in which they are located; (2) comparing the potential concurrent functions and the concurrent functions in the patch according to the concurrent behavior modes of the shared variables in the functions;
[0103] Output module 6 is used to consider that data competition exists if the concurrent behavior modes are the same and the two are not restricted by the same kernel synchronization primitive, and output a data competition detection report.
[0104] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0105] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0106] Correspondingly, the present application also provides an electronic device, comprising: one or more processors; a memory for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the kernel data contention detection method based on patch and concurrent behavior pattern analysis as described above.
[0107] Correspondingly, the present application also provides a computer-readable storage medium on which computer instructions are stored. When the instructions are executed by a processor, the kernel data competition detection method based on patch and concurrent behavior pattern analysis as described above is implemented.
[0108] Those skilled in the art will readily appreciate other embodiments of the present application after considering the description and practicing the contents disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The description and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.
[0109] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A kernel data race detection method based on patch and concurrent behavior pattern analysis, characterized in that: include: Collect kernel patches, and use vulnerability repair patch identification tools and natural language processing methods to screen the kernel patches to obtain kernel patches that repair concurrent vulnerabilities; For the kernel patch for fixing the concurrent vulnerability, extract the concurrent functions and shared variables in the patch; Performing alias analysis on the concurrent function in the patch to obtain an alias pointer in the concurrent function, wherein the alias pointer is a potential shared variable, and the function where the alias pointer is located is a potential concurrent function; For the concurrent functions in the patch, the shared variables in the patch, the potential shared variables and the potential concurrent functions, a concurrent behavior pattern analysis is performed through variable access operation types, control flow graphs, data flow graphs and kernel synchronization primitives; According to the concurrent behavior pattern analysis result, performing concurrent behavior pattern comparison includes: (1) comparing the potential shared variables and the shared variables in the patch according to the concurrent behavior patterns of the functions in which they are located; (2) comparing the potential concurrent functions and the concurrent functions in the patch according to the concurrent behavior patterns of the shared variables in the functions; If the concurrent behavior patterns are the same and the two are not restricted by the same kernel synchronization primitives, data competition is considered to exist and a data competition detection report is output.
2. The method according to claim 1, characterized in that Use vulnerability patch identification tools and natural language processing methods to screen kernel patches and obtain kernel patches that fix concurrent vulnerabilities, including: Use distributed version control tools to collect kernel patches; Analyze the kernel patch using a vulnerability repair patch identification tool and a keyword matching method to obtain a kernel patch that repairs the vulnerability; Natural language processing technology is applied to analyze the natural language description part of the kernel patch for repairing the vulnerability, identify patches related to concurrent repair, and obtain the kernel patch for repairing the concurrent vulnerability.
3. The method according to claim 1, characterized in that For the kernel patch for fixing the concurrent vulnerability, extract the concurrent functions and shared variables in the patch, including: Extract the modified files in the patch through distributed version control tools and regular expression matching; For all functions in the file modified by the patch, determine whether there are pointer type parameters or access operations to global variables in the function one by one. If so, the function is considered to be a potential concurrent function in the file; Performing taint analysis on potential concurrent functions in the file to obtain potential shared variables in the file; The potential concurrent functions in the file and the potential shared variables in the file are matched with the natural language description part and the code modification part of the patch. If the match is successful, the potential concurrent functions in the file or the potential shared variables in the file are considered to be concurrent functions in the patch or shared variables in the patch.
4. The method according to claim 3, characterized in that Perform taint analysis on potential concurrent functions in the file to obtain potential shared variables in the file, including: Initializing a potential shared variable set in a file to a set of pointer type parameters and global variables of potential concurrent functions in the file, and marking variables in the potential shared variable set in the file as tainted information; Obtain the variables accessed by each instruction in the potential concurrent function in the file and the access operation type. If the accessed variable is in the potential shared variable set in the file, the instruction is considered to be a potential concurrent instruction, and other variables written by the instruction are contaminated variables and potential shared variables in the file, and the other variables written by the instruction are added to the potential shared variable set in the file. When all code paths of the potential concurrent functions in the file are analyzed, the taint analysis is terminated, and the potential shared variables in the file identified by the taint analysis, the access operation types of the potential shared variables, and the potential concurrent instructions are saved in the potential shared variable information set in the file.
5. The method according to claim 4, characterized in that The concurrent functions in the patch, the shared variables in the patch, the potential shared variables and the potential concurrent functions are analyzed through variable access operation types, control flow graphs, data flow graphs and kernel synchronization primitives, including: Obtaining access operation types of potential shared variables and shared variables in patches from the potential shared variable information set in the file; Generate control flow graphs and data flow graphs for concurrent functions and potential concurrent functions in the patch; Determine the location of shared variables and potential shared variables in the patch in the control flow graph; According to the positions of the shared variables in the patch and the potential shared variables in the control flow graph, the relative positions of the potential shared variables and the shared variables in the patch in the control flow graph are calculated; Security impact analysis: Determine whether the shared variables and potential shared variables in the patch are used in conditional judgment statements. If so, the variables used for conditional judgment are considered to be security-related variables. Determine whether there is a release operation on the potential shared variables. If so, the potential shared variables are considered to be security-related variables. According to the data flow graph, it is analyzed whether the shared variables and potential shared variables in the patch are restricted by the same kernel synchronization primitives.
6. The method according to claim 5, characterized in that The potential shared variables and the shared variables in the patch are compared according to the concurrent behavior mode of the function in which they are located, including: Comparing the access operation types of the potential shared variable and the shared variable in the patch to determine whether both are write access operations or both are read access operations; Comparing whether the relative position of the potential shared variable and the shared variable in the patch in the control flow graph is less than a given threshold; Comparison of security impact consistency: If the shared variable in the patch is a security-related variable, compare whether the potential shared variable is a security-related variable. If both are or neither is a security-related variable, the potential shared variable is considered to have the same security impact as the shared variable in the patch. If the access operation types of the potential shared variable and the shared variable in the patch are the same, the relative position is less than a given threshold, and the security impact is consistent, then the concurrent behavior patterns of the two are considered to be the same.
7. The method according to claim 1, characterized in that The potential concurrent functions and the concurrent functions in the patch are compared based on the concurrent behavior patterns of the shared variables in the functions, including: Compare the shared variables in the patch, and determine whether the access operation types in the potential concurrent function and the concurrent function in the patch are all write access operations or all read access operations; Comparison of security impact consistency: If the shared variable in the patch is a security-related variable in the concurrent function in the patch, compare whether the shared variable in the patch is a security-related variable in the potential concurrent function; if the shared variable in the patch is a security-related variable in both or neither, the security impact of the shared variable in the patch in the potential concurrent function is considered to be consistent with that in the concurrent function in the patch; If the access operation type of the shared variable in the patch in the potential concurrent function is the same as that in the concurrent function in the patch, and the security impact is consistent, then the concurrent behavior modes of the two are considered to be the same.
8. A kernel data contention detection device based on patch and concurrent behavior pattern analysis, characterized in that: include: The collection and processing module is used to collect kernel patches, screen the kernel patches using vulnerability patch identification tools and natural language processing methods, and obtain kernel patches that repair concurrent vulnerabilities; The extraction module is used to extract concurrent functions and shared variables fixed by kernel patches that fix concurrent vulnerabilities; The alias analysis module is used to perform alias analysis on the concurrent function in the patch, obtain the alias pointer in the concurrent function, and consider the alias pointer to be a potential shared variable, and the function in which it is located is a potential concurrent function; Pattern analysis module, used to analyze concurrent behavior patterns of potential shared variables and potential concurrent functions through variable access operation types, control flow graphs, data flow graphs, and kernel synchronization primitives; A pattern comparison module is used to compare concurrent behavior patterns according to the concurrent behavior pattern analysis result, including: (1) comparing the potential shared variables and the shared variables in the patch according to the concurrent behavior patterns of the functions in which they are located; (2) comparing the potential concurrent functions and the concurrent functions in the patch according to the concurrent behavior patterns of the shared variables in the functions; The output module is used to output a data competition detection report if the concurrent behavior patterns are the same and the two are not restricted by the same kernel synchronization primitives.
9. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data-scoped dynamic data race detection
CN102314394A
Kernel data race detection method based on static program analysis and fuzzy testing
CN114428733A
Fast and accurate data race detection for concurrent programs with asynchronous calls
US20100235817A1
