Methods, apparatuses, devices, media, and products for elf file validation

By running the first verification process during the system kernel startup phase and having the first child process continue to verify the digital signature of the ELF file after the system kernel is initialized, the security deficiency of ELF file verification in the Linux system is solved, ensuring the security and reliability of the system during the initialization process.

CN123179383APending Publication Date: 2026-11-27UNIONTECH SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611584785.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-13
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

In the Linux operating system, existing technologies cannot effectively verify the digital signature of ELF files during system initialization, resulting in insufficient system security. This is especially true when the initialization process has not yet started or has stopped, making it impossible to guarantee the reliability and trustworthiness of ELF files.

Method used

The first verification process runs during the system kernel startup phase to perform digital signature verification on the ELF file loaded by the system kernel. It replaces the initialization process by creating a first child process. After the system kernel initialization is completed, the first child process continues the verification. The second verification process restarts the first child process if it encounters an error, ensuring the continuity of the verification process and the security of the system.

Benefits of technology

It enables continuous digital signature verification of ELF files before and after system kernel initialization, improving system security and reliability and avoiding security gaps during the initialization process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123179383A_ABST
    Figure CN123179383A_ABST
Patent Text Reader

Abstract

According to embodiments of the present disclosure, a method, device, equipment, medium and product for ELF file verification are provided. The method comprises: running a first verification process in a system kernel startup phase to perform digital signature verification on an ELF file loaded in the startup phase before the system kernel completes initialization; calling a process creation function through the first verification process to create a first child process of the first verification process, and replacing the first verification process with an initialization process to perform digital signature verification on the ELF file after the system kernel completes initialization. A second verification process is created through the initialization process to restart the first child process when the first child process is abnormal. Thus, the digital signature verification on the ELF file can be performed before and after the system kernel initialization, and the normal operation of the verification process is ensured, thereby improving the continuity of the ELF file digital signature verification and the system security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The exemplary embodiments disclosed herein generally relate to the field of computers, and particularly to methods, apparatuses, devices, media, and products for ELF file verification. Background Technology

[0002] In the Linux operating system, binary executable files typically use the Executable and Linkable Format (ELF). To ensure the reliability and trustworthiness of ELF files during loading and execution, current implementations usually call a user-space signature verification program when the kernel loads the ELF file to perform digital signature verification on the ELF file to be executed. The user-space signature verification program usually runs as a system service, and its lifecycle is controlled by the service management mechanism of the initialization process. During the phase before the initialization process starts or has stopped running, digital signature verification may have gaps, affecting the security of the ELF file and the overall security of the system. Summary of the Invention

[0003] Therefore, this disclosure provides a technical solution for ELF file verification to solve the above-mentioned technical problems and improve system security.

[0004] In a first aspect of this disclosure, a method for verifying ELF files is provided, comprising: running a first verification process during the system kernel startup phase to perform digital signature verification on ELF files loaded during the system kernel startup phase before the system kernel completes initialization; creating a first child process of the first verification process by calling a process creation function through the first verification process, and replacing the first verification process with an initialization process; the initialization process is used to initiate the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF files after the system kernel initialization is completed; creating a second verification process through the initialization process; and the second verification process is used to restart the first child process when the first child process encounters an error.

[0005] Optionally, creating a first child process of the first verification process by calling a process creation function through the first verification process, and replacing the first verification process with an initialization process includes: in response to creating the first child process through the process creation function, causing the first child process to continue executing the program code of the first verification process; and replacing the program image of the first verification process with the executable file of the system initialization program by calling a process image replacement function through the first verification process, thereby obtaining the initialization process.

[0006] Optionally, after creating a first child process of the first verification process by calling the process creation function of the first verification process and replacing the first verification process with the initialization process, the method further includes: adding an immune prefix character to the process name of the first child process, the immune prefix character being used to make the termination process during the shutdown phase skip the first child process when traversing processes; setting the process termination mode in the service configuration corresponding to the second verification process to terminate only the main process and disabling the forced termination signal sending, so as to maintain the operation of the first child process when the initialization process stops.

[0007] Optionally, creating a second verification process through an initialization process includes: reading the service unit file corresponding to the second verification process through the initialization process to obtain the configuration data of the second verification process; the configuration data includes at least one of the following: executable file path, process termination mode, whether to send a forced termination signal, and environment variables; creating a second child process of the initialization process according to the configuration data, and loading the executable file corresponding to the executable file path in the second child process to create the second verification process; the second verification process is used to listen for the connection of the first child process, receive heartbeat messages, and trigger the restart of the first child process if the heartbeat message times out.

[0008] Optionally, restarting the first subprocess when the first subprocess encounters an error includes: establishing a communication connection between the first subprocess and the second verification process so that the first subprocess can send a heartbeat message to the second verification process through the communication connection; and restarting the first subprocess through the second verification process in response to determining that no heartbeat message has been received within a preset time.

[0009] Optionally, establishing a communication connection between the first child process and the second verification process includes: creating a Unix domain socket client through the first child process and initiating a connection request to the listening address pre-bound to the second verification process based on the Unix domain socket client; in response to determining that the connection between the first child process and the second verification process has failed, re-initiating the connection request based on a timer and an exponential backoff strategy until the connection between the first child process and the second verification process is successful; in response to determining that the connection between the first child process and the second verification process is successful, receiving the connection request through the second verification process and registering the client socket and timeout timer corresponding to the connection request; and periodically sending heartbeat messages to the second verification process through the first child process based on the communication connection.

[0010] In a second aspect of this disclosure, an apparatus for ELF file verification is provided, comprising: an execution module configured to run a first verification process during the system kernel startup phase, wherein the first verification process performs digital signature verification on ELF files loaded during the system kernel startup phase before the system kernel completes initialization; a replacement module configured to create a first child process of the first verification process by calling a process creation function of the first verification process, and replace the first verification process with an initialization process; the initialization process is used to initiate the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF files after the system kernel initialization is completed; and a creation module configured to create a second verification process through the initialization process; the second verification process is used to restart the first child process when the first child process encounters an error.

[0011] In a third aspect of this disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit. When executed by the at least one processing unit, the instructions cause the device to perform the method of the first aspect.

[0012] In a fourth aspect of this disclosure, a computer-readable storage medium is provided. This computer-readable storage medium stores a computer program that can be executed by a processor to implement the method of the first aspect described above.

[0013] In a fifth aspect of this disclosure, a computer program product is provided. The computer program product includes computer instructions that, when executed by a processor, implement the method of the first aspect described above.

[0014] In this manner, the first verification process performs digital signature verification on the ELF file loaded during the system kernel startup phase before the system kernel completes initialization. The first child process continues to perform digital signature verification on the ELF file after the system kernel initialization is complete. The second verification process restarts the first child process if it encounters an error. Therefore, digital signature verification of the ELF file can be performed before and after system kernel initialization, and the execution of the first child process can be resumed if it encounters an error, improving the continuity of ELF file digital signature verification and system security.

[0015] It should be understood that the content described in this content section is not intended to limit the key or essential features of the embodiments of this disclosure, nor is it intended to restrict the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0016] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. In the drawings, the same or similar reference numerals denote the same or similar elements, wherein: Figure 1 A schematic diagram is shown of an example environment in which embodiments of the present disclosure may be implemented; Figure 2 A schematic block diagram of an example process for ELF file verification according to some embodiments of the present disclosure is shown; Figure 3 A schematic block diagram illustrating the ELF file verification process according to some embodiments of the present disclosure is shown; Figure 4 A schematic diagram of an example architecture for ELF file verification according to some embodiments of the present disclosure is shown; Figure 5a A first interaction timing diagram of the master process and slave process according to some embodiments of the present disclosure is shown; Figure 5b A second interaction timing diagram of the master process and slave process according to some embodiments of the present disclosure is shown; Figure 6 A timing diagram illustrating the establishment of a communication connection according to some embodiments of the present disclosure is shown; Figure 7 A timing diagram of the heartbeat interaction loop and process management according to some embodiments of the present disclosure is shown; Figure 8 A schematic block diagram of a shutdown process according to some embodiments of the present disclosure is shown; Figure 9 A schematic block diagram of an example apparatus for ELF file verification according to some embodiments of the present disclosure is shown; and Figure 10 A block diagram of an electronic device capable of implementing several embodiments of the present disclosure is shown. Detailed Implementation

