Container pseudo file system isolation and availability analysis method, system and equipment based on static analysis and medium

Through the static analysis method combined with the Pass technology of the LLVM compiler, the isolation and availability of the container pseudo-file system are identified, and the file overlay and identification accuracy problems in dynamic analysis are solved, achieving higher isolation analysis accuracy and security risk assessment.

CN119026125APending Publication Date: 2024-11-26XIDIAN UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411209921.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

Existing container pseudo-file system isolation analysis methods have problems with file coverage and identification accuracy in dynamic analysis, and cannot effectively identify the isolation status of some pseudo-files, especially when the system-specific state or hardware devices exist, and rely on management. Staff-configured access control policies make it difficult to block pseudo-file targets.

Method used

Using a static analysis method, the kernel code is systematically analyzed using Pass technology in the LLVM compiler, and the isolation of pseudo-files is identified through intermediate code processing technology, combining pseudo-file registration related content, callback function analysis and data source isolation judgment. Provides more accurate isolation and availability analysis.

Benefits of technology

It improves the coverage degree and accuracy of isolation judgment of pseudo-file analysis targets, can more effectively identify the security risks of unisolated pseudo-files, and provides targeted protection, avoiding the incompleteness of targets in dynamic analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119026125A_ABST
    Figure CN119026125A_ABST
Patent Text Reader

Abstract

A static analysis-based container pseudo file system isolation and availability analysis method, system, device and medium, the method comprising: compiling a Linux kernel code into an intermediate code IR file, scanning the intermediate code IR file, positioning and collecting pseudo file registration related content in the kernel code, and statically analyzing the pseudo file registration related content to obtain a static analysis result; the method comprises the following steps: identifying whether each pseudo file uses a Linux namespace isolation mechanism or not, judging the condition of a data source influenced by the isolation mechanism in the pseudo file using the isolation mechanism to obtain a pseudo file isolation analysis result, and finally judging whether a non-isolated pseudo file can initiate an attack in a container or not from the pseudo file isolation analysis result. Obtaining an available pseudo file capable of causing container attack in the isolation analysis result; the system, the equipment and the medium are used for implementing the method. According to the method, the incomplete pseudo file analysis target in dynamic analysis is avoided, and the coverage degree of the pseudo file analysis target and the accuracy of isolation analysis are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of container security technology, and specifically relates to a container pseudo file system isolation and availability analysis method, system, device and medium based on static analysis. Background Art

[0002] Pseudo file systems are a major way for applications to interact with the operating system. When opening a file in a pseudo file system, information is not read from a data storage device such as a hard disk, but a series of functions in the corresponding kernel are executed. When a container environment is created, the container runtime will mount pseudo file systems such as procfs and sysfs for the container environment. By using Linux namespace technology in the kernel execution process of pseudo file reading, containerized isolation of related subsystem contents can be achieved. This isolation mechanism enables pseudo files to only display system information from the perspective of the container, thereby effectively limiting the container process from obtaining host-level system information through pseudo files. However, since Linux namespace technology only implements containerized isolation of six types of subsystem resources, namely PID (process number), MNT (mount point), (UTC) host name, (NET) network stack, IPC (inter-process communication), and USER (user list), the procfs and sysfs pseudo file systems also expose a large amount of resource information that has no corresponding namespace type in the system kernel. Therefore, when a process in a container reads such non-isolated pseudo files, host-level system information will be leaked. Among these non-isolated system resources, there are some subsystems that are considered low priority during containerization. In addition, when replacing the code base for implementing containerized isolation, a large range of code modifications are required, which brings a high cost burden. In order to mitigate such leakage, current container runtime software and container cloud providers usually use access control policies to block the reading of some pseudo files that are not isolated using Linux namespaces. However, this manual processing method that relies on administrator configuration requires a full understanding of the isolation of the container pseudo file system and the availability of unisolated pseudo files, so as to select appropriate pseudo file blocking targets. If too many pseudo file targets are blocked, the normal functional operation of the program in the container may be affected; if too few pseudo file targets are blocked, the security risk problem brought by protecting unisolated pseudo files cannot be solved.

[0003] Therefore, container users need to systematically analyze the pseudo file system of the container, obtain the isolation of the pseudo file system in the kernel of the operating system used, understand whether the target pseudo file has been isolated using the Linux namespace, and provide system information from the container perspective. At the same time, for pseudo files that are not isolated, it is necessary to understand the kernel variables they expose and the exploitability of the pseudo file in common container attack scenarios, so as to determine the pseudo file targets that need to be protected or blocked first.

[0004] Gao et al. implemented a container pseudo-file isolation analysis tool based on dynamic analysis (GAO X, GU Z, KAYAALP M, et al. Containerleaks: Emerging security threats of information leakage in container clouds [C] / / 2017 47th Annual IEEE / IFIP International Conference on Dependable Systems and Networks (DSN). 2017: 237-248.) to automatically discover the pseudo-file list that shares host information to all containers. The tool recursively traverses and opens all pseudo-files under procfs and sysfs in two execution contexts, the container environment and the host environment. Files are aligned and reordered according to the file path, and then the content of the same file is analyzed in pairs between the two contexts. Specifically, if the system resources accessed from a specific pseudo-file are not isolated by Linux namespaces in the Linux kernel, the host and container will access the same kernel data. Otherwise, if the target pseudo-file is isolated by the corresponding Linux namespace, then the container environment will obtain its own private kernel data.

