Fuzz testing methods and related equipment for machine learning frameworks
By parsing the source code of the machine learning framework, and fuzzing is performed based on these constraints, the problem that the existing technology cannot cover different operating scenarios is solved, and full coverage detection of multiple operating environments of the machine learning framework is achieved. Improved security.
Patent Information
- Application Number
- CN202410302906.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-15
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-03-15
AI Technical Summary
The prior art cannot effectively cover machine learning framework detection tools that operate different operating scenarios, making it difficult to fully identify and solve security risks.
By obtaining the source code of the machine learning framework, parsing the source code to extract test case constraints, including hardware environment constraints and run mode constraints, and fuzzing based on these constraints to achieve full coverage of multiple run environments.
This method can overcome the problem that existing detection tools cannot cover different operating scenarios to a certain extent, and identify possible security problems in various operating environments through fuzzy testing, improving the security of the machine learning framework.
Smart Images

Figure CN118194293B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer and communication technology, and in particular to a fuzz testing method and related equipment for a machine learning framework. Background Art
[0002] At present, the implementation of machine learning frameworks is becoming increasingly complex, which means that many security risks are hidden in them. Since there are many developers using the framework and the products released by developers are aimed at a large number of users, once there is a security problem in the framework, it may cause serious harm.
[0003] As more and more machine learning framework vulnerabilities are disclosed, current framework-oriented detection tools are unable to cover different operating scenarios. Summary of the invention
[0004] The embodiments of the present application provide a fuzz testing method and related equipment for a machine learning framework, which can at least to some extent overcome the problem that detection tools in the prior art cannot cover different operating scenarios.
[0005] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0006] According to one aspect of an embodiment of the present application, a fuzzy testing method for a machine learning framework is provided, including: obtaining source code of the machine learning framework; parsing the source code to obtain test case constraints, wherein there are multiple test case constraints, including hardware environment constraints and operation mode constraints; performing fuzzy testing according to each of the test case constraints to obtain test results.
[0007] In an embodiment of the present application, parsing the source code to obtain test case constraints specifically includes: parsing the source code to obtain operator calling code; and obtaining the hardware environment constraints and the operation mode constraints according to the operator test code.
[0008] In an embodiment of the present application, parsing the source code to obtain the operator calling code specifically includes: parsing the source code to obtain an operator name list; performing pattern matching according to the operator name list to obtain the operator calling code.
[0009] In an embodiment of the present application, the hardware environment constraints and the operating mode constraints are obtained according to the operator test code, specifically including: parsing the operator test code to construct an abstract syntax tree; matching the abstract syntax tree according to a predetermined matching rule to extract the hardware environment constraints and the operating mode constraints.
[0010] In an embodiment of the present application, the test case constraints also include file dependency constraints, and parsing the source code to obtain the test case constraints also includes: analyzing the operator calling code to obtain the operator test code; and monitoring the disk file according to the operator calling code and the operator test code to obtain the file dependency constraints.
[0011] In an embodiment of the present application, analyzing the operator calling code to obtain the operator testing code specifically includes: analyzing the file name and function name of the operator calling code; if the operator testing code contains a predetermined file name or a predetermined function name, the operator calling code is the operator testing code.
[0012] In an embodiment of the present application, the method of monitoring the disk file according to the operator calling code and the operator testing code to obtain the file dependency constraint specifically includes: using a modified function to instrument the operator calling code to obtain an instrumentation result; executing the operator testing code and monitoring the disk file to obtain a monitoring result; and obtaining the file dependency constraint according to the instrumentation result and the monitoring result.
[0013] In an embodiment of the present application, fuzzy testing is performed according to the constraints of each test case to obtain a test result, which specifically includes: generating a test case according to the constraints of each test case; executing the test case, performing fuzzy testing, and obtaining a test result, wherein the test result includes security issues arising from the test.
[0014] According to one aspect of an embodiment of the present application, a fuzzy testing device for a machine learning framework is provided, and the fuzzy testing device for the machine learning framework includes: a code acquisition module, used to acquire the source code of the machine learning framework; a code parsing module, used to parse the source code to obtain test case constraints, and there are multiple test case constraints, including hardware environment constraints and operation mode constraints; a fuzzy testing module, used to perform fuzzy testing according to each of the test case constraints to obtain a test result.
[0015] In an embodiment of the present application, the code parsing module specifically includes: a code parsing submodule, used to parse the source code to obtain the operator calling code; an environment constraint submodule, used to obtain the hardware environment constraint and the operation mode constraint according to the operator test code.
[0016] In an embodiment of the present application, the code parsing submodule specifically includes: a code parsing unit, used to parse the source code to obtain an operator name list; and a pattern matching unit, used to perform pattern matching according to the operator name list to obtain the operator calling code.
[0017] In an embodiment of the present application, the environmental constraint submodule specifically includes: an abstract syntax tree unit, used to parse the operator test code and construct an abstract syntax tree; a rule matching unit, used to match the abstract syntax tree according to a predetermined matching rule, and extract the hardware environment constraints and the operating mode constraints.
[0018] In an embodiment of the present application, the test case constraints also include file dependency constraints, and the code parsing module also includes: a code screening submodule, used to analyze the operator call code and obtain the operator test code; a dependency constraint submodule, used to monitor disk files according to the operator call code and the operator test code to obtain the file dependency constraints.
[0019] In an embodiment of the present application, the code screening submodule specifically includes: a code analysis unit, used to analyze the file name and function name of the operator call code; a code determination unit, used to determine that if the operator test code contains a predetermined file name or a predetermined function name, the operator call code is an operator test code.
[0020] In an embodiment of the present application, the dependency constraint submodule specifically includes: an operator instrumentation unit, which is used to instrument the operator call code using a modified function to obtain an instrumentation result; a code execution unit, which is used to execute the operator test code and monitor the disk file to obtain a monitoring result; and a dependency constraint unit, which is used to obtain the file dependency constraint based on the instrumentation result and the monitoring result.
[0021] In an embodiment of the present application, the fuzzy testing module specifically includes: a test case generation submodule, used to generate test cases according to the test case constraints; a test case execution submodule, used to execute the test cases, perform fuzzy testing, and obtain test results, which include security issues that arise during the test.
[0022] According to one aspect of an embodiment of the present application, a computer-readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the fuzzy testing method of the machine learning framework as described in the above embodiment is implemented.
[0023] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a fuzzy testing method for a machine learning framework as described in the above embodiments.
[0024] In the technical solutions provided in some embodiments of the present application, the source code of a machine learning framework is obtained, the code corresponding to each operator in the source code is analyzed, and the corresponding various test case constraints are extracted. The test cases include hardware environment constraints and operating mode constraints. Then, fuzzy testing is performed based on the various hardware environment constraints, various operating mode constraints and their combinations, so that the corresponding test results under various operating environments are obtained, thereby achieving full coverage of multiple operating environments.
[0025] 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
[0026] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0027] Figure 1 A schematic diagram of an exemplary system architecture to which the technical solution of the embodiments of the present application can be applied is shown.
[0028] Figure 2 A flow chart of a fuzzy testing method for a machine learning framework provided in an embodiment of the present application is shown.
[0029] Figure 3 Shown according to Figure 2 A specific implementation flowchart of step S200 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment.
[0030] Figure 4 Shown according to Figure 2 A specific implementation flowchart of step S200 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment.
[0031] Figure 5 The overall framework diagram of a machine learning framework fuzzy testing system provided by an embodiment of the present application is shown.
[0032] Figure 6 Shown according to Figure 5 A flowchart of a machine learning framework fuzz testing system shown in the corresponding embodiment.
[0033] Figure 7 A structural schematic diagram of a fuzzy testing device for a machine learning framework provided in an embodiment of the present application is shown.
[0034] Figure 8A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0035] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.
[0036] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the application.
[0037] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0038] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0039] Figure 1 A schematic diagram of an exemplary system architecture to which the technical solution of the embodiments of the present application can be applied is shown.
[0040] like Figure 1 As shown, the system architecture may include terminal devices (such as Figure 1 The embodiment of the present invention is a schematic diagram of a mobile phone 101, a tablet computer 102, a portable computer 103, a desktop computer, etc., a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the terminal device and the server 105. The network 104 may include various connection types, such as a wired communication link, a wireless communication link, etc.
[0041] It should be understood that Figure 1The number of terminal devices, networks and servers in the embodiment is only for illustration. According to the implementation requirements, there may be any number of terminal devices, networks and servers. For example, the server 105 may be a server cluster composed of multiple servers.
[0042] The user can use the terminal device to interact with the server 105 through the network 104 to receive or send messages, etc. The server 105 can be a server that provides various services. For example, the user uses the terminal device 103 (or the terminal device 101 or 102) to upload the operator code of the machine learning framework to the server 105, and the server 105 can analyze the operator code to obtain test case constraints, and there are multiple test case constraints, including hardware environment constraints and operation mode constraints; then according to each of the test case constraints, fuzzy testing is performed to obtain test results.
[0043] It should be noted that the fuzzy testing method of the machine learning framework provided in the embodiment of the present application is generally executed by the server 105, and accordingly, the fuzzy testing device of the machine learning framework is generally set in the server 105. However, in other embodiments of the present application, the terminal device may also have similar functions to the server, so as to execute the fuzzy testing solution provided in the embodiment of the present application.
[0044] The implementation details of the technical solution of the embodiment of the present application are described in detail below:
[0045] Figure 2 A flowchart of a fuzzy testing method for a machine learning framework according to an embodiment of the present application is shown. The fuzzy testing method for the machine learning framework can be executed by a server, which can be Figure 1 Refer to the server shown in . Figure 2 As shown, the fuzz testing method of the machine learning framework at least includes:
[0046] Step S100, obtaining the source code of the machine learning framework.
[0047] Step S200, parsing the source code to obtain test case constraints, wherein there are multiple test case constraints, including hardware environment constraints and operation mode constraints.
[0048] Step S300, performing fuzzy testing according to the constraints of each test case to obtain a test result.
[0049] In an embodiment of the present application, the source code of a machine learning framework is obtained, the code corresponding to each operator in the source code is analyzed, and the corresponding various test case constraints are extracted. The test cases include hardware environment constraints and operating mode constraints. Then, fuzzy testing is performed based on various hardware environment constraints, various operating mode constraints and their combinations, so as to obtain corresponding test results under various operating environments, thereby achieving full coverage of multiple operating environments.
[0050] In step S100, the user uploads the source code of the framework of the machine learning model to the server 105, and the server 105 obtains the source code of the machine learning framework, and the source code can be Python code.
[0051] In this embodiment, the security test of the machine learning framework is mainly to test the security of the operator interface provided by the framework. The application developers use the operator interface provided by the machine learning framework to directly build the network model without worrying about the neural network layering and internal implementation details, and can quickly design and develop intelligent applications.
[0052] In step S200, the source code is parsed to extract test case constraints such as hardware environment constraints and operation mode constraints corresponding to each operator in the machine learning framework.
[0053] Specifically, in some embodiments, the specific implementation of step S200 can be found in Figure 3 . Figure 3 is based on Figure 2 The detailed description of step S200 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, step S200 may include the following steps:
[0054] Step S210, parsing the source code to obtain the operator calling code.
[0055] Step S220: Obtain the hardware environment constraint and the operation mode constraint according to the operator test code.
[0056] In an embodiment of the present application, the source code is parsed, and the operator calling code is matched and filtered out in the source code. The operator calling code is the related code for calling the operator to perform an action, which is the code related to the operator. The operator test code is analyzed to obtain the hardware environment constraints corresponding to the operator and the operating mode constraints.
[0057] In step S210, the source code is parsed, and operator calling codes are matched and filtered out in the source code.
[0058] Specifically, in some embodiments, the specific implementation of step S210 can refer to the following embodiments. Figure 3The detailed description of step S210 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, step S210 may include the following steps:
[0059] Parse the source code to obtain an operator name list.
[0060] According to the operator name list, pattern matching is performed to obtain the operator calling code.
[0061] In an embodiment of the present application, firstly, a list of operator names is obtained by parsing official documents in the source code, and then the operator calling code contained in the source code is found out by pattern matching.
[0062] In step S220, the operator test code is analyzed to obtain the hardware environment constraints corresponding to the operator and the operation mode constraints.
[0063] Specifically, in some embodiments, the specific implementation of step S220 can refer to the following embodiments. Figure 3 The detailed description of step S220 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, step S220 may include the following steps:
[0064] Parsing the operator test code and constructing an abstract syntax tree;
[0065] The abstract syntax tree is matched according to a predetermined matching rule to extract the hardware environment constraint and the operation mode constraint.
[0066] In an embodiment of the present application, an abstract syntax tree is constructed for the operator code to extract the hardware environment constraints and the operation mode constraints. The operator test code is parsed into an abstract syntax tree using the AST library in the Python standard library for further hardware environment constraints and operation mode constraints extraction.
[0067] When performing constraint extraction, based on the constructed abstract syntax tree, predetermined matching rules are used to perform matching, and hardware environment constraints and operation mode constraints are extracted therefrom.
[0068] Among them, the hardware environment data specifically represents whether the executed operator requires a GPU environment or a TPU environment; the operation mode data specifically represents whether the executed operator requires a dynamic graph environment or a static graph environment. The above-mentioned predetermined matching rules can be directly configured in advance based on expert experience, or can be obtained based on the analysis of a large amount of operator data, which is not limited in this application.
[0069] Specifically, in some other embodiments, the specific implementation of step S200 can be found in Figure 4 . Figure 4 is based on Figure 3 The detailed description of step S200 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, the test case constraint also includes a file dependency constraint, and step S200 may also include the following steps:
[0070] Step S250: Analyze the operator calling code to obtain the operator test code.
[0071] Step S260: Monitor the disk file according to the operator calling code and the operator testing code to obtain the file dependency constraint.
[0072] In this embodiment, the corresponding test code is usually written during the development of the machine learning framework to test the correctness of the code logic, and in order to test the file-dependent operators, the file generation code logic is usually built in. Therefore, in the process of executing the test code, the disk file changes are monitored to parse the file dependency constraints.
[0073] In step S250, the operator test code is screened in the operator calling code.
[0074] Specifically, in some embodiments, the specific implementation of step S250 can refer to the following embodiments. Figure 4 The detailed description of step S250 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, step S250 may include the following steps:
[0075] Analyze the file name and function name of the operator calling code.
[0076] If the operator test code includes a predetermined file name or a predetermined function name, the operator call code is the operator test code.
[0077] In an embodiment of the present application, by analyzing file names and function names, such as file names or function names containing "test", operator test code files are screened.
[0078] In step S260, the disk file is monitored through the operator calling code and the operator testing code to obtain the file dependency constraint.
[0079] Specifically, in some embodiments, the specific implementation of step S260 can refer to the following embodiments. Figure 4 The detailed description of step S260 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, step S260 may include the following steps:
[0080] The operator call code is instrumented using a modified function to obtain an instrumentation result.
[0081] Execute the operator test code, monitor the disk file, and obtain the monitoring result.
[0082] The file dependency constraint is obtained according to the instrumentation result and the monitoring result.
[0083] In an embodiment of the present application, based on the monitoring of the instrumentation during the execution of the operator test code, the file dependency constraints are parsed and extracted. Specifically, the corresponding association relationship between the disk file and the operator is determined by combining the operator code instrumentation process with the disk file monitoring process.
[0084] It should be noted that the operator call code processing includes not only the operator test code, but also the operator execution code corresponding to the operator test code. When the operator test code is executed, the operator actually executes the operator execution code. The operator test code is the trigger code. Therefore, the stub of this embodiment is mainly to stub the operator execution code to ensure that the internal situation of the operator during execution can be obtained, such as the operator name, operator parameters and other operator-related parameters.
[0085] In other embodiments, only the operator execution code may be instrumented.
[0086] The machine learning framework provides developers with a Python interface for quickly building network models without having to worry about the neural network layering and internal implementation details. At the same time, in order to speed up the calculation process of the operator, the machine learning framework backend uses C / C++ to implement specific calculation logic. Usually, the front end and the back end communicate directly through a predefined interface. The embodiment of the present application automatically parses the predefined interface of the Python front end, and implements the plugging process for the operator code by inserting a modified function with a monitoring function. In the specific implementation of the modified function, the parsing of data such as the operator name and operator parameters (i.e., the plugging result) is included. At the same time, this embodiment monitors the file changes of the disk, such as during the execution of the operator test code file, the operation of writing files on the monitoring disk is monitored, and the operator name and file path, file data and other information (i.e., monitoring results) are collected for further file dependency analysis. According to the plugging results and monitoring results, the operator name, operator parameters, file path, file data and other information can be associated with each other to obtain the corresponding association relationship between the disk file and the operator, and then the file dependency constraint is obtained.
[0087] There are some file-dependent operators in the machine learning framework. This type of operator needs to load a specific type of file during execution. When the file does not exist or the file type does not match, the operator will fail to call. For example, the operator LoadAndRemapMatrix in the tensorflow framework has a parameter ckpt_path of string type, which represents the path of the ckpt type file. When the test data is randomly generated only according to the string type during the test, the operator will not be able to obtain valid dependent files. The embodiment of the present application is based on the combination of operator plugging and disk file monitoring, and comprehensively analyzes the data when writing files and the data when executing operators to form a corresponding relationship and extract file dependency constraints. When the operator LoadAndRemapMatrix is executed, it is monitored that the disk writes the ckpt file. The present application automatically associates the parameter ckpt_path with the file path by analyzing the operator parameters, and re-determines its type as "Path" for the later fuzzy testing process.
[0088] In step S300, fuzzy testing is performed based on various hardware environment constraints, various operating mode constraints and combinations thereof to obtain corresponding test results under various operating environments.
[0089] Specifically, in some embodiments, the specific implementation of step S300 can refer to the following embodiments. Figure 2 The detailed description of step S300 in the fuzzy testing method of the machine learning framework shown in the corresponding embodiment, in the fuzzy testing method of the machine learning framework, step S300 may also include the following steps:
[0090] Generate test cases according to the test case constraints.
[0091] Execute the test case, perform fuzz testing, and obtain test results, which include security issues that arise during the test.
[0092] In an embodiment of the present application, test cases are generated according to the various test case constraints such as the above-mentioned various hardware environment constraints, various operating mode constraints, various file dependency constraints, and combinations of various test case constraints, and fuzz testing is performed. Vulnerabilities are mined through fuzz testing to obtain test results. The test results will include security issues (i.e., security vulnerabilities) that arise during the testing process.
[0093] The machine learning framework provides a Python front end, but it involves complex calculations and other operations, and the framework is mainly implemented using C / C++ code. This embodiment generates test data for fuzzy testing based on the three types of test case constraints extracted in step S200. During the test process, coverage detection, selection of functions to be tested, variation of parameters of functions to be tested, and monitoring of abnormal function crashes can also be performed.
[0094] In an embodiment of the present application, a fuzzy testing method is used to automatically construct random, unexpected, deformed data as test cases, input them into the target program, monitor the anomalies that may occur during the execution of the target program, and implement automated or semi-automated program security testing technology.
[0095] The current mainstream fuzz testing tools include AFL, Peach, Honggfuzz, libfuzzer, etc., but the above-mentioned testing tools still have shortcomings in machine learning framework detection.
[0096] Rule-based testing tools such as Peach perform fuzzy testing by manually writing test rules, which requires a lot of labor costs. However, the embodiments of the present application automatically generate test cases and perform tests through the above three types of test case constraints, which greatly saves labor costs.
[0097] Fuzz testing tools such as AFL have strong random mutations, and it is difficult to generate test data that meets the format for the function interface parameters provided by the machine learning framework. This embodiment generates valid test data based on the extracted environmental constraints (including hardware environment constraints and operation mode constraints) to ensure that the test data corresponds to the operator interface and meets the format of the operator interface. For file-dependent operators, test cases are generated by combining file dependency constraints with other test case constraints to ensure that the files they depend on can be loaded during the execution of the fuzz test.
[0098] This embodiment generates effective test data based on the extracted environmental constraints, covering the code logic of the corresponding function. For example, in the test of the tensorflow framework, adding the @tf.function identifier to the operator can be the code logic of the operator under the static graph, adding withtf.device(' / device:GPU:2') to the operator can execute the GPU implementation logic of the operator, and adding a specific type of file to the file-dependent operator can successfully execute this type of operator. Fuzz testing based on environmental constraints to generate test data can effectively cover a wider range of code logic of the machine learning framework, discover more hidden vulnerabilities, and improve the detection efficiency and success rate of the overall framework test. In addition, in this embodiment, while performing fuzz testing, coverage detection, selection of the function to be tested, variation of the parameters of the function to be tested, and monitoring of function abnormal crashes can also be performed simultaneously. The security risk types that can also be evaluated in this embodiment include memory access out of bounds, null pointer reference, integer overflow, floating point exception, etc., and the hazard assessment types include information leakage, denial of service, arbitrary code execution, etc.
[0099] like Figure 5 and Figure 6As shown, the method of the present application can be applied to a machine learning framework fuzz testing system. The system is mainly divided into four parts: an environment data preparation module, an environment data collection module, an environment constraint analysis module, and a fuzz testing engine.
[0100] The environment data preparation module includes an operator call code collection unit, an operator test code screening unit, and an operator test code execution unit.
[0101] The environment data preparation module is oriented to the Python code level and is mainly responsible for collecting the operator calling codes provided by the machine learning framework and screening the test codes corresponding to the operators.
[0102] Specifically, the operator call code collection unit is used to collect the operator call code, that is, to obtain the operator call code in the source code by parsing the source code for pattern matching. The operator test code screening unit is used to further search for the corresponding operator test code in the operator call code by file name and function name. The operator test code execution unit is used to execute the operator test code.
[0103] The environment data collection module includes: operator code instrumentation unit, abstract syntax tree construction unit and disk file monitoring unit.
[0104] The environmental data collection module is mainly responsible for collecting data related to the operating environment.
[0105] Specifically, the operator code plugging unit is used to plug the operator call code collected by the operator call code collecting unit. The abstract syntax tree construction unit is used to construct an abstract syntax tree according to the operator test code screened by the operator test code screening unit. The disk file monitoring unit is used to monitor the disk file of the operator test code executed by the operator test code execution unit.
[0106] The environmental constraint analysis module includes a dependency file analysis module, a hardware environment analysis module and an operation mode analysis module.
[0107] The environmental constraint analysis module is mainly responsible for parsing environmental data and extracting environmental constraints.
[0108] Specifically, the dependency file analysis module is used to extract dependency file constraints based on the results obtained by the operator code instrumentation unit and the results obtained by the disk file monitoring unit. The hardware environment parsing module and the operation mode parsing module are used to parse the abstract syntax tree constructed by the abstract syntax tree construction unit, and extract the hardware environment constraints and the operation mode constraints respectively.
[0109] The fuzz testing engine is mainly responsible for vulnerability mining. The machine learning framework provides a Python front end, but it involves complex calculations and other operations, so the framework is mainly implemented using C / C++ code. This module is responsible for generating test data for fuzz testing based on the three types of constraints extracted by the environmental constraint analysis module. During the test, it is also responsible for coverage detection, selection of functions to be tested, variation of parameters of functions to be tested, and monitoring of abnormal function crashes.
[0110] The following describes an embodiment of the device of the present application, which can be used to execute the fuzzy testing method of the machine learning framework in the above embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the fuzzy testing method of the machine learning framework in the above embodiment of the present application.
[0111] Figure 7 A block diagram of a fuzzy testing device for a machine learning framework according to an embodiment of the present application is shown.
[0112] Reference Figure 7 As shown, a fuzzy testing device 700 of a machine learning framework according to an embodiment of the present application includes: a code acquisition module 710, a code parsing module 720, and a fuzzy testing module 730.
[0113] Among them, the code acquisition module 510 is used to obtain the source code of the machine learning framework; the code parsing module 520 is used to parse the source code to obtain test case constraints, and there are multiple test case constraints, including hardware environment constraints and operation mode constraints; the fuzzy testing module 530 is used to perform fuzzy testing according to each test case constraint to obtain test results.
[0114] In an embodiment of the present application, the code parsing module specifically includes: a code parsing submodule, used to parse the source code to obtain the operator calling code; an environment constraint submodule, used to obtain the hardware environment constraint and the operation mode constraint according to the operator test code.
[0115] In an embodiment of the present application, the code parsing submodule specifically includes: a code parsing unit, used to parse the source code to obtain an operator name list; and a pattern matching unit, used to perform pattern matching according to the operator name list to obtain the operator calling code.
[0116] In an embodiment of the present application, the environmental constraint submodule specifically includes: an abstract syntax tree unit, used to parse the operator test code and construct an abstract syntax tree; a rule matching unit, used to match the abstract syntax tree according to a predetermined matching rule, and extract the hardware environment constraints and the operating mode constraints.
[0117] In an embodiment of the present application, the test case constraints also include file dependency constraints, and the code parsing module also includes: a code screening submodule, used to analyze the operator call code and obtain the operator test code; a dependency constraint submodule, used to monitor disk files according to the operator call code and the operator test code to obtain the file dependency constraints.
[0118] In an embodiment of the present application, the code screening submodule specifically includes: a code analysis unit, used to analyze the file name and function name of the operator call code; a code determination unit, used to determine that if the operator test code contains a predetermined file name or a predetermined function name, the operator call code is an operator test code.
[0119] In an embodiment of the present application, the dependency constraint submodule specifically includes: an operator instrumentation unit, which is used to instrument the operator call code using a modified function to obtain an instrumentation result; a code execution unit, which is used to execute the operator test code and monitor the disk file to obtain a monitoring result; and a dependency constraint unit, which is used to obtain the file dependency constraint based on the instrumentation result and the monitoring result.
[0120] In an embodiment of the present application, the fuzzy testing module specifically includes: a test case generation submodule, used to generate test cases according to the test case constraints; a test case execution submodule, used to execute the test cases, perform fuzzy testing, and obtain test results, which include security issues that arise during the test.
[0121] In an embodiment of the present application, the source code of a machine learning framework is obtained, the code corresponding to each operator in the source code is analyzed, and the corresponding various test case constraints are extracted. The test cases include hardware environment constraints and operating mode constraints. Then, fuzzy testing is performed based on various hardware environment constraints, various operating mode constraints and their combinations, so as to obtain corresponding test results under various operating environments, thereby achieving full coverage of multiple operating environments.
[0122] Figure 8 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.
[0123] It should be noted that Figure 8 The computer system of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0124] like Figure 8As shown, the computer system includes a central processing unit (CPU) 1801, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1802 or the program loaded from the storage part 1808 to the random access memory (RAM) 1803, such as executing the method described in the above embodiment. In RAM 1803, various programs and data required for system operation are also stored. CPU 1801, ROM 1802 and RAM 1803 are connected to each other through bus 1804. Input / output (I / O) interface 1805 is also connected to bus 1804.
[0125] The following components are connected to the I / O interface 1805: an input section 1806 including a keyboard, a mouse, etc.; an output section 1807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1808 including a hard disk, etc.; and a communication section 1809 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1809 performs communication processing via a network such as the Internet. A drive 1810 is also connected to the I / O interface 1805 as needed. A removable medium 1811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1810 as needed so that a computer program read therefrom is installed into the storage section 1808 as needed.
[0126] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 1809, and / or installed from a removable medium 1811. When the computer program is executed by a central processing unit (CPU) 1801, various functions defined in the system of the present application are executed.
[0127] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0128] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0129] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0130] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.
[0131] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0132] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the implementation methods of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the implementation methods of the present application.
[0133] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application.
[0134] 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 fuzz testing method for a machine learning framework, characterized in that: The fuzz testing method of the machine learning framework includes: Get the source code of the machine learning framework; Parsing the source code to obtain test case constraints, wherein the test case constraints include multiple constraints, including hardware environment constraints, operation mode constraints, and file dependency constraints; Perform fuzzy testing according to the test case constraints to obtain test results; Wherein, parsing the source code to obtain test case constraints includes: Parsing the source code to obtain an operator calling code, where the operator calling code is a code related to calling an operator to perform an action, and the operator calling code includes an operator test code; Analyze the operator call code and obtain the operator test code, where the operator test code is the trigger code; Based on the instrumentation monitoring during the execution of the operator test code, the file dependency constraints are parsed and extracted; The hardware environment constraint and the operation mode constraint are obtained according to the operator test code.
2. The fuzz testing method for a machine learning framework according to claim 1, characterized in that: The parsing of the source code to obtain the operator calling code specifically includes: Parse the source code to obtain a list of operator names; According to the operator name list, pattern matching is performed to obtain the operator calling code.
3. The fuzz testing method for a machine learning framework as claimed in claim 1, characterized in that: The obtaining the hardware environment constraint and the operation mode constraint according to the operator test code specifically includes: Parsing the operator test code and constructing an abstract syntax tree; The abstract syntax tree is matched according to a predetermined matching rule to extract the hardware environment constraint and the operation mode constraint.
4. The fuzz testing method for a machine learning framework as claimed in claim 1, characterized in that: The test case constraint also includes a file dependency constraint, and the parsing of the source code to obtain the test case constraint also includes: According to the operator calling code and the operator testing code, the disk file is monitored to obtain the file dependency constraint.
5. The fuzz testing method of the machine learning framework according to claim 4, characterized in that: The analyzing the operator calling code to obtain the operator test code specifically includes: Analyze the file name and function name of the operator calling code; If the operator calling code includes a predetermined file name or a predetermined function name, the operator calling code is an operator test code.
6. The fuzz testing method of the machine learning framework according to claim 4, characterized in that: The step of monitoring the disk file according to the operator calling code and the operator testing code to obtain the file dependency constraint specifically includes: Use the modified function to instrument the operator call code to obtain the instrumentation result; Execute the operator test code, monitor the disk file, and obtain the monitoring result; The file dependency constraint is obtained according to the instrumentation result and the monitoring result.
7. The fuzz testing method of the machine learning framework according to claim 1, characterized in that: The fuzzy test is performed according to the constraints of each test case to obtain the test result, which specifically includes: Generate test cases according to the test case constraints; Execute the test case, perform fuzz testing, and obtain test results, which include security issues that arise during the test.
8. A fuzzy testing device for a machine learning framework, characterized in that: The fuzz testing device of the machine learning framework includes: Code acquisition module, used to obtain the source code of the machine learning framework; A code parsing module, used to parse the source code to obtain test case constraints, wherein the test case constraints include multiple constraints, including hardware environment constraints and operation mode constraints; A fuzzy testing module, used to perform fuzzy testing according to the constraints of each test case to obtain a test result; The code parsing module specifically includes: A code parsing submodule, used to parse the source code to obtain an operator calling code, wherein the operator calling code is a code related to calling an operator to perform an action, and the operator calling code includes an operator test code; The code screening submodule is used to analyze the operator call code and obtain the operator test code, which is the trigger code; based on the instrumentation monitoring during the execution of the operator test code, the file dependency constraints are parsed and extracted; The environment constraint submodule is used to obtain the hardware environment constraint and the operation mode constraint according to the operator test code.
9. The fuzzy testing device of the machine learning framework according to claim 8, characterized in that: The code parsing submodule specifically includes: A code parsing unit, used for parsing the source code to obtain an operator name list; The pattern matching unit is used to perform pattern matching according to the operator name list to obtain the operator calling code.
10. The fuzzy testing device of the machine learning framework according to claim 8, characterized in that: The environmental constraint submodule specifically includes: An abstract syntax tree unit, used to parse the operator test code and construct an abstract syntax tree; A rule matching unit is used to match the abstract syntax tree according to a predetermined matching rule, and extract the hardware environment constraint and the operation mode constraint.
11. The fuzzy testing device of the machine learning framework according to claim 8, characterized in that: The test case constraint also includes a file dependency constraint, and the code parsing module also includes: The dependency constraint submodule is used to monitor the disk file according to the operator calling code and the operator testing code to obtain the file dependency constraint.
12. The fuzzy testing device of the machine learning framework according to claim 11, characterized in that: The code screening submodule specifically includes: A code analysis unit, used for analyzing the file name and function name of the operator calling code; A code determination unit is used to determine that if the operator test code contains a predetermined file name or a predetermined function name, the operator call code is the operator test code.
13. The fuzzy testing device of the machine learning framework according to claim 12, characterized in that: The dependency constraint submodule specifically includes: An operator instrumentation unit, used to instrument the operator call code using a modified function to obtain an instrumentation result; A code execution unit, used to execute the operator test code, monitor the disk file, and obtain the monitoring result; The dependency constraint unit is used to obtain the file dependency constraint according to the instrumentation result and the monitoring result.
14. The fuzzy testing device of the machine learning framework according to claim 8, characterized in that: The fuzz testing module specifically includes: A test case generation submodule, used to generate test cases according to the test case constraints; The test case execution submodule is used to execute the test case, perform fuzzy testing, and obtain test results, which include security issues that arise during the test.
15. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the fuzzy testing method of the machine learning framework according to any one of claims 1 to 7 is implemented.
16. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the fuzz testing method of the machine learning framework as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Security test method and device, equipment and storage medium
CN116127464A
Method and device for automatically generating operator calling code, medium and equipment
CN116932092A