[0017] The embodiments of this disclosure will be further described below with reference to the accompanying drawings. The embodiments shown in the drawings are for illustrative purposes only and should not be construed as meaning that this disclosure can only be implemented in these specific forms. Rather, this disclosure can be implemented in various ways, and the embodiments provided herein are intended to make this disclosure clearer and more complete. The drawings and embodiments are exemplary only and are not intended to limit the scope of protection of this disclosure.

[0018] The headings of any section or subsection appearing in this document do not constitute a limitation on the content of this disclosure. The various embodiments described throughout this disclosure can be combined arbitrarily, regardless of whether they belong to the same section or subsection. In the description of this disclosure, "including" should be understood as "including but not limited to," "based on" should be understood as "at least partially based on," "one embodiment" or "this embodiment" should be understood as "at least one embodiment," and "some embodiments" should be understood as "at least some embodiments." Terms such as "first," "second," etc., can refer to the same or different objects.

[0019] The embodiments of this disclosure may involve user data, data acquisition, and / or data use. All related processing complies with laws, regulations, and relevant provisions, and is conducted with the user's knowledge and confirmation. When implementing the embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the data or information that may be involved, in accordance with relevant laws and regulations, and user authorization should be obtained. Where personal information processing is involved, it should be done within the prescribed or agreed scope, provided there is a legal basis. A user's refusal to process personal information beyond what is necessary for basic functions will not affect their use of basic functions.

[0020] In some embodiments, the system kernel may include an initrd phase before initialization is complete; the initialization process may be a systemd process; the first verification process may be a verification process that runs before the initialization process in the initrd phase; the first child process may be a process created by the first verification process using a process creation function and continuing to execute the program code of the first verification process; the second verification process may be a verification process created by the initialization process based on the service unit file. The first child process is used to perform digital signature verification of the ELF file after the system kernel initialization is complete, and the second verification process is used to listen for connections of the first child process, receive heartbeat messages, and trigger the restart of the first child process if the heartbeat message times out. In the master-slave process description below, the second verification process is the master process, and the first child process is the slave process.

[0021] Figure 1 A schematic diagram is shown illustrating an example environment in which embodiments of the present disclosure may be implemented. For example... Figure 1 As shown, example environment 100 may include terminal device 110 and server 120.

[0022] In this example environment 100, terminal device 110 may run application 130. Application 130 may be any suitable type of application capable of running on terminal device 110. Exemplarily, application 130 may be an application for loading an executable file, or an application implemented via an executable file. A user can interact with application 130 via terminal device 110 and / or its attached devices. In some embodiments, application 130 may provide or be configured with a digital assistant to interact with the user. In some embodiments, application 130 may interact with the user through an interface.

[0023] In some embodiments, terminal device 110 communicates with server 120 to provide services to application 130. Terminal device 110 can be any type of mobile terminal, fixed terminal, or portable terminal, including mobile phones, desktop computers, laptop computers, notebook computers, netbook computers, tablet computers, media computers, multimedia tablets, handheld computers, portable gaming terminals, VR / AR devices, personal communication system (PCS) devices, personal navigation devices, personal digital assistants (PDAs), audio / video players, digital cameras / camcorders, positioning devices, television receivers, radio receivers, e-book devices, gaming devices, or any combination thereof, including accessories and peripherals of these devices or any combination thereof. In some embodiments, terminal device 110 can also support any type of user-facing interface (such as "wearable" circuitry).

[0024] Server 120 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks, and big data and artificial intelligence platforms. Server 120 may include, for example, computing systems / servers such as mainframes, edge computing nodes, computing devices in a cloud environment, etc. Server 120 can provide backend services for application 130 in terminal device 110.

[0025] Server 120 and terminal device 110 can be physically separate devices, or they can be the same device playing different roles during the software development and runtime phases. For example, in a development environment, the development organization, acting as "server 120," signs the compiled ELF file and packages the signed file and the ELF file together into a deb package. The user device, acting as "terminal device 110," installs the deb package through a package manager and runs the ELF file within it.

[0026] A communication connection can be established between server 120 and terminal device 110. This communication connection can be established via wired or wireless means. The communication connection may include, but is not limited to, Bluetooth, mobile network, Universal Serial Bus (USB), and Wireless Fidelity (WiFi) connections; the embodiments of this disclosure are not limited in this respect. In the embodiments of this disclosure, server 120 and terminal device 110 can achieve signaling interaction through the communication connection between them.

[0027] It should be understood that the structure and function of the various elements in the example environment 100 are described for illustrative purposes only and do not imply any limitation on the scope of this disclosure.

[0028] As mentioned earlier, signature verification of binary executable files is necessary to ensure system security. Currently, most verification services rely on advanced initialization systems (such as systemd). However, if the advanced initialization system is not running during system operation (e.g., it has not yet started or has stopped running), the verification service will be unable to function. For example, if systemd is not running in the early stages of system startup, the verification service may not be able to be started in time, causing kernel modules, drivers, and basic tools started within the initrd to be unable to undergo signature verification. Furthermore, when the verification service is an ELF file that needs to be verified, if its startup depends on systemd-executor, and systemd-executor in turn depends on the verification service to perform signature verification, this circular dependency can cause system initialization to deadlock, ultimately preventing the verification service from starting normally.

[0029] This disclosure provides a scheme for ELF file verification. In this scheme, a first verification process runs during the system kernel startup phase to perform digital signature verification on ELF files loaded during the system kernel startup phase before the system kernel completes initialization. A first child process of the first verification process is created by calling a process creation function, and the first verification process is replaced by an initialization process. The initialization process is used to initiate the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF files after the system kernel initialization is completed. A second verification process is created by the initialization process, and the second verification process is used to restart the first child process if the first child process encounters an error.

[0030] According to embodiments of this disclosure, a first verification process can perform digital signature verification on ELF files loaded during the system kernel startup phase before the system kernel completes initialization; a first child process can continue to perform digital signature verification on ELF files after the system kernel initialization is completed; and a second verification process can restart the first child process if it encounters an error. Therefore, digital signature verification of ELF files can be performed before and after system kernel initialization, ensuring the normal operation of the verification process and improving the continuity of ELF file digital signature verification and system security.

[0031] The following section provides a detailed description of various example implementations of this scheme, with reference to the accompanying drawings.

[0032] Figure 2 A schematic block diagram of an example process for ELF file verification according to some embodiments of this disclosure is shown. Figure 2 As shown, the example process can be implemented or included in Figure 1 In the terminal device 110 and / or server 120 shown. In this embodiment, taking the implementation in the terminal device 110 as an example, example process 200 is used to perform full lifecycle verification of the digital signature of the executable file.

[0033] like Figure 2 As shown in box 210, a first verification process is run during the system kernel startup phase to perform digital signature verification on the ELF file loaded during the system kernel startup phase before the system kernel completes initialization.

[0034] In some embodiments, after the computer system powers on, the BIOS or UEFI bootloader loads the kernel into memory. After the kernel completes its basic initialization, it creates the first user-mode process in the initrd environment. This disclosure sets this first user-mode process as the first verification process. The first verification process runs in the initrd file system and performs digital signature verification on all subsequently loaded ELF files (e.g., kernel module loader tools, mount commands, etc.). Therefore, digital signature verification can be performed on ELF files loaded during the system kernel startup phase before the system kernel completes initialization, improving system security.