[0005] However, there are some problems with the existing identification methods in terms of file coverage and recognition accuracy. First, during the dynamic analysis process, since there are some pseudo files in the container pseudo file system that only appear when the system is in a specific state or when a certain type of specific hardware device exists in the system, the above-mentioned container pseudo file isolation analysis tool does not study the file object loss caused by such situations, so the identification method has limitations in terms of file coverage. Secondly, the isolation status of pseudo files in some containers may not be intuitively identified from the pseudo file content. For example, there are some pseudo files whose system information output is consistent in different namespaces. Although such pseudo files are actually isolated by Linux namespaces, they cannot be identified from the perspective of file content. If the address information of the output content is considered, in the pseudo file where the system information is saved to the function local variable for output, the stack address where the local variable is located still cannot reflect the pseudo file isolation. Therefore, there will be certain errors in identifying the isolation of such pseudo files from the perspective of output content. Summary of the invention

[0006] In order to overcome the shortcomings of the above-mentioned prior art, the purpose of the present invention is to provide a container pseudo file system isolation and availability analysis method, system, device and medium based on static analysis, which systematically analyzes the isolation of kernel code by using the Pass intermediate code processing technology in the open source LLVM compiler, and obtains high-value targets in the container pseudo file system that can be used to launch container attacks, with the characteristics of method availability, file list integrity, and isolation judgment accuracy.

[0007] In order to achieve the above object, the technical solution adopted by the present invention is:

[0008] A method for analyzing the isolation and exploitability of a container pseudo file system based on static analysis includes the following steps:

[0009] Scanning phase:

[0010] Step 1, compile the Linux kernel code into an intermediate code IR file, the compiled intermediate code IR file includes an IR assembly file and an IR bit code file;

[0011] Step 2, by scanning the intermediate code IR file obtained in step 1, locate and collect pseudo file registration related content in the kernel code, the related content includes: pseudo file registration point context information, pseudo file path information, pseudo file kernel callback function information and pseudo file data source information;

[0012] Analysis phase:

[0013] Step 3: statically analyze the pseudo-file registration related content collected in step 2 to identify whether each pseudo-file uses the Linux namespace isolation mechanism, and determine the data source affected by the isolation mechanism in the pseudo-files that use the isolation mechanism, and finally obtain the pseudo-file isolation analysis results;

[0014] Step 4: From the pseudo-file isolation analysis results obtained in step 3, determine whether the discovered non-isolated pseudo-files can be used to launch attacks in the container, and obtain the exploitable pseudo-files that can cause container attacks in the isolation analysis results.

[0015] The step 1 specifically includes:

[0016] Use the Clang compiler front end in the LLVM toolset to compile the Linux kernel code into an intermediate code IR file, and select the .config file generated by the default configuration in the kernel code for the kernel compilation configuration used.

[0017] The step 2 specifically includes:

[0018] Step 2.1, by traversing the function instance list in the IR assembly file obtained in step 1, and then matching the corresponding function instance according to the pseudo-file registration function name, and adding the function instance to the registered function instance set, after completing the collection of registered function instances, traverse the called statements of each registered function instance in the set, and obtain the pseudo-file registration point context information from its called statement, including all actual parameters passed to the pseudo-file registration function at the called statement, return value variables, and the function instance where the calling statement is located, and finally save the content contained in the pseudo-file registration point context information in the pseudo-file registration call instance set;

[0019] Step 2.2, scan all directory registration function instances in the IR assembly file obtained in step 1, and obtain the function instance calling statement. For the calling instance of the directory registration function, obtain the registered directory name string in the calling instance parameter and the parent directory variable where the registered target directory is located, save the directory path information and the parent directory variable in the pseudo-file directory parent-child table, build a directory-parent directory relationship table, and complete the collection of pseudo-file path information;

[0020] Step 2.3, taking out the file operation function instance from the pseudo file registration call instance set obtained in step 2.1, including the two-stage callback functions of open and read;

[0021] Step 2.4, traverse the function call statements in the read phase callback function obtained in step 2.3, obtain the output parameter content passed in the function call instruction, filter the index class parameters and constant value content in the output parameter content, and trace the output parameters at the same time to obtain the number of data sources and location information of the pseudo file.

[0022] The step 3 is analyzed from the following three perspectives:

[0023] Perspective 1, through the isolation analysis of pseudo-file callback functions for the two-stage callback functions of open and read, first check whether the Linux namespace type variable in the open callback function exists and is used to execute the conditional judgment instruction. If it is used to execute the conditional judgment instruction, compare the conditional jump branches involved in the instruction, check whether the branch has an error exit operation, so as to determine whether the Linux namespace type variable is used to terminate the file opening operation, then the pseudo-file is isolated, and all data sources are isolated; in the read callback function, if the Linux namespace type variable is used, first check whether the Linux namespace type variable is used to execute the conditional judgment instruction. If it is used for conditional judgment, analyze the conditional jump branch, check whether there is a difference in calling the data output function between the branches, so as to determine whether the Linux namespace variable is used to control whether a kernel variable is output, so as to achieve the isolation of the kernel data passed in by the output function; in addition, it can also be checked whether the namespace variable is used for data fetching operation, then the read callback function takes out the data in the namespace where the process is located for output, so as to achieve the isolation of the fetched kernel data;

[0024] Perspective 2: Perform kernel data source isolation analysis on the pseudo file, extract the kernel data source parameters passed in from the actual parameters, first obtain the user instructions of all target variables, check whether there are any storage operations on the kernel data source parameters, if so, use the source variable as the next backtracking node, otherwise check the declaration position of the target variable, and set the backtracking node position in different situations; in the process of data flow backtracking, first check the next node variable obtained to see if its type is a Linux namespace type, if so, determine that the pseudo file kernel data source is taken out from the reading process namespace variable, and the pseudo file kernel data source has been isolated, then analyze from the perspective of instruction control flow, check whether the conditional branch variables passed through during the backtracking process contain Linux namespace types, if so, determine that the value of the pseudo file kernel data source is affected by the Linux namespace, and the pseudo file kernel data source has been isolated;

