Trusted measurement method based on eBPF and TEE technologies
Through the CO-RE characteristics and TEE technology of eBPF technology, the process is verified with confidence without modifying the Linux kernel code, which solves the compatibility and kernel stability problems in the existing technology, and improves the operating system Stability and safety.
Patent Information
- Application Number
- CN202411460100.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-02-14
AI Technical Summary
The existing trusted metrics technology has compatibility problems in Linux kernel iteration, and LSM technology poses risks to kernel stability and security.
Using the CO-RE characteristics of eBPF technology and combining TEE technology, it realizes reliable measurement of the process without modifying the kernel code. Through the cooperation of the eBPF kernel program and user programs, data transmission is carried out using ring_buff and hash maps. and check.
Compatibility between different kernel versions is achieved, kernel modification is avoided, operating system stability and security is improved, and data security is ensured through TEE technology.
Smart Images

Figure CN119442247A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of information security, and in particular relates to trusted computing. Background Art
[0002] The existing trusted measurement technology mainly uses LSM technology alone, and uses LSM hook functions to monitor and track certain system calls to achieve trusted measurement of processes. This technology has some shortcomings in trusted measurement of processes. For example, with the continuous iteration of the Linux kernel, the use of LSM technology will bring compatibility issues, which in turn brings a huge adaptation workload to cope with the continuous expansion of the trusted computing market. The present invention solves this problem by utilizing the CO-RE (CompileOnce, RunEverywhere) feature of eBPF technology; LSM technology modifies the operating system kernel, which brings certain risks to the stability and security of the operating system. The present invention avoids modifying the kernel by using eBPF technology, and uses TEE technology to ensure data security. Summary of the invention
[0003] The present invention provides a trusted measurement method for operating system application processes, which can be compatible with multiple versions of kernels to perform trusted measurement on processes without modifying the kernel code, thereby improving the stability and security of the operating system. The present invention improves on the existing trusted software infrastructure, introduces eBPF technology and TEE technology to obtain a trusted measurement method with high adaptability, greater security and stability.
[0004] The application process trust measurement method provided by the present invention is based on TEE technology and eBPF technology, and the specific scheme includes:
[0005] 1. Get the path of the executable file called when the process starts;
[0006] a) The eBPF kernel program that obtains the executable file path is mounted on the bprm_check_security, mmap_file, and kernel_read_file kernel functions, which are responsible for tracking the calls of binary files, so files, and ko files, respectively, and obtaining the file path.
[0007] b) When the binary file is running, the bprm_check_security kernel function will be called, and the structlinux_binprm structure will be sent to the eBPF kernel program. The eBPF program will take out the file path from the struct linux_binprm structure, store the file pid and path in the structure struct event, upload it to bprm_ringbuf, and wait for the eBPF user program to process it. Then, it will be uploaded to mark_map with pid as the key and the structure struct flag_struct as the value. The structure struct flag_struct stores check and ret to record whether the user layer check is completed and the check result respectively. Check mark_map cyclically. If check = 0, it means that the user layer check is completed. Then check ret. If ret = 0, it means that the check is successful and the file can be run. Otherwise, it means that the file check is wrong.
[0008] c) When the so file is running, the mmap_file function will be called, and the struct file structure will be sent to the eBPF kernel program. The eBPF kernel program will indirectly extract the file path from the struct file, store the file pid and path in the structure struct event, upload it to mmap_ringbuf, and wait for the eBPF user program to process it. Then, pid is used as the key and the structure struct flag_struct is used as the value to upload it to mark_map, where the structure struct flag_struct stores check and ret to record whether the user layer check is completed and the check result respectively. Check mark_map in a loop. If check = 0, it means that the user layer check is completed. Then check ret. If ret = 0, it means that the check is successful and the file can be run. Otherwise, it means that the file check is wrong.
[0009] d) kernel_read_file, when the ko file is running, the kernel_read_file kernel function will be called, and the struct file structure will be sent to the eBPF kernel program. The eBPF kernel program will indirectly extract the file path from the struct file, store the file pid and path in the structure struct event, upload it to kernel_ringbuf, and wait for the eBPF user program to process it. Then, pid is used as the key and the structure struct flag_struct is used as the value to upload it to mark_map, where the structure struct flag_struct stores check and ret to record whether the user layer check is completed and the check result respectively. Check mark_map cyclically. If check = 0, it means that the user layer check is completed. Then check ret. If ret = 0, it means that the check is successful and the file can be run. Otherwise, it means that the file check is wrong.
[0010] e) Since the file path is not directly stored in the struct file, the entire file path needs to be obtained indirectly from it. The struct file stores the struct path structure, which is used to represent the file system path in the Linux kernel. It contains two fields: struct vfsmount*mnt: a pointer to the virtual file system mount point, indicating the mount point where the file or directory is located. struct dentry*dentry: a pointer to the directory entry, indicating the actual entry of the file or directory. First, take out the dentry structure. The struct dentry structure contains the directory entry information of the file, as well as a pointer to the parent directory entry. Therefore, by traversing the parent directory entry pointer of the dentry structure, the complete path of the file can be obtained step by step. When the parent node is empty, it means that the traversal has reached the root node and the loop ends.
[0011] f) The communication between the eBPF kernel program and the user program uses a map of type ring_buff. In the eBPF kernel program, the map definition macro is used to create a ring_buff, which contains two data items in an anonymous structure: __uint(type, BPF_MAP_TYPE_RINGBUF) and __uint(max_entries, 256*1024). The former specifies that the map type is BPF_MAP_TYPE_RINGBUF, indicating that this is a Ring Buffer; the latter defines the maximum number of entries in the ring_buf, which is set to 256*1024, or 256KB. After obtaining the file path information in the eBPF kernel program, the bpf_ring_buffer_reserve function is used to reserve the corresponding space for the data to be stored, and finally the bpf_ring_buffer_submit function is used to submit the data of the ring_buff so that it can be read by the eBPF user program. At the same time, the mark_map that the eBPF kernel program checks cyclically is a map of type BPF_MAP_TYPE_HASH, which stores the inspection results of the executable file. The eBPF kernel program decides whether to allow the application to execute based on the data in it;
[0012] 2. The eBPF user program reads the file path data sent by the kernel program and sends it to the TEE environment;
[0013] a) After loading the eBPF kernel program, the eBPF user program searches for the loaded map by name through the bpf_object__find_map_by_name method, including bprm_ringbuf, mmap_ringbuf, and kernel_ringbuf, and returns the pointer of the corresponding map. Then, the bpf_map__fd method is used to obtain the file descriptor corresponding to the map. Finally, the ring_buffer__new method is used to obtain the data of bprm_ringbuf, mmap_ringbuf, and kernel_ringbuf submitted by the kernel space, and the callback function is used to further process the data.
[0014] b) For binary files, the eBPF user program reads data from bprm_ringbuf and stores it in structevent. After obtaining the file path, the file path information is sent to the trusted software base kernel module in the TEE environment by using NetLink technology, and waits for the judgment result of the trusted software base.
[0015] c) For the so file, the eBPF user program reads data from mmap_ringbuf and stores it in struct event. After obtaining the file path, the file path information is sent to the trusted software base kernel module in the TEE environment by using NetLink technology, and waits for the judgment result of the trusted software base.
[0016] d) For the ko file, the eBPF user program reads data from kernel_ringbuf and stores it in struct event. After obtaining the file path, the file path information is sent to the trusted software base kernel module in the TEE environment by using NetLink technology, and waits for the judgment result of the trusted software base.
[0017] 3. Determine the executable file digest value based on the executable file path in the TEE environment;
[0018] The trusted software base in TEE obtains the executable file path transmitted from the user space through NetLink communication, and calculates the summary value of the executable file using the sm3 algorithm through the trusted cryptographic module.
[0019] 4. Compare the summary value with the trusted reference library to check whether the file has been tampered with;
[0020] Compare the digest value calculated in step 3 with the trusted reference library data to determine whether the file has been modified. The return value is determined according to the judgment structure, 0 for unmodified and -1 for modified.
[0021] 5. Send the comparison results to the eBPF kernel program;
[0022] The return result of step 4 is sent back to the user space through NetLink communication. The eBPF program in the user space fills the judgment result of the trusted software base into mark_map in the callback function mentioned in step a) of step 2; in the callback function of the eBPF user program, the bpf_object__find_map_by_name method is used to find the hash type map named mark_map, and then the bpf_map__fd method is used to get the file descriptor of mark_map. Finally, the comparison result is updated to mark_map through the bpf_map_update_elem method and sent to the eBPF kernel program.
[0023] 6. The eBPF kernel program reads the mark_map data to determine the execution of the file;
[0024] When the eBPF user program updates the mark_map data, the eBPF kernel program immediately reads the judgment result of the trusted software base in the TEE through the bpf_map_lookup_elem method, and decides whether to allow the execution of the file based on the result. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 This is a schematic diagram of the architecture of the present invention that introduces the eBPF technology based on the existing trusted software base;
[0026] Figure 2 It is a flow chart of a trusted measurement method based on eBPF technology provided by the present invention;
[0027] Figure 3 It is a flowchart of the eBPF kernel program provided by the present invention;
[0028] Figure 4 The present invention provides a schematic diagram of the eBPF user program flow; DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solutions and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the present invention.
[0030] First, let’s introduce the following contents:
[0031] 1. eBPF technology
[0032] eBPF is a mechanism for executing secure and efficient programs in the Linux kernel. It allows users to inject custom code at runtime without modifying the kernel source code, dynamically expanding the kernel's functionality. eBPF technology is widely used in filtering and processing network packets, tracking system events, performance monitoring, security auditing, and other aspects.
[0033] eBPF can dynamically load and execute secure, restricted programs in the kernel without recompiling the kernel. eBPF programs are subject to strict security restrictions when loaded and executed. They run in kernel mode and are protected by a strict security sandbox mechanism, which does not allow damage to the system or leakage of sensitive information. This makes eBPF a safe and trusted way to extend kernel functionality.
[0034] Libbpf is one of the tool chains that implement eBPF technology. It has the feature of "Compile Once Run Everywhere" (CO-RE), which makes eBPF programs highly portable. Once an eBPF program is compiled into bytecode, it can run in any kernel with the BTF function enabled without recompiling or modifying the code.
[0035] 2. Related technologies
[0036] The existing trust measurement technology mainly uses LSM technology alone, and uses LSM hook functions to monitor and track certain system calls to achieve trust measurement of the process.
[0037] The existing related technologies have some shortcomings in the trusted measurement of processes. For example, with the continuous iteration of the Linux kernel, the use of LSM technology will bring compatibility issues, which in turn brings a huge adaptation workload to cope with the continuous expansion of the trusted computing market. The present invention introduces eBPF technology and uses its CO-RE (Compile Once, Run Everywhere) feature to enable the security measurement of the trusted software base to run on different kernel versions without redevelopment for each platform; LSM technology modifies the operating system kernel, which brings certain risks to the stability and security of the operating system. The present invention avoids modifying the kernel by using eBPF technology, and uses TEE technology to ensure data security.
[0038] The following describes the trust measurement method based on eBPF technology and TEE technology provided by the present invention in conjunction with the accompanying drawings.
[0039] Figure 1 This is a schematic diagram of the architecture of the present invention based on the existing trusted software base introducing eBPF technology, such as Figure 1 The method shown introduces eBPF technology in the middle layer between the executable file and the trusted software base. The eBPF program is divided into two parts: the kernel program and the user program. The eBPF kernel program is responsible for monitoring the executable file and controlling whether it is executed; the eBPF user program is responsible for interacting with the trusted software base in the TEE. Through the cooperation between the eBPF kernel program, the user program and the trusted software base, the trusted measurement of the executable file is completed, and whether it can be run is further controlled.
[0040] Figure 2 FIG. 1 is a flow chart of a trust measurement method based on eBPF technology provided by the present invention, such as Figure 2 As shown, in one embodiment of the present invention, performing a trust measurement on an executable file includes the following steps:
[0041] a) The eBPF user program dynamically loads the eBPF kernel program into the kernel
[0042] b) The eBPF kernel program is loaded into the bprm_check_security, mmap_file, and kernel_read_file kernel functions to monitor the executable program
[0043] c) Get the file path by monitoring the relevant kernel functions and put the path into the map1 of the ringbuff type; at the same time, loop and check the map2 of the hash type
[0044] d) The eBPF user program gets the file path from map1
[0045] e) The eBPF user program sends the path information to the trusted software base module by using NetLink technology
[0046] f) The trusted software base module accepts the executable file path sent by the eBPF user program through NetLink technology, and uses the SM3 algorithm of the trusted cryptographic module to measure the integrity of the executable file
[0047] g) Query the trusted benchmark library to obtain the correct measurement value of the executable file and compare it with the measurement value calculated in step f)
[0048] h) Return the metric comparison results to the eBPF user program
[0049] i) The eBPF user program writes the measurement results into map2
[0050] j) The eBPF kernel program checks map2 and decides whether the file can be executed based on the measurement results. If the measurement is successful, the file can be executed. If not, the file execution is terminated.
[0051] Figure 3 The present invention provides a flow chart of the eBPF kernel program, such as Figure 3 As shown, in one embodiment of the present invention, the eBPF kernel program includes the following steps:
[0052] a) When the executable file is executed, the bprm_check_security, mmap_file, and kernel_read_file kernel functions are used to trigger the eBPF kernel program
[0053] b) The eBPF kernel program gets the struct linux_binprm / structfile structure
[0054] c) Get the file path from the structure
[0055] d) Put the file path into map1 and submit it to the eBPF user program through the bpf_ringbuf_reserve and bpf_ringbuf_submit functions
[0056] e) Use the bpf_map_update_elem function to put pid as the key and the structure containing intcheck and intret as the value into map2
[0057] f) Loop to check the values of check and ret in map2
[0058] g) First check whether check is 0, indicating whether the file check is complete
[0059] h) After the file check is completed, the value of ret is taken. If ret is 0, it means that the file is executable after passing the measurement. Otherwise, it cannot be executed.
[0060] Figure 4 The present invention provides a flow chart of the eBPF user program, such as Figure 4 As shown, in one embodiment of the present invention, the eBPF user program includes the following steps:
[0061] a) The eBPF user program uses the bpf_object__open function to open the compiled eBPF kernel program file, and then uses the bpf_object_load function to complete the loading of the eBPF kernel program
[0062] b) Use the bpf_object__find_map_by_name function to get the pointer of map1, and use bpf_map__fd to get the file descriptor of map1. Finally, use the ring_buffer__new method to create ringbuff and get the file path in map1 in the callback function.
[0063] c) Use NetLink to send the file path to the trusted software base and wait for the measurement results to be received
[0064] d) After getting the measurement result, set check = 0 and set the value of ret according to the measurement result
[0065] e) Get the pointer of map2 through the bpf_object__find_map_by_name function, get the map2 file descriptor through the bpf_map__fd function, and finally upload the measurement results to map2 through the bpf_map_update_elem function.
Claims
1. A trusted measurement method based on eBPF and TEE technology, characterized in that include: 1) Get the path of the executable file called when the process starts; a) The eBPF kernel program that obtains the executable file path is mounted on the bprm_check_security, mmap_file, and kernel_read_file kernel functions, which are responsible for tracking the calls of binary files, so files, and ko files, respectively, and obtaining the file path; b) When the binary file is running, the bprm_check_security kernel function will be called, and the struct linux_binprm structure will be sent to the eBPF kernel program. The eBPF program will take out the file path from the struct linux_binprm structure, store the file pid and path in the structure struct event, upload it to the bprm_ringbuf, and wait for the eBPF user program to process it; then, the pid is used as the key and the structure struct flag_struct is used as the value to upload it to the mark_map, where the structure struct flag_struct stores check and ret to record whether the user layer check is completed and the check result respectively; the mark_map is checked cyclically. If check = 0, it means that the user layer check is completed, and then ret is checked. If ret = 0, it means that the check is successful and the file can be run, otherwise it means that the file check is wrong; c) When the so file is running, the mmap_file function will be called, and the struct file structure will be sent to the eBPF kernel program. The eBPF kernel program will indirectly take out the file path from the struct file, store the file pid and path in the structure struct event, upload it to the mmap_ringbuf, and wait for the eBPF user program to process it; then, the pid is used as the key and the structure struct flag_struct is used as the value to upload it to the mark_map, where the structure struct flag_struct saves check and ret to record whether the user layer check is completed and the check result respectively; the mark_map is checked cyclically. If check = 0, it means that the user layer check is completed, and then ret is checked. If ret = 0, it means that the check is successful and the file can be run, otherwise it means that the file check is wrong; d) kernel_read_file, when the ko file runs, the kernel_read_file kernel function is called, and the struct file structure is sent to the eBPF kernel program. The eBPF kernel program indirectly takes out the file path from the struct file, stores the file pid and path in the structure struct event, uploads it to kernel_ringbuf, and waits for the eBPF user program to process it; then, pid is used as the key and the structure struct flag_struct is used as the value to upload it to mark_map, where the structure struct flag_struct stores check and ret to record whether the user layer check is completed and the check result respectively; the mark_map is checked cyclically, if check = 0, it means that the user layer check is completed, and then ret is checked. If ret = 0, it means that the check is successful and the file can be run, otherwise it means that the file check is wrong; e) Since the file path is not directly stored in struct file, the entire file path needs to be obtained indirectly from it; the struct file stores the struct path structure, which is used to represent the file system path in the Linux kernel; it contains two fields: struct vfsmount*mnt: a pointer to the virtual file system mount point, indicating the mount point where the file or directory is located; struct dentry*dentry: a pointer to the directory entry, indicating the actual entry of the file or directory; first take out the dentry structure, which contains the directory entry information of the file and also includes a pointer to the parent directory entry; so by traversing the parent directory entry pointer of the dentry structure, the complete path of the file can be obtained step by step; when the parent node is empty, it means that the traversal has reached the root node and the loop ends; f) The communication between the eBPF kernel program and the user program uses a map of type ring_buff. In the eBPF kernel program, a map definition macro is used to create a ring_buff, which contains two data items __uint(type, BPF_MAP_TYPE_RINGBUF) and __uint(max_entries, 256*1024) in an anonymous structure. The former specifies that the map type is BPF_MAP_TYPE_RINGBUF, indicating that this is a Ring Buffer; the latter defines the maximum number of entries in ring_buf, which is set to 256*1024, i.e. 256KB; after getting the file path information in the eBPF kernel program, the corresponding space is reserved for the data to be stored by using the bpf_ring_buffer_reserve function, and finally the data of ring_buff is submitted by the bpf_ring_buffer_submit function so that it can be read by the eBPF user program; at the same time, the mark_map that the eBPF kernel program checks cyclically is a map of type BPF_MAP_TYPE_HASH, which stores the inspection results of the executable file. The eBPF kernel program decides whether to allow the application to execute based on the data in it; 2) The eBPF user program reads the file path data sent by the kernel program and sends it to the TEE environment; a) After loading the eBPF kernel program, the eBPF user program searches for the loaded map by name through the bpf_object__find_map_by_name method, including bprm_ringbuf, mmap_ringbuf, and kernel_ringbuf, and returns the pointer of the corresponding map. Then, the bpf_map__fd method is used to obtain the file descriptor corresponding to the map. Finally, the ring_buffer__new method is used to obtain the data of bprm_ringbuf, mmap_ringbuf, and kernel_ringbuf submitted by the kernel space, and the callback function is used to further process the data. b) For binary files, the eBPF user program reads data from bprm_ringbuf and stores it in struct event. After obtaining the file path, it uses NetLink technology to send the file path information to the trusted software base kernel module in the TEE environment and waits for the judgment result of the trusted software base. c) For the so file, the eBPF user program reads data from mmap_ringbuf and stores it in struct event. After obtaining the file path, the file path information is sent to the trusted software base kernel module in the TEE environment by using NetLink technology, and waits for the judgment result of the trusted software base. d) For the ko file, the eBPF user program reads data from kernel_ringbuf and stores it in struct event. After obtaining the file path, the file path information is sent to the trusted software base kernel module in the TEE environment by using NetLink technology, and waits for the judgment result of the trusted software base. 3) Determine the summary value of the executable file based on the path of the executable file in the TEE environment; The trusted software base in TEE obtains the executable file path sent from the user space through NetLink communication, and calculates the digest value of the executable file using the sm3 algorithm through the trusted cryptographic module; 4) Compare the summary value with the trusted reference library to check whether the file has been tampered with; Compare the digest value calculated in step 3 with the trusted reference library data to determine whether the file has been modified. The return value is determined according to the judgment structure, 0 for unmodified and -1 for modified. 5) Send the comparison results to the eBPF kernel program; The return result of step 4 is sent back to the user space through NetLink communication. The eBPF program in the user space fills the judgment result of the trusted software base into mark_map in the callback function mentioned in step a) of step 2; in the callback function of the eBPF user program, the bpf_object__find_map_by_name method is used to find the hash type map named mark_map, and then the bpf_map__fd method is used to get the file descriptor of mark_map. Finally, the comparison result is updated to mark_map through the bpf_map_update_elem method and sent to the eBPF kernel program; 6) The eBPF kernel program reads the mark_map data to determine the execution of the file; When the eBPF user program updates the mark_map data, the eBPF kernel program immediately reads the judgment result of the trusted software base in the TEE through the bpf_map_lookup_elem method, and decides whether to allow the execution of the file based on the result.