[0035] In box 220, the first verification process calls the process creation function to create a first child process of the first verification process, and replaces the first verification process with the initialization process. The initialization process is used to initiate the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF file after the system kernel initialization is completed. The initialization process is responsible for taking over the subsequent startup process of the system, including starting service management tools such as systemd. The first child process continues to reside in memory and performs digital signature verification on the loading and execution of the ELF file during normal system operation.

[0036] In some embodiments, the first verification process may call a process creation function to create a first child process of the first verification process, so that the first child process continues to execute the program code of the first verification process; the first verification process may also replace its own program image with the executable file of the system initialization program through a process image replacement function to obtain the initialization process.

[0037] Terminal device 110 can create a first child process of the first verification process by calling the process creation function of the first verification process, and replace the first verification process with the initialization process. For example, the first verification process can be PID1 process, first calling the fork function to create the first child process. The first child process continues to run the program code of the first verification process and performs digital signature verification on the ELF file after the system kernel initialization is complete. Subsequently, the first verification process calls a process image replacement function (e.g., the execve function) to replace the program image of the first verification process with the executable file of the system initialization program to obtain the initialization process. After the replacement, the original first verification process becomes the initialization process, retaining the identity of PID1.

[0038] In box 230, a second verification process is created through the initialization process. The second verification process is used to restart the first child process in case of an exception. In the master-slave mode described below, the first child process is the slave process, used to perform digital signature verification on the ELF file during normal system kernel operation; the second verification process is the master process, used to manage the running status of the first child process, such as monitoring whether the first child process is running normally, obtaining the running parameters of the first child process, and terminating or restarting the first child process.

[0039] In some embodiments, the initialization process (e.g., systemd) starts a new process, namely the second verification process, based on a preset service unit file. The master process does not perform actual digital signature verification but is used to monitor the health status of the slave processes. The master process can detect whether the slave processes are alive through a heartbeat mechanism. If the first child process is abnormal, the second verification process restarts the first child process to restore its operation. The master process is managed by the initialization process, but the slave processes have a lifecycle independent of the initialization process.

[0040] In some embodiments, creating a second verification process through an initialization process includes: reading the service unit file corresponding to the second verification process through the initialization process to obtain configuration data of the second verification process; the configuration data includes at least one of the following: executable file path, process termination mode, whether to send a forced termination signal, and environment variables, wherein whether to send a forced termination signal is used to indicate whether to send a final forced termination signal to the remaining processes after the service stop timeout expires; creating a second child process of the initialization process according to the configuration data, and loading the executable file corresponding to the executable file path in the second child process to create the second verification process; the second verification process is used to listen for the connection of the first child process, receive heartbeat messages, and trigger the restart of the first child process if the heartbeat message times out.

[0041] For example, the initialization process (systemd) first reads the service unit file, which contains the configuration data for the second verification process. This configuration data includes the executable path, process termination mode, whether to send a forced termination signal, and other environment variables. Whether to send a forced termination signal can be indicated by the SendSIGKILL configuration item; SIGKILL can be used as the final forced termination signal to terminate the remaining processes after the service stop timeout expires. After parsing these configurations, systemd calls the fork function to create a second child process, and then calls the execve function in the created second child process to load the / usr / bin / elfverify-master executable file to create the second verification process. The executable file implements all the logic of the main process, including creating an event manager, establishing a Unix domain socket listener, receiving heartbeat messages from slave processes, managing timers, and restarting slave processes after timeouts. Since systemd manages the lifecycle of the main process, administrators can control the main process using standard commands such as systemctl start and systemctl stop.

[0042] In some embodiments, restarting the first subprocess when the first subprocess is abnormal includes: establishing a communication connection between the first subprocess and the second verification process so that the first subprocess can send a heartbeat message to the second verification process through the communication connection; and restarting the first subprocess through the second verification process in response to determining that no heartbeat message is received within a preset time.

[0043] A communication connection is established between the first child process and the second verification process. For example, a Unix domain socket can be used as the communication carrier. After the connection is established, the first child process actively sends heartbeat messages to the second verification process at fixed time intervals (e.g., 30 seconds). The heartbeat message can be in a simple JSON format, such as {"type":"ping","payload":1700000000}, where the payload field carries a timestamp for debugging purposes.

[0044] The second verification process maintains a timer for each connected first child process. Whenever the second verification process reads a valid heartbeat message from the communication connection, it resets the timer corresponding to that first child process, resetting the timeout to the pre-set maximum timeout (e.g., 90 seconds). If the second verification process's timer expires, meaning no heartbeat message has been received within the last 90 seconds, the second verification process determines that the first child process has abnormally exited or entered a zombie state. At this point, the second verification process performs the following recovery operations: calls the `kill` function to send a SIGKILL signal to the first child process, forcibly terminating any remaining old processes; closes the file descriptors associated with the connection, cleaning up timer resources; and restarts a new first child process instance using `fork` and `exec`. The SIGKILL signal here is actively sent by the second verification process during fault recovery to clean up any remaining old processes, and belongs to a different trigger path than the final forced termination signal sent by the initialization process after the service stop timeout period expires according to the service configuration. After the new first child process instance starts, it will retry connecting to the second verification process according to the established logic. Upon successful connection, it sends the first heartbeat message, resuming the normal heartbeat monitoring loop.

[0045] In some embodiments, a Unix domain socket client can be created by a first child process, and a connection request can be initiated to the listening address pre-bound by the second verification process based on the Unix domain socket client to establish a communication connection between the first child process and the second verification process. The communication connection can be initiated actively by the first child process. Specifically, after starting (including initial startup and startup after restarting by the main process), the first child process immediately creates a Unix domain socket client and attempts to connect to the listening address pre-bound by the second verification process, such as / run / elfverify.sock. Since the second verification process may start later than the first child process (the first child process already exists in the initrd stage, while the second verification process needs to wait for systemd to start before it can run), the first child process's initial connection attempt will fail. To cope with this situation, the first child process adopts an exponential backoff retry strategy: after the first connection failure, it waits 1 second, after the second failure, it waits 2 seconds, after the third failure, it waits 4 seconds, and so on, until the connection is successful or the maximum number of connections is reached. After the second verification process starts and creates the listening socket, the first child process can establish a communication connection with the second verification process. After the connection is established, the `accept` function of the second authentication process returns the connected socket file descriptor corresponding to the connection request. The second authentication process encapsulates this connected socket as a client socket source and registers it in the epoll event loop, while also creating an associated timer for it. At this point, the bidirectional communication channel is officially established, and the first child process immediately begins sending heartbeats.

[0046] Figure 3 A schematic block diagram illustrating the ELF file verification process according to some embodiments of this disclosure is shown. Figure 3 As shown, the ELF file verification process can be implemented or included in the terminal device 110 to perform digital signature verification on the ELF file during the system kernel startup phase or the system runtime phase.

[0047] like Figure 3As shown, in box 301, the first verification process starts. In box 302, the first verification process performs digital signature verification on the ELF file loaded during the system kernel startup phase before the system kernel completes initialization. In box 303, the first verification process calls a process creation function (e.g., the fork function) to create a first child process. In box 304, the first child process continues to execute the program code of the first verification process and performs digital signature verification on the ELF file after the system kernel initialization is completed. Corresponding to the first child process continuing to execute the signature verification task, in box 305, the first verification process calls a process image replacement function (e.g., the execve function) to replace its own program image with the executable file of the system initialization program to obtain the initialization process. In box 306, a second verification process is created through the initialization process. In box 307, the second verification process restarts the first child process if the first child process encounters an error.