[0025] Angle 3: Analysis from the perspective of the built-in isolation mechanism of pseudo files, including: analysis of using pseudo file registration locations to achieve isolation, and analysis of using pseudo file visibility mechanisms to achieve isolation;

[0026] The analysis of using the pseudo-file registration position to achieve isolation is performed by backtracking the directory parameter variable through the directory parameter variable in the actual parameter, and checking whether the Linux namespace type variable appears in the backtracking path. If it appears, it means that the pseudo-file has namespace isolation and all data sources are isolated. If the Linux namespace type variable does not appear in the backtracking process, recursively check whether the parent directory uses the Linux namespace mechanism through the parent directory corresponding to the directory variable where the pseudo-file is located;

[0027] The analysis of using the pseudo-file visibility mechanism to achieve isolation is to determine whether the visibility judgment function pointer in the kernel object variable structure is a null pointer through the kernel object variable in the actual parameter. When the visibility judgment function pointer is not null, the instructions in the visibility judgment function instance are traversed. When a Linux namespace type variable is encountered during the traversal check and the Linux namespace type variable participates in the parameters of the branch jump, it is determined that the pseudo-file has namespace isolation and all data sources therein are isolated.

[0028] Step 4 is analyzed through the following three scenarios:

[0029] Scenario 1: Kernel resource DoS exploitation. Obtain the unisolated pseudo file through step 3, traverse the kernel variables contained in the target unisolated pseudo file, recursively check the usage of kernel variables in the kernel through the def-use chain, and determine whether there are self-increment and comparison operations on kernel variables in the user set of kernel variables, and the results of the comparison operations are used for conditional jumps. If there are self-increment and comparison operations on kernel variables and the operation results are used for conditional jumps, the kernel variables contained in the unisolated pseudo file are kernel resource counter type variables. The attacker can trace back the call stack from the instruction where the kernel resource variable usage feature appears, obtain the relevant system calls that can trigger the resource application operation, and provide kernel resource DoS attack entry information for the container user space process;

[0030] Scenario 2: Determine whether containers are co-resident. Obtain unisolated pseudo files through step 3, traverse the kernel global variable information exposed by the unisolated pseudo files, and store them in the unisolated global variable table in the form of pseudo files-global variable names. In multiple hosts with the same system version, kernel version, and startup parameters, use the SystemTap kernel observation tool to observe the kernel global variables contained in the unisolated files, extract kernel variables that have not changed in a short period of time on the same host and store them in the short-term unchanged kernel variable set, compare the short-term unchanged kernel variable sets in each host, extract the variables in the short-term unchanged kernel variable set whose contents are inconsistent on different hosts as fingerprint-class shared kernel variables that can mark the host, and map them to the corresponding unisolated pseudo files through the unisolated global variable table to obtain a list of unisolated pseudo files that can be used to determine whether containers are co-resident.

[0031] Scenario 3, container escape exploitation, starts from the feature function call_usermodehelper_setup() in the usermodehelper mechanism. The first parameter of the feature function is the registered custom handler path. The path parameter variable is backtracked through the def-use chain. If the backtracking node reaches the kernel global variable, the backtracking is stopped, and the kernel global variable reached is recorded as a global variable that can be used for container escape exploitation. After completing the collection of global variables that can be used for escape exploitation, the kernel variables contained in the non-isolated pseudo-file obtained in step 3 are traversed and queried in the global variable table that can be used for escape exploitation. If the query is successful, it means that the kernel variables exposed by the non-isolated pseudo-file have an escape risk. Then the writability of the non-isolated pseudo-file is checked to see whether the file write operation in the pseudo-file callback function contains global variable parameters that can be used for escape exploitation. If it contains global variable parameters that can be used for escape exploitation, the non-isolated pseudo-file can be used to initiate container escape.

[0032] A container pseudo file system isolation and availability analysis system based on static analysis, including the following modules:

[0033] The kernel code compilation module compiles the Linux kernel code into an intermediate code IR file. The compiled intermediate code IR file includes an IR assembly file and an IR bit code file.

[0034] The pseudo file information collection module locates and collects pseudo file registration related content in the kernel code by scanning the intermediate code IR file, and the related content includes: pseudo file registration point context information, pseudo file path information, pseudo file kernel callback function information and pseudo file data source information;

[0035] The pseudo-file isolation analysis module performs static analysis on the pseudo-file registration-related content to identify whether each pseudo-file uses the Linux namespace isolation mechanism, and determines the data source affected by the isolation mechanism in the pseudo-files that use the isolation mechanism, and finally obtains the pseudo-file isolation analysis results;

[0036] The pseudo file exploitability analysis module determines whether the discovered non-isolated pseudo files can be used to launch attacks in the container from the pseudo file isolation analysis results, and obtains the exploitable pseudo files that can cause container attacks from the isolation analysis results.

[0037] A container pseudo file system isolation and availability analysis device based on static analysis, comprising:

[0038] Memory: used for storing a computer program for implementing the container pseudo file system isolation and availability analysis method based on static analysis;

[0039] Processor: used to implement the container pseudo file system isolation and availability analysis method based on static analysis when executing the computer program.

[0040] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of a container pseudo file system isolation and availability analysis method based on static analysis.

[0041] Compared with the prior art, the beneficial effects of the present invention are:

[0042] 1. The present invention analyzes the isolation of the container pseudo file system from the perspective of source code static analysis, thereby avoiding incomplete pseudo file analysis targets caused by kernel parameters or system status in dynamic analysis and improving the coverage of pseudo file analysis targets.

[0043] 2. The present invention performs static analysis on all processes involved in pseudo-file reading, and analyzes whether the pseudo-file is isolated by the Linux namespace from three angles: pseudo-file reading callback function, file data source isolation, and built-in isolation mechanism usage, so as to obtain higher isolation analysis accuracy.

