Kernel driver test method and device, electronic equipment and storage medium
By mutating the corpus seeds of the kernel-driven code and generating test cases, the problem of difficult to ensure effectiveness of manual writing rules in the existing technology is solved, and the efficiency and coverage of kernel fuzz testing are improved.
Patent Information
- Application Number
- CN202311110112.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-30
- Publication Date
- 2025-03-04
AI Technical Summary
In the prior art, fuzz testing of kernel-driven code requires manual writing of a large number of rules, making it difficult to guarantee the validity of the rules.
By obtaining corpus seeds, adding them to the seed queue, and mutation operations on the corpus seeds in the seed queue, generating mutated corpus seeds, which are used to generate test cases and then testing the kernel driver.
Improves the efficiency of kernel fuzz testing, provides more corpus seeds to generate more test cases, and enhances test coverage of kernel-driven code.
Smart Images

Figure CN119557202A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of vehicle-related technologies, and in particular to a kernel driver testing method, device, electronic equipment and storage medium. Background Art
[0002] Operating systems, such as Linux operating systems, require testing of kernel driver codes. Linux operating systems are free to use and freely disseminated multi-user, multi-tasking, multi-threaded and multi-CPU (Central Processing Unit) operating systems. At present, fuzz testing of kernel driver codes of operating systems usually requires manual writing of relevant driver rules, which include one or more kernel functions. Fuzz testing tools use these rules to generate corresponding test cases to call the kernel functions included in the driver rules, and execute the test cases through the kernel driver program to check whether there are vulnerabilities in the kernel driver code. The code coverage information is used to judge and evaluate the effect of the driver rules. While continuously optimizing and correcting the driver rules, the generated test data can be used to detect vulnerabilities.
[0003] However, this detection method requires manual work and a lot of time to write rules, and it is difficult to ensure the effectiveness of the rules. Summary of the invention
[0004] Based on this, it is necessary to provide a kernel driver testing method, device, electronic device and storage medium to address the technical problem that the kernel driver testing method in the prior art requires manual writing of a large number of rules.
[0005] The present invention provides a kernel driver testing method, comprising:
[0006] Acquire a corpus seed, and add the corpus seed to a seed queue, wherein the corpus seed is a driving rule for generating a kernel driver;
[0007] Performing a mutation operation on one or more of the corpus seeds in the seed queue to generate a mutant corpus seed;
[0008] Generate test cases using the variant corpus seed;
[0009] By executing the test case, the kernel driver is tested to obtain the test result of the kernel driver.
[0010] Furthermore, performing a mutation operation on one or more of the corpus seeds in the seed queue to generate a mutant corpus seed includes:
[0011] A plurality of the corpus seeds are randomly selected from the seed queue as crossover seeds, and a crossover operation is performed on the crossover seeds to generate variant corpus seeds; and / or one or more of the corpus seeds are randomly selected from the seed queue as mutation seeds, and a mutation operation is performed on the mutation seeds to generate variant corpus seeds.
[0012] Furthermore, the corpus seed includes one or more kernel functions, and the cross operation on the cross seed includes:
[0013] The kernel functions included in the multiple cross seeds are exchanged, and / or function parameters of the same kernel function included in the multiple cross seeds are exchanged.
[0014] Furthermore, the corpus seed includes one or more kernel functions, and the mutation operation on the mutation seed includes:
[0015] For one or more kernel functions included in the mutation seed, randomly modify function parameters of the kernel function; and / or
[0016] Deleting the kernel function; and / or
[0017] One or more kernel functions are selected from other corpus seeds and added to the mutation seed. Further, the randomly modifying the function parameters of the kernel function includes: generating a random value that conforms to the type of the function parameter of the kernel function, and updating the function parameter.
[0018] Furthermore, after the kernel driver is tested by executing the test case and the test result of the kernel driver is obtained, the method further includes:
[0019] When the test result of the test case is an abnormal crash, save the test case, and add the variant corpus seed for generating the test case to the seed queue; and / or
[0020] If the test result of the test case is normal and the test case triggers a new path, save the test case and add the variant corpus seed for generating the test case to the seed queue; and / or
[0021] When the test result of the test case is normal and the test case does not trigger a new path, the test case and the variant corpus seed for generating the test case are discarded.
[0022] Furthermore, the obtaining of corpus seeds includes: crawling corpus from a designated website using a crawler program as the corpus seeds.
[0023] The present invention provides a kernel driver testing device, comprising:
[0024] A corpus seed acquisition module, used for acquiring corpus seeds and adding the corpus seeds into a seed queue, wherein the corpus seeds are driving rules for generating a kernel driver;
[0025] A seed mutation module, used for performing a mutation operation on one or more corpus seeds in the seed queue to generate a mutant corpus seed;
[0026] A test case generation module, used to generate test cases using the variant corpus seed;
[0027] The test case execution module is used to test the kernel driver by executing the test case to obtain the test result of the kernel driver.
[0028] The present invention provides an electronic device, comprising:
[0029] at least one processor; and,
[0030] a memory communicatively connected to at least one of the processors; wherein,
[0031] The memory stores instructions that can be executed by at least one of the processors. The instructions are executed by at least one of the processors to enable the at least one of the processors to execute the kernel driver testing method as described above.
[0032] The present invention provides a storage medium, wherein the storage medium stores computer instructions, and when a computer executes the computer instructions, it is used to execute all steps of the kernel drive testing method as described above.
[0033] The present invention performs mutation operation on the driving rules as corpus seeds to generate mutated corpus seeds, and uses the mutated corpus seeds to generate test cases to call the kernel driver program to obtain the test results of the test cases. By performing mutation operation on the corpus seeds, more corpus seeds are provided to generate more test cases, thereby improving the efficiency of kernel fuzzy testing and ensuring the results after execution to a greater extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 A flowchart of a kernel driver testing method according to an embodiment of the present invention;
[0035] Figure 2 A flowchart of a kernel driver testing method according to another embodiment of the present invention;
[0036] Figure 3 A system schematic diagram of the best embodiment of the present invention;
[0037] Figure 4 A flowchart of a kernel driver testing method according to a preferred embodiment of the present invention;
[0038] Figure 5 A schematic diagram of a kernel driver testing device according to an embodiment of the present invention;
[0039] Figure 6 The figure is a schematic diagram of the hardware structure of an electronic device of the present invention. DETAILED DESCRIPTION
[0040] The specific embodiments of the present invention are further described below in conjunction with the accompanying drawings. The same components are represented by the same reference numerals. It should be noted that the words "front", "rear", "left", "right", "upper" and "lower" used in the following description refer to directions in the accompanying drawings, and the words "inner" and "outer" refer to directions toward or away from the geometric center of a specific component, respectively.
[0041] like Figure 1 The flowchart of a kernel driver testing method according to an embodiment of the present invention includes:
[0042] Step S101, obtaining a corpus seed, and adding the corpus seed to a seed queue, wherein the corpus seed is a driving rule for generating a kernel driver;
[0043] Step S102, performing a mutation operation on one or more of the corpus seeds in the seed queue to generate a mutant corpus seed;
[0044] Step S103, generating test cases using the variant corpus seed;
[0045] Step S104, testing the kernel driver by executing the test case to obtain the test result of the kernel driver.
[0046] Specifically, the present invention can be applied to electronic devices having processing capabilities.
[0047] First, the electronic device executes step S101 to obtain a corpus seed and add the corpus seed to a seed queue.
[0048] The corpus seed is a driving rule for generating a kernel driver. The driving rule includes multiple kernel functions, and the kernel function can be a kernel function with parameters or a kernel function without parameters. The kernel function is a function in the kernel driver code used to perform a specific function.
[0049] The kernel is preferably the Linux kernel, which is a multi-user, multi-tasking, multi-threaded and multi-central processing unit (CPU) operating system that is free to use and freely disseminated.
[0050] The method of obtaining corpus seeds can be to crawl from a pre-set high-quality corpus through a crawler program. Among them, a crawler program simulates a browser to send network requests and receive request responses. It is a program that automatically crawls Internet information according to certain rules. The high-quality corpus can be high-quality corpora stored on a specified website, such as the corpus information publicly available on the syz-bot website.
[0051] Specifically, by deploying a crawler to parse the corpus to be crawled from the specified website using regular matching, and then cleaning the corpus, an initial corpus is finally formed. Corpora of different architectures can be generated according to different target architectures.
[0052] Then, step S102 is executed to perform a mutation operation on the corpus seeds in the seed queue, and the corpus seeds after the mutation operation are the mutated corpus seeds.
[0053] The mutation operation changes the kernel function and / or the function parameters of the kernel function included in the corpus seed. The mutation operation includes but is not limited to exchange and mutation operations.
[0054] Among them, the same corpus seed can undergo multiple mutation operations to obtain multiple variant corpus seeds.
[0055] Then, step S103 is executed to generate test cases using the variant corpus seeds. The existing method for generating test cases based on corpus seeds can be used to generate a process of calling a kernel driver according to the kernel functions and function parameters included in the marginal user corpus seeds, thereby obtaining test cases.
[0056] Finally, step S104 is performed to test the kernel driver by executing the test case to obtain the test result of the kernel driver, wherein the test result includes abnormal crash or no abnormality.
[0057] Preferably, the test cases are generated by fuzz testing. Fuzz testing is a software testing method that automatically generates a large number of test cases and inputs them into the program under test to find errors in the software.
[0058] The present invention performs mutation operation on the driving rules as corpus seeds to generate mutated corpus seeds, and uses the mutated corpus seeds to generate test cases to call the kernel driver program to obtain the test results of the test cases. By performing mutation operation on the corpus seeds, more corpus seeds are provided to generate more test cases, thereby improving the efficiency of kernel fuzzy testing and ensuring the results after execution to a greater extent.
[0059] like Figure 2 The flowchart of a kernel driver testing method in another embodiment of the present invention includes:
[0060] Step S201, obtaining a corpus seed, and adding the corpus seed to a seed queue, wherein the corpus seed is a driving rule for generating a kernel driver.
[0061] In one embodiment, obtaining the corpus seed includes: crawling the corpus from a designated website using a crawler program as the corpus seed.
[0062] Step S202: randomly select a plurality of the corpus seeds from the seed queue as crossover seeds, perform a crossover operation on the crossover seeds, and generate variant corpus seeds; and / or randomly select one or more of the corpus seeds from the seed queue as mutation seeds, perform a mutation operation on the mutation seeds, and generate variant corpus seeds.
[0063] In one embodiment, the corpus seed includes one or more kernel functions, and the crossover operation on the crossover seed includes:
[0064] The kernel functions included in the multiple cross seeds are exchanged, and / or function parameters of the same kernel function included in the multiple cross seeds are exchanged.
[0065] In one embodiment, the corpus seed includes one or more kernel functions, and the performing mutation operation on the mutation seed includes:
[0066] For one or more kernel functions included in the mutation seed, randomly modify function parameters of the kernel function; and / or
[0067] Deleting the kernel function; and / or
[0068] One or more kernel functions are selected from other corpus seeds and added to the mutation seed.
[0069] In one of the embodiments, the randomly modifying the function parameters of the kernel function includes: generating a random value that conforms to the type of the function parameters of the kernel function, and updating the function parameters.
[0070] Step S203: Generate test cases using the variant corpus seed.
[0071] Step S204, testing the kernel driver by executing the test case to obtain the test result of the kernel driver.
[0072] Step S205, when the test result of the test case is abnormal crash, save the test case, and add the variant corpus seed for generating the test case to the seed queue; and / or
[0073] If the test result of the test case is normal and the test case triggers a new path, save the test case and add the variant corpus seed for generating the test case to the seed queue; and / or
[0074] When the test result of the test case is normal and the test case does not trigger a new path, the test case and the variant corpus seed for generating the test case are discarded.
[0075] This embodiment captures verified high-quality kernel vulnerability corpora, and performs fine processing and packaging on them. These corpora are used as seeds for fuzz testing tools to perform mutations. Combined with the ability of genetic algorithms to mutate corpora, more accurate kernel test cases can be generated, effectively avoiding the time when fuzz testing starts to mutate from invalid corpora. This improves the efficiency of Linux kernel fuzz testing and guarantees the results after execution to a greater extent. The present invention can use high-quality seed queues to detect disclosed or undisclosed vulnerabilities in kernel driver code.
[0076] Specifically, firstly, step S201 is executed to obtain a corpus seed, and the corpus seed is added to a seed queue.
[0077] In one embodiment, obtaining the corpus seed includes: crawling the corpus from a designated website using a crawler program as the corpus seed.
[0078] Specifically, a crawler can be deployed to parse the corpus to be crawled from a specified website using regular matching, and then the corpus is cleaned to finally form an initial corpus. Corpora of different architectures can be generated according to different target architectures. Then, step S201 is executed to obtain corpus seeds from the corpus and add them to the seed queue.
[0079] This embodiment crawls corpus from a specified website through a crawler program, thereby automatically collecting corpus.
[0080] Then, step S202 is executed to perform a mutation operation, which includes a crossover operation and a mutation operation.
[0081] Specifically, a plurality of the corpus seeds are randomly selected from the seed queue as crossover seeds, and a crossover operation is performed on the crossover seeds to generate variant corpus seeds; or
[0082] randomly selecting one or more of the corpus seeds from the seed queue as mutation seeds, performing mutation operations on the mutation seeds, and generating variant corpus seeds; or
[0083] A plurality of the corpus seeds are randomly selected from the seed queue as crossover seeds, a crossover operation is performed on the crossover seeds, and one or more corpus seeds are randomly selected from the seed queue as mutation seeds, a mutation operation is performed on the mutation seeds, and variant corpus seeds are generated.
[0084] In one embodiment, the corpus seed includes one or more kernel functions, and the crossover operation on the crossover seed includes:
[0085] The kernel functions included in the multiple cross seeds are exchanged, and / or function parameters of the same kernel function included in the multiple cross seeds are exchanged.
[0086] Specifically, this embodiment is a crossover operation, in which the corpus seed includes one or more kernel functions.
[0087] Among them, kernel functions include functions with parameters and functions without parameters. For functions with parameters:
[0088] swapping the kernel functions in the selected swap seeds with each other; and / or
[0089] The function parameters of the same kernel function in the selected exchange seed are exchanged.
[0090] For the parameter-free function, the parameter-free kernel functions in the selected exchange seeds are exchanged with each other.
[0091] Preferably, two-to-two interactions are performed, that is, the kernel functions included in the two cross seeds are exchanged, and / or the function parameters of the same kernel function included in the two cross seeds are exchanged.
[0092] This embodiment implements a specific crossover operation, and generates more corpus seeds through the crossover operation.
[0093] In one embodiment, the corpus seed includes one or more kernel functions, and the performing mutation operation on the mutation seed includes:
[0094] For one or more kernel functions included in the mutation seed, randomly modify function parameters of the kernel function; and / or
[0095] Deleting the kernel function;
[0096] And / or select one or more of the kernel functions from other corpus seeds and add them to the mutation seed.
[0097] Specifically, this embodiment is a mutation operation, in which the corpus seed includes one or more kernel functions.
[0098] The corpus seed contains one or more kernel functions.
[0099] Among them, kernel functions include functions with parameters and functions without parameters. For functions with parameters:
[0100] The function parameters of one or more kernel functions in the selected mutation seed are randomly modified.
[0101] In addition, for functions with parameters and functions without parameters, the mutation operation may also delete one or more kernel functions in the mutation seed, and / or select one or more kernel functions from other corpus seeds in the seed queue and add them to the selected mutation seed.
[0102] This embodiment implements a specific mutation operation and generates more corpus seeds through a mutation fork operation.
[0103] In one of the embodiments, the randomly modifying the function parameters of the kernel function includes: generating a random value that conforms to the type of the function parameters of the kernel function, and updating the function parameters.
[0104] Specifically, the function parameters of the kernel function have specific types, such as integer (int), floating point type (float), character type (char), string type (string), etc. If the function parameters input to the kernel function do not conform to the type of the function parameters, the kernel function cannot be executed, therefore, a random value conforming to the type of the function parameters of the kernel function is generated, and the function parameters are updated to avoid the kernel function being unable to execute.
[0105] In some embodiments, generating a random value of a type that conforms to a function parameter of the kernel function and updating the function parameter comprises:
[0106] If the function parameter type of the kernel function is an integer, randomly generate an integer parameter value and update the function parameter;
[0107] If the function parameter type of the kernel function is a floating point type, randomly generating a floating point parameter value and updating the function parameter;
[0108] If the function parameter type of the kernel function is character type, randomly generate a character type parameter value and update the function parameter;
[0109] If the function parameter type of the kernel function is a string type, a string type parameter value is randomly generated and the function parameter is updated.
[0110] This embodiment ensures that the mutated function parameters still meet the function parameter rules of the kernel function.
[0111] Then, step S203 is executed to generate test cases using the variant corpus seeds. The existing method for generating test cases based on corpus seeds can be used to generate a process of calling a kernel driver according to the kernel functions and function parameters included in the marginal user corpus seeds, thereby obtaining test cases.
[0112] Afterwards, step S204 is executed to execute the test case, call the kernel driver, and obtain the test result of the test case.
[0113] The test result includes abnormal crash or no abnormality. Therefore, according to the test result, step S205 is executed.
[0114] If the test result of the test case is an abnormal crash, the test case is saved, and the variant corpus seed for generating the test case is added to the seed queue.
[0115] The test case that causes the abnormal crash detects the public or unpublicized vulnerability in the kernel driver code, so the test case is saved. At the same time, the mutant corpus seed that generates the test case is saved in the seed queue. The mutant corpus seeds saved in the seed queue can continue to perform mutation operations to generate more corpus seeds to obtain more test cases.
[0116] If the test result of the test case is normal and the test case triggers a new path, the test case is saved, and the variant corpus seed for generating the test case is added to the seed queue.
[0117] If the test result of the test case is normal, the code coverage is used to determine whether the test case triggers a new path. If a new path is triggered, the test case can improve the code coverage. Therefore, the test case is saved, and at the same time, the mutant corpus seed that generates the test case is saved in the seed queue. The mutant corpus seeds saved in the seed queue can continue to perform mutation operations to generate more corpus seeds to obtain more test cases.
[0118] If the test result of the test case is no exception and the test case does not trigger a new path, the test case and the variant corpus seed used to generate the test case are discarded.
[0119] This embodiment can automatically obtain a large amount of corpus as input for fuzz testing, and generate a large number of test cases by mutating the corpus to discover potential vulnerabilities in the kernel driver code. It can provide a method for R&D personnel to check the driver code, which is an important tool for checking the security of kernel drivers at this stage.
[0120] like Figure 3 The system schematic diagram of the best embodiment of the present invention is shown, which includes: a corpus preparation part 310, a corpus mutation part 320 and a corpus verification part 330, wherein:
[0121] The corpus preparation part 310 is divided into a crawler deployment module 311, a regular matching module 312, and a corpus cleaning module 313. The crawler deployment module 311 deploys the crawler to parse the corpus to be crawled from the specified website based on the regular matching module 312 using regular matching, and then the corpus cleaning module 313 cleans the corpus to finally form an initial corpus. Corpora of different architectures can be generated according to different target architectures.
[0122] The corpus mutation part 320 includes a seed queue module 321, a mutation strategy module 322 and a test case generation module 323. The seed queue module 321 adds the corpus in the first part of the corpus as a seed to the seed queue of the fuzzy test program. The test case module 323 generates the required test cases through the mutation strategy of the mutation strategy module 322.
[0123] The corpus verification part 330 includes a target input module 331, a use case screening module 332 and a path exploration module 333. The target input module 331 inputs the previously generated test cases into the target program, the use case screening module 332 screens valid test cases based on the feedback of the target program, and explores more code test paths through the path exploration module 333.
[0124] like Figure 4 The flowchart of a kernel driver testing method according to the best embodiment of the present invention is shown, comprising:
[0125] Step S401, determine whether to update the corpus or directly perform fuzzy testing according to the needs, if the corpus needs to be updated, execute step S402, otherwise execute step S404;
[0126] Step S402, select the updated corpus, and run the crawler to match the target corpus to be crawled;
[0127] Step S403, cleaning the crawled corpus locally to remove invalid information in the corpus;
[0128] Step S404, using the processed corpus as an initial corpus seed for fuzzy testing;
[0129] Step S405, adding the initial corpus seed to the seed queue of the fuzzy test;
[0130] Step S406, determine whether the number of mutations has been reached, if so, then end, otherwise, execute step S407;
[0131] Step S407, executing the mutation strategy to mutate the seed;
[0132] Step S408, generating test cases through the mutated seeds;
[0133] Step S409, executing the test case and inputting the test case into the driver;
[0134] Step S410, the driver executes the test case, if an abnormal crash occurs, jumps to step S411 for execution, if no abnormal crash occurs, jumps to step S412 for execution;
[0135] Step S411, the driver crashes abnormally, records the current abnormal scenario, saves the test case that triggers the current abnormality, and adds the corpus seed for generating the test case as a new round of seeds to the seed queue, and executes step S415;
[0136] Step S412: If no exception occurs in the test case, the fuzzy test determines whether the test case triggers a new path through code coverage. If so, the test jumps to step S413 for execution; if not, the test jumps to step S414 for execution;
[0137] Step S413: the current test case triggers a new code path, and the corpus seed is added to the seed queue as a new round of seeds, and a new mutation is performed on this basis, and step S415 is executed;
[0138] Step S414: the current test case does not trigger a new code path, so the current test case is discarded and the process goes to step S415;
[0139] Step S415, determine whether there are any test cases, if there are, execute step S409, otherwise execute step S406.
[0140] Specifically, first, step S401 determines the user's needs. If the user needs to update the corpus in the corpus, then steps S402 to S403 are executed, crawling is performed through the crawler, and step S404 is executed to obtain the initial corpus seed. If the user does not need to update the corpus, step S404 is executed to use the corpus previously stored in the corpus as the initial corpus seed. Then step S405 is executed to add the initial corpus seed to the seed queue, and step S406 is executed to mutate the corpus seed in the seed queue. Among them, step 406 can mutate the corpus seed multiple times to obtain multiple mutated corpus seeds.
[0141] Then, step S406 is executed to determine whether the mutation number is reached, which is preset. If the mutation number is reached, the process ends; otherwise, step S407 is executed to execute the mutation strategy to mutate the seed, and step S408 is executed to generate a test case through the mutated seed using the existing test case generation method.
[0142] Verify all test cases.
[0143] Specifically, execute step S409 to input the test case into the kernel driver, and execute step S410 to determine whether an abnormal crash occurs. If the driver executes the test case and an abnormal crash occurs, execute step S411 to record the abnormal scenario and keep the test case, and at the same time add the corpus seed corresponding to the test case that triggers the current abnormality to the seed queue as a new round of seeds, and then execute step S415 to determine whether it is the last test case. If it is the last test case, execute step S406 to mutate again when the mutation number is not reached. If it is not the last test case, continue to execute step S409 to execute the next test case.
[0144] If the driver does not crash when executing the test case, execute step S412, and determine whether the case triggers a new path through code coverage. If a new path is triggered, jump to step S413, add the corpus seeds to the seed queue as a new round of seeds, and perform new mutations on this basis. Then execute step S415 to determine whether it is the last test case. If it is the last test case, execute step S406. If the number of mutations is not reached, mutate again. If it is not the last test case, continue to execute step S409 and execute the next test case.
[0145] If no new path is triggered, jump to step S414, discard the use case, and then execute step S415 to determine whether it is the last test case. If it is the last test case, execute step S406. If the mutation number is not reached, mutate again. If it is not the last test case, continue to execute step S409 and execute the next test case.
[0146] This embodiment applies crawler technology to kernel driver code fuzz testing, uses crawlers to crawl high-quality corpus, uses it as a seed for fuzz testing, and generates test cases as driver input according to mutation strategies. This embodiment can automatically collect corpus, and use test cases mutated based on high-quality corpus for kernel driver input, which can more efficiently check whether the code has vulnerabilities. The kernel vulnerability inspection method proposed in this embodiment can make up for the problems of invalid corpus and incomplete corpus coverage in kernel driver vulnerability detection in the prior art, and effectively improve the detection efficiency of kernel driver vulnerabilities. This embodiment can automatically crawl a large amount of corpus as the input of fuzz testing, generate a large number of test cases by mutating corpus, and discover potential vulnerabilities in kernel driver code, which can provide a method for R&D personnel to check driver code, and serve as an important tool for checking kernel driver security at this stage.
[0147] Based on the same inventive concept, Figure 5 FIG. 1 is a schematic diagram of a kernel driver testing device according to an embodiment of the present invention, comprising:
[0148] A corpus seed acquisition module 501 is used to acquire a corpus seed and add the corpus seed to a seed queue. The corpus seed is a driving rule for generating a kernel driver.
[0149] A seed mutation module 502, configured to perform a mutation operation on one or more of the corpus seeds in the seed queue to generate a mutant corpus seed;
[0150] A test case generation module 503, used to generate test cases using the variant corpus seed;
[0151] The test case execution module 504 is used to test the kernel driver by executing the test case to obtain the test result of the kernel driver.
[0152] The present invention performs mutation operation on the driving rules as corpus seeds to generate mutated corpus seeds, and uses the mutated corpus seeds to generate test cases to call the kernel driver program to obtain the test results of the test cases. By performing mutation operation on the corpus seeds, more corpus seeds are provided to generate more test cases, thereby improving the efficiency of kernel fuzzy testing and ensuring the results after execution to a greater extent.
[0153] In one of the embodiments, performing a mutation operation on one or more of the corpus seeds in the seed queue to generate a mutant corpus seed includes:
[0154] A plurality of the corpus seeds are randomly selected from the seed queue as crossover seeds, and a crossover operation is performed on the crossover seeds to generate variant corpus seeds; and / or one or more of the corpus seeds are randomly selected from the seed queue as mutation seeds, and a mutation operation is performed on the mutation seeds to generate variant corpus seeds.
[0155] In one embodiment, the corpus seed includes one or more kernel functions, and the crossover operation on the crossover seed includes:
[0156] The kernel functions included in the multiple cross seeds are exchanged, and / or function parameters of the same kernel function included in the multiple cross seeds are exchanged.
[0157] In one embodiment, the corpus seed includes one or more kernel functions, and the performing mutation operation on the mutation seed includes:
[0158] For one or more kernel functions included in the mutation seed, randomly modify function parameters of the kernel function; and / or
[0159] Deleting the kernel function; and / or
[0160] One or more kernel functions are selected from other corpus seeds and added to the mutation seed.
[0161] In one of the embodiments, the randomly modifying the function parameters of the kernel function includes: generating a random value that conforms to the type of the function parameters of the kernel function, and updating the function parameters.
[0162] In one embodiment, the device further comprises:
[0163] A crash recording module, used for saving the test case when the test result of the test case is an abnormal crash, and adding the variant corpus seed for generating the test case to the seed queue; and / or
[0164] a new path triggering module, configured to save the test case and add the variant corpus seed for generating the test case to the seed queue when the test result of the test case is normal and the test case triggers a new path; and / or
[0165] The no-abnormal module is used to discard the test case and generate the variant corpus seed of the test case when the test result of the test case is no abnormality and the test case does not trigger a new path.
[0166] In one embodiment, obtaining the corpus seed includes: crawling the corpus from a designated website using a crawler program as the corpus seed.
[0167] 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.
[0168] like Figure 6 The figure shows a hardware structure diagram of an electronic device of the present invention, including:
[0169] at least one processor 601; and,
[0170] A memory 602 is communicatively connected to at least one of the processors 601; wherein,
[0171] The memory 602 stores instructions that can be executed by at least one of the processors. The instructions are executed by at least one of the processors so that the at least one of the processors can execute the kernel driver testing method as described above.
[0172] Figure 6 A processor 601 is taken as an example.
[0173] The electronic device may further include: an input device 603 and a display device 604 .
[0174] The processor 601, the memory 602, the input device 603 and the display device 604 may be connected via a bus or other means, and the figure takes the connection via a bus as an example.
[0175] The memory 602 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the kernel driver test method in the embodiment of the present application, for example, Figure 1 , Figure 2 The processor 601 executes various functional applications and data processing by running the non-volatile software programs, instructions and modules stored in the memory 602, that is, the kernel driver test method in the above embodiment is implemented.
[0176] The memory 602 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created according to the use of the kernel driver test method, etc. In addition, the memory 602 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 602 may optionally include a memory remotely arranged relative to the processor 601, and these remote memories may be connected to the device for executing the kernel driver test method via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0177] The input device 603 can receive user clicks and generate signal inputs related to user settings and function controls of the kernel driver test method. The display device 604 can include display devices such as a display screen.
[0178] The one or more modules are stored in the memory 602 and when executed by the one or more processors 601 , the kernel driver testing method in any of the above method embodiments is executed.
[0179] The present invention performs mutation operation on the driving rules as corpus seeds to generate mutated corpus seeds, and uses the mutated corpus seeds to generate test cases to call the kernel driver program to obtain the test results of the test cases. By performing mutation operation on the corpus seeds, more corpus seeds are provided to generate more test cases, thereby improving the efficiency of kernel fuzzy testing and ensuring the results after execution to a greater extent.
[0180] An embodiment of the present invention provides a storage medium, wherein the storage medium stores computer instructions. When a computer executes the computer instructions, the storage medium is used to execute all steps of the kernel driver testing method as described above.
[0181] In the context of the present disclosure, a storage medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. The storage medium may be a machine-readable signal medium or a machine-readable storage medium. Alternatively, the storage medium may be a non-temporary computer-readable storage medium, for example, a non-temporary computer-readable storage medium may be a ROM, a random access memory (Random Access Memory, RAM), a compact disc read-only memory (Compact Disc ROM, CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0182] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
Claims
1. A kernel driver testing method, characterized in that: include: Acquire a corpus seed, and add the corpus seed to a seed queue, wherein the corpus seed is a driving rule for generating a kernel driver; Performing a mutation operation on one or more of the corpus seeds in the seed queue to generate a mutant corpus seed; Generate test cases using the variant corpus seed; By executing the test case, the kernel driver is tested to obtain the test result of the kernel driver.
2. The kernel driver testing method according to claim 1, characterized in that: The step of performing a mutation operation on one or more corpus seeds in the seed queue to generate a mutant corpus seed includes: randomly selecting a plurality of the corpus seeds from the seed queue as crossover seeds, performing a crossover operation on the crossover seeds, and generating variant corpus seeds; and / or randomly selecting one or more of the corpus seeds from the seed queue as mutation seeds, performing a mutation operation on the mutation seeds, and generating variant corpus seeds.
3. The kernel driver testing method according to claim 2, characterized in that: The corpus seed includes one or more kernel functions, and the cross operation on the cross seed includes: The kernel functions included in the multiple cross seeds are exchanged, and / or function parameters of the same kernel function included in the multiple cross seeds are exchanged.
4. The kernel driver testing method according to claim 2, characterized in that: The corpus seed includes one or more kernel functions, and the mutation operation on the mutation seed includes: For one or more kernel functions included in the mutation seed, randomly modify function parameters of the kernel function; and / or Deleting the kernel function; and / or One or more kernel functions are selected from other corpus seeds and added to the mutation seed.
5. The kernel driver testing method according to claim 4, characterized in that: The randomly modifying the function parameters of the kernel function includes: generating a random value that conforms to the type of the function parameters of the kernel function, and updating the function parameters.
6. The kernel driver testing method according to claim 1, characterized in that: After the kernel driver is tested by executing the test case and the test result of the kernel driver is obtained, the method further comprises: When the test result of the test case is an abnormal crash, save the test case, and add the variant corpus seed for generating the test case to the seed queue; and / or If the test result of the test case is normal and the test case triggers a new path, save the test case and add the variant corpus seed for generating the test case to the seed queue; and / or When the test result of the test case is normal and the test case does not trigger a new path, the test case and the variant corpus seed for generating the test case are discarded.
7. The kernel driver testing method according to claim 1, characterized in that: The obtaining of corpus seeds includes: crawling corpus from a designated website using a crawler program as the corpus seeds.
8. A kernel driver testing device, characterized in that: include: A corpus seed acquisition module, used for acquiring corpus seeds and adding the corpus seeds into a seed queue, wherein the corpus seeds are driving rules for generating a kernel driver; A seed mutation module, used for performing a mutation operation on one or more corpus seeds in the seed queue to generate a mutant corpus seed; A test case generation module, used to generate test cases using the variant corpus seed; The test case execution module is used to test the kernel driver by executing the test case to obtain the test result of the kernel driver.
9. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to at least one of the processors; wherein, The memory stores instructions that can be executed by at least one of the processors, and the instructions are executed by at least one of the processors to enable at least one of the processors to execute the kernel driver testing method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores computer instructions, and when a computer executes the computer instructions, it is used to execute all steps of the kernel driver testing method according to any one of claims 1 to 7.