[0048] Figure 4 A schematic diagram of an example architecture for ELF file verification according to some embodiments of this disclosure is shown. Figure 4 As shown, the architecture mainly includes an event manager 401, an event handler 402, and an event source 403. In addition, the architecture also includes a timer handler 404, a server-side connection handler 405, a client-side socket handler 406, a timer source 407, a socket source 408, and a heartbeat manager 409.

[0049] Figure 4 Shown as " <interface>"" indicates an abstract interface, not a communication protocol layer. Event handler 402 provides the HandleEvent(event) interface, enabling different types of handlers to process events in a unified manner; event source 403 provides the Register(fd), GetFd(), and Close() interfaces, enabling timer source 407 and socket source 408 to register with event manager 401 in a unified manner.

[0050] Figure 4 In the event manager 401, `epollFd` represents the epoll instance file descriptor used to wait for events, `controlFd` represents the file descriptor used to wake up or control the event loop, `eventHandlers map` records the correspondence between file descriptors and event handlers, and `eventSources map` records the correspondence between file descriptors and event sources. In this paper, a socket is a communication endpoint provided by the operating system; socket source 408 is an implementation of event source 403, used to encapsulate sockets and their file descriptors, and register the encapsulated sockets with event manager 401. In timer handler 404, `ts` represents its associated timer source, and `notifier` represents the timed event notification object; in server-side connection handler 405, `ServerSocket` represents the listening socket source, and `eventMngr` represents its associated event manager; in client-side socket handler 406, `ht` represents the heartbeat manager, and `eventMngr` represents its associated event manager. In timer source 407, fd represents the timer file descriptor, and interval represents the timing period; in socket source 408, fd represents the socket file descriptor, conn represents the connection object, and role indicates whether the socket source is used as a server or client; in heartbeat manager 409, conn represents the connection object used to send or receive heartbeat messages.

[0051] In some embodiments, the event manager 401 is used to simultaneously monitor I / O events of multiple file descriptors and wake up the event loop when necessary. The event manager 401 maintains two mapping tables: one for recording the event source corresponding to each file descriptor, and the other for recording the event handler corresponding to each file descriptor. The event manager 401 provides three main operations: registering event sources (adding the event source and its handler to monitoring), running the main loop (repeatedly calling epoll_wait to wait for events), and cleaning up resources (closing all file descriptors). The server-side connection handler 405 is associated with the listening socket. When the listening socket receives a new connection request, the server-side connection handler 405 is invoked. The server-side connection handler 405 accepts the connection and creates a client socket source and a client socket handler for the new connection, then registers the created client socket source and client socket handler with the event manager 401. The client socket handler 406 is associated with an established client socket connection. When the socket is readable, the client socket handler 406 reads the data and calls the heartbeat manager for parsing.

[0052] In some embodiments, after the main process starts, it first creates an event manager. A server-side socket source is created, bound to a fixed Unix domain socket address, and registered with the event manager along with the server-side connection handler. Subsequently, the main process calls the run method, entering the event loop. When a slave process initiates a connection to the main process, epoll detects that the listening socket is readable, and the event manager calls the server-side connection handler's processing function. This function accepts the connection and obtains the connected socket file descriptor corresponding to the connection request. Then, the connected socket is encapsulated as a client-side socket source, and its corresponding client-side socket handler is created; additionally, a timer source (timeout timer, e.g., 90 seconds) and its corresponding timer handler are created. All these new event sources and handlers are registered with the event manager, and timeout periods are set for the timers.

[0053] Subsequently, whenever data arrives on the client socket, the client socket handler reads the data and calls the heartbeat manager to parse it. If a valid Ping message is parsed, the master process resets the timer associated with the client, i.e., resets the timeout period to 90 seconds. If no Ping message is received within 90 seconds, the timer source expires, the timer handler is invoked, and the slave process restarts. The slave process starts in the initrd phase and creates an event manager. The slave process creates a client socket source and attempts to connect to the master process's listening address. Simultaneously, the slave process creates a periodic timer source (with a period of 30 seconds) and associates it with the timer handler. Before a successful connection, the slave process's event loop is in a waiting state, and the timer handler is used to implement exponential backoff reconnection: after each connection failure, the timer sets an increasingly longer delay, and attempts to connect again upon expiration. After a successful connection, the slave process's periodic timer handler begins constructing Ping messages and sends them to the master process via the client socket source.

[0054] In some embodiments, Figure 4 The event-driven architecture shown is used to establish a connection, receive heartbeats, and handle timeouts between the first child process and the second verification process. The event manager 401 uniformly schedules the socket source 408 and the timer source 407. The event handler 402 may include a server-side connection handler 405, a client-side socket handler 406, and a timer handler 404. The heartbeat manager 409 parses the heartbeat messages sent by the first child process and triggers a timer reset when the heartbeat message is valid. If the heartbeat message times out, it works with the timer handler 404 to trigger the restart process of the first child process.

[0055] Figure 5a A first interaction timing diagram of the master process and slave process according to some embodiments of the present disclosure is shown. Figure 5b A second interaction timing diagram of the master process and slave process according to some embodiments of the present disclosure is shown. Figure 6 A timing diagram illustrating the establishment of a communication connection according to some embodiments of the present disclosure is shown. Figure 7 A timing diagram of the heartbeat interaction loop and process management according to some embodiments of this disclosure is shown. Figures 5a to 7 Describe the interaction process between the first subprocess and the second verification process at different stages: Figure 5a The initrd startup process corresponds to stage 1. Figure 5b The corresponding stage 2 is the systemd startup main process. Figure 6 The connection is established by the process in phase 3. Figure 7 The corresponding phase 4 heartbeat interaction loop and failure handling after timeout.

[0056] like Figure 5a and Figure 5b As shown, in phase 1, the first child process starts as a slave process in the initrd phase, creating an event manager, socket sources, and timer sources, and enters an exponential backoff retry loop. Since the second verification process has not yet started, the first child process continues to execute the digital signature verification of the ELF file loaded in the initrd phase after the connection request fails. In phase 2, after the system switches to the root file system and starts systemd, the initialization process starts the second verification process according to the service configuration. The second verification process creates an event manager and server socket sources, and enters an event loop to wait for slave processes to connect.

[0057] like Figure 6 As shown, in stage 3, after the first child process detects that the listening socket of the second verification process is available, it initiates a connection request to the second verification process. The second verification process, as the main process, calls accept() to accept the connection, creates a client socket source and a client socket handler corresponding to the connection, and establishes a mapping between eventSources[fd] and client socket sources, as well as a mapping between eventHandlers[fd] and client socket handlers in the event manager, thereby including the connection in the event loop.

[0058] like Figure 7 As shown, in stage 4, the first child process generates Ping messages according to a preset period using a timer source and sends them to the second verification process via a Unix domain socket. When the client socket corresponding to the connection between the second verification process and the first child process is readable, the second verification process calls the client socket handler and parses the Ping message through the heartbeat manager. After confirming the validity of the heartbeat message, the second verification process resets the timeout timer corresponding to the first child process. If the second verification process does not receive the next Ping message within a preset time, the timer expires and triggers expiration processing to initiate the slave process restart process.

[0059] In some embodiments, during the system build phase, it is necessary to prepare an executable file for a slave process (e.g., named elfverify-slave) and an executable file for a master process (e.g., named elfverify-master). The slave process actually performs the digital signature verification of the ELF file and is also responsible for sending heartbeats to the master process; the master process is responsible for listening for connections, receiving heartbeats, monitoring timeouts, and restarting the slave process.

[0060] In some embodiments, after the computer is powered on, the BIOS or UEFI loads the bootloader, which loads the Linux kernel and initrd image into memory. After the kernel completes its most basic initializations (such as setting page tables, initializing interrupts, and starting the scheduler), it creates the first user-space process in the initrd environment.