[0044] 3. The present invention not only analyzes the Linux namespace isolation of pseudo-files, but also determines the usability of non-isolated pseudo-files in three common container attack scenarios, so as to understand the security risks brought by non-isolated pseudo-files.

[0045] In summary, the present invention avoids the incompleteness of pseudo-file analysis targets due to kernel parameters or system status in dynamic analysis, improves the coverage of pseudo-file analysis targets, and simultaneously obtains higher isolation analysis accuracy and grasps the security risks brought by unisolated pseudo-files. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] Figure 1 It is the overall structural diagram of the present invention.

[0047] Figure 2 The present invention is a flow chart analyzing the isolation of pseudo files from the perspective of pseudo file callback functions.

[0048] Figure 3 The present invention is a flow chart analyzing the isolation of pseudo-files from the perspective of the isolation of pseudo-file data sources.

[0049] Figure 4 This is a flow chart of analyzing the isolation of pseudo files from the perspective of the built-in isolation mechanism of pseudo files and the isolation judgment part of the pseudo file registration location of the present invention.

[0050] Figure 5 This is a flow chart of analyzing the isolation of pseudo files by the isolation judgment part of the pseudo file visibility mechanism from the perspective of the built-in isolation mechanism of pseudo files in the present invention. DETAILED DESCRIPTION

[0051] The present invention will be described in detail below in conjunction with the accompanying drawings.

[0052] A method for analyzing the isolation and exploitability of a container pseudo file system based on static analysis includes the following steps:

[0053] Scanning phase:

[0054] Step 1, compile the Linux kernel code into an intermediate code IR file, the compiled intermediate code IR file includes an IR assembly file and an IR bit code file;

[0055] Step 2, by scanning the intermediate code IR file obtained in step 1, locate and collect pseudo file registration related content in the kernel code, the related content includes: pseudo file registration point context information, pseudo file path information, pseudo file kernel callback function information and pseudo file data source information;

[0056] Analysis phase:

[0057] Step 3: statically analyze the pseudo-file registration related content collected in step 2 to identify whether each pseudo-file uses the Linux namespace isolation mechanism, and determine the data source affected by the isolation mechanism in the pseudo-files that use the isolation mechanism, and finally obtain the pseudo-file isolation analysis results;

[0058] Step 4: From the pseudo-file isolation analysis results obtained in step 3, determine whether the discovered non-isolated pseudo-files can be used to launch attacks in the container, and obtain the exploitable pseudo-files that can cause container attacks in the isolation analysis results.

[0059] The step 1 specifically includes:

[0060] Use the Clang compiler front end in the LLVM toolset to compile the Linux kernel code into an intermediate code IR file, and select the .config file generated by the default configuration in the kernel code for the kernel compilation configuration used.

[0061] The step 2 specifically includes:

[0062] Step 2.1, the pseudo-file path information, callback function information, and output data source information can all be obtained from the processing of the pseudo-file registration point context information. The getFunctionList() function is called on the entire kernel intermediate code module object in the IR assembly file obtained in step 1 to obtain a list of all function instances in the compiled kernel code, traverse the function instance list, and then match the corresponding function instance according to the pseudo-file registration function name, and add the function instance to the registered function instance set. After completing the collection of registered function instances, traverse the called statements of each registered function instance in the set, and obtain the pseudo-file registration point context information from its called statement, including all actual parameters passed to the pseudo-file registration function at the called statement, return value variables, and the function instance where the calling statement is located. Finally, the content contained in the pseudo-file registration point context information is saved in the pseudo-file registration call instance set;

[0063] Step 2.2, obtain the function list in the source code by calling the getFunctionList() function on the entire kernel intermediate code module object in the IR assembly file obtained in step 1, and obtain the pseudo-file directory registration function in the kernel through function name matching. For each directory registration function instance, obtain its called instance, parse the registered directory name string in the calling instance parameter, and the parent directory variable where the registered target directory is located, save the directory path information and the parent directory variable in the pseudo-file directory parent-child table, build a directory-parent directory relationship table, then take out a pseudo-file registration information from the pseudo-file registration point context set, obtain the registered pseudo-file name value passed in the parameter list, obtain its actual string content through the getAsString() function, and take out the directory pointer variable where the passed pseudo-file is located from the parameter list, and finally recursively query the corresponding parent directory in the pseudo-file directory-parent directory relationship table, take out the directory path string in the matching item and splice it before the registered pseudo-file directory name string, and complete the collection of pseudo-file path information;

[0064] Step 2.3, take out the file operation function instance from the pseudo file registration context set obtained in step 2.1, including the two-stage callback functions of open and read. Since the developer can customize the kernel function called in the open and read stages when the pseudo file is opened, or implement the sequence file operation function interface for the pseudo file in the open stage, the pseudo file reading process is called in a sequence form. At this time, in the read stage of the pseudo file reading process, the sequence class file general function will be called, and the sequence file reading function registered in the open stage will be executed in the form of a dynamic call function pointer. When calling the pseudo file registration function as a complete interface, that is, the actual parameter of the pseudo file registration point context information contains a complete file operation stage kernel function, the getAggregateElement() function is used to obtain the function pointers stored in the open and read member variables of the parameter list of the pseudo file registration context information, and the function pointer is passed to the dyn_cast() function to obtain the pseudo file kernel callback function instance. When the pseudo-file registration function called is a simple interface, that is, the actual parameter of the pseudo-file registration point context information only includes the kernel function called in the pseudo-file read phase, and the pseudo-file open phase callback function is a common function defined by the pseudo-file system, it is only necessary to use getOperand() to retrieve the read phase kernel callback function pointer in the parameter list of the pseudo-file registration context information and pass it into the dyn_cast() function to obtain the pseudo-file kernel callback function entity;

