A dynamic measurement method for kernel-level processes in Linux
By importing the measurement file in the LINUX operating system and comparing the hash value of the executable ELF file, the existing technology solves the security problem of being unable to guarantee the entire execution process, realizes dynamic measurement of the executable ELF file, and ensures the security of the code. Completeness and robustness.
Patent Information
- Application Number
- CN202111445262.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-11-30
AI Technical Summary
Existing dynamic measurement methods can only measure the executable file before it is executed, and cannot guarantee the security of the entire execution process. An attacker can modify the executable code at runtime without triggering a page fault exception, which poses security risks.
Provides a LINUX kernel-level process dynamic measurement method. By importing measurement files in the LINUX operating system, it obtains and compares the hash values of different code segments of the executable ELF file, generates alarm logs to prevent tampering, and during program execution. Measure periodically to ensure code integrity.
It realizes the dynamic measurement of the entire execution process of the executable ELF file, avoids frequent function call level dynamic measurement, and does not need to modify a large amount of kernel code. It can be made into a plug-in module, which improves the robustness and practicality.
Smart Images

Figure CN114168934B
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of computer science, and in particular to a LINUX kernel-level process dynamic measurement method. Background Art
[0002] With the development of science and technology, technology is also advancing by leaps and bounds, and hacker techniques have also changed significantly. Now many hackers no longer use file replacement to attack, but look for loopholes and directly modify memory data to achieve the purpose of invading the system, which puts higher requirements on host protection.
[0003] To this end, static measurement and dynamic measurement methods are generally used for protection.
[0004] The static measurement method refers to the control method of verifying whether the measurement value is consistent with the measurement value at a certain point in time when the process is created. This cannot meet the new requirements of current host protection. When performing static measurement, it is necessary to regularly scan the key memory parts of all processes. This technology cannot detect the modified process in the first time, and there is a great security risk; when performing static measurement, it is also necessary to detect jump or call assembly jump instructions. When encountering these sensitive jump instructions, the memory where the code segment after the jump is located will cause frequent measurement, which is inefficient; when performing static measurement, it is also necessary to map the memory of all processes to the high-end memory area, and then create a new kernel thread to measure these memories. This method has high requirements for synchronous access and has a greater risk of causing deadlock. At the same time, it requires a lot of modification of the kernel source code, and it is not suitable to be written as a plug-in module.
[0005] Dynamic measurement is an important method to ensure the integrity of program operation. Dynamic measurement achieves trustworthy and secure execution of programs by performing corresponding integrity measurements on programs at runtime, ensuring that the execution results of programs meet expectations. In an operating system, when a program executable file is loaded into memory and is being or waiting to be executed, its executable code segment should be the same as the preset executable file. If a change occurs, it means that the executable code has been abnormally modified, which will lead to incomplete program execution and unreliable program execution results. By measuring the executable code of the program, it can be ensured that the executable code has not been tampered with by attackers, ensuring the integrity of the program. The memory of the operating system is allocated and managed in units of memory pages, and the executable code of the program is also loaded into the memory in units of memory pages. When the operating system scheduler schedules and selects the process to be executed, the scheduler will point the control pointer (PC pointer) to the memory address of the executable code of the process to be executed.
[0006] However, existing dynamic measurement methods only measure executable files before they are executed, allowing attackers to modify executable code while it is running without triggering a page fault exception.
[0007] Therefore, it is necessary to provide a dynamic measurement method to ensure the security of the entire execution process of the executable file. Summary of the invention
[0008] Technical issues solved
[0009] In view of the above shortcomings of the prior art, the present invention provides a LINUX kernel-level process dynamic measurement method, which dynamically measures the execution process of an executable ELF file for the LINUX operating system to ensure that the executable ELF file is not tampered with during the entire execution process.
[0010] Technical Solution
[0011] To achieve the above objectives, the present invention is implemented through the following technical solutions:
[0012] The present invention provides a LINUX kernel-level process dynamic measurement method, comprising the following steps:
[0013] S1, importing a measurement file into the kernel state of LINUX, wherein the measurement file includes a preset executable ELF file;
[0014] S2, when executing a program and obtaining a first code of an executable ELF file of the program, simultaneously obtaining a first preset code corresponding to the first code in the measurement file, and generating an alarm log if the first code is inconsistent with the first preset code, otherwise not generating an alarm log;
[0015] S3, when running the program and verifying the correctness of the bprm file of the program, the second code read from the executable ELF file is compared with the second preset code corresponding to the second code in the measurement file, and if they are inconsistent, an alarm log is generated, otherwise no alarm log is generated;
[0016] S4. After the program calls the __schedule() function, the third code included in the process pointed to by the current macro is compared with the third preset code corresponding to the third code in the measurement file. If they are inconsistent, an alarm log is generated, otherwise no alarm log is generated.
[0017] Furthermore, the code segments and data segments of the executable ELF file preset in the metric file are hashed to obtain and store the hash values of each code segment and data segment.
[0018] Furthermore, by performing hash calculation on the first code, the second code and the third code, respective hash values are obtained, and compared with the hash values stored in the measurement file, so as to find the corresponding first preset code, the second preset code and the third preset code.
[0019] Further, the step of importing the measurement file into the kernel state of LINUX specifically includes:
[0020] When a LINUX-based machine is started, the measurement file is imported into the kernel state of LINUX using the mmap() function through the procfs interface.
[0021] Further, the first code of obtaining the executable ELF file of the program specifically includes:
[0022] Before the sched_exec() function, the get_user_pages() function is used to obtain the first code of the executable ELF file of the program.
[0023] Furthermore, verifying the correctness of the bprm file refers to calling the function pointed to by the security_bprm_check function pointer of the Linux security module to verify the correctness of the bprm file.
[0024] Furthermore, the program calling the __schedule() function means that the periodic scheduler and / or load balancing of the program calls the __schedule() function.
[0025] Based on the same inventive concept, the present invention provides an electronic device, including a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, any of the methods described above is implemented.
[0026] Based on the same inventive concept, the present invention provides a readable storage medium, wherein the readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the above-mentioned methods is implemented.
[0027] Beneficial Effects
[0028] Compared with the known public technology, the technical solution provided by the present invention has the following beneficial effects:
[0029] 1) The dynamic measurement method provided by the present invention is aimed at the LINUX operating system, and dynamically measures the execution process of the executable ELF file to ensure that the executable ELF file is not tampered with during the entire execution process.
[0030] 2) The present invention can dynamically measure the process while avoiding frequent dynamic measurement at the function call level, and will not modify a large amount of kernel code. It can be made into a plug-in module with good robustness and practicality. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0032] Figure 1 A schematic diagram of the steps of a method for dynamically measuring a kernel-level process of LINUX provided by an embodiment of the present invention;
[0033] Figure 2 A schematic flow chart of a method for dynamically measuring a kernel-level process in LINUX provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0035] First, some technical terms mentioned in the present invention are explained:
[0036] ELF file: In computer science, it is a file format used for binary files, executable files, object code, shared libraries, and core dumps. ELF files were developed and released by the UNIX System Laboratory (USL) as an Application Binary Interface (ABI), and are also the main executable file format for Linux. ELF files consist of four parts, namely the ELF header, program header table, section, and section header table. In fact, a file may not contain all the contents, and their positions may not be arranged as shown. Only the position of the ELF header is fixed, and the position, size, and other information of the remaining parts are determined by the values in the ELF header.
[0037] LSM: Linux Security Module (LSM) is a lightweight universal access control framework for the Linux kernel. It enables various security access control models to be implemented in the form of Linux loadable kernel modules. Users can select appropriate security modules to load into the Linux kernel according to their needs, thereby greatly improving the flexibility and usability of the Linux security access control mechanism. The design of Linux Security Module (LSM) must try to meet the requirements of two parties: to minimize the trouble for those who do not need it; and to provide useful and efficient functions for those who need it.
[0038] Domestic hash algorithm (SM3): SM3 is a cryptographic hash function standard adopted by the government of the People's Republic of China, issued by the State Cryptography Administration on December 17, 2010. The relevant standard is "GM / T 0004-2012 SM3 Cryptographic Hash Algorithm". In the commercial cryptographic system, SM3 is mainly used for digital signature and verification, message authentication code generation and verification, random number generation, etc. Its algorithm is public. According to the State Cryptography Administration, its security and efficiency are equivalent to SHA-256.
[0039] See also Figure 1 An embodiment of the present invention provides a LINUX kernel-level process dynamic measurement method, comprising the following steps:
[0040] S1, importing a measurement file into the kernel state of LINUX, wherein the measurement file includes a preset executable ELF file;
[0041] S2, when executing a program and obtaining a first code of an executable ELF file of the program, simultaneously obtaining a first preset code corresponding to the first code in the measurement file, and generating an alarm log if the first code is inconsistent with the first preset code, otherwise not generating an alarm log;
[0042] S3, when running the program and verifying the correctness of the bprm file of the program, the second code read from the executable ELF file is compared with the second preset code corresponding to the second code in the measurement file, and if they are inconsistent, an alarm log is generated, otherwise no alarm log is generated;
[0043] S4. After the program calls the __schedule() function, the third code included in the process pointed to by the current macro is compared with the third preset code corresponding to the third code in the measurement file. If they are inconsistent, an alarm log is generated, otherwise no alarm log is generated.
[0044] When implementing it, the preparation work is as follows:
[0045] You can use the CentOS7.5 operating system and kernel-3.10.0-862.el7.src.rpm source code package to download the domestic hash algorithm, compile it into a so dynamic library, and transplant the domestic hash algorithm to the kernel-state program of LINUX, and compile it into a KO kernel module. The user-state program of LINUX scans all executable ELF files in the system, performs domestic hash calculations on the code segments and data segments of the executable ELF files found, and obtains the hash values of each code segment and data segment. The executable ELF files found, that is, the preset executable ELF files, and the hash values of each code segment and data segment are stored in the measurement file for subsequent dynamic measurement. The hash value is for the location of the code segment and data segment.
[0046] In this embodiment, see Figure 1 and Figure 2 For step S1, generally when a LINUX-based machine is started, the measurement file is imported into the kernel state of LINUX through the procfs interface using the mmap() function.
[0047] In this embodiment, see Figure 2 , step S2 is actually the process of dynamic measurement of the program when it is loaded, and the process specifically includes: when executing a program, before the sched_exec() function, use the get_user_pages() function to obtain the stack segment and code segment in the memory, which can be called the first code, and calculate the hash value of the first code through the kernel-state domestic hash software algorithm, and then find the corresponding first preset code in the measurement file through hash value comparison, and then measure the first code and the first preset code. When the comparison is inconsistent, an alarm log is generated.
[0048] In this embodiment, see Figure 2 , step S3 is actually a dynamic measurement of the program during the process of running the process creation, specifically including: when the program is running, the kernel state of LINUX will choose to call the function pointed to by the security_bprm_check function pointer of the LSM technology to verify the correctness of the bprm file. During the operation of the security_bprm_check function, the code segment and stack segment will be read from the executable ELF file, which is called the second code. The hash value of the second code is calculated through the kernel state domestic hash software algorithm, and then the corresponding second preset code in the measurement file is found through hash value comparison, and then the second code and the second preset code are measured. When the comparison is inconsistent, an alarm log is generated.
[0049] In this embodiment, see Figure 2, step S3 is actually a dynamic measurement of scheduling during the program running process, specifically including: LINUX kernel state has periodic scheduler and load balancing mechanisms. Both will call the __schedule() function, in which the pick_next_task() function will be used to select the next process entity to be scheduled. Use the kallsyms_lookup_name() function to find the address of the __schedule() function. After the execution of this function, the code segment and stack segment contained in the process pointed to by the current macro are called the third code. The hash value of the third code is calculated through the domestic hash software algorithm in the kernel state, and then the corresponding third preset code in the measurement file is found through hash value comparison, and then the third code and the third preset code are measured. When the comparison is inconsistent, an alarm log is generated. In this dynamic measurement, since the scheduling is relatively frequent, it can be set to measure once every 30 seconds.
[0050] Based on the same inventive concept, the present invention also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the program implements the LINUX kernel-level process dynamic measurement method.
[0051] The processor may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor (e.g., a GPU (Graphics Processing Unit)), or other data processing chips in some embodiments. The processor is generally used to control the overall operation of the electronic device. In this embodiment, the processor is used to run the program code stored in the memory or process data, such as running the program code of the kernel-level process dynamic measurement method of the LINUX.
[0052] The memory includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory can be an internal storage unit of the electronic device, such as a hard disk or memory of the electronic device. In other embodiments, the memory can also be an external storage device of the electronic device, such as a plug-in hard disk equipped on the electronic device, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory can also include both the internal storage unit of the electronic device and its external storage device. In this embodiment, the memory is generally used to store the operating method and various application software installed in the electronic device, such as the kernel-level process dynamic measurement method code of the LINUX, etc. In addition, the memory can also be used to temporarily store various types of data that have been output or are to be output.
[0053] Based on the same inventive concept, the present invention also provides a readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, a kernel-level process dynamic measurement method of LINUX is implemented.
[0054] The advantages of the present invention are that the dynamic measurement method provided is for the LINUX operating system, and dynamically measures the execution process of the executable ELF file, ensuring that the executable ELF file is not tampered with during the entire execution process. In addition, the process can be dynamically measured, while avoiding frequent dynamic measurement at the function call level, and a large amount of kernel code will not be modified, and the method can be made into a plug-in module, with good robustness and practicality.
[0055] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements will not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
Claims
1. A LINUX kernel-level process dynamic measurement method, characterized in that: The steps include: S1, importing a measurement file into the kernel state of LINUX, wherein the measurement file includes a preset executable ELF file; S2, when executing a program and obtaining a first code of an executable ELF file of the program, simultaneously obtaining a first preset code corresponding to the first code in the measurement file, and generating an alarm log if the first code is inconsistent with the first preset code, otherwise not generating an alarm log; S3, when running the program and verifying the correctness of the bprm file of the program, the second code read from the executable ELF file is compared with the second preset code corresponding to the second code in the measurement file, and if they are inconsistent, an alarm log is generated, otherwise no alarm log is generated; S4, after the program calls the __schedule() function, the third code included in the process pointed to by the current macro is compared with the third preset code corresponding to the third code in the measurement file. If they are inconsistent, an alarm log is generated, otherwise no alarm log is generated; The method further comprises: Hash calculation is performed on the code segment and data segment of the executable ELF file preset in the measurement file, and the hash value of each code segment and data segment is obtained and stored, specifically: using the CentOS7.5 operating system and the kernel-3.10.0-862.el7.src.rpm source code package, downloading the domestic hash algorithm, compiling it into an so dynamic library, and transplanting the domestic hash algorithm into the kernel state program of LINUX, and compiling it into a KO kernel module; the user state program of LINUX scans all the executable ELF files in the system, and performs domestic hash calculation on the code segment and data segment of the found executable ELF file to obtain the hash value of each code segment and data segment; the found executable ELF file, that is, the preset executable ELF file, and the hash value of each code segment and data segment are stored in the measurement file for subsequent dynamic measurement, and the hash value is for locating the code segment and the data segment; In the steps S2, S3 and S4, the first code, the second code and the third code are hashed to obtain respective hash values, and the hash values are compared with the hash values stored in the measurement file, so as to find the corresponding first preset code, the second preset code and the third preset code; The first code for obtaining the executable ELF file of the program specifically includes: Before the sched_exec() function, the get_user_pages() function is used to obtain the first code of the executable ELF file of the program.
2. The LINUX kernel-level process dynamic measurement method according to claim 1, characterized in that: The step of importing the measurement file into the kernel state of LINUX specifically includes: When a LINUX-based machine is started, the measurement file is imported into the kernel state of LINUX using the mmap() function through the procfs interface.
3. The LINUX kernel-level process dynamic measurement method according to claim 1, characterized in that: The verification of the correctness of the bprm file of the program refers to calling the function pointed to by the security_bprm_check function pointer of the Linux security module to verify the correctness of the bprm file.
4. The LINUX kernel-level process dynamic measurement method according to claim 1, characterized in that: The program calling the __schedule() function means that the periodic scheduler and / or load balancing of the program calls the __schedule() function.
5. An electronic device, characterized in that: The method comprises a processor and a memory, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the method according to any one of claims 1 to 4 is implemented.
6. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