[0061] After the first verification process starts, it first determines whether it is currently in the initrd stage. For example, this can be done by checking whether the rdinit parameter is included in / proc / cmdline, or by checking whether the root file system is an initrd temporary file system (e.g., rootfs type). If the result is "in the initrd stage", the first verification process prepares to perform a process transition operation.

[0062] In some embodiments, the first verification process calls the fork system call to create a first child process. At this point, the system includes two processes: the parent process (the original PID1) and the first child process (the new PID, such as PID2). Both processes execute the same program code and are distinguished by the return value of fork.

[0063] The parent process (originally PID1) immediately invokes the execve system call to replace its own program image with the actual system initializer (i.e., / init.real). After the replacement is complete, the original first verification process becomes the initializer (systemd) while retaining the identity of PID1. The initializer then takes over the entire system startup process.

[0064] The first child process (PID2) does not execute the exec call, but continues to run the program code of the original first verification process, and performs digital signature verification of subsequent ELF files as a slave process 502. At this time, the parent process of the first child process is the initialization process (systemd), but the life cycle of the first child process is not directly managed by systemd, because systemd does not have a service unit corresponding to the first child process. When starting the first child process, the process name of the first child process is set to start with the immune prefix character "@". The process name referred to in this article refers to the zeroth command line parameter (argv[0]) set for the first child process; for example, setting the process name to "@ / usr / bin / elfverify-slave" makes the first character of / proc / [pid] / cmdline "@". The immune prefix character is used to protect the first child process during the shutdown phase.

[0065] After the first child process starts, it creates an event manager. The first child process calls the event manager creation function to perform the following operations: It calls the `epoll_create1` system call to create an `epoll` instance and obtain an `epoll` file descriptor, which will be used to monitor all I / O events and timer events. It calls `pipe2` or `eventfd` to create a control pipe, used to wake up the event loop from the outside when needed (e.g., when dynamically adding or removing event sources). Subsequently, the first child process initializes a mapping table to store the correspondence between file descriptors and event sources, and a mapping table to store the correspondence between file descriptors and event handlers, for quickly finding the corresponding processing logic when an event occurs.

[0066] In some embodiments, the first child process cannot determine when the second verification process (i.e., the main process 501) will start during the initrd stage, therefore it needs to repeatedly attempt to connect to the second verification process. For example, the first child process creates a timer source. The timer source is based on the Linux kernel's timerfd mechanism: it calls timerfd_create to generate a timer file descriptor and immediately performs a connection attempt; if the connection attempt fails, it sets the expiration time to 1 second. The first child process associates the timer source with a timer handler, which is dedicated to handling connection retry logic. Subsequently, the first child process calls the event manager's add event source method to register the timer source and its handler with the event manager. At this point, the epoll instance begins monitoring readable events for the timer file descriptor.

[0067] The first child process creates a socket source and sets its role as a client. Internally, the socket source calls the `socket` function to create a Unix domain socket (address family AF_UNIX, type SOCK_STREAM) and sets the socket to non-blocking mode. The socket source also pre-configures the socket address that the second verification process will listen on, for example, ` / run / elfverify.sock`. After creation, the first child process immediately calls the socket's connect method to attempt to connect to that address. Since the second verification process has not yet started, the listening socket does not exist, and the kernel immediately returns a connection error (usually ECONNREFUSED or ENOENT). Upon catching the error, the first child process does not exit immediately but prepares to enter a retry loop.

[0068] If the initial connection between the first child process and the second verification process fails, the first child process sets a backoff delay of 1 second and calls the event manager's run method, entering the event loop. At this time, `epoll_wait` blocks, waiting for the timer to expire or for other events to occur. After 1 second, the timer file descriptor becomes readable, `epoll_wait` returns, and the event manager calls the timer handler's function. In the handler, the first child process calls the socket client's connection method again. If this still fails (the second verification process has not yet started), the backoff delay is doubled to 2 seconds. This process is repeated until the first child process and the second verification process successfully establish a communication connection.

[0069] While waiting for retry, the first child process monitors all subsequently started processes. The initrd script typically executes commands such as loading kernel modules, mounting file systems, and switching root file systems. Whenever these commands trigger the loading and execution of an ELF file, the kernel sends a signature verification request to the first child process. Only after the first child process verifies the signature is the process allowed to continue execution. Therefore, the first child process is constantly performing digital signature verification tasks while retrying the connection.

[0070] In some embodiments, the retry loop of the first child process continues until the second verification process starts and creates a listening socket. Since the second verification process is started by the initialization process (systemd) in a later stage, while the first child process starts looping during initialization, the first child process needs to retry multiple times. However, after the system switches to the root file system and starts systemd, the second verification process is quickly restarted. When the first child process initiates its next connection attempt, the listening socket of the second verification process already exists, and a communication connection can be successfully established. At this point, the first child process exits the retry loop and enters the heartbeat message sending phase.

[0071] When the initialization script completes the root file system switch and executes the initialization process, the original first verification process has been replaced by the initialization process (systemd), while the first child process is still running. At this time, two critical processes are running in the system: the initialization process (PID1) and the first child process (PID2 or higher). The first child process continues to perform digital signature verification and connection retry tasks.

[0072] In some embodiments, after the initialization process (systemd) starts, it reads all service unit files. When the initialization process reads the deepin-elf-verify-master.service file, it parses the file configuration data and starts the corresponding service according to the configuration data. systemd calls the fork system call to create a second child process. The process ID of the second child process is greater than 1 (e.g., PID 123). In the second child process, systemd calls execve to execute the executable file / usr / bin / elfverify-master of the second verification process to create the second verification process.

[0073] In some embodiments, the second verification process creates an event manager after startup. Similar to the first child process, the second verification process calls the event manager creation function to generate an epoll instance, control pipe, and initialize the mapping table. The second verification process creates a socket source and sets its role to server. This socket source calls `socket` to create a Unix domain socket, and then calls `bind` to bind it to a fixed address (e.g., ` / run / elfverify.sock`). After successful binding, it calls `listen` to start listening, with the maximum number of waiting connections set to 1 (since only the first child process is running, but it could be set to a larger value). The second verification process associates the listening socket source with a server-side connection handler. The server-side connection handler is an event handler whose processing function will be called when the listening socket is readable.

[0074] In some embodiments, the second verification process calls the event manager's add event source method to register the listening socket source and its handler to epoll, focusing on the EPOLLIN event type (indicating a new connection request). Then, the second verification process calls the event manager's run method, entering an infinite event loop. At this point, epoll_wait is blocked, waiting for connection events on the listening socket. Since the first child process has not yet connected (and may still be performing a final retry), the event loop is in an idle waiting state.

[0075] In some embodiments, the event loop of the second verification process is designed to be extensible. The second verification process can handle multiple client connections, timer events, and possible control pipeline events simultaneously (for dynamically adding or removing event sources). However, in the initial phase, the event loop only monitors the listening socket.

[0076] After the second verification process starts listening, the first child process begins its next connection retry. The first child process's timer expires, the timer processor is invoked, and the first child process calls the socket client's connection method again. Since the second verification process is already listening on ` / run / elfverify.sock`, the kernel completes the Unix domain socket connection operation, and the connection function returns successfully. The first child process detects the successful connection, immediately stops the exponential backoff retry logic, and prepares to enter heartbeat message sending mode.

[0077] In some embodiments, after the first subprocess establishes a communication connection with the second authentication process, the first subprocess needs to start periodically sending heartbeat messages to the second authentication process. For example, the first subprocess reconfigures its original timer source from retry mode to fixed-period mode: setting the timer to expire periodically every 30 seconds. This timer source remains associated with the same timer processor, but the processor's internal logic changes: instead of performing connection retries, it constructs and sends Ping messages. The first subprocess also registers a client socket processor to handle messages (e.g., Pong or commands) that may be returned from the second authentication process. The second authentication process can return a Pong message or a command based on its processing logic, or it can simply reset the timer to complete the liveness confirmation.