[0065] Step 2.4, traverse the function call statements in the read phase callback function obtained in step 2.3, use getArgs() in the file output function call instruction to obtain the passed output parameter content, filter the index class parameters and constant value content in the output parameter content, and backtrack the output parameters at the same time, using the operands in the output variable user list as the backtracking result and the next backtracking node, until the backtracking result is the kernel's global variable or custom data source, then stop. At this time, the global variable and custom data source are the data source quantity and location information for obtaining the pseudo file.

[0066] The step 3 is analyzed from the following three perspectives:

[0067] Perspective 1: Through the isolation analysis of the two-stage callback functions of open and read, the analysis process is as follows: Figure 2First, check whether the Linux namespace type variable in the open callback function exists and is used to execute the conditional judgment instruction. If it is used to execute the conditional judgment instruction, compare the conditional jump branches involved in the instruction, check whether the branch has an error exit operation, and thus determine whether the Linux namespace type variable is used to terminate the file opening operation. In this way, the pseudo file is isolated, and all data sources are isolated. In the read callback function, if the Linux namespace type variable is used, first check whether the Linux namespace type variable is used to execute the conditional judgment instruction. If it is used for conditional judgment, analyze the conditional jump branch and check whether there is a difference in calling the data output function between the branches. In this way, it is determined that the Linux namespace variable is used to control whether a kernel variable is output, so that the kernel data passed in by the output function is isolated. In addition, it can also be checked whether the namespace variable is used for data fetching operation. The read callback function fetches the data in the namespace where the process is located for output, and the fetched kernel data is isolated.

[0068] Perspective 2: Perform kernel data source isolation analysis on pseudo files. The process is as follows: Figure 3 , take out the passed-in kernel data source parameters in the actual parameters, first obtain the user instructions of all target variables, check whether there is a storage operation on the kernel data source parameters, if so, use the source variable as the next backtracking node, otherwise check the declaration position of the target variable, and set the backtracking node position in different situations; in the process of data flow backtracking, first check the next node variable obtained, whether its type is the Linux namespace type, if so, it is determined that the pseudo-file kernel data source is taken out from the reading process namespace variable, and the pseudo-file kernel data source has been isolated, and then analyze from the perspective of instruction control flow, check whether the conditional branch variable passed in the backtracking process contains the Linux namespace type, if so, it is determined that the value of the pseudo-file kernel data source is affected by the Linux namespace, and the pseudo-file kernel data source has been isolated;

[0069] Angle 3: Analysis from the perspective of the built-in isolation mechanism of pseudo files, including: analysis of using pseudo file registration locations to achieve isolation, and analysis of using pseudo file visibility mechanisms to achieve isolation;

[0070] The analysis of using the pseudo file registration position to achieve isolation is to backtrack the directory parameter variable through the directory parameter variable in the actual parameter, and check whether the Linux namespace type variable appears in the backtracking path. If it appears, it means that the pseudo file has namespace isolation and all data sources are isolated. If the Linux namespace type variable does not appear in the backtracking process, the parent directory corresponding to the directory variable where the pseudo file is located is recursively checked to see if the parent directory uses the Linux namespace mechanism. The analysis process of achieving isolation of the pseudo file registration position is as shown in the attached figure. Figure 4 ;

[0071] The analysis of isolation achieved by using the pseudo-file visibility mechanism is to determine whether the visibility judgment function pointer in the kernel object variable structure is a null pointer through the kernel object variable in the actual parameter. When the visibility judgment function pointer is not null, the instructions in the visibility judgment function instance are traversed. When a Linux namespace type variable is encountered during the traversal check and the Linux namespace type variable participates in the parameter of the branch jump, it is determined that the pseudo-file has namespace isolation and all data sources are isolated. The isolation analysis process achieved by the pseudo-file visibility mechanism is shown in the attached figure. Figure 5 .

[0072] Step 4 is analyzed through the following three scenarios:

[0073] Scenario 1: Kernel resource DoS exploitation. Obtain the unisolated pseudo file through step 3, traverse the kernel variables contained in the target unisolated pseudo file, recursively check the usage of kernel variables in the kernel through the def-use chain, and determine whether there are self-increment and comparison operations on kernel variables in the user set of kernel variables, and the results of the comparison operations are used for conditional jumps. If there are self-increment and comparison operations on kernel variables and the operation results are used for conditional jumps, the kernel variables contained in the unisolated pseudo file are kernel resource counter type variables. The attacker can trace back the call stack from the instruction where the kernel resource variable usage feature appears, obtain the relevant system calls that can trigger the resource application operation, and provide kernel resource DoS attack entry information for the container user space process;

[0074] Scenario 2: Determine whether containers are co-resident. Obtain unisolated pseudo files through step 3, traverse the kernel global variable information exposed by the unisolated pseudo files, and store them in the unisolated global variable table in the form of pseudo files-global variable names. In multiple hosts with the same system version, kernel version, and startup parameters, use the SystemTap kernel observation tool to observe the kernel global variables contained in the unisolated files, extract kernel variables that have not changed in a short period of time on the same host and store them in the short-term unchanged kernel variable set, compare the short-term unchanged kernel variable sets in each host, extract the variables in the short-term unchanged kernel variable set whose contents are inconsistent on different hosts as fingerprint-class shared kernel variables that can mark the host, and map them to the corresponding unisolated pseudo files through the unisolated global variable table to obtain a list of unisolated pseudo files that can be used to determine whether containers are co-resident.

