Memory accounting anomaly detection method, device, electronic device and storage medium
By scanning the LLVM IR of the Linux system kernel, identifying and analyzing memory application and accounting functions, it solves the problem of automated analysis of the Linux memory control group's memory accounting operations, achieves the correctness and security of memory accounting, and ensures the system's Stability and interest protection.
Patent Information
- Application Number
- CN202111032254.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-03
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-09-03
AI Technical Summary
It is difficult to automatically analyze the correctness of memory accounting operations of Linux memory control groups with existing technology, leading to potential memory accounting vulnerabilities and security issues, affecting the interests of tenants and cloud service providers.
By scanning the LLVM IR of the Linux system kernel, it identifies the memory application and accounting-related function set of the target container, determines the mapping relationship between functions, automatically detects abnormalities in memory accounting operations, and ensures the correctness and security of memory accounting.
It achieves rapid and accurate detection of potential memory accounting vulnerabilities, ensures the security of Linux systems, and protects the interests of tenants and cloud service providers.
Smart Images

Figure CN113835917B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of Linux system accounting technology, and in particular, to a memory accounting anomaly detection method, device, electronic device, and machine-readable storage medium. Background Art
[0002] With the advent of the cloud-native era, more and more users are starting to use containers; containers are a kernel virtualization technology of the Linux system that can be used to isolate processes and allocate system resources such as CPU, memory, disk I / O, etc. to each process. In actual applications, the kernel function cgroups (control groups, Linux control groups) can be used to account for system resources and limit the resource usage of each process.
[0003] Among them, memcg (memory control groups, Linux memory control groups) is one of the sub-controllers of cgroups, which can be used for memory accounting and memory usage restrictions. In actual applications, the memory management mechanism of the Linux system is very complex, which makes the strategy and implementation of memcg memory accounting very complex. Only when memcg performs fair, just and correct memory accounting for each container can the interests of users and cloud service providers be protected. Summary of the invention
[0004] The present application provides a memory accounting anomaly detection method, which is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the method comprises:
[0005] Scan the IR intermediate representation of the LLVM compiler of the Linux system kernel to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory application operations for the target container; and the second-class function set includes a number of second-class functions related to memory accounting operations for the target container;
[0006] Determine the first type of functions in the first type of function set as target functions in sequence, and determine whether there is a second type of function in the second type of function set that has a mapping relationship with the target function;
[0007] If there is no second-type function having a mapping relationship with the target function in the second-type function set, it is determined that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container.
[0008] Optionally, the method further includes:
[0009] If there is a second type function having a mapping relationship with the objective function in the second type function set, further determining a target number of second type functions having a mapping relationship with the objective function in the second type function set;
[0010] Determining whether the target quantity is greater than 1;
[0011] If the target quantity is greater than 1, it is determined that a memory accounting operation of the Linux memory control group for the target container is abnormal.
[0012] Optionally, if there is no second-type function having a mapping relationship with the target function in the second-type function set, determining that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container includes:
[0013] If there is no second type function having a mapping relationship with the target function in the second type function set, further determining whether the __GFP_ACCOUNT flag carried in the target function is set;
[0014] If the __GFP_ACCOUNT flag carried in the target function is not set, it is determined that an abnormality exists in the memory accounting operation of the Linux memory control group for the target container.
[0015] Optionally, the first type of function includes a basic memory application function and a wrapper function of the basic memory application function; the second type of function includes a basic memory accounting function and a wrapper function of the basic memory accounting function;
[0016] The scanning of the IR intermediate representation of the LLVM compiler of the Linux system kernel to identify the first-class function set and the second-class function set for the target container to be detected includes:
[0017] Scanning the IR of the LLVM compiler of the Linux system kernel to generate a function relationship call graph of the Linux system kernel;
[0018] Based on a memory page allocation operation for the target container, a basic memory request function is identified, and based on a count increase operation for a page counter in the Linux memory control group for performing memory accounting for the target container, a basic accounting function is identified;
[0019] Based on the function relationship call graph, a wrapper function of the basic memory application function and a wrapper function of the basic memory accounting function are recursively identified, and the basic memory application function and the wrapper function of the basic memory application function are determined as the first type of function set for the target container, and the basic memory accounting function and the wrapper function of the basic memory accounting function are determined as the second type of function set for the target container.
[0020] The present application also provides another memory accounting anomaly detection method, which is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the method comprises:
[0021] Scan the IR of the LLVM compiler of the Linux system kernel to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory release operations for the target container; and the second-class function set includes a number of second-class functions related to memory clearing operations for the target container;
[0022] Determine the first type of functions in the first type of function set as target functions in sequence, and determine whether there is a second type of function in the second type of function set that has a mapping relationship with the target function;
[0023] If there is no second-type function having a mapping relationship with the target function in the second-type function set, it is determined that there is an abnormality in the memory clearing operation of the Linux memory control group on the target container.
[0024] Optionally, the method further includes:
[0025] If there is a second type function having a mapping relationship with the objective function in the second type function set, further determining a target number of second type functions having a mapping relationship with the objective function in the second type function set;
[0026] Determining whether the target quantity is greater than 1;
[0027] If the target quantity is greater than 1, it is determined that a memory clearing operation of the Linux memory control group on the target container is abnormal.
[0028] Optionally, the first type of function includes a basic memory release function and a wrapper function of the basic memory release function; the second type of function includes a basic memory clearing function and a wrapper function of the basic memory clearing function;
[0029] The scanning of the IR of the LLVM compiler of the Linux system kernel to identify the first type of function set and the second type of function set for the target container to be detected includes:
[0030] Scanning the IR of the LLVM compiler of the Linux system kernel to generate a function relationship call graph of the Linux system kernel;
[0031] Based on a memory page release operation for the target container, a basic memory release function is identified, and based on a count reduction operation for a page counter in the Linux memory control group for performing memory accounting for the target container, a basic account clearing function is identified;
[0032] Based on the function relationship call graph, a wrapper function of the basic memory release function and a wrapper function of the basic memory clearing function are recursively identified, and the basic memory release function and the wrapper function of the basic memory release function are determined as the first type of function set for the target container, and the basic memory clearing function and the wrapper function of the basic memory clearing function are determined as the second type of function set for the target container.
[0033] The present application also provides a memory accounting anomaly detection device, which is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the device comprises:
[0034] An identification unit is used to scan the IR intermediate representation of the LLVM compiler of the Linux system kernel, and identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory application operations for the target container; and the second-class function set includes a number of second-class functions related to memory accounting operations for the target container;
[0035] A mapping unit, used to determine the first type functions in the first type function set as target functions in sequence, and determine whether there is a second type function in the second type function set that has a mapping relationship with the target function;
[0036] A determining unit is configured to determine that an abnormality exists in a memory accounting operation of the Linux memory control group for the target container if there is no second-type function having a mapping relationship with the target function in the second-type function set.
[0037] The present application also provides another memory accounting anomaly detection device, which is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the device comprises:
[0038] An identification unit is used to scan the IR of the LLVM compiler of the Linux system kernel, and identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory release operations for the target container; and the second-class function set includes a number of second-class functions related to memory clearing operations for the target container;
[0039] A mapping unit, used to determine the first type functions in the first type function set as target functions in sequence, and determine whether there is a second type function in the second type function set that has a mapping relationship with the target function;
[0040] A determining unit is configured to determine that a memory clearing operation of the Linux memory control group on the target container is abnormal if there is no second-type function having a mapping relationship with the target function in the second-type function set.
[0041] The present application also provides an electronic device, comprising a communication interface, a processor, a memory and a bus, wherein the communication interface, the processor and the memory are interconnected via the bus;
[0042] The memory stores machine-readable instructions, and the processor executes any one of the above methods by calling the machine-readable instructions.
[0043] The present application also provides a machine-readable storage medium, wherein the machine-readable storage medium stores machine-readable instructions, and when the machine-readable instructions are called and executed by a processor, any of the above methods is implemented.
[0044] Through the above embodiments, by scanning the LLVM IR of the Linux system kernel, a first type of function set related to the memory application operation (or memory release operation) for the target container and a second type of function set related to the memory accounting operation (or memory clearing operation) for the target container can be first identified, and then the first type of functions in the first type of function set are sequentially determined as target functions. According to whether there is a second type of function having a mapping relationship with the target function in the second type of function set, it can be determined whether the memory accounting operation (or memory clearing operation) of the Linux memory control group for the target container is abnormal; thereby realizing automatic analysis of the correctness of the memory accounting of the Linux memory control group, quickly and accurately detecting potential memory accounting vulnerabilities, and thus ensuring the security of the Linux system and protecting the interests of tenants and cloud service providers. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 is a flowchart of a memory accounting anomaly detection method shown in an exemplary embodiment;
[0046] Figure 2 is a flow chart of another memory accounting anomaly detection method shown in an exemplary embodiment;
[0047] Figure 3 It is a structural schematic diagram of an electronic device in which a memory accounting anomaly detection device is located, shown in an exemplary embodiment;
[0048] Figure 4 is a block diagram of a memory accounting anomaly detection device shown in an exemplary embodiment;
[0049] Figure 5 It is a block diagram of another memory accounting anomaly detection device shown in an exemplary embodiment. DETAILED DESCRIPTION
[0050] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0051] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0052] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of this specification, the related technologies of memory accounting involved in the embodiments of this specification are briefly described below.
[0053] memcg (memory control groups, Linux memory control groups) is one of the sub-controllers of cgroups (controlgroups, Linux control groups), which can be used to perform memory accounting and memory usage restrictions on each container installed on the Linux system.
[0054] memcg can be widely used in various Linux-based environments; for example, memcg can be applied to data centers, Docker containers, OpenVZ containers, server-less computing, memory monitoring applications on mobile devices, etc.
[0055] In actual applications, the memory management mechanism of the Linux system is very complex, which makes the strategy and implementation of memcg's memory accounting also very complex.
[0056] For example, at the location where memory allocation is performed on a container, a charge function for performing memory accounting operations on the container can usually be inserted. Correspondingly, at the location where memory release is performed on a container, an uncharge function for performing memory clearing operations on the container can usually be inserted. However, memory application operations and memory release operations in the Linux system kernel are very frequent. It is obviously difficult to insert charge / uncharge functions or call charge / uncharge interfaces in hundreds of thousands of code execution paths related to memory application / release functions without omission and correctly implement the corresponding memory charge / uncharge operations. For another example, there is a complex nested relationship between the memory management interfaces of the Linux system. If the charge / uncharge function is inserted or the charge / uncharge interface is called at the wrong location, it will cause errors and omissions in the memory charge / uncharge operations.
[0057] In fact, the correctness of memory accounting is not only a requirement for ensuring the security of the Linux system, but also a key indicator for protecting the interests of tenants and cloud service providers.
[0058] On the one hand, if there is too little memory accounting, for example, some users can apply for and abuse system memory without being charged, which may cause losses to cloud service providers; it may even trigger a DoS (Denial of Service) attack, causing system memory resources to be exhausted and unable to provide services to users normally. On the other hand, if there is too much memory accounting, for example, the same memory allocation operation for a container is accounted for multiple times, it may cause losses to the interests of users corresponding to the container.
[0059] Currently, there is no related tool in the art that can automatically analyze the correctness of the memory accounting / clearing operations of the Linux memory control group.
[0060] In view of this, this specification aims to propose a static analysis tool for Linux memory control groups, which can detect the technical solution of memory accounting anomalies of Linux memory control groups for containers based on automated analysis of LLVM IR.
[0061] During implementation, the LLVM IR of the Linux system kernel can be scanned to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory application operations (or memory release operations) for the target container; the second-class function set includes a number of second-class functions related to memory accounting operations (or memory clearing operations) for the target container; further, the first-class functions in the first-class function set can be sequentially determined as target functions, and it can be determined whether there is a second-class function in the second-class function set that has a mapping relationship with the target function; if not, it can be determined that there is an abnormality in the memory accounting operation (or memory clearing operation) of the Linux memory control group for the target container.
[0062] It can be seen that in the technical solution in this specification, by scanning the LLVM IR of the Linux system kernel, it is possible to first identify a first-class function set related to the memory application operation (or memory release operation) for the target container and a second-class function set related to the memory accounting operation (or memory clearing operation) for the above target container, and then determine the first-class functions in the above-mentioned first-class function set as the target function in turn. According to whether there is a second-class function having a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, it is possible to determine whether there is an abnormality in the memory accounting operation (or memory clearing operation) of the Linux memory control group for the above-mentioned target container; thereby realizing automated analysis of the correctness of the memory accounting of the Linux memory control group, quickly and accurately detecting potential memory accounting vulnerabilities, and thus ensuring the security of the Linux system and protecting the interests of tenants and cloud service providers.
[0063] The following describes the present application in combination with a specific application scenario by taking an example in which the first category of functions includes functions related to memory application operations for containers, and the second category of functions includes functions related to memory accounting operations for containers.
[0064] See also Figure 1 , Figure 1 This is a flowchart of a memory accounting anomaly detection method shown in an exemplary embodiment. The above method can be applied to a terminal device equipped with a Linux system; the above Linux system is equipped with a number of containers corresponding to different tenants and isolated from each other, and a Linux memory control group for memory accounting for the above containers; the above method performs the following steps:
[0065] Step 102: Scan the LLVM IR of the Linux system kernel to identify a first-class function set and a second-class function set for the target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory application operations for the target container; and the second-class function set includes a number of second-class functions related to memory accounting operations for the target container;
[0066] Step 104: determining the first type functions in the first type function set as target functions in sequence, and determining whether there is a second type function in the second type function set that has a mapping relationship with the target function;
[0067] Step 106: If not, it is determined that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container.
[0068] In this specification, the above-mentioned terminal device may include a server equipped with a Linux system, or a server cluster formed by multiple servers, or may include a client-side network device equipped with a Linux system, and this specification does not impose any special restrictions.
[0069] For example, the terminal device may specifically include a network device equipped with a memory accounting anomaly detection program or a Linux memory control group analysis tool.
[0070] In this specification, the LLVM IR of the Linux system kernel can be scanned to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set may include several first-class functions related to memory application operations for the target container; and the second-class function set may include several second-class functions related to memory accounting operations for the target container.
[0071] Among them, the above-mentioned LLVM IR (LLVM Intermediate Representation) is an intermediate language code that is independent of the source programming language and the target machine architecture; LLVM IR usually has three forms of expression, namely: compiled intermediate language in memory, binary code in disk, and readable assembly text. The three forms of the above-mentioned LLVM IR are essentially equivalent, and this specification does not impose any special restrictions.
[0072] In practical applications, by identifying the above-mentioned first-category function set and the above-mentioned second-category function set based on LLVM IR, the positions of all memory application operations and all memory accounting operations for the above-mentioned target container on the corresponding code execution path can be determined respectively; that is, all interfaces with memory application functions and memory accounting functions in the Linux kernel can be quickly and accurately located, and serve as the basis for subsequent analysis of the mapping relationship between the memory application interface and the memory accounting interface, and detection of whether there are abnormalities in the memory accounting.
[0073] For example, an analysis tool mounted on a terminal device may scan the LLVM IR of the Linux system kernel and identify a first set of functions related to memory request operations for a target container and a second set of functions related to memory accounting operations for the target container.
[0074] It should be noted that, in the various embodiments shown in this specification, the above-mentioned "first-class functions" and "second-class functions" are merely descriptions for distinguishing between memory application / release functions and memory accounting / clearing functions, and do not represent any special limitations on this specification.
[0075] In one embodiment shown, the first type of function may include a basic memory application function and a wrapper function of the basic memory application function; wherein the basic memory application function may include a function for performing memory page allocation operations on a container; the wrapper function of the basic memory application function may include a function for calling the basic memory application function. The second type of function may include a basic memory accounting function and a wrapper function of the basic memory accounting function; wherein the basic memory accounting function may include a function for performing count increment operations on a page counter provided by a Linux memory control group, and the page counter may be used for memory accounting for a container; the wrapper function of the basic memory accounting function may include a function for calling the basic memory accounting function.
[0076] During implementation, the process of scanning the LLVM IR of the Linux system kernel and identifying the first and second function sets for the target container may specifically include: scanning the LLVM IR of the Linux system kernel to generate a function relationship call graph (Interactive Map of Linux Kernel) of the Linux system kernel; identifying a basic memory application function based on a memory page allocation operation for the target container, and identifying a basic accounting function based on a count increase operation of a page counter in the Linux memory control group for performing memory accounting for the target container; recursively identifying a wrapper function of the basic memory application function and a wrapper function of the basic memory accounting function based on the function relationship call graph; determining the basic memory application function and the wrapper function of the basic memory application function as the first function set for the target container, and determining the basic memory accounting function and the wrapper function of the basic memory accounting function as the second function set for the target container.
[0077] For example, the LLVM IR of the Linux system kernel can be scanned and a corresponding function relationship call graph can be generated; based on the memory page allocation operation for the target container, the basic memory application function A (such as the __alloc_pages function, etc.) can be identified, and, based on the count increase operation of the page counter in the Linux memory control group for memory accounting for the above target container, the basic accounting function B (such as the charge function, etc.) can be identified; further, assuming that function C calls the basic memory application function A and function D calls the basic accounting function B, then based on the generated function relationship call graph, the wrapper function C of the basic memory application function A and the wrapper function D of the basic memory accounting function B can be recursively identified; therefore, it can be determined that the first type of function set for the above target container includes the basic memory application function A and the corresponding wrapper function C, and the above second type of function set for the above target container includes the basic accounting function B and the corresponding wrapper function D.
[0078] It should be noted that in the memory management mechanism of the Linux system, each physical memory node can usually be divided into multiple memory management areas (zones) to represent different ranges of memory. The kernel can use different mapping methods to map physical memory; further, the memory can be divided into multiple page frames (page frames, also called page frames, physical pages), each page frame can contain a page; therefore, the Linux kernel can usually use memory pages as the basic unit of memory management.
[0079] In addition, it should be noted that, in the above-described implementation, the number of basic memory application functions and wrapper functions of the basic memory application functions that can be included in the above-described first-category function set, and the number of basic accounting functions and wrapper functions of the basic accounting functions that can be included in the above-described second-category function set, are merely exemplary descriptions and do not limit this specification; in actual applications, the above-described first-category function set and the above-described second-category function set may include a greater number of basic memory application functions, basic accounting functions, or corresponding wrapper functions. In addition, for the specific implementation method of generating the above-described function relationship call graph, please refer to the relevant technology, which will not be described in detail here.
[0080] In the present specification, after identifying a first-class function set related to memory application operations for the target container and a second-class function set related to memory accounting operations for the target container, the first-class functions in the first-class function set can be determined as target functions in turn, and it can be determined whether there is a second-class function in the second-class function set that has a mapping relationship with the target function.
[0081] In actual applications, there is a mapping relationship between the first-class function and the second-class function. It can be understood that, in response to calling the first-class function to allocate memory pages for the target container, the second-class function can be called to perform memory accounting operations on the memory pages allocated for the target container.
[0082] For example, after identifying the first-class function set and the second-class function set for the target container, the first-class functions in the above-mentioned first-class function set can be determined as target functions in turn, and it is determined whether there is a second-class function in the above-mentioned second-class function set that has a mapping relationship with the above-mentioned target function, that is, it is determined whether there is a second-class function in the above-mentioned second-class function set that can perform memory accounting operations for the memory page allocated for the above-mentioned target container by calling the above-mentioned target function.
[0083] Continuing with the above example, after identifying that the first-category function set for the target container includes a basic memory request function A and a corresponding wrapper function C, and that the second-category function set for the target container includes a basic accounting function B and a corresponding wrapper function D, the basic memory request function A in the first-category function set can be first determined as the target function, and it can be determined whether there is a mapping relationship between the function B and the function D included in the second-category function set and the target function A; similarly, the wrapper function C in the first-category function set can continue to be determined as the target function, and it can be determined whether there is a mapping relationship between the function B and the function D included in the second-category function set and the target function C.
[0084] It should be noted that, in the implementation shown above, based on the identification of the above-mentioned first-category function set and the above-mentioned second-category function set, the memory page allocated for the above-mentioned target container for calling the above-mentioned target function can be marked first based on source recognition technology, and then for the above-mentioned marked memory page, the data flow analysis between the processes is recursively performed upward along the call chain to accurately analyze the mapping relationship between the above-mentioned first-category function and the above-mentioned second-category function, thereby solving the complex function calling relationship and interface nesting problems in the Linux kernel.
[0085] In this specification, if there is no second-class function having a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, it can be determined that there is an abnormality in the memory accounting operation of the Linux memory control group for the above-mentioned target container; otherwise, it is determined that there is no abnormality in the memory accounting operation of the Linux memory control group for the above-mentioned target container.
[0086] In actual applications, if there is no mapping relationship between the first-class function and the second-class function, it can be considered that, in response to calling the first-class function to allocate memory pages for the target container, the second-class function is not called to perform memory accounting operations on the memory pages allocated for the target container; that is, it can be detected that there is an accounting omission problem in the memory accounting of the target container by the Linux memory control group.
[0087] For example, after determining the first type of function in the above-mentioned first type of function set as the target function, if there is no second type of function in the above-mentioned second type of function set that has a mapping relationship with the above-mentioned target function, it can be determined that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container, and there may be a memory accounting omission problem.
[0088] It should be noted that, further, for the locations where abnormalities may exist in the memory accounting operations automatically detected based on the above-mentioned analysis tool, technical personnel in this field can also determine through manual analysis whether the above-mentioned memory accounting anomalies are accounting errors and omissions that will be actually triggered by syscall, and can also analyze the degree of harm of the above-mentioned accounting errors and omissions to the security of the Linux system, which is not limited in this specification.
[0089] For example, through the above-mentioned memory accounting anomaly detection method, it is detected that when the bpf program is loaded into the kernel, memory allocation operations are performed, but memory accounting operations are not performed. It can be determined that there is a memory accounting omission problem in memcg; therefore, if a malicious container repeatedly loads the bpf program, it can exhaust the memory resources of the Linux system without triggering the memory usage limit of memcg for the container, thereby triggering a DoS attack on the entire system.
[0090] In one embodiment shown, in addition to detecting memory accounting omission problems, memory accounting duplication problems can also be detected based on the number of second-class functions that have a mapping relationship with the same first-class function, thereby detecting more potential memory accounting anomalies, better ensuring the security of the Linux system, and protecting the interests of tenants and cloud service providers. In implementation, the above method may also include: if there is a second-class function that has a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, then further determining the target number of second-class functions that have a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set; further, it can be determined whether the above-mentioned target number is greater than a preset threshold; if it is greater than the above-mentioned preset threshold, it is determined that the Linux memory control group has an abnormality in the memory accounting operation for the above-mentioned target container; if it is not greater than the above-mentioned preset threshold, it is determined that there is no abnormality in the memory accounting operation of the Linux memory control group for the above-mentioned target container.
[0091] In actual applications, the target number of the second-type functions having a mapping relationship with the target function can be understood as, in response to calling the target function to allocate memory pages for the target container, the number of times the Linux memory group calls the second-type function to perform memory accounting operations on the memory pages.
[0092] In addition, in practical applications, the above preset threshold can usually be set to 1, that is, in order to ensure the fairness of memory accounting and take into account the interests of cloud service providers and users, only one memory accounting operation should be performed for a memory page allocation operation. It can be seen that if the above target number is greater than 1, it can be considered that the Linux memory group has performed multiple memory accounting operations on the same memory page, and there is a memory accounting duplication problem.
[0093] For example, if there is a second-type function having a mapping relationship with the target function in the second-type function set, the target number of second-type functions having a mapping relationship with the target function in the second-type function set can be determined; when the preset threshold is 1, if the target number is 2, it can be considered that the Linux memory group has performed two memory accounting operations for calling the target function to allocate the same memory page for the target container, that is, there may be a memory accounting duplication problem.
[0094] In another embodiment shown, memory accounting operations are performed on containers. In addition to inserting an accounting function or calling an accounting interface at the location where memory allocation operations are performed on the container, memory accounting operations may also rely on a GFP (get free page) flag passed into the memory request function; specifically, the first-class function may perform the memory accounting function when and only when the __GFP_ACCOUNT flag carried in the first-class function is set.
[0095] During implementation, if there is no second-category function having a mapping relationship with the target function in the second-category function set, it can be determined that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container. Specifically, the process may include: if there is no second-category function having a mapping relationship with the target function in the second-category function set, further determining whether the __GFP_ACCOUNT flag carried in the target function is set; if not set, determining that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container; if set, determining that there is no abnormality in the memory accounting operation of the Linux memory control group for the target container.
[0096] It can be seen that if there is no mapping relationship between the first-class function and the second-class function, and the __GFP_ACCOUNT flag carried in the first-class function is set, it can be considered that the Linux memory group has performed memory accounting operations for the memory pages allocated for the target container by calling the first-class function, and there is no problem of memory accounting omission, thereby improving the accuracy of memory accounting anomaly detection. It should be noted that the specific form of whether the __GFP_ACCOUNT flag is set can be set by those skilled in the art, and this specification does not limit it; for example, the __GFP_ACCOUNT flag can be set to 1 when it is set and to 0 when it is not set.
[0097] For example, if there is no second-category function in the second-category function set that has a mapping relationship with the target function, the GFP flag passed into the target function can be further traced, and the __GFP_ACCOUNT flag in the source data can be checked to see if it is 1; if it is 1, it can be determined that there is no abnormality in the memory accounting operation of the Linux memory control group for the target container; if it is 0, there may be a memory accounting omission problem.
[0098] It should be noted that, compared with the standard value tracking analysis provided by LLVM, in the implementation shown above, context-sensitive inter-procedural analysis can be used to improve the analysis accuracy; at the same time, since only the above-mentioned accounting flag (i.e., the __GFP_ACCOUNT flag) is analyzed, a low performance overhead can be retained.
[0099] Through the above technical solution, it can be known that by scanning the LLVM IR of the Linux system kernel, a first-class function set related to the memory application operation for the target container and a second-class function set related to the memory accounting operation for the above target container can be first identified, and then the first-class functions in the above-mentioned first-class function set are successively determined as target functions. According to whether there is a second-class function having a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, it can be determined whether there is an abnormality in the memory accounting operation of the Linux memory control group for the above-mentioned target container; thereby realizing automated analysis of the correctness of the memory accounting of the Linux memory control group, quickly and accurately detecting potential memory accounting vulnerabilities, and thus ensuring the security of the Linux system and protecting the interests of tenants and cloud service providers.
[0100] The following describes the present application in combination with a specific application scenario by taking an example in which the first type of function includes functions related to memory release operations for containers, and the second type of function includes functions related to memory clearing operations for containers.
[0101] See also Figure 2 , Figure 2 This is a flowchart of another memory accounting anomaly detection method shown in an exemplary embodiment. The above method can be applied to a terminal device equipped with a Linux system; the above Linux system is equipped with a number of containers corresponding to different tenants and isolated from each other, and a Linux memory control group for memory accounting for the above containers; the above method performs the following steps:
[0102] Step 202: Scan the LLVM IR of the Linux system kernel to identify a first-class function set and a second-class function set for the target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory release operations for the target container; and the second-class function set includes a number of second-class functions related to memory clearing operations for the target container;
[0103] Step 204: determining the first type functions in the first type function set as target functions in sequence, and determining whether there is a second type function in the second type function set that has a mapping relationship with the target function;
[0104] Step 206: If not, it is determined that there is an abnormality in the memory clearing operation of the Linux memory control group for the target container.
[0105] In this specification, the LLVM IR of the Linux system kernel can be scanned to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set may include several first-class functions related to memory release operations for the target container; and the second-class function set may include several second-class functions related to memory clearing operations for the target container.
[0106] In practical applications, by identifying the first type of function set and the second type of function set based on LLVM IR, the positions of all memory release operations and all memory clearing operations for the target container on the corresponding code execution path can be determined respectively; that is, all interfaces with memory release and memory clearing functions in the Linux kernel can be quickly and accurately located, and serve as the basis for subsequent analysis of the mapping relationship between the memory release interface and the memory clearing interface, and detection of whether there are abnormalities in the memory clearing operation.
[0107] For example, an analysis tool mounted on a terminal device may scan the LLVM IR of a Linux system kernel and identify a first set of functions related to a memory release operation for a target container and a second set of functions related to a memory clearing operation for the target container.
[0108] In one embodiment shown, the first type of function may include a basic memory release function and a wrapper function of the basic memory release function; wherein the basic memory release function may include a function for performing memory page release operations on containers; the wrapper function of the basic memory release function may include a function for calling the basic memory release function. The second type of function may include a basic memory clearing function and a wrapper function of the basic memory clearing function; wherein the basic memory clearing function may include a function for performing count reduction operations on a page counter provided by a Linux memory control group, and the page counter may be used for memory accounting for containers; the wrapper function of the basic memory clearing function may include a function for calling the basic memory clearing function.
[0109] During implementation, the process of scanning the LLVM IR of the Linux system kernel and identifying the first and second function sets for the target container may specifically include: scanning the LLVM IR of the Linux system kernel to generate a function relationship call graph of the Linux system kernel; identifying a basic memory release function based on a memory page release operation for the target container, and identifying a basic account clearing function based on a count reduction operation of a page counter in the Linux memory control group for performing memory clearing for the target container; recursively identifying a wrapper function of the basic memory release function and a wrapper function of the basic memory clearing function based on the function relationship call graph; determining the basic memory release function and the wrapper function of the basic memory release function as the first function set for the target container, and determining the basic memory clearing function and the wrapper function of the basic memory clearing function as the second function set for the target container.
[0110] For example, the LLVM IR of the Linux system kernel can be scanned and a corresponding function relationship call graph can be generated; based on the memory page release operation for the target container, the basic memory release function E (such as the __free_pages function, etc.) can be identified, and based on the count increase operation of the page counter in the Linux memory control group for performing memory clearing for the above target container, the basic clearing function F (such as the uncharge function, etc.) can be identified; further, assuming that function G calls the basic memory release function E and function H calls the basic clearing function F, then based on the generated function relationship call graph, the wrapper function G of the basic memory release function E and the wrapper function H of the basic memory clearing function F can be recursively identified; therefore, it can be determined that the first type of function set for the above target container includes the basic memory release function E and the corresponding wrapper function G, and the above second type of function set for the above target container includes the basic clearing function F and the corresponding wrapper function H.
[0111] In addition, it should be noted that, in the implementation mode shown above, the number of basic memory release functions and wrapper functions of basic memory release functions that can be included in the above-mentioned first-category function set, and the number of basic account clearing functions and wrapper functions of basic account clearing functions that can be included in the above-mentioned second-category function set are merely exemplary descriptions and do not limit this specification; in actual applications, the above-mentioned first-category function set and the above-mentioned second-category function set may include a larger number of basic memory release functions, basic account clearing functions, or corresponding wrapper functions.
[0112] In the present specification, after identifying a first-class function set related to the memory release operation for the above-mentioned target container and a second-class function set related to the memory clearing operation for the above-mentioned target container, the first-class functions in the above-mentioned first-class function set can be determined as target functions in turn, and it can be determined whether there is a second-class function in the above-mentioned second-class function set that has a mapping relationship with the above-mentioned target function.
[0113] In actual applications, there is a mapping relationship between the first type of function and the second type of function. It can be understood that in response to calling the first type of function to release the memory page for the target container, the second type of function can be called to perform a memory clearing operation on the memory page released for the target container.
[0114] For example, after identifying the first-class function set and the second-class function set for the target container, the first-class functions in the above-mentioned first-class function set can be determined as target functions in turn, and it is determined whether there is a second-class function in the above-mentioned second-class function set that has a mapping relationship with the above-mentioned target function, that is, it is determined whether there is a second-class function in the above-mentioned second-class function set that can perform memory clearing operations on the memory pages released by calling the above-mentioned target function for the above-mentioned target container.
[0115] Continuing with the above example, after identifying that the first-category function set for the target container includes a basic memory release function E and a corresponding wrapper function G, and that the second-category function set for the target container includes a basic account clearing function F and a corresponding wrapper function H, the basic memory release function E in the first-category function set can be first determined as the target function, and it can be determined whether there is a mapping relationship between the function F and the function H included in the second-category function set and the target function E; similarly, the wrapper function G in the first-category function set can continue to be determined as the target function, and it can be determined whether there is a mapping relationship between the function F and the function H included in the second-category function set and the target function G.
[0116] In this specification, if there is no second-class function having a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, it can be determined that there is an abnormality in the memory clearing operation of the Linux memory control group for the above-mentioned target container; otherwise, it is determined that there is no abnormality in the memory clearing operation of the Linux memory control group for the above-mentioned target container.
[0117] In actual applications, if there is no mapping relationship between the first-class function and the second-class function, it can be considered that, in response to calling the first-class function to release memory pages for the target container, the second-class function is not called to perform a memory clearing operation on the memory pages released for the target container; that is, it can be detected that there is a clearing omission problem in the memory clearing of the target container by the Linux memory control group.
[0118] For example, after determining the first type of function in the above-mentioned first type of function set as the target function, if there is no second type of function in the above-mentioned second type of function set that has a mapping relationship with the above-mentioned target function, it can be determined that there is an abnormality in the memory clearing operation of the Linux memory control group on the target container, and there may be a memory clearing omission problem.
[0119] In one embodiment shown, in addition to detecting memory clearing omissions, memory clearing duplications can also be detected based on the number of second-class functions that have a mapping relationship with the same first-class function, thereby detecting more potential memory clearing anomalies, better ensuring the security of the Linux system, and protecting the interests of tenants and cloud service providers. In implementation, the above method may also include: if there is a second-class function that has a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, then further determining the target number of second-class functions that have a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set; further, it can be determined whether the above-mentioned target number is greater than 1; if it is greater than 1, it is determined that the Linux memory control group has an abnormality in the memory clearing operation for the above-mentioned target container; if it is not greater than 1, it is determined that the Linux memory control group has no abnormality in the memory clearing operation for the above-mentioned target container.
[0120] In practical applications, the target number of the second type of function having a mapping relationship with the target function can be understood as the number of times the Linux memory group calls the second type of function to perform a memory clearing operation on the memory page in response to calling the target function to release the memory page for the target container. It can be seen that if the target number is greater than 1, it can be considered that the Linux memory group has performed multiple memory clearing operations on the same memory page, and there is a problem of repeated memory clearing.
[0121] For example, if there is a second-class function having a mapping relationship with the target function in the second-class function set, the target number of second-class functions having a mapping relationship with the target function in the second-class function set can be determined; if the target number is 2, it can be considered that the Linux memory group has performed two memory clearing operations for calling the target function to release the same memory page for the target container, that is, there may be a memory clearing duplication problem.
[0122] Through the above technical solution, it can be known that by scanning the LLVM IR of the Linux system kernel, a first-class function set related to the memory release operation for the target container and a second-class function set related to the memory clearing operation for the above target container can be first identified, and then the first-class functions in the above-mentioned first-class function set are successively determined as target functions. According to whether there is a second-class function having a mapping relationship with the above-mentioned target function in the above-mentioned second-class function set, it can be determined whether there is an abnormality in the memory clearing operation of the Linux memory control group for the above-mentioned target container; thereby realizing automated analysis of the correctness of the memory clearing of the Linux memory control group, quickly and accurately detecting potential memory clearing vulnerabilities, and thus ensuring the security of the Linux system and protecting the interests of tenants and cloud service providers.
[0123] It can be seen that in the technical solution requested for protection in this specification, on the basis of identifying all interfaces with memory application / release functions and interfaces with memory accounting / clearing functions in the Linux kernel (that is, identifying the above-mentioned first type of function set and the above-mentioned second type of function set), corresponding detection strategies are customized for different types of memory accounting anomalies, and by analyzing the mapping relationship between the above-mentioned two types of interfaces, it can be determined whether the Linux memory control group has normally implemented the memory accounting function.
[0124] Corresponding to the above-mentioned embodiment of the memory accounting anomaly detection method, this specification also provides an embodiment of a memory accounting anomaly detection device.
[0125] See also Figure 3 , Figure 3 This is a hardware structure diagram of an electronic device in which a memory accounting anomaly detection device is located, which is shown as an exemplary embodiment. At the hardware level, the device includes a processor 302, an internal bus 304, a network interface 306, a memory 308, and a non-volatile memory 310, and of course may also include hardware required for other services. One or more embodiments of this specification can be implemented based on software, such as the processor 302 reading the corresponding computer program from the non-volatile memory 310 into the memory 308 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0126] See also Figure 4 , Figure 4 FIG. 1 is a block diagram of a memory accounting anomaly detection device shown in an exemplary embodiment. The memory accounting anomaly detection device can be applied to Figure 3 In the electronic device shown in the figure, the technical solution of this specification is implemented. Among them, the above-mentioned memory accounting anomaly detection device may include:
[0127] The identification unit 402 is used to scan the IR intermediate representation of the LLVM compiler of the Linux system kernel, and identify a first-class function set and a second-class function set for the target container to be detected; wherein the first-class function set includes a plurality of first-class functions related to the memory application operation for the target container; and the second-class function set includes a plurality of second-class functions related to the memory accounting operation for the target container;
[0128] A mapping unit 404 is used to sequentially determine the first type functions in the first type function set as target functions, and determine whether there is a second type function in the second type function set that has a mapping relationship with the target function;
[0129] The determining unit 406 is configured to determine that an abnormality exists in the memory accounting operation of the Linux memory control group for the target container if there is no second-type function having a mapping relationship with the target function in the second-type function set.
[0130] In this embodiment, the determining unit 406 is further configured to:
[0131] If there is a second type function having a mapping relationship with the objective function in the second type function set, further determining a target number of second type functions having a mapping relationship with the objective function in the second type function set;
[0132] Determine whether the above target quantity is greater than 1;
[0133] If the target quantity is greater than 1, it is determined that the memory accounting operation of the Linux memory control group for the target container is abnormal.
[0134] In this embodiment, the determining unit 406 is specifically configured to:
[0135] If there is no second-category function having a mapping relationship with the target function in the second-category function set, further determining whether the __GFP_ACCOUNT flag carried in the target function is set;
[0136] If the __GFP_ACCOUNT flag carried in the target function is not set, it is determined that the memory accounting operation of the Linux memory control group for the target container is abnormal.
[0137] In this embodiment, the first type of function includes a basic memory application function and a wrapper function of the basic memory application function; the second type of function includes a basic memory accounting function and a wrapper function of the basic memory accounting function;
[0138] The identification unit 402 is specifically used for:
[0139] Scan the IR of the LLVM compiler of the Linux system kernel to generate a function relationship call graph of the above Linux system kernel;
[0140] Based on the memory page allocation operation for the target container, a basic memory request function is identified, and based on the count increase operation for a page counter in the Linux memory control group for performing memory accounting for the target container, a basic accounting function is identified;
[0141] Based on the above function relationship call graph, recursively identify the wrapper function of the above basic memory application function and the wrapper function of the above basic memory accounting function, and determine the above basic memory application function and the wrapper function of the above basic memory application function as the above first type of function set for the above target container, and determine the above basic memory accounting function and the wrapper function of the above basic memory accounting function as the above second type of function set for the above target container.
[0142] See also Figure 5 , Figure 5 FIG. 1 is a block diagram of another memory accounting anomaly detection device according to an exemplary embodiment. The memory accounting anomaly detection device can be applied to Figure 3 In the electronic device shown, the technical solution of this specification is implemented.
[0143] The above-mentioned memory accounting anomaly detection device may include:
[0144] The identification unit 502 is used to scan the IR of the LLVM compiler of the Linux system kernel, and identify a first-class function set and a second-class function set for the target container to be detected; wherein the first-class function set includes a plurality of first-class functions related to the memory release operation for the target container; and the second-class function set includes a plurality of second-class functions related to the memory clearing operation for the target container;
[0145] A mapping unit 504 is used to sequentially determine the first type functions in the first type function set as target functions, and determine whether there is a second type function in the second type function set that has a mapping relationship with the target function;
[0146] The determining unit 506 is configured to determine that a memory clearing operation of the Linux memory control group on the target container is abnormal if there is no second-type function having a mapping relationship with the target function in the second-type function set.
[0147] In this embodiment, the determining unit 506 is further configured to:
[0148] If there is a second type function having a mapping relationship with the objective function in the second type function set, further determining a target number of second type functions having a mapping relationship with the objective function in the second type function set;
[0149] Determine whether the above target quantity is greater than 1;
[0150] If the target quantity is greater than 1, it is determined that the memory clearing operation of the Linux memory control group for the target container is abnormal.
[0151] In this embodiment, the first type of function includes a basic memory release function and a wrapper function of the basic memory release function; the second type of function includes a basic memory clearing function and a wrapper function of the basic memory clearing function;
[0152] The identification unit 502 is specifically used for:
[0153] Scan the IR of the LLVM compiler of the Linux system kernel to generate a function relationship call graph of the above Linux system kernel;
[0154] Based on the memory page release operation for the target container, a basic memory release function is identified; and based on the count reduction operation for the page counter in the Linux memory control group for performing memory accounting for the target container, a basic account clearing function is identified;
[0155] Based on the function relationship call graph, a wrapper function of the basic memory release function and a wrapper function of the basic memory clearing function are recursively identified, and the basic memory release function and the wrapper function of the basic memory release function are determined as the first type of function set for the target container, and the basic memory clearing function and the wrapper function of the basic memory clearing function are determined as the second type of function set for the target container.
[0156] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0157] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Ordinary technicians in this field can understand and implement it without paying creative work.
[0158] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0159] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0160] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0161] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0162] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0163] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0164] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "one", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0165] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0166] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A memory accounting anomaly detection method, characterized in that: The method is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the method comprises: Scan the IR intermediate representation of the LLVM compiler of the Linux system kernel to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory application operations for the target container, and the first-class functions include basic memory application functions and wrapper functions of the basic memory application functions; the second-class function set includes a number of second-class functions related to memory accounting operations for the target container, and the second-class functions include basic memory accounting functions and wrapper functions of the basic memory accounting functions; Determine the first type of functions in the first type of function set as target functions in sequence, and determine whether there is a second type of function in the second type of function set that has a mapping relationship with the target function; If there is no second-type function having a mapping relationship with the target function in the second-type function set, it is determined that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container.
2. The method according to claim 1, characterized in that The method further comprises: If there is a second type function having a mapping relationship with the objective function in the second type function set, further determining a target number of second type functions having a mapping relationship with the objective function in the second type function set; Determining whether the target quantity is greater than 1; If the target quantity is greater than 1, it is determined that a memory accounting operation of the Linux memory control group for the target container is abnormal.
3. The method according to claim 1, characterized in that If there is no second type function having a mapping relationship with the target function in the second type function set, determining that there is an abnormality in the memory accounting operation of the Linux memory control group for the target container includes: If there is no second type function having a mapping relationship with the target function in the second type function set, further determining whether the __GFP_ACCOUNT flag carried in the target function is set; If the __GFP_ACCOUNT flag carried in the target function is not set, it is determined that an abnormality exists in the memory accounting operation of the Linux memory control group for the target container.
4. The method according to claim 1, characterized in that: The scanning of the IR intermediate representation of the LLVM compiler of the Linux system kernel to identify the first-class function set and the second-class function set for the target container to be detected includes: Scanning the IR of the LLVM compiler of the Linux system kernel to generate a function relationship call graph of the Linux system kernel; Based on a memory page allocation operation for the target container, a basic memory request function is identified, and based on a count increase operation for a page counter in the Linux memory control group for performing memory accounting for the target container, a basic accounting function is identified; Based on the function relationship call graph, a wrapper function of the basic memory application function and a wrapper function of the basic memory accounting function are recursively identified, and the basic memory application function and the wrapper function of the basic memory application function are determined as the first type of function set for the target container, and the basic memory accounting function and the wrapper function of the basic memory accounting function are determined as the second type of function set for the target container.
5. A memory accounting anomaly detection method, characterized in that: The method is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the method comprises: Scan the IR of the LLVM compiler of the Linux system kernel to identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory release operations for the target container, and the first-class functions include a basic memory release function and a wrapper function of the basic memory release function; the second-class function set includes a number of second-class functions related to memory clearing operations for the target container, and the second-class functions include a basic memory clearing function and a wrapper function of the basic memory clearing function; Determine the first type of functions in the first type of function set as target functions in sequence, and determine whether there is a second type of function in the second type of function set that has a mapping relationship with the target function; If there is no second-type function having a mapping relationship with the target function in the second-type function set, it is determined that there is an abnormality in the memory clearing operation of the Linux memory control group on the target container.
6. The method according to claim 5, characterized in that The method further comprises: If there is a second type function having a mapping relationship with the objective function in the second type function set, further determining a target number of second type functions having a mapping relationship with the objective function in the second type function set; Determining whether the target quantity is greater than 1; If the target quantity is greater than 1, it is determined that a memory clearing operation of the Linux memory control group on the target container is abnormal.
7. The method according to claim 5, characterized in that The scanning of the IR of the LLVM compiler of the Linux system kernel to identify the first type of function set and the second type of function set for the target container to be detected includes: Scanning the IR of the LLVM compiler of the Linux system kernel to generate a function relationship call graph of the Linux system kernel; Based on a memory page release operation for the target container, a basic memory release function is identified, and based on a count reduction operation for a page counter in the Linux memory control group for performing memory accounting for the target container, a basic account clearing function is identified; Based on the function relationship call graph, a wrapper function of the basic memory release function and a wrapper function of the basic memory clearing function are recursively identified, and the basic memory release function and the wrapper function of the basic memory release function are determined as the first type of function set for the target container, and the basic memory clearing function and the wrapper function of the basic memory clearing function are determined as the second type of function set for the target container.
8. A memory accounting anomaly detection device, characterized in that: The device is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the device comprises: An identification unit is used to scan the IR intermediate representation of the LLVM compiler of the Linux system kernel, and identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory application operations for the target container, and the first-class functions include basic memory application functions and wrapper functions of the basic memory application functions; the second-class function set includes a number of second-class functions related to memory accounting operations for the target container, and the second-class functions include basic memory accounting functions and wrapper functions of the basic memory accounting functions; A mapping unit, used to determine the first type functions in the first type function set as target functions in sequence, and determine whether there is a second type function in the second type function set that has a mapping relationship with the target function; A determining unit is configured to determine that an abnormality exists in a memory accounting operation of the Linux memory control group for the target container if there is no second-type function having a mapping relationship with the target function in the second-type function set.
9. A memory accounting anomaly detection device, characterized in that: The device is applied to a terminal device equipped with a Linux system; the Linux system is equipped with a plurality of mutually isolated containers corresponding to different tenants, and a Linux memory control group for performing memory accounting for the plurality of containers; the device comprises: An identification unit is used to scan the IR of the LLVM compiler of the Linux system kernel, and identify a first-class function set and a second-class function set for a target container to be detected; wherein the first-class function set includes a number of first-class functions related to memory release operations for the target container, and the first-class functions include a basic memory release function and a wrapper function of the basic memory release function; the second-class function set includes a number of second-class functions related to memory clearing operations for the target container, and the second-class functions include a basic memory clearing function and a wrapper function of the basic memory clearing function; A mapping unit, used to determine the first type functions in the first type function set as target functions in sequence, and determine whether there is a second type function in the second type function set that has a mapping relationship with the target function; A determining unit is configured to determine that a memory clearing operation of the Linux memory control group on the target container is abnormal if there is no second-type function having a mapping relationship with the target function in the second-type function set.
10. An electronic device, characterized in that: It includes a communication interface, a processor, a memory and a bus, wherein the communication interface, the processor and the memory are interconnected via the bus; The memory stores machine-readable instructions, and the processor executes the method of any one of claims 1-4 or claims 5-7 by calling the machine-readable instructions.
11. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-readable instructions, and when the machine-readable instructions are called and executed by a processor, the method of any one of claims 1-4 or claims 5-7 is implemented.