[0078] In some embodiments, the event loop of the second authentication process is blocked on `epoll_wait`. When a connection request arrives from the first child process, the listening socket becomes readable, and `epoll_wait` returns. The event manager finds the corresponding server-side connection handler based on the file descriptor and calls its handling function. This handling function performs the following actions: calls `accept` to accept the new connection, obtains the file descriptor of the connected socket corresponding to the connection with the first child process. This connected socket is also set to non-blocking mode. The connected socket is encapsulated as a client socket source, and this client socket source is associated with a client socket handler. Here, the client socket source is located on the second authentication process side and is used to represent the connection established with the first child process as a client. The client socket handler is responsible for reading the data sent by the first child process and parsing the heartbeat. A timer source is created with a timeout of 90 seconds, and this timer source is associated with a timer handler. This timer handler will trigger the first child process restart logic if the timeout occurs. The event manager's add event source method is called to register the new client socket source and its handler to epoll, and to monitor the `EPOLLIN` event. Register the new timer source and its handler to epoll, and monitor the EPOLLIN event (timerfd expiration). Establish mapping relationships: In the event manager's mapping table, map the client socket file descriptor to its event source and handler; also map the timer file descriptor to its event source and handler.

[0079] The second verification process associates the client socket and timeout timer corresponding to the connection with the first child process. Typically, a pointer to the corresponding timer source is stored in the context of the client socket processor so that the timer can be reset when a heartbeat is received.

[0080] In some embodiments, the event manager of the second verification process monitors the listening socket, the connected socket corresponding to the connection with the first child process, and the timeout timer corresponding to that connection. The listening socket is used to wait for new connections; the connected socket is encapsulated as a client socket source for receiving data sent by the first child process. The event manager of the first child process monitors the client socket it creates as a client and a periodic timer. The client socket is used to send or receive data, and the periodic timer expires every 30 seconds. Thus, a communication channel is established between the first child process and the second verification process.

[0081] In some embodiments, the periodic timer of the first child process expires for the first time 30 seconds after the connection is established. The timerfd file descriptor becomes readable, and the event manager of the first child process detects this event via epoll_wait, calling the timer handler's processing function. This processing function performs the following sub-steps: obtains the current system timestamp (e.g., by calling clock_gettime); constructs a JSON-formatted message, such as {"type":"ping","payload":1715123456}. The message only needs to contain the type field and the timestamp field. The message is sent via the client socket source. Because sockets are non-blocking, the send operation may return EAGAIN due to a full buffer. If this happens, the first child process needs to register a write event and wait for the buffer to become writable before continuing to send. However, for simplicity, it is assumed that the kernel send buffer is large enough that a single write or send call can complete the process. If the send is successful, the timer handler returns. If the transmission fails (e.g., the connection has been broken), the first child process needs to re-enter the reconnection logic; if the second verification process does not receive a heartbeat message within a preset time, the timeout mechanism of the second verification process will trigger the restart of the first child process.

[0082] In some embodiments, when the Ping message from the first child process reaches the second authentication process, the client socket corresponding to the connection between the second authentication process and the first child process becomes readable. The second authentication process's `epoll_wait` returns, and the event manager calls the processing function of the client socket handler associated with that socket. This handler performs the following steps: calling `read` or `recv` to read data from the socket. Since Ping messages are typically short, a single read is sufficient to obtain the complete message. The read byte stream is passed to the heartbeat manager module. The heartbeat manager calls a JSON parser to parse the message and extract the `type` field. If the `type` field is "ping", it indicates that this is a valid heartbeat message. The heartbeat manager notifies the second authentication process that the first child process is still alive.

[0083] After receiving the notification, the second verification process identifies the timer source associated with the client and calls `timerfd_settime` to reset the timeout. The timeout is reset to 90 seconds, and the countdown restarts.

[0084] In some embodiments, if the first child process fails to send a heartbeat message within a preset timeout period of 90 seconds due to high CPU load or I / O blocking but does not crash, the timer for the second verification process may expire. However, since the first child process has not crashed, it may recover and send a heartbeat message within a short period after the timer expires. To avoid false positives, the second verification process may not immediately restart the first child process after the timer expires, but instead wait for a certain period of time (e.g., 2 seconds), or wait for multiple consecutive timeouts before restarting.

[0085] In some embodiments, if the first child process exits due to a segmentation fault, deadlock, or external termination, it will no longer send any heartbeats. When the timer for the second verification process expires, the timer handler's function is invoked. The handler determines a timeout and performs a restart. The second verification process calls `kill` to send a SIGKILL signal to the process ID of the first child process to forcibly terminate any remaining old processes. This SIGKILL signal is actively sent by the second verification process during fault recovery and is not controlled by the `SendSIGKILL` configuration option of the service corresponding to the second verification process. The second verification process closes the file descriptors associated with the client and unregisters the client socket source and timer source from the event manager, releasing resources. The second verification process calls `fork` to create a new process, and then calls `execve` in the new process to reload the executable file of the first child process.

[0086] In some embodiments, after the new first child process starts, it repeats the steps of creating an event manager and establishing a connection: creating an event manager and attempting to connect to the second authentication process. Since the second authentication process's listening socket still exists, the new first child process re-establishes a communication connection with the second authentication process and restarts the heartbeat interaction.

[0087] In some embodiments, if the second verification process crashes for some reason (e.g., a memory error), the initialization process (systemd) will detect the second verification process's exit based on the control group mechanism configured in the service configuration. Since `Restart=always` is not set in the service file, systemd may not automatically restart the second verification process. This would cause the first child process to lose monitoring. To improve robustness, the corresponding parameters in the service file can be adjusted.

[0088] Under normal circumstances, the heartbeat interaction loop between the first child process and the second verification process will run indefinitely. The first child process sends a Ping every 30 seconds, and the second verification process resets its timer every time it receives a Ping. During system operation, the first child process continues to execute its core digital signature verification task: whenever a new ELF file is executed by execve, the first child process verifies the signature. The second verification process only needs to process heartbeat messages, resulting in extremely low CPU consumption (because epoll_wait blocks most of the time and is rarely woken up).

[0089] In some embodiments, an immune prefix character can be added to the process name of the first child process. This immune prefix character is used to ensure that the termination process during the shutdown phase skips the first child process when traversing processes. The process termination mode in the service configuration corresponding to the second verification process is set to terminate only the main process, and the forced termination signal sending is disabled to maintain the first child process running when the initialization process stops. The process termination mode is used to limit the recipients of the regular termination signal when the service stops; disabling the forced termination signal sending prevents the sending of a final forced termination signal to the remaining processes after the service stop timeout expires. Therefore, the systemd-shutdown process skips the first child process during both the SIGTERM and SIGKILL broadcast phases of the shutdown phase. When the initialization process stops the service corresponding to the second verification process, the stop action is limited to the second verification process, which is the main process, and the final forced termination step after timeout is not executed, thus maintaining the first child process running when the initialization process stops and reducing the verification window during the shutdown phase.

[0090] In one implementation, when starting the first child process, the process name of the first child process is set to begin with an immune prefix character. The process name referred to herein is the zeroth command-line argument (argv[0]) set when starting the first child process. For example, setting the process name to "@ / usr / bin / elfverify-slave" makes the first character of / proc / [pid] / cmdline "@". The immune prefix character is located before the original process name of the first child process and is used to enable the termination process during the shutdown phase to determine whether to skip the first child process based on its process name without changing the execution logic of the first child process. During the shutdown phase, the termination process traverses the currently running processes, reads the command-line information of the traversed processes, and determines whether the process name begins with an immune prefix character based on the first character of the command-line information. When the process name begins with an immune prefix character, the termination process skips the process and does not send a shutdown termination signal to it; when the process name does not begin with an immune prefix character, the termination process processes the process according to the shutdown termination procedure. Using the above method, the first child process will not be prematurely terminated due to the process traversal termination process during the shutdown phase.