[0075] Scenario 3, container escape exploitation, starts from the feature function call_usermodehelper_setup() in the usermodehelper mechanism. The first parameter of the feature function is the registered custom handler path. The path parameter variable is backtracked through the def-use chain. If the backtracking node reaches the kernel global variable, the backtracking is stopped, and the kernel global variable reached is recorded as a global variable that can be used for container escape exploitation. After completing the collection of global variables that can be used for escape exploitation, the kernel variables contained in the non-isolated pseudo-file obtained in step 3 are traversed and queried in the global variable table that can be used for escape exploitation. If the query is successful, it means that the kernel variables exposed by the non-isolated pseudo-file have an escape risk. Then the writability of the non-isolated pseudo-file is checked to see whether the file write operation in the pseudo-file callback function contains global variable parameters that can be used for escape exploitation. If it contains global variable parameters that can be used for escape exploitation, the non-isolated pseudo-file can be used to initiate container escape.

[0076] A container pseudo file system isolation and availability analysis system based on static analysis, including the following modules:

[0077] A kernel code compilation module compiles the Linux kernel code into an intermediate code IR file. The compiled intermediate code IR file includes an IR assembly file and an IR bit code file, which are used to implement step 1 of a container pseudo file system isolation and availability analysis method based on static analysis;

[0078] The pseudo file information collection module locates and collects pseudo file registration related content in the kernel code by scanning the intermediate code IR file, wherein the related content includes: pseudo file registration point context information, pseudo file path information, pseudo file kernel callback function information and pseudo file data source information, which is used to implement step 2 of a container pseudo file system isolation and availability analysis method based on static analysis;

[0079] The pseudo file isolation analysis module performs static analysis on the pseudo file registration related content to identify whether each pseudo file uses the Linux namespace isolation mechanism, and determines the data source affected by the isolation mechanism in the pseudo file that uses the isolation mechanism, and finally obtains the pseudo file isolation analysis result, which is used to implement step 3 of a container pseudo file system isolation and availability analysis method based on static analysis;

[0080] The pseudo-file exploitability analysis module determines from the pseudo-file isolation analysis results whether the discovered non-isolated pseudo-files can be used to launch attacks in the container, and obtains the exploitable pseudo-files that can cause container attacks in the isolation analysis results, which is used to implement step 4 of a container pseudo-file system isolation and exploitability analysis method based on static analysis.

[0081] A container pseudo file system isolation and availability analysis device based on static analysis, comprising:

[0082] Memory: used for storing a computer program for implementing the container pseudo file system isolation and availability analysis method based on static analysis;

[0083] Processor: used to implement the container pseudo file system isolation and availability analysis method based on static analysis when executing the computer program.

[0084] The present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the container pseudo file system isolation and availability analysis method based on static analysis.

[0085] Verification (comparison) analysis:

[0086] Starting from the kernel code, we avoid ignoring some file analysis objects in the existing identification methods due to the existence of some pseudo files in the container pseudo file system that only appear when the system is in a specific state or a certain type of specific hardware device exists in the system. During the scanning of the pseudo file registration interface, a total of 9 procfs pseudo file system file registration functions and 2 sysfs pseudo file system file registration functions were found. There are a total of 780 file registration call instructions for the above two types of pseudo file systems. Next, the pseudo file registration context information is processed, and the pseudo file path, pseudo file callback function, and kernel data source content output in the pseudo file in the pseudo file registration function call instruction are collected. A total of 2208 pseudo file information registered in the kernel are obtained, including a total of 2946 kernel data sources. The statistics of the container pseudo file system scanning stage are shown in Table 1.

[0087] Table 1 Container pseudo file system scanning phase number table

[0088]

[0089] In the pseudo-file isolation analysis module, Linux namespace isolation analysis is performed from three perspectives: kernel callback function, kernel data source, and built-in isolation mechanism, and the statistical results of unisolated files in the pseudo-file system are obtained, as shown in Table 2. The proportion of unisolated pseudo-files in the procfs pseudo-file system is about 50%, and the proportion of unisolated pseudo-files in the sysfs pseudo-file system is 97.4%. The statistical results of unisolated files obtained by the container pseudo-file isolation analysis tool used in the existing identification method in dynamic analysis are shown in Table 3. The number of unisolated pseudo-files obtained in the analysis results is much lower than the number of unisolated pseudo-files obtained by the pseudo-file isolation module of the present invention, that is, the existing identification method has the situation of incorrectly judging the isolation of pseudo-files, such as / proc / locks file.

[0090] Table 2 Statistics of unisolated files in pseudo file system

[0091]

[0092]

[0093] Table 3 Analysis results of existing recognition methods

[0094]

[0095] In the unisolated pseudo-file exploitable module, after analyzing the shared kernel data exposed in the unisolated pseudo-file, the system identified 10 system resource counter class variables, of which 7 were counter value variables and 3 were counter upper limit variables, corresponding to 9 unisolated pseudo-files, which can assist in launching kernel resource DoS attacks; after observing the kernel global variables exposed in the unisolated pseudo-files in multiple hosts, 107 fingerprint class kernel global variables that can be used to mark the host were obtained, mapped to 42 fingerprint class unisolated pseudo-files of the host that can be used to determine the co-resident container; 7 call instructions of the call_usermodehelper_setup() function were identified in the Linux kernel intermediate code, of which the handler path variables in the parameter list of 3 call instructions overlapped with the global variables exposed by the unisolated pseudo-files, corresponding to 3 unisolated pseudo-files that can be used to escape the container. Some results are shown in Table 4.

[0096] Table 4 Document available analysis results

[0097]

[0098]

[0099] For the completeness of the pseudo file list, the kernel configuration file that is the same as the kernel configuration file used by the kernel compilation module is compiled into a Linux kernel binary file, which is used as the kernel file of the test machine to start. It is found that the files existing in the procfs and sysfs pseudo file systems in the test machine can all be queried in the isolation analysis results. The corresponding isolation analysis entries. This verifies that the pseudo file isolation analysis results can cover the pseudo files that appear in the kernel running with the same configuration, and the analysis results are complete.

