A hot patch processing method, device and storage medium
By limiting the number of patch threads and security detection time in thermal patch technology, ensuring that thermal patches are executed after safety checks are performed when conditions are met, the problems of low efficiency and poor stability of thermal patch operations in the existing technology are solved, and the improvement is achieved Safe and efficient thermal patching process.
Patent Information
- Application Number
- CN202110343192.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-30
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-03-30
AI Technical Summary
Existing hot patching technology is inefficient when performing security checks, which may cause the program to be suspended for a long time, and may even cause program logic errors or crashes, and cannot effectively avoid service interruptions.
By determining the number of threads and security detection of the interrupt time of the patch thread meets the preset threshold, decide whether to perform hot patch operations, and pause the thread for security checks when the conditions are met, then perform hot patches to ensure that the system stability is not affected Patch operation in the case of
It effectively avoids program pause and interrupt problems caused by excessive thread count or long security checking, improves the security and efficiency of hot patch operations, and reduces service interruption time.
Smart Images

Figure CN115146273B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software technology, and in particular to a hot patch processing method, device and storage medium. Background Art
[0002] Hot patching is a technology that modifies program code or the business logic of program code without restarting the running program. In the past, when there was no hot patching technology, if you wanted to update the software, you had to close the program first and then start the modified new program. This restart solution would cause a long service interruption; and restarting the program would lose the temporary status information in the memory, and the information that was not saved after the program was restarted could no longer be restored. Using hot patching technology does not require restarting the program, and the temporary information can be retained, while reducing the service interruption time.
[0003] The prior art uses an unconditional jump instruction to overwrite the header of the patched function code in the memory, directly skipping the execution of the subsequent logic of the patched function and executing the patched function instead. Directly overwriting the code is a very dangerous operation. If the overwritten code is being executed, it may cause program logic errors or even crash the patched program.
[0004] Process hot patching usually requires patching multiple functions at the same time, and these functions are interrelated. If a hot patch is applied when some functions are being executed, the pre-patch version of the function and the post-patch version of the function may be running at the same time after the patch is applied, causing program logic errors or even crashing the patched program.
[0005] In response to the above two unsafe situations, some existing solutions have adopted security check operations. However, existing process hot patching technology usually uses two strategies for security checks. One is not to perform the security check step. This solution does not suspend the execution of the program, does not check the function stack of the program, and directly replaces the function. Although the operation takes a short time and is very efficient, it is extremely dangerous and can easily cause program logic errors or even crash the patched program. The other uses unoptimized security checks. The security check in this solution takes a long time and is inefficient, causing the program to be suspended for a long time and not respond for a long time. In typical application cases, the service interruption time is as long as half an hour. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a hot patch processing method, device and storage medium.
[0007] The technical solution of the embodiment of the present invention is implemented as follows:
[0008] An embodiment of the present invention provides a hot patch processing method, including:
[0009] Determine parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information includes at least: the number of threads of the patch thread and / or information indicating the interruption duration of the patched program when the patch thread performs security detection during the patch operation;
[0010] Determining whether the parameter information satisfies a patch execution condition;
[0011] Whether to execute a hot patch operation is determined according to whether the parameter information satisfies a patch execution condition.
[0012] In the above solution, the step of determining whether to execute the hot patch operation according to whether the parameter information satisfies the patch execution condition includes:
[0013] When the parameter information meets the patch execution condition, performing a hot patch operation;
[0014] or,
[0015] When the parameter information does not satisfy the patch execution condition, the hot patch operation is skipped.
[0016] In the above solution, the parameter information satisfies the patch execution conditions, including:
[0017] The number of the patch threads does not exceed a first preset threshold,
[0018] and / or,
[0019] The patch thread interrupts the patch program when performing security detection during the patch operation process for a duration that does not exceed a second preset threshold.
[0020] In the above scheme, the method further comprises:
[0021] pausing the patch thread;
[0022] Performing a security check on the patch thread after the pause;
[0023] The operation of performing the hot patch includes:
[0024] After passing the security check, the hot patch operation is performed.
[0025] In the above scheme, the method further comprises:
[0026] Determining whether the patch thread needs to perform the security check;
[0027] The performing of a security check on the patch thread after the pause includes:
[0028] When it is determined that the patch thread needs to perform the security check, perform the security check operation and configure cache space for the patch thread;
[0029] The cache space provides the storage capacity required by the patch thread to perform security checks.
[0030] In the above solution, the step of determining whether the patch thread needs to perform the security check includes:
[0031] When it is determined that the patch thread does not need to perform the security check, the security check operation is skipped.
[0032] In the above solution, the security check on the patch thread after the pause includes:
[0033] Determining the inspection result of the security inspection;
[0034] According to the inspection result, when it is determined that the security inspection of the patch thread passes, the hot patch operation is performed.
[0035] In the above solution, the determining the inspection result of the security inspection further includes:
[0036] When it is determined according to the check result that the security check of the patch thread fails, the operation of shielding the hot patch is skipped.
[0037] The embodiment of the present invention further provides a hot patch processing device, the device comprising: a determination module, a judgment module and an execution module; wherein:
[0038] A determination module, used to determine parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information includes at least: the number of threads of the patch thread and / or information indicating the interruption duration of the patched program when the patch thread performs security detection during the patch operation;
[0039] A judgment module, used to determine whether the parameter information meets the patch execution condition;
[0040] The execution module is used to determine whether to execute the hot patch operation according to whether the parameter information meets the patch execution condition.
[0041] An embodiment of the present invention further provides a hot patch processing device, the device comprising: a processor and a memory for storing a computer program that can be run on the processor;
[0042] Wherein, when the processor is used to run the computer program, it executes the steps provided in any one of the above embodiments.
[0043] An embodiment of the present invention further provides a computer storage medium, characterized in that the computer storage medium stores computer executable instructions; after the computer executable instructions are executed by a processor, the method provided in any of the above embodiments can be implemented.
[0044] In the embodiment of the present invention, by limiting the number of threads in the patch thread in the patched process that executes the patch operation, the effect of ensuring the service interruption duration of executing the hot patch operation before the hot patch operation is performed is achieved; in addition, during the patch operation, the patch thread limits the interruption duration of the patched program when performing security detection, and limits the duration of the security check of the patch thread, thereby solving the problem in the prior art that the security check is time-consuming and inefficient, causing the program to be suspended and unresponsive for a long time; by limiting the number of threads of the patch thread and the interruption duration of the patch program, long interruptions of services when executing the hot patch operation are avoided. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0046] Figure 1 It is a schematic flow chart of the thermal patch processing method provided by the present invention;
[0047] Figure 2 A schematic diagram of a flow chart of a patch thread security check method provided in the present invention;
[0048] Figure 3 A schematic structural diagram of a thermal patch processing device provided by the present invention;
[0049] Figure 4 A schematic structural diagram of another thermal patch processing device provided by the present invention;
[0050] Figure 5 A schematic flow chart of another thermal patch processing method provided by the present invention. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present invention. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present invention.
[0052] In the absence of conflict, the embodiments and features of the embodiments of the present invention can be combined with each other at will. The steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions. In addition, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be performed in an order different from that here.
[0053] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present invention belongs. The terms used herein are only for the purpose of describing the embodiments of the present invention and are not intended to limit the present invention.
[0054] An embodiment of the present invention provides a thermal patch processing method. Figure 1 A schematic diagram of the process flow of the thermal patch processing method provided by the present invention; Figure 1 As shown, the method includes:
[0055] Step S101: determining parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information at least includes: the number of threads of the patch thread and / or information indicating the interruption duration of the patched program when the patch thread performs security detection during the patch operation;
[0056] Step S102: Determine whether the parameter information meets the patch execution condition;
[0057] Step S103: Determine whether to execute a hot patch operation according to whether the parameter information satisfies a patch execution condition.
[0058] Hot patching technology is divided into kernel hot patching and process hot patching. Kernel hot patching specifically refers to the hot patching technology that modifies the kernel of operating systems such as the Linux kernel, while process hot patching is the hot patching technology that modifies user programs. The working principle of process hot patching is to replace the erroneous function in the program with the patch function.
[0059] In this embodiment, in step S102, if the parameter information meets the patch execution condition, it means that the patched program can currently perform the hot patch operation; or when the patched program performs the hot patch operation, the program will not be suspended or unresponsive for a long time due to too many patch threads or too long interruption time of the patched program during the security check. By performing security detection on the patch thread, the problem of outgoing business logic errors and patch failures when the patched program performs the hot patch operation is also avoided.
[0060] In the step S101, in one embodiment, the parameter information of the patch thread in the patched process that performs the patch operation may be the parameter information of the patch thread in the patch process that determines the file to be patched; here, the parameter information includes the number of patch threads in the patch process and / or information indicating the interruption duration of the patched program when the patch thread performs security detection during the patch operation; wherein the interruption duration information may be the interruption duration when the patch thread is interrupted for security detection.
[0061] In the step S103, the operation of executing the hot patch includes: executing a loading operation of the hot patch or executing an unloading operation of the hot patch.
[0062] The hot patch operation is performed only when it is determined that the number of threads in the patch thread of the patched process that executes the patch operation meets the preset conditions, thereby avoiding the phenomenon that the program is suspended or unresponsive for a long time during the execution of the hot patch operation due to too many threads in the patch thread, and the service is interrupted for a long time; by limiting the interruption time of the patched program when executing the security check, the time for the security check of the patch thread is limited, and the problem of long time-consuming and low efficiency in the security check process and causing the program to be suspended or unresponsive for a long time in the prior art is solved; by limiting the two patch execution conditions of the number of threads of the patch thread and the interruption time of the patch program, the long interruption of the service when executing the hot patch operation is avoided.
[0063] Furthermore, before step S101, a patch file is loaded into the memory space of a patch thread in the patched process that performs the patch operation, wherein the patch file includes: a binary code compiled from the function to be patched.
[0064] Furthermore, the step S103 also includes: executing the hot patch operation when the parameter information meets the patch execution condition; and / or skipping the hot patch operation when the parameter information does not meet the patch execution condition.
[0065] Specifically, when it is determined that the parameter information meets the patch execution condition, the loading or unloading operation of the hot patch is performed; and / or, when the parameter information does not meet the patch execution condition, the patch thread skips the hot patch operation. In some embodiments, when it is determined that the number of threads of the patch thread does not meet the patch execution condition, the hot patch operation is skipped; waiting for user instructions, when the number of threads of the patch thread meets the patch execution condition, the hot patch operation is performed again. And / or, in the process of determining that the patch thread performs security detection, when the interruption duration of the interruption by the patch program does not meet the patch execution condition, the security check operation at this time is stopped, any action of the hot patch is canceled, and the operation of the patch thread is restored, and the hot patch loading or unloading operation fails; wait for the user's next hot patch operation to start, until the patch thread meets the patch execution condition, the hot patch operation is performed to complete the patch operation of the patch thread.
[0066] Furthermore, the parameter information satisfies the patch execution condition, including: the number of threads of the patch thread does not exceed a first preset threshold, and / or the interruption duration of the patch program when the patch thread performs security detection during the patch operation does not exceed a second preset threshold. Specifically, the first preset threshold may be the maximum allowed number of threads of the patch thread in the patch process; in some embodiments, the first preset threshold may be configured by the user.
[0067] In some other embodiments, the first preset threshold may be a default value or an empirical value preconfigured for the patch thread.
[0068] Here, the first preset threshold can be determined according to the number of executable threads on a single core and the number of physical cores of the computer. The first preset threshold can be any value less than the product of the number of executable threads on a single core and the number of physical cores of the computer.
[0069] The second preset threshold may be the maximum allowed interruption duration of the patch program when the patch thread performs security detection during the patch operation; in some embodiments, the second preset threshold may be configured by the user; in other embodiments, the second preset threshold may be a pre-configured default value for the patch thread.
[0070] Specifically, when the number of threads of the patch thread does not exceed the maximum allowed number of threads of the patch thread, and / or the interruption duration of the patch program when the patch thread performs security checks during the patch operation does not exceed the maximum allowed interruption duration, it is determined that the parameter information of the patch thread meets the patch execution conditions, and the loading or unloading operation of the hot patch can be executed.
[0071] The interruption duration may be: the difference between the real time of executing the current security detection and the start time of executing the current security detection.
[0072] It should be noted that, in the present embodiment, by limiting the number of threads in the patch thread in the patched process that executes the patch operation, the effect of ensuring the service interruption duration of the hot patch operation before the hot patch operation is performed is achieved; in addition, during the patch operation, the patch thread sets a second threshold for the information of the interruption duration of the patched program when performing the security check, thereby limiting the duration of the security check for the patch thread, thereby solving the problem in the prior art that the security check is time-consuming and inefficient, causing the program to be suspended or unresponsive for a long time; by limiting the number of threads of the patch thread and the interruption duration of the patch program, long interruptions of the service when performing the hot patch operation are avoided.
[0073] Furthermore, the step S103 also includes: pausing the patch thread; performing a security check on the patch thread after the pause; and the operation of executing the hot patch includes: executing the operation of the hot patch after passing the security check.
[0074] Specifically, the patch thread can be suspended by the user inputting a pause thread command of the corresponding system to suspend the patch thread; in a Linux system, the patch operation can be suspended by the ptrace attach command line; in a Windows system, the operation of the patch thread can be suspended by SuspendThread; the system where the patch thread is located can be any system, which is not limited here; the method of suspending the patch thread can be any method, which is not limited here.
[0075] Specifically, after the patch thread is suspended, a security check is performed on the patch thread, and when all the patch threads pass the security check, the operation of loading or unloading the hot patch is executed.
[0076] Furthermore, the security check is used to check whether all functions in the patched thread include functions in a stack; the stack is used to store running functions, that is, to determine whether the running functions in the stack include functions in the patched thread.
[0077] Specifically, according to the memory address range in the patched function code, it is determined whether the stack top frame address of the function corresponding to the stack top needle of the patch thread in the patched process that performs the patch operation exists in the memory address range in the patched function code.
[0078] If it exists, it means that the function corresponding to the top frame of the stack is the function that needs to be patched, but because the function is in the stack, that is, it is running; therefore, the patch thread contains the running function to be patched. At this time, if the hot patch operation is performed, the patched thread will have business logic errors, thread crashes, or patch failures. In this case, the security check will be considered to have failed.
[0079] If it does not exist, it means that the function corresponding to the top frame of the stack does not need to be patched.
[0080] Furthermore, it is determined in turn whether other functions of the patch thread in the stack exist in the memory address range of the patched function code. When all functions of all patch threads in the stack are not in the memory address range of the function code to be patched, it is determined that the function in the patched thread does not exist in the stack, and the security check passes.
[0081] Furthermore, before performing a security check on the patch thread after being paused, it also includes: determining whether the patch thread needs to perform the security check; the security check on the patch thread after being paused includes: when it is determined that the patch thread needs to perform the security check, performing the security check operation and configuring cache space for the patch thread; wherein the cache space provides the storage capacity required for the security check in the patch thread.
[0082] Specifically, the security check can be performed by the user setting a list of allowed security checks or a list of prohibited security checks for the thread under the patch, wherein the allowed list and the prohibited list are set by the user and cannot be effective at the same time; the allowed list and the prohibited list support fuzzy matching or expression matching.
[0083] The allowed list includes: the names of patch threads in the patched process that need to be security checked.
[0084] The prohibition list includes: names of patch threads in the patched process that do not require security checks.
[0085] The determination that the patch thread needs to undergo the security check may be: determining that the process ID (pid) or name of the patch thread matches the allowed list, or that the pid or name of the patch thread does not match the prohibited list.
[0086] Specifically, in one embodiment, the user selects to set an allow list that allows the patch thread to perform a security check. After completing the setting of the allow list, the patch thread queries the pid and / or name of the patch thread in the allow list according to the allow list. When it is determined that the patch thread pid or name is found in the allow list, the patch thread is said to match the allow list. At this time, it is determined that the patch thread needs to perform the security check, the security check operation is performed, and cache space is configured for the patch thread.
[0087] In another embodiment, the user chooses to set a prohibition list that prohibits the patch thread from performing a security check. After completing the setting of the prohibition list, the patch thread queries the pid and / or name of the patch thread in the prohibition list according to the prohibition list. When it is determined that the patch thread pid and / or name is not found in the prohibition list, it is said that the patch thread does not match the prohibition list. At this time, it is determined that the patch thread needs to perform the security check, the security check operation is performed, and cache space is configured for the patch thread.
[0088] Specifically, the cache space is used to cache the address offset between the function top frame addresses of the patch thread in the memory for performing the security check in the patch thread.
[0089] It should be noted that, according to the cache space, by introducing a cache mechanism in the security check process, the address offset between the function top frame address of the patch thread undergoing the security check in the memory is cached in the cache space; and then in the process of performing a security check on the patch thread, the address offset in the cache space can be queried to skip the time-consuming address offset calculation and speed up the check, thereby greatly improving the efficiency of the security check step and shortening the interruption time, thereby achieving safe and fast hot patching of the operation process.
[0090] Further, when it is determined that the patch thread does not need to perform the security check, the security check operation is skipped.
[0091] Specifically, in one embodiment, the user selects to set an allow list that allows the patch thread to perform a security check. After completing the setting of the allow list, the patch thread queries the pid and / or name of the patch thread in the allow list according to the allow list. When it is determined that the patch thread pid and / or name is not found in the allow list, it is said that the patch thread does not match the allow list. At this time, it is determined that the patch thread does not need to perform the security check, and the operation of performing the security check on the patch thread is skipped.
[0092] In another embodiment, the user chooses to set a prohibition list that prohibits the patch thread from performing a security check. After completing the setting of the prohibition list, the patch thread searches the prohibition list for the pid and / or name of the patch thread according to the prohibition list. When it is determined that the patch thread pid and / or name is found in the prohibition list, the patch thread is said to match the prohibition list. At this time, it is determined that the patch thread does not need to perform the security check, and the operation of performing the security check on the patch thread is skipped.
[0093] It should be noted that an allow list or a prohibit list is set, and the features such as the patch thread PID or name are matched with the allow list or the prohibit list, so as to filter out the threads that need to be security checked, and perform the security check operation only when the conditions for performing the security check are met, thereby reducing the number of executions of time-consuming security check steps, thereby reducing the workload of the inspection and improving efficiency.
[0094] Furthermore, after performing a security check on the patch thread after the pause, the method includes: determining a result of the security check; and executing the hot patch operation when it is determined that the security check of the patch thread passes according to the check result.
[0095] Furthermore, when it is determined according to the inspection result that the security inspection of the patch thread fails, the hot patch operation is skipped.
[0096] An embodiment of the present invention provides a method for checking the security of a patch thread. Figure 2 A schematic diagram of a flow chart of a patch thread security check method provided by the present invention; Figure 2 As shown, the method includes:
[0097] Step S201: Obtain the RIP address of the stack top frame of the function being executed in the patch thread in the RIP register, wherein the RIP address indicates the memory address of the stack top frame of the function currently running in the patch thread.
[0098] Specifically, the EIP register is expanded to the RIP 64-bit instruction register in 64-bit mode; the instruction register marks the location of the instruction to be executed by the current process. In this embodiment, the acquisition of the current frame address of the top frame of the function being executed in the patch thread in the RIP register is to determine the memory address of the top frame of the function being executed in the patch thread; the memory address of the top frame is the machine code address of the start instruction of the function.
[0099] Specifically, the memory address of the function start instruction in the RIP register of the function currently running in the patch thread is obtained; here, the memory address of the function start instruction is called the current frame address.
[0100] Step S202: Determine whether the current frame address belongs to the memory address range of the patch file.
[0101] Step S203: If the current frame address is within the memory address range of the patch file, the function corresponding to the current frame is the patched function, that is, the patch thread is in the stack; at this time, the security check fails and the security check ends.
[0102] Specifically, if the current frame address is within the range of the memory address of the patch file, the function corresponding to the current frame needs to be replaced by the patch function, but since the current frame is in the stack, the function corresponding to the current frame is running; at this time, if a hot patch operation is performed, it will cause program logic errors and even crash the patch thread program; therefore, step S203 is determined as failing the security check.
[0103] Step S204: If the current frame address is not within the memory address range of the patch file, the security check of the current frame passes, and step S205 is executed.
[0104] Step S205: Using the current frame address as a clue, query the address offset between the next frame and the current frame address in the cache space. If there is no result in the cache space, execute step S206; if there is a result in the cache space, execute step S208.
[0105] Here, in the process of performing security checks on the patch thread, by querying the address offset in the cache space, the time-consuming address offset calculation can be skipped, the check can be accelerated, the efficiency of the security check step is greatly improved, and the interruption time is shortened, thereby achieving safe and fast hot patching of the operation process.
[0106] Step S206: Calculate the address offset between the current frame address and the next frame address by using the Debugging With Attributed Record Formats (DWARF).
[0107] Specifically, the scheduler holds a certain mapping between the function name of the high-level code and the machine code address of the function start instruction. The high-level code can be composed of code languages such as Javascript, JAVA, C#, Python, etc. The DWARF can calculate the address offset of the memory address between the start instruction of any function in the thread and the start instruction of the next function by mapping the function name in the thread and the memory address of the function start instruction corresponding to the function.
[0108] Specifically, DWARF calculates the address offset between the current frame and the next frame address based on the current frame address and the function name; the next frame address is the memory address between the function start instructions of the next function.
[0109] Step S207: Cache the address offset into the cache space;
[0110] Step S208: Calculate the next frame address according to the frame address and the address offset;
[0111] Step S209: Determine whether the next frame reaches the bottom of the stack. If it reaches the bottom of the stack, it means that all frames in the patch thread have passed the security check and the patch thread is safe for hot patching operations; if it does not reach the bottom of the stack, execute step S210.
[0112] Specifically, it is determined whether the next frame reaches the bottom of the stack. If it reaches the bottom of the stack, this indicates that there is no next function, and the functions included in the patch thread have passed the security check, and the patch thread can perform hot patch operations; if it does not reach the bottom of the stack, the security check will continue to be performed on the next function.
[0113] Step S210: step into the next frame in the RIP register of the patch thread and execute step S201.
[0114] In this embodiment, according to the cache space, by introducing a cache mechanism during the security check process, the address offset between the current frame address and the next frame address during the security check is cached in the cache space; and then in the process of performing a security check on the patch thread, the address offset in the cache space can be queried to skip the time-consuming address offset calculation, thereby accelerating the check, greatly improving the efficiency of the security check step, and shortening the interruption time, thereby achieving safe and fast hot patching of the operation process.
[0115] The following is a specific example to illustrate the hot patch processing method of the embodiment of the present invention. Figure 5 As shown:
[0116] Step 1: Load the patch file into the memory space of the patched program. The patch file is the binary code compiled from the modified function.
[0117] Step 2: Get the number of threads of the patched process. If the number of threads is greater than the allowed number, cancel the patch operation.
[0118] Step 2.1: In the Linux system, query the number of subfolders in the process task folder under the process directory to obtain the number of threads of the patched process.
[0119] Step 2.2: After obtaining the number of threads of the patch process that needs to be patched by the patch file, if the number of threads is greater than the maximum allowed number of threads, the hot patch operation is skipped; if the number of threads is within the range of the maximum allowed number of threads, the subsequent patch process is continued.
[0120] The maximum number of threads allowed can be configured by the user, or a pre-configured default value can be used.
[0121] Step 3: Pause the execution of all patch threads of the patched process. In the Linux system, all patch threads are paused by calling the ptraceattach command line.
[0122] Step 4: Determine whether all patch threads need to be security checked one by one. For patch threads that need to be security checked, perform subsequent security check steps; for patch threads that do not need to be security checked, skip the check step.
[0123] Step 4.1: The user enters and sets the allow list and prohibit list as the basis for determining whether a security check is required. The allow list and prohibit list can only be selected one at a time, and cannot be effective at the same time. The allow list and prohibit list can support fuzzy matching or expression matching.
[0124] Step 4.2: In the Linux system, obtain the name of the patch thread through the comm file in the thread folder under the task directory in the process directory.
[0125] Step 4.3: If the patch thread process identifier (pid) or name matches the allowed list, continue with the subsequent security check operation; otherwise, skip the security check on the patch thread.
[0126] Step 4.4: If the patch thread process identifier (pid) or name matches the prohibition list, the subsequent security check operation is skipped; otherwise, a security check on the patch thread is performed.
[0127] Step 5: For patch threads that require security checks, introduce cache operations to speed up the process of checking thread security.
[0128] Step 5.1: For the patch thread that is being security checked, first obtain the value of the RIP register that is being executed in the thread, which points to the function run by the top frame of the patch thread stack. In the Linux system, the register value is obtained through the ptrace function.
[0129] Step 5.2: Determine whether the RIP address belongs to the memory address range of the patched function code. If it is within the memory address range of the patched function code, the function executed by the current frame is the function that needs to be patched, which means that the patched function is in the stack and the security check fails.
[0130] Step 5.3: If the current frame passes the security check, the address offset between the next frame and the current frame is queried in the cache space using the RIP value as a clue. If there is a result in the cache space, the time-consuming offset calculation process is skipped and step 5.7 is executed; otherwise, step 5.4 is executed.
[0131] Step 5.4: In Linux, calculate the address offset between the next frame and the current frame according to the DWARF standard. :
[0132] Step 5.5: Add the calculated address offset result to the cache space.
[0133] Step 5.6: Calculate the next frame address based on the current frame address and the next frame address offset.
[0134] Step 5.7: Determine whether the next frame reaches the bottom of the stack. If it reaches the bottom of the stack, it means that all frames in the patch thread have passed the security check and the patch thread is safe for hot patch operations.
[0135] Step 5.8: If the stack has not reached the bottom, do not proceed to the next frame, obtain the RIP register value of this frame, and then continue with step 5.2.
[0136] Step 6: When performing a security check, calculate the time the process has been suspended and determine whether it has timed out. If so, resume all threads.
[0137] Step 6.1: Set the maximum allowed interruption duration when the patch thread is interrupted for security detection, wherein the maximum allowed interruption duration can be configured by the user, or a pre-configured default value can be used.
[0138] Step 6.2: Record the start time when the patch thread interrupts the patched program when performing security detection during the patch operation.
[0139] Step 6.3: After the security check is completed, the interruption time of the patched program is obtained, and the time the patched process has been suspended is calculated. If the suspension time is greater than the maximum allowed interruption time, all threads are resumed to avoid long service interruptions. At this time, the hot patch operation fails.
[0140] Step 7: After all patch threads are processed and the security checks of all patch threads are normal, a hot patch operation is performed on the original function to complete the loading or unloading of the hot patch file.
[0141] Step 8: In the Linux system, resume thread operation through ptrace detach call. Resume the operation of all patch threads, and the hot patch operation process ends.
[0142] like Figure 3 , which is a schematic diagram of the structure of a hot patch processing device provided by an embodiment of the present invention, the hot patch processing device includes: a determination module 301, a judgment module 302 and an execution module 303.
[0143] The determination module 301 is used to determine parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information at least includes: the number of threads of the patch thread and / or information indicating the interruption duration of the patched program when the patch thread performs security detection during the patch operation;
[0144] The judgment module 302 is used to determine whether the parameter information meets the patch execution condition;
[0145] The execution module 303 is used to determine whether to execute a hot patch operation according to whether the parameter information meets a patch execution condition.
[0146] To implement the method of the embodiment of the present invention, the embodiment of the present invention provides a thermal patch processing device, specifically, as follows Figure 4 As shown, the device 40 includes a processor 401 and a memory 402 for storing a computer program that can be run on the processor;
[0147] Wherein, when the processor 401 is used to run the computer program, the following is performed: determining parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information includes at least: the number of threads of the patch thread and / or information indicating the interruption duration of the patched program when the patch thread performs a security check during the patch operation; determining whether the parameter information meets a patch execution condition; and determining whether to perform a hot patch operation based on whether the parameter information meets the patch execution condition.
[0148] In one embodiment, the processor 401 is also used to execute, when running the computer program: when the parameter information meets the patch execution condition, perform the hot patch operation; or when the parameter information does not meet the patch execution condition, skip the hot patch operation.
[0149] In one embodiment, the processor 401 is also used to execute, when running the computer program: determining that the parameter information satisfies the patch execution condition, including: the number of threads of the patch thread does not exceed a first preset threshold, and / or the interruption duration of the patch program when the patch thread performs security detection during the patch operation does not exceed a second preset threshold.
[0150] In one embodiment, the processor 401 is also used to execute, when running the computer program: pausing the patch thread; performing a security check on the patch thread after the pause; the operation of executing the hot patch includes: executing the hot patch operation after passing the security check.
[0151] In one embodiment, the processor 401 is also used to execute, when running the computer program: determining whether the patch thread needs to perform the security check; performing a security check on the patch thread after the pause, including: when it is determined that the patch thread needs to perform the security check, performing the security check operation and configuring cache space for the patch thread; wherein the cache space provides the storage capacity required for the patch thread to perform the security check.
[0152] In one embodiment, the processor 401 is also used to execute, when running the computer program: determining whether the patch thread needs to perform the security check, including: when it is determined that the patch thread does not need to perform the security check, skipping the security check operation.
[0153] In one embodiment, the processor 401 is also used to execute, when running the computer program: performing a security check on the patch thread after the pause, including: determining a result of the security check; and based on the check result, executing the hot patch operation when it is determined that the security check of the patch thread passes.
[0154] In one embodiment, the processor 401 is also used to execute, when running the computer program: determining the inspection result of the security check, and also including: skipping the hot patch operation when it is determined according to the inspection result that the security check of the patch thread fails.
[0155] It should be noted that the thermal patch processing device and the thermal patch processing method embodiment provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0156] Of course, in practical applications, Figure 4As shown, the device 40 may also include: at least one network interface 403. The various components in the hot patch processing device 40 are coupled together through a bus system 404. It can be understood that the bus system 404 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 404 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 4 In the figure, various buses are marked as bus system 404. There may be at least one processor 401. The network interface 403 is used for wired or wireless communication between the hot patch processing device 40 and other devices.
[0157] The memory 402 in the embodiment of the present invention is used to store various types of data to support the operation of the thermal patch processing device 40 .
[0158] The method disclosed in the above embodiment of the present invention can be applied to the processor 401, or implemented by the processor 401. The processor 401 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 401 or the instruction in the form of software. The above processor 401 may be a general processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 401 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiment of the present invention. The general processor may be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present invention, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 402. The processor 401 reads the information in the memory 1002 and completes the steps of the above method in combination with its hardware.
[0159] In an exemplary embodiment, the hot patch processing device 40 can be implemented by one or more application-specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), field programmable gate array (FPGA), general-purpose processor, controller, microcontroller (MCU), microprocessor, or other electronic components to execute the aforementioned method.
[0160] In an exemplary embodiment, the embodiment of the present invention further provides a computer-readable storage medium, such as a memory 402 including a computer program. The computer program can be executed by a processor 401 of a hot patch processing device 40 to complete the steps of the aforementioned method.
[0161] Specifically, an embodiment of the present invention also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the following operations are performed: determining parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information includes at least: the number of threads of the patch thread and / or information indicating the interruption duration of the patched program when the patch thread performs a security check during the patch operation; determining whether the parameter information meets a patch execution condition; and determining whether to perform a hot patch operation based on whether the parameter information meets the patch execution condition.
[0162] In one embodiment, when the computer program is executed by the processor, the following operations are performed: when the parameter information meets the patch execution condition, the hot patch operation is executed; or when the parameter information does not meet the patch execution condition, the hot patch operation is skipped.
[0163] In one embodiment, when the computer program is executed by the processor, it executes: determining that the parameter information satisfies the patch execution condition, including: the number of threads of the patch thread does not exceed a first preset threshold, and / or the interruption time of the patch thread when performing security detection during the patch operation does not exceed a second preset threshold.
[0164] In one embodiment, when the computer program is executed by the processor, the following operations are performed: pausing the patch thread; performing a security check on the patch thread after the pause; and the operation of executing the hot patch includes: executing the operation of the hot patch after passing the security check.
[0165] In one embodiment, when the computer program is executed by the processor, the following is performed: determining whether the patch thread needs to perform the security check; performing a security check on the patch thread after the pause, including: when it is determined that the patch thread needs to perform the security check, performing the security check operation and configuring cache space for the patch thread; wherein the cache space provides the storage capacity required for the patch thread to perform the security check.
[0166] In one embodiment, when the computer program is executed by the processor, the determination of whether the patch thread needs to perform the security check includes: when it is determined that the patch thread does not need to perform the security check, skipping the security check operation.
[0167] In one embodiment, when the computer program is executed by the processor, the following is performed: performing a security check on the patch thread after the pause, including: determining a result of the security check; and executing the hot patch operation when it is determined that the security check of the patch thread passes based on the check result.
[0168] In one embodiment, when the computer program is executed by the processor, the steps of determining the result of the security check and skipping the hot patch operation when it is determined based on the check result that the security check of the patch thread fails.
[0169] It should be noted that the computer-readable storage medium provided in the embodiment of the present invention may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface memory, optical disk, or CD-ROM; or it may be various devices including one or any combination of the above memories.
[0170] The above description is only an embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement and improvement made within the spirit and scope of the present invention are included in the protection scope of the present invention.
Claims
1. A thermal patch processing method, characterized in that: include: Determine parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information includes at least: the number of threads of the patch thread and information indicating the interruption duration of the patched program when the patch thread performs a security check during the patch operation; the interruption duration information is the difference between the real time of performing the current security check and the start time of performing the current security check; Determining whether the parameter information satisfies a patch execution condition; Determining whether to execute a hot patch operation according to whether the parameter information satisfies a patch execution condition; The step of determining whether to execute the hot patch operation according to whether the parameter information satisfies the patch execution condition includes: If the parameter information satisfies the patch execution condition and it is determined that the patch thread passes the security detection, the hot patch operation is executed.
2. The method according to claim 1, characterized in that Determining whether to execute a hot patch operation according to whether the parameter information satisfies a patch execution condition includes: When the parameter information does not satisfy the patch execution condition, the hot patch operation is skipped.
3. The method according to claim 1 or 2, characterized in that: The parameter information satisfies the patch execution conditions, including: The number of the patch threads does not exceed a first preset threshold, and / or, The patch thread interrupts the patch program when performing security detection during the patch operation process for a duration that does not exceed a second preset threshold.
4. The method according to claim 3, characterized in that The method further comprises: pausing the patch thread; Performing a security check on the patch thread after the pause; The operation of performing the hot patch includes: After passing the security check, the hot patch operation is performed.
5. The method according to claim 4, characterized in that The method further comprises: Determining whether the patch thread needs to perform the security check; The step of performing a security check on the patch thread after the pause includes: When it is determined that the patch thread needs to perform the security check, perform the security check operation and configure cache space for the patch thread; The cache space provides the storage capacity required by the patch thread to perform security checks.
6. The method according to claim 5, characterized in that The determining whether the patch thread needs to perform the security check includes: When it is determined that the patch thread does not need to perform the security check, the security check operation is skipped.
7. The method according to claim 4, characterized in that The step of performing a security check on the patch thread after the pause includes: Determining the inspection result of the security inspection; According to the inspection result, when it is determined that the security inspection of the patch thread passes, the hot patch operation is performed.
8. The method according to claim 7, characterized in that The step of determining the inspection result of the security inspection further includes: When it is determined according to the check result that the security check of the patch thread fails, the hot patch operation is skipped.
9. A thermal patch processing device, characterized in that: The device comprises: a determination module, a judgment module and an execution module; wherein, A determination module, used to determine parameter information of a patch thread in a patched process that performs a patch operation, wherein the parameter information includes at least: the number of threads of the patch thread and information indicating the interruption duration of the patched program when the patch thread performs a security check during the patch operation; the interruption duration information is the difference between the real time of performing the current security check and the start time of performing the current security check; A judgment module, used to determine whether the parameter information meets the patch execution condition; The execution module is used to execute the hot patch operation when the parameter information meets the patch execution condition and it is determined that the patch thread passes the security detection.
10. A thermal patch processing device, characterized in that: The apparatus comprises: a processor and a memory for storing a computer program capable of running on the processor; Wherein, when the processor is used to run the computer program, it executes the steps of any one of the methods described in claims 1 to 8.
11. A computer storage medium, characterized in that: The computer storage medium stores computer executable instructions; after the computer executable instructions are executed by the processor, the hot patch processing method according to any one of claims 1 to 8 can be implemented.
Citation Information
Patent Citations
Method, device and system for patching kernel on line
CN101799763A
Method and system for injecting hotfix into software of embedded system
CN104809018A
Hot patch realization method and apparatus, and terminal
CN107870777A
Application hot patch monitoring method and device
CN111258841A
Hot patch loading method and device, electronic equipment and storage medium
CN111949292A