[0091] In this embodiment, the service configuration corresponding to the second verification process is also configured. The process termination mode in this service configuration is set to terminate only the main process. For example, setting KillMode to `process` restricts the sending of the regular termination signal to the main process (the second verification process) when the initialization process stops the service corresponding to the second verification process. The regular termination signal can be SIGTERM, used to request the process to exit normally. This service configuration also disables the sending of forced termination signals. For example, setting SendSIGKILL to `no` prevents the step of sending a final forced termination signal to still-living processes after the service stop timeout expires. The final forced termination signal can be SIGKILL, used to forcibly terminate processes that have not exited after the SIGTERM stage. Therefore, the process termination mode limits the sending of regular termination signals, while the sending of a forced termination signal controls the final forced termination step after timeout; their functions and purposes differ.

[0092] Therefore, when the initialization process stops the second verification process, the first child process is skipped by systemd-shutdown during the SIGTERM and SIGKILL broadcast phases because its process name begins with an immune prefix character. Furthermore, when the initialization process stops the service corresponding to the second verification process, the regular termination action and the final forced termination action after timeout for that service will not extend to the first child process. The first child process can continue running when the initialization process stops.

[0093] The above processing is mainly used during the shutdown phase. Even if the initialization process stops and the second verification process may be terminated, the first child process continues to run to maintain its signature verification function when the initialization process stops.

[0094] Figure 8 A schematic block diagram of a shutdown process according to some embodiments of the present disclosure is shown. Figure 8 As shown, in box 801, the systemd-shutdown process is terminated. In box 802, it is determined whether the target process's name begins with an immune prefix character (for example, whether the process cmdline begins with the character "@"). If it begins with an immune prefix character, proceed to box 803; otherwise, proceed to box 804. In box 803, the process is skipped, and no further SIGTERM signals are sent to the target process.

[0095] For example, when the system executes `systemctl poweroff`, the initialization process (systemd) gradually stops services, finally calling `systemd-shutdown`. `systemd-shutdown` first enters the SIGTERM broadcast phase, and then the SIGKILL broadcast phase. Before sending the corresponding signal, `systemd-shutdown` iterates through the currently running processes, reading the first character of ` / proc / [pid] / cmdline` to determine if the process name begins with an immune prefix character. If the first child process's name begins with "@", `systemd-shutdown` skips that process, not sending it SIGTERM or SIGKILL. Therefore, the first child process continues to live until the kernel unloads the file system, disables the swap device, and finally calls the `reboot` system call. During this time, the first child process can still verify ELF files called by the executed script, etc. If the second verification process is not terminated prematurely by systemd when stopping services, the second verification process, because its process name does not contain the aforementioned immune prefix character, will receive SIGTERM during the SIGTERM broadcast phase of `systemd-shutdown`, but the termination of the second verification process does not affect the continued execution of the first child process.

[0096] SIGTERM is a regular termination signal used to request a process to exit normally; SIGKILL is a final forced termination signal used to forcibly terminate a process still running after the SIGTERM broadcast phase. After completing the SIGTERM phase traversal, the terminating process enters the SIGKILL broadcast phase and obtains the next still running process. The terminating process again checks if the process name begins with an immune prefix character. If it does, the process is skipped, and no SIGKILL signal is sent to it; otherwise, the SIGKILL signal is sent. This process is repeated until all still running processes have been processed, and then the process proceeds to box 805.

[0097] In box 804, a SIGTERM signal is sent to the process to request its normal exit. This process is repeated until the SIGTERM broadcast phase is complete; then, running processes are processed according to the aforementioned SIGKILL broadcast phase, and after the SIGKILL broadcast phase is complete, the process proceeds to box 805. In box 805, the file system is unmounted. In box 806, the swap device is disabled. In box 807, the final shutdown operation is performed. This allows the first child process to continue running even when the initialization process stops.

[0098] Embodiments of this disclosure also provide corresponding apparatus for implementing the above methods or processes. Figure 9 A schematic block diagram of an example apparatus for ELF file verification according to some embodiments of the present disclosure is shown. The ELF file verification apparatus may be implemented as or included in terminal device 110 or server 120. The various modules / components in the example apparatus 900 for ELF file verification may be implemented by hardware, software, firmware, or any combination thereof.

[0099] like Figure 9 As shown, the example apparatus 900 for ELF file verification includes an execution module 910 configured to run a first verification process during the system kernel startup phase to perform digital signature verification on ELF files loaded during the system kernel startup phase before the system kernel completes initialization. A replacement module 920 is configured to create a first child process of the first verification process by calling a process creation function, and replace the first verification process with an initialization process; the initialization process is used to initiate the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF files after the system kernel initialization is completed. A creation module 930 is configured to create a second verification process through the initialization process; the second verification process is used to restart the first child process if the first child process encounters an error.

[0100] In some embodiments, the replacement module 920 is further configured to, in response to creating a first child process through a process creation function, allow the first child process to continue executing the program code of the first verification process; and, through the first verification process calling a process image replacement function, replace the program image of the first verification process with the executable file of the system initialization program to obtain the initialization process.

[0101] In some embodiments, the apparatus 900 for ELF file verification is further configured to, after creating a first child process of the first verification process by calling a process creation function through the first verification process and replacing the first verification process with an initialization process, add an immune prefix character to the process name of the first child process. The immune prefix character is used to cause the termination process during the shutdown phase to skip the first child process when traversing processes. Furthermore, the process termination mode in the service configuration corresponding to the second verification process is set to terminate only the main process, and the forced termination signal sending is disabled. Disabling the forced termination signal sending means disabling the function of sending a final forced termination signal to the remaining processes after the service stop timeout expires, so as to maintain the operation of the first child process when the initialization process stops.

[0102] In some embodiments, the creation module 930 is further configured to read the service unit file corresponding to the second verification process through the initialization process to obtain the configuration data of the second verification process; the configuration data includes at least one of the following: executable file path, process termination mode, whether to send a forced termination signal, and environment variables, wherein whether to send a forced termination signal is used to indicate whether to send a final forced termination signal to the remaining processes after the service stop timeout expires; create a second child process of the initialization process according to the configuration data, and load the executable file corresponding to the executable file path in the second child process to create the second verification process; the second verification process is used to listen for the connection of the first child process, receive heartbeat messages, and trigger the restart of the first child process if the heartbeat message times out.

[0103] In some embodiments, the creation module 930 is further configured to establish a communication connection between the first subprocess and the second verification process, so that the first subprocess sends a heartbeat message to the second verification process through the communication connection; in response to determining that no heartbeat message is received within a preset time, the first subprocess is restarted by the second verification process.

[0104] In some embodiments, the creation module 930 is further configured to create a Unix domain socket client through a first child process and initiate a connection request to the listening address pre-bound to the second verification process based on the Unix domain socket client; in response to determining that the connection between the first child process and the second verification process fails, re-initiating the connection request based on a timer according to an exponential backoff strategy until the first child process and the second verification process successfully connect; in response to determining that the connection between the first child process and the second verification process is successful, receiving the connection request through the second verification process and registering a client socket and a timeout timer corresponding to the connection request, wherein the client socket is the connected socket obtained by the second verification process after receiving the connection request; and periodically sending heartbeat messages to the second verification process through the first child process based on the communication connection. Thus, the device 900 for ELF file verification can monitor the heartbeat status of the first child process through the second verification process and trigger the first child process to restart when the heartbeat message times out, improving the continuity of the verification service.