[0100] For the correctness of the pseudo-file Linux namespace isolation judgment, the kernel dynamic characteristics in the pseudo-file reading process are verified by kernel observation to verify whether the isolation is shown. The SystemTap tool is used to observe the sub-function call situation in the callback function, the output data address, and the pseudo-file visibility in the process of the kernel opening the pseudo-file, and record the target pseudo-file path name in the pseudo-file opening process, the function call stack information in the callback function, the output kernel data pointer address, and whether the file exists. Then, two container processes are started in the host machine. The two container processes are in their own Linux namespaces, and the files in the procfs and sysfs file systems in the container are traversed and read respectively. The differences in the three types of data in the pseudo-file reading process of the same path of the two processes are compared. If the data of the two container processes are the same, the pseudo-file does not achieve containerized isolation. The results of the pseudo-file isolation verification are shown in Table 5.

[0101] Table 5: Verification of pseudo-file isolation results

[0102]

[0103]

[0104] From the verification results, we can see that during this dynamic verification process, a total of 572 procfs pseudo files were observed, accounting for 90.8% of the number of procfs pseudo files in the static analysis file results, and 1154 sysfs pseudo files, accounting for 73.1% of the number of sysfs pseudo files in the static analysis file results. Among all observable files appearing on the running system, the pseudo file namespace isolation obtained through kernel observation is consistent with the pseudo file namespace isolation results obtained by the pseudo file isolation analysis results, which verifies the correctness of the pseudo file isolation judgment results.

Claims

1. A method for analyzing the isolation and availability of container pseudo file systems based on static analysis, characterized in that: The following steps are involved: Scanning phase: Step 1, compile the Linux kernel code into an intermediate code IR file, the compiled intermediate code IR file includes an IR assembly file and an IR bit code file; Step 2, by scanning the intermediate code IR file obtained in step 1, locate and collect pseudo file registration related content in the kernel code, the related content includes: pseudo file registration point context information, pseudo file path information, pseudo file kernel callback function information and pseudo file data source information; Analysis phase: Step 3: statically analyze the pseudo-file registration related content collected in step 2 to identify whether each pseudo-file uses the Linux namespace isolation mechanism, and determine the data source affected by the isolation mechanism in the pseudo-files that use the isolation mechanism, and finally obtain the pseudo-file isolation analysis results; Step 4: From the pseudo-file isolation analysis results obtained in step 3, determine whether the discovered non-isolated pseudo-files can be used to launch attacks in the container, and obtain the exploitable pseudo-files that can cause container attacks in the isolation analysis results.

2. According to the static analysis-based container pseudo file system isolation and availability analysis method of claim 1, it is characterized in that: The step 1 specifically includes: Use the Clang compiler front end in the LLVM toolset to compile the Linux kernel code into an intermediate code IR file, and select the .config file generated by the default configuration in the kernel code for the kernel compilation configuration used.

3. According to the static analysis-based container pseudo file system isolation and availability analysis method of claim 1, it is characterized in that: The step 2 specifically includes: Step 2.1, by traversing the function instance list in the IR assembly file obtained in step 1, and then matching the corresponding function instance according to the pseudo-file registration function name, and adding the function instance to the registered function instance set, after completing the collection of registered function instances, traverse the called statements of each registered function instance in the set, and obtain the pseudo-file registration point context information from its called statement, including all actual parameters passed to the pseudo-file registration function at the called statement, return value variables, and the function instance where the calling statement is located, and finally save the content contained in the pseudo-file registration point context information in the pseudo-file registration call instance set; Step 2.2, scan all directory registration function instances in the IR assembly file obtained in step 1, and obtain the function instance calling statement. For the calling instance of the directory registration function, obtain the registered directory name string in the calling instance parameter and the parent directory variable where the registered target directory is located, save the directory path information and the parent directory variable in the pseudo-file directory parent-child table, build a directory-parent directory relationship table, and complete the collection of pseudo-file path information; Step 2.3, taking out the file operation function instance from the pseudo file registration call instance set obtained in step 2.1, including the two-stage callback functions of open and read; Step 2.4, traverse the function call statements in the read phase callback function obtained in step 2.3, obtain the output parameter content passed in the function call instruction, filter the index class parameters and constant value content in the output parameter content, and trace the output parameters at the same time to obtain the number of data sources and location information of the pseudo file.

4. According to the static analysis-based container pseudo file system isolation and availability analysis method of claim 1, it is characterized in that: The step 3 is analyzed from the following three perspectives: Perspective 1, through the isolation analysis of pseudo-file callback functions for the two-stage callback functions of open and read, first check whether the Linux namespace type variable in the open callback function exists and is used to execute the conditional judgment instruction. If it is used to execute the conditional judgment instruction, compare the conditional jump branches involved in the instruction, check whether the branch has an error exit operation, so as to determine whether the Linux namespace type variable is used to terminate the file opening operation, then the pseudo-file is isolated, and all data sources are isolated; in the read callback function, if the Linux namespace type variable is used, first check whether the Linux namespace type variable is used to execute the conditional judgment instruction. If it is used for conditional judgment, analyze the conditional jump branch, check whether there is a difference in calling the data output function between the branches, so as to determine whether the Linux namespace variable is used to control whether a kernel variable is output, so as to achieve the isolation of the kernel data passed in by the output function; in addition, it can also be checked whether the namespace variable is used for data fetching operation, then the read callback function takes out the data in the namespace where the process is located for output, so as to achieve the isolation of the fetched kernel data; Perspective 2: Perform kernel data source isolation analysis on the pseudo file, extract the kernel data source parameters passed in from the actual parameters, first obtain the user instructions of all target variables, check whether there are any storage operations on the kernel data source parameters, if so, use the source variable as the next backtracking node, otherwise check the declaration position of the target variable, and set the backtracking node position in different situations; in the process of data flow backtracking, first check the next node variable obtained to see if its type is a Linux namespace type, if so, determine that the pseudo file kernel data source is taken out from the reading process namespace variable, and the pseudo file kernel data source has been isolated, then analyze from the perspective of instruction control flow, check whether the conditional branch variables passed through during the backtracking process contain Linux namespace types, if so, determine that the value of the pseudo file kernel data source is affected by the Linux namespace, and the pseudo file kernel data source has been isolated; Angle 3: Analysis from the perspective of the built-in isolation mechanism of pseudo files, including: analysis of using pseudo file registration locations to achieve isolation, and analysis of using pseudo file visibility mechanisms to achieve isolation; The analysis of using the pseudo-file registration position to achieve isolation is performed by backtracking the directory parameter variable through the directory parameter variable in the actual parameter, and checking whether the Linux namespace type variable appears in the backtracking path. If it appears, it means that the pseudo-file has namespace isolation and all data sources are isolated. If the Linux namespace type variable does not appear in the backtracking process, recursively check whether the parent directory uses the Linux namespace mechanism through the parent directory corresponding to the directory variable where the pseudo-file is located; The analysis of using the pseudo-file visibility mechanism to achieve isolation is to determine whether the visibility judgment function pointer in the kernel object variable structure is a null pointer through the kernel object variable in the actual parameter. When the visibility judgment function pointer is not null, the instructions in the visibility judgment function instance are traversed. When a Linux namespace type variable is encountered during the traversal check and the Linux namespace type variable participates in the parameters of the branch jump, it is determined that the pseudo-file has namespace isolation and all data sources therein are isolated.

5. According to the static analysis-based container pseudo file system isolation and availability analysis method of claim 1, it is characterized in that: Step 4 is analyzed through the following three scenarios: Scenario 1: Kernel resource DoS exploitation. Obtain the unisolated pseudo file through step 3, traverse the kernel variables contained in the target unisolated pseudo file, check the usage of the kernel variables in the kernel, and determine whether there are self-increment and comparison operations on the kernel variables in the user set of the kernel variables, and the results of the comparison operations are used for conditional jumps. If there are self-increment and comparison operations on the kernel variables and the operation results are used for conditional jumps, the kernel variables contained in the unisolated pseudo file are kernel resource counter type variables. The attacker can trace back the call stack from the instruction where the kernel resource variable usage feature appears, obtain the relevant system calls that can trigger the resource application operation, and provide kernel resource DoS attack entry information for the container user space process; Scenario 2: Determine whether containers are co-resident. Obtain unisolated pseudo files through step 3, traverse the kernel global variable information exposed by the unisolated pseudo files, and store them in the unisolated global variable table in the form of pseudo files-global variable names. In multiple hosts with the same system version, kernel version, and startup parameters, use the SystemTap kernel observation tool to observe the kernel global variables contained in the unisolated files, extract kernel variables that have not changed in a short period of time on the same host and store them in the short-term unchanged kernel variable set, compare the short-term unchanged kernel variable sets in each host, extract the variables in the short-term unchanged kernel variable set whose contents are inconsistent on different hosts as fingerprint-class shared kernel variables that can mark the host, and map them to the corresponding unisolated pseudo files through the unisolated global variable table to obtain a list of unisolated pseudo files that can be used to determine whether containers are co-resident. Scenario 3, container escape exploitation, starts from the feature function call_usermodehelper_setup() in the usermodehelper mechanism. The first parameter of the feature function is the registered custom handler path. The path parameter variable is backtracked through the def-use chain. If the backtracking node reaches the kernel global variable, the backtracking is stopped, and the kernel global variable reached is recorded as a global variable that can be used for container escape exploitation. After completing the collection of global variables that can be used for escape exploitation, the kernel variables contained in the non-isolated pseudo-file obtained in step 3 are traversed and queried in the global variable table that can be used for escape exploitation. If the query is successful, it means that the kernel variables exposed by the non-isolated pseudo-file have an escape risk. Then the writability of the non-isolated pseudo-file is checked to see whether the file write operation in the pseudo-file callback function contains global variable parameters that can be used for escape exploitation. If it contains global variable parameters that can be used for escape exploitation, the non-isolated pseudo-file can be used to initiate container escape.

6. A system based on the container pseudo file system isolation and availability analysis method based on static analysis according to any one of claims 1 to 5, characterized in that: Includes the following modules: The kernel code compilation module compiles the Linux kernel code into an intermediate code IR file. The compiled intermediate code IR file includes an IR assembly file and an IR bit code file. The pseudo file information collection module locates and collects pseudo file registration related content in the kernel code by scanning the intermediate code IR file, and the related content includes: pseudo file registration point context information, pseudo file path information, pseudo file kernel callback function information and pseudo file data source information; The pseudo-file isolation analysis module performs static analysis on the pseudo-file registration-related content to identify whether each pseudo-file uses the Linux namespace isolation mechanism, and determines the data source affected by the isolation mechanism in the pseudo-files that use the isolation mechanism, and finally obtains the pseudo-file isolation analysis results; The pseudo file exploitability analysis module determines whether the discovered non-isolated pseudo files can be used to launch attacks in the container from the pseudo file isolation analysis results, and obtains the exploitable pseudo files that can cause container attacks from the isolation analysis results.

7. A container pseudo file system isolation and availability analysis device based on static analysis, characterized in that: include: Memory: used to store a computer program for implementing a container pseudo file system isolation and availability analysis method based on static analysis as described in any one of claims 1 to 5; Processor: used to implement the container pseudo file system isolation and availability analysis method based on static analysis as described in any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a container pseudo file system isolation and availability analysis method based on static analysis as described in any one of claims 1 to 5 are implemented.

Citation Information

Cited By

  • Redundant code identification method and system based on data flow diagram

    CN121144168A

  • A method and system for identifying redundant code based on a dataflow graph

    CN121144168B