[0105] According to the example device for ELF file verification, the execution module 910 can run a first verification process before the system kernel completes initialization to perform digital signature verification on the ELF file loaded during the system kernel startup phase; the replacement module 920 can create a first child process, which continues to perform digital signature verification on the ELF file after the system kernel initialization is complete, and replaces the first verification process with the initialization process; the creation module 930 can create a second verification process through the initialization process, which restarts the first child process if the first child process encounters an error. This improves the continuity of ELF file digital signature verification and system security.

[0106] Figure 10 Block diagrams of electronic devices capable of implementing various embodiments of the present disclosure are shown. (See diagram for example.) Figure 10 As shown, electronic device 1000 is in the form of a general-purpose electronic device. Components of electronic device 1000 may include, but are not limited to, one or more processing units 1010, memory 1020, storage device 1030, one or more communication units 1040, one or more input devices 1050, and one or more output devices 1060. Processing unit 1010 may be a physical or virtual processor and is capable of performing various processes according to programs stored in memory 1020. In a multiprocessor system, multiple processing units execute computer-executable instructions in parallel to improve the parallel processing capability of electronic device 1000.

[0107] Electronic device 1000 typically includes multiple computer storage media. Such media can be any accessible media that is accessible to electronic device 1000, including but not limited to volatile and non-volatile media, removable and non-removable media. Memory 1020 can be volatile memory (e.g., registers, cache, random access memory (RAM)), non-volatile memory (e.g., read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. Storage device 1030 can be removable or non-removable media and may include machine-readable media, such as flash drives, disks, or any other media capable of storing information and / or data and accessible within electronic device 1000.

[0108] Electronic device 1000 may further include additional removable / non-removable, volatile / non-volatile storage media. Although not explicitly stated... Figure 10 As shown, disk drives for reading from or writing to removable, non-volatile disks (e.g., "floppy disks") and optical disk drives for reading from or writing to removable, non-volatile optical disks can be provided. In these cases, each drive can be connected to a bus (not shown) via one or more data media interfaces. Memory 1020 may include computer program product 1025 having one or more program modules configured to perform various methods or actions of various embodiments of this disclosure.

[0109] The communication unit 1040 enables communication with other electronic devices via a communication medium. Additionally, the functionality of the components of the electronic device 1000 can be implemented using a single computing cluster or multiple computing machines capable of communicating via communication connections. Therefore, the electronic device 1000 can operate in a networked environment using logical connections to one or more other servers, network personal computers (PCs), or another network node.

[0110] Input device 1050 can be one or more input devices, such as a mouse, keyboard, trackball, etc. Output device 1060 can be one or more output devices, such as a monitor, speaker, printer, etc. Electronic device 1000 can also communicate with one or more external devices (not shown) via communication unit 1040 as needed. These external devices include storage devices, display devices, etc., and can communicate with one or more devices that enable user interaction with electronic device 1000, or with any device that enables electronic device 1000 to communicate with one or more other electronic devices (e.g., network card, modem, etc.). Such communication can be performed via input / output (I / O) interface (not shown).

[0111] According to an exemplary implementation of this disclosure, a computer-readable storage medium is provided that stores computer-executable instructions thereon, wherein the computer-executable instructions are executed by a processor to implement the methods described above. According to an exemplary implementation of this disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, which are executed by a processor to implement the methods described above.

[0112] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatuses, devices, and computer program products implemented according to this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0113] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processing unit of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0114] Computer-readable program instructions may be loaded onto a computer, other programmable data processing apparatus or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus or other device to produce a computer-implemented process, thereby causing the instructions that execute on the computer, other programmable data processing apparatus or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0115] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction, which contains one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0116] Various implementations of this disclosure have been described above. The foregoing description is exemplary and not exhaustive, nor is it limited to the disclosed implementations. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described implementations. The terminology used herein is chosen to best explain the principles, practical applications, or improvements to technology in the market, or to enable others skilled in the art to understand the various implementations disclosed herein.< / interface>

Claims

1. A method for ELF file verification, characterized in that, The method includes: During the system kernel startup phase, a first verification process is run to perform digital signature verification on the ELF file loaded during the system kernel startup phase before the system kernel completes initialization. The first verification process calls the process creation function to create a first child process of the first verification process, and replaces the first verification process with an initialization process; the initialization process is used to start the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF file after the system kernel initialization is completed; A second verification process is created through the initialization process; the second verification process is used to restart the first sub-process when the first sub-process encounters an error.

2. The method according to claim 1, characterized in that, The step of creating a first child process of the first verification process by calling a process creation function of the first verification process, and replacing the first verification process with an initialization process, includes: In response to the creation of the first child process through the process creation function, the first child process continues to execute the program code of the first verification process; The first verification process calls the process image replacement function to replace the program image of the first verification process with the executable file of the system initialization program, thereby obtaining the initialization process.

3. The method according to claim 1, characterized in that, After creating a first child process of the first verification process by calling the process creation function of the first verification process and replacing the first verification process with the initialization process, the method further includes: An immune prefix character is added to the process name of the first child process. The immune prefix character is used to make the terminated process during the shutdown phase skip the first child process when traversing the process. Set the process termination mode in the service configuration corresponding to the second verification process to terminate only the main process and disable the forced termination signal sending, so as to maintain the first child process running when the initialization process stops.

4. The method according to claim 1, characterized in that, The creation of the second verification process through the initialization process includes: The initialization process reads the service unit file corresponding to the second verification process to obtain the configuration data of the second verification process; the configuration data includes at least one of the following: executable file path, process termination mode, whether to send a forced termination signal, and environment variables; The second subprocess of the initialization process is created according to the configuration data, and the executable file corresponding to the executable file path is loaded in the second subprocess to create the second verification process; the second verification process is used to listen for the connection of the first subprocess, receive heartbeat messages, and trigger the restart of the first subprocess if the heartbeat message times out.

5. The method according to claim 1, characterized in that, The second verification process restarts the first child process when the first child process encounters an error, including: Establish a communication connection between the first subprocess and the second verification process, so that the first subprocess can send a heartbeat message to the second verification process through the communication connection; In response to the determination that no heartbeat message is received within a preset time, the first subprocess is restarted through the second verification process.

6. The method according to claim 5, characterized in that, Establishing a communication connection between the first subprocess and the second verification process includes: The first child process creates a Unix domain socket client and initiates a connection request to the listening address pre-bound to the second authentication process based on the Unix domain socket client. In response to the determination that the connection between the first subprocess and the second verification process has failed, the connection request is re-initiated based on a timer and an exponential backoff strategy until the first subprocess and the second verification process successfully connect. In response to determining that the first subprocess and the second verification process have successfully connected, the second verification process receives the connection request and registers the client socket and timeout timer corresponding to the connection request; the first subprocess periodically sends the heartbeat message to the second verification process based on the communication connection.

7. An apparatus for verifying ELF files, characterized in that, The device includes: The execution module is configured to run a first verification process during the system kernel startup phase, so as to perform digital signature verification on the ELF file loaded during the system kernel startup phase before the system kernel completes initialization. The replacement module is configured to create a first child process of the first verification process by calling the process creation function of the first verification process, and replace the first verification process with an initialization process; the initialization process is used to start the initialization of the system kernel, and the first child process is used to perform digital signature verification on the ELF file after the system kernel initialization is completed; A creation module is configured to create a second verification process through the initialization process; the second verification process is used to restart the first subprocess when the first subprocess encounters an error.

8. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the method for ELF file verification as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor performs the method for ELF file verification as described in any one of claims 1 to 6.

10. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the method for ELF file verification as described in any one of claims 1 to 6.