Data processing methods, apparatus, electronic devices and readable media
By processing kernel code files through indirect addressing and relocation, extracting differences and performing symbol replacements, and generating hot patch files, the problem of low loading efficiency of hot patch files is solved, and efficient kernel repair is achieved.
Patent Information
- Application Number
- CN202611087878.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-21
- Publication Date
- 2026-11-17
AI Technical Summary
The hot patch files generated in the existing technology have low loading efficiency and sometimes fail to load properly, resulting in low operating system kernel repair efficiency.
The original kernel code file and the repaired kernel code file are processed by indirect addressing relocation. By comparing and extracting the difference files, and performing symbol replacement operations on other sections except for the specified section files, hot patch files are generated.
This avoids module loading failures and the generation of redundant code, ensuring that hot patch files can be loaded normally and used efficiently.
Smart Images

Figure CN123114853A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a data processing method, apparatus, electronic device, and readable medium. Background Technology
[0002] Currently, to ensure the continuous online operation of the operating system, in the event of a kernel anomaly, a hot patch file containing repair code is generated to fix the kernel. The faulty device can achieve anomaly repair without rebooting or interrupting operation by dynamically loading and running the hot patch file.
[0003] In related technologies, whether hot patch files can be loaded normally and efficiently is the key to improving the efficiency of anomaly repair. Summary of the Invention
[0004] This invention provides a data processing method, apparatus, electronic device, and readable medium that can solve the problem of how to ensure that the generated hot patch file can be loaded normally and efficiently.
[0005] To address the above problems, this invention discloses a data processing method, the method comprising: Obtain the original compiled kernel code file and the repaired kernel code file; both the original kernel code file and the repaired kernel code file are relocated using an indirect addressing relocation method; The repaired kernel code file is compared with the original kernel code file, and the difference file is extracted from the repaired kernel code file; Symbol substitution operations are performed on all section files in the difference file except for the specified section file, and a hot patch file is generated; the specified section file includes a section file used to record the stack frame index.
[0006] On the other hand, embodiments of the present invention disclose a data processing apparatus, the apparatus comprising: The first acquisition module is used to acquire the compiled original kernel code file and the repaired kernel code file; both the original kernel code file and the repaired kernel code file are relocated through indirect addressing relocation. The comparison module is used to compare the repaired kernel code file with the original kernel code file, and extract the difference file from the repaired kernel code file; The processing module is used to perform symbol replacement operations on the section files other than the specified section file in the difference file, and generate a hot patch file; the specified section file includes a section file used to record the stack frame index.
[0007] In another aspect, embodiments of the present invention disclose an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store executable instructions, which cause the processor to execute the aforementioned method.
[0008] This invention also discloses a machine-readable medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described above.
[0009] The embodiments of this invention have the following advantages: The data processing method provided in these embodiments obtains the compiled original kernel code file and the repaired kernel code file; both the original and repaired kernel code files undergo relocation processing using indirect addressing relocation. The repaired kernel code file is compared with the original kernel code file, and the difference file is extracted from the repaired kernel code file. Symbol substitution operations are performed on all section files in the difference file except for the specified section file, and a hot patch file is generated; the specified section file includes a section file used to record the stack frame index. In these embodiments, since the relocation processing for relocation items using indirect addressing relocation is not affected by the distance between the module load address and the kernel base address, the problem of module loading failure can be avoided, ensuring that the hot patch file can be loaded normally. Furthermore, by performing symbol substitution operations on all section files except the specified section file, unnecessary operations can be avoided, thereby avoiding the generation of redundant code in the hot patch file, allowing the hot patch file to be efficiently loaded by the operating system kernel. Attached Figure Description
[0010] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments of the present invention will be briefly introduced below.
[0011] Figure 1 This is a flowchart of the steps of a data processing method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a processing flow provided in an embodiment of the present invention; Figure 3 This is a block diagram of a data processing device provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0012] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0013] First, an application scenario related to an embodiment of the present invention will be described. This embodiment can be applied to kernel hot patch generation scenarios. Kernel hot patches can dynamically repair security vulnerabilities and errors in the kernel during operating system operation without restarting the operating system. By replacing the functions that cause exceptions during kernel runtime with kernel hot patches, dynamic repair of the kernel can be achieved, thereby improving system availability and security.
[0014] In related technologies, when the operating system kernel in a device malfunctions, technicians write repair code specifically for the device. This repair code is used to fix the currently running kernel source code (hereinafter referred to as the original kernel source code) on the device, resulting in a repaired kernel source code. The original and repaired kernel source codes are then compiled separately to obtain original and repaired kernel code files. A hot patch file is then generated based on these files. Finally, the hot patch file is applied to the device to repair the malfunctioning operating system kernel. However, the hot patch files generated in these technologies suffer from low loading efficiency and sometimes fail to load correctly.
[0015] Therefore, embodiments of the present invention provide a data processing method, which will be described in detail below.
[0016] Figure 1 This is a flowchart of the steps of a data processing method provided in an embodiment of the present invention, as follows: Figure 1 As shown, the data processing method may include the following steps: Step 101: Obtain the original compiled kernel code file and the repaired kernel code file; both the original kernel code file and the repaired kernel code file are relocated using the indirect addressing relocation method.
[0017] Step 102: Compare the repaired kernel code file with the original kernel code file, and extract the difference file from the repaired kernel code file.
[0018] Step 103: Perform symbol replacement operations on all section files in the difference file except for the specified section file, and generate a hot patch file; the specified section file includes the section file used to record the stack frame index.
[0019] In this invention, hot-patched files are essentially kernel modules that can be dynamically loaded and used by the operating system kernel. The original kernel code file is an executable file obtained by compiling the original kernel source code, while the repaired kernel code file is an executable file obtained by compiling the repaired kernel source code. In this embodiment, both the compiled original kernel code file and the repaired kernel code file employ indirect addressing relocation. That is, during the compilation process of the original and repaired kernel source code, relocation entries indicating the use of indirect addressing relocation are directly generated, ensuring that all relocation entries in both the original and repaired kernel code files indicate that relocation processing is performed using indirect addressing relocation.
[0020] In related technologies, when generating hot patch files, the original kernel code file and the repaired kernel code file often employ direct addressing relocation. This means that the relocation entries (e.g., the R_LARCH_PCALA relocation entry) included in the original and repaired kernel code files represent direct addressing. This results in the relocation entries in the generated hot patch file also indicating direct addressing relocation. However, when loading a hot patch file onto an abnormal device for relocation processing, if the distance between the module load address of the hot patch file and the kernel base address of the abnormal device is too large, relocation errors often occur, preventing the hot patch file from being loaded correctly. In contrast, relocation entries indicating indirect addressing relocation are unaffected by the distance between the module load address and the kernel base address during relocation processing, avoiding module loading failures and ensuring successful module loading.
[0021] Furthermore, during the compilation process, when encountering function call points, the symbols of the called functions are often represented in the form of section symbol addresses (section symbol + offset). However, related technologies typically require replacing all section files in the hot patch file during its generation. This leads to unnecessary replacement of section files (i.e., specified section files) that use section symbol addresses to represent stack frame indices, resulting in redundant code, increased hot patch file size, and subsequent inefficient loading. In this embodiment, after obtaining the repaired kernel code file and the original kernel code file, a comparison is performed to identify and extract relevant content that differs between the repaired and original kernel code files, resulting in a difference file. Symbol replacement is performed only on section files in the difference file, except for the specified section file, resulting in a size-optimized hot patch file. This avoids redundant code in the hot patch file generated based on the replaced difference file, allowing the hot patch file to be efficiently loaded by the operating system kernel.
[0022] In summary, the data processing method provided in this embodiment of the invention obtains both the compiled original kernel code file and the repaired kernel code file. Both the original and repaired kernel code files undergo relocation processing using an indirect addressing relocation method. The repaired kernel code file is compared with the original kernel code file, and the difference file is extracted from the repaired kernel code file. Symbol substitution operations are performed on all section files in the difference file except for the specified section file, and a hot patch file is generated. The specified section file includes the section file used to record the stack frame index. Since the relocation processing for relocation items using the indirect addressing relocation method is not affected by the distance between the module load address and the kernel base address, the problem of module loading failure can be avoided, ensuring that the hot patch file can be loaded normally. Furthermore, by performing symbol substitution operations on all section files except the specified section file, unnecessary operations can be avoided, thereby avoiding the generation of redundant code in the hot patch file, allowing the hot patch file to be efficiently loaded by the operating system kernel.
[0023] Optionally, in this embodiment of the invention, the relocation entries in the original kernel code file and the repaired kernel code file are indirect addressing relocation entries based on the Global Offset Table (GOT). The indirect addressing relocation entry is used to instruct the kernel loader to use an indirect addressing processing method. This indirect addressing processing method includes: writing the actual address of the function to the GOT address corresponding to the called function in the GOT; and filling the function call instruction with the instruction address difference between the GOT address and the function call instruction, so as to jump to the actual address of the function written at the GOT address through the function call instruction.
[0024] The Gate Address Table (GOT) stores the absolute address of a symbol (i.e., the actual address of the function). When a function is called, the stored actual address is retrieved from the GOT, and the caller jumps to that address to execute the called function. The GOT allows overcoming the limitations of direct addressing. Indirect addressing relocation entries based on the GOT can be R_LARCH_GOT_PC relocation entries. These R_LARCH_GOT_PC relocation entries can include two types: R_LARCH_GOT_PC_HI20 and R_LARCH_GOT_PC_LO12, which respectively indicate filling the immediate field of the pcalau12i instruction and the immediate field of the ld.d instruction.
[0025] Function call instructions are a set of instructions used to call a function (i.e., jump to the actual address of the function for execution). If direct addressing is used, during the compilation process, for each call point of a function, corresponding function call instructions will be generated in the code section file. The function call instructions for a function usually include a set of instructions (hereinafter referred to as the call instruction set), and the function call is achieved by executing this set of instructions.
[0026] For example, in one implementation, the function call instruction set may include the pcalau12i instruction and the addi.d instruction. Correspondingly, for this call instruction set, two relocation entries for direct addressing mode (hereinafter referred to as direct addressing relocation entries) are generated. The type of the relocation entry corresponding to the pcalau12i instruction can be R_LARCH_PCALA_HI20, and the type of the relocation entry corresponding to the addi.d instruction can be R_LARCH_PCALA_LO12. The instructions of types R_LARCH_PCALA_HI20 and R_LARCH_PCALA_LO12 implement relocation via direct addressing. The two types R_LARCH_PCALA_HI20 and R_LARCH_PCALA_LO12 are used to indicate filling the immediate field of the pcalau12i instruction and filling the immediate field of the addi.d instruction, respectively. In related technologies, relocation items can include Info, Offset, Type, Symbol, and Addend. Info represents a symbol index item, and before symbol replacement, the value of Info can be a section symbol. Offset points to the position of the immediate value that needs to be filled in the instruction corresponding to the relocation item. Type represents the type of the relocation item. Symbol represents the function name of the function called corresponding to the relocation item. Addend represents the fine-tuning parameter, and before symbol replacement, the value of Addend can be an offset.
[0027] For example, taking a call point for the print function as an example, a set of pcalau12i instructions and addi.d instructions (i.e., the function call instructions corresponding to the print function) will be generated for the called function (print function in this example). Two relocation entries will be generated for the pcalau12i instructions and the addi.d instructions respectively. The called function corresponding to these two relocation entries is the print function.
[0028] In this approach, all relocation entries in the relocation section of the difference file are direct addressing relocation entries. Correspondingly, when the faulty device loads the hot patch file generated based on the difference file for relocation processing, the kernel loader directly determines the runtime address (i.e., the actual address of the function) of the called function in the kernel symbol table. The kernel loader is part of the operating system kernel and is implemented in the kernel code. For the direct addressing relocation entry corresponding to the called function, the difference between the actual address of the function and the instruction address of the instruction corresponding to the direct addressing relocation entry is calculated to fill the immediate field of the pcalau12i instruction and the immediate field of the addi.d instruction. The instruction address corresponding to the direct addressing relocation entry refers to the address of the instruction in the calling instruction group corresponding to the direct addressing relocation entry. Next, if the type of the relocation entry is R_LARCH_PCALA_HI20, the high 20 bits of the difference are written to the immediate field of the corresponding instruction; if the type of the relocation entry is R_LARCH_PCALA_LO12, the low 12 bits of the difference are written to the immediate field of the corresponding instruction.
[0029] For example, for the direct addressing relocation entry corresponding to the pcalau12i instruction, the difference between the actual address of the function and the instruction address of the pcalau12i instruction is calculated, and the high 20 bits of this difference are written into the immediate field of the pcalau12i instruction. For the direct addressing relocation entry corresponding to the addi.d instruction, the difference between the actual address of the function and the instruction address of the addi.d instruction is calculated, and the low 12 bits of this difference are written into the immediate field of the addi.d instruction to achieve relocation processing. By executing the pcalau12i instruction and the addi.d instruction after they have been filled, relocation is performed with the immediate fields updated by the two instructions, jumping to the actual address of the function for execution, thereby calling the function.
[0030] Since the instruction address corresponding to the relocation item in the hot patch file is often determined by the module load address allocated by the hot patch file when it is loaded, for example, the value of the instruction address is: module load address + offset of the instruction in the code section file.
[0031] The called function is often a kernel function, and the actual address of the called function is: kernel base address + fixed offset of the called function. The kernel base address is a fixed value determined during the compilation of the original kernel code file, while the module load address depends on the memory layout when the module is loaded, the number of loaded modules, and the location of free regions. Therefore, sometimes the distance between the kernel base address and the module load address is too large; for example, the difference between the kernel base address and the module load address exceeds a preset upper limit. This leads to a problem where the difference between the actual function address and the instruction address corresponding to the direct addressing relocation entry is too large (e.g., the difference exceeds the preset upper limit).
[0032] The relocation mechanism requires that the calculated difference not exceed a preset upper limit, which can be the range supported by the representation of the difference (hereinafter referred to as the preset representation range). For example, if the calculated difference is represented by a 32-bit signed number, the calculated difference must not exceed the representation range of a 32-bit signed number. If the distance between the module load address and the kernel base address is too large, the difference may become too large, exceeding the preset upper limit, i.e., exceeding the preset representation range, resulting in data overflow. This can lead to problems such as the hot patch file failing to load correctly and kernel crashes.
[0033] This invention employs an indirect addressing relocation method. During compilation, for each called function, a relocation entry of type R_LARCH_64 is generated. This R_LARCH_64 relocation entry instructs the kernel loader to write the actual address of the called function to the corresponding GOT address in the GOT. For any call point of a function, a corresponding call instruction set is generated in the code section file, allowing the function to be called by executing the instructions in the call instruction set.
[0034] For example, in one implementation, the function call instruction group may include: pcalau12i instructions, ld.d instructions, and jirl instructions. Correspondingly, for the pcalau12i and ld.d instructions in this call instruction group, two relocation entries for indirect addressing mode (hereinafter referred to as indirect addressing relocation entries) are generated respectively. The type of the relocation entry corresponding to the pcalau12i instruction can be R_LARCH_GOT_PC_HI20, and the type of the relocation entry corresponding to the ld.d instruction can be R_LARCH_GOT_PC_LO12. The indirect addressing relocation entries include: relocation entries of type R_LARCH_64, relocation entries of type R_LARCH_GOT_PC_HI20, and relocation entries of type R_LARCH_GOT_PC_LO12, respectively indicating that the runtime address of the called function is written to the GOT address of the called function, the immediate field of the pcalau12i instruction is filled, and the immediate field of the ld.d instruction is filled. In this embodiment of the invention, the relocation section file including indirect addressing relocation entries includes: a relocation section file storing relocation entries of type R_LARCH_64 (hereinafter referred to as the first relocation section file), and a relocation section file storing relocation entries of type R_LARCH_GOT_PC_HI20 and relocation entries of type R_LARCH_GOT_PC_LO12 (hereinafter referred to as the second relocation section file).
[0035] In this approach, all relocation entries in the relocation section of the difference file are indirect addressing relocation entries. Correspondingly, when the faulty device loads the hot patch file generated based on the difference file and performs relocation processing, the kernel loader first processes relocation entries of type R_LARCH_64 in the loading mechanism. When processing R_LARCH_64 relocation entries, the kernel loader determines the runtime address (i.e., the actual address of the function) of the function called in the kernel symbol table, and uses the base address of the first relocation section file (hereinafter referred to as GOT_base) plus the value of Offset in the R_LARCH_64 relocation entry as the GOT address of the called function corresponding to that R_LARCH_64 relocation entry. Here, the GOT address can also be called the GOT entry address, and the Offset parameter in the R_LARCH_64 relocation entry represents the offset of the called function relative to the base address of the first relocation section file. Next, the runtime address of the called function is written to the GOT address of the called function, so that the actual function address can be retrieved from it later, and the caller can jump to the retrieved actual function address to execute the called function. The GOT address points to an entry in the GOT. For example, assuming GOT_base is 0xffff900000002000, and the offset value in the R_LARCH_64 type relocation entry is 0x0000, then the GOT address of the called function can be 0xffff900000002000. Assuming the runtime address (i.e., the actual function address) of the called function is 0xffffffff81112233, then the actual function address 0xffffffff81112233 can be written to the GOT entry pointed to by memory address 0xffff900000002000 for subsequent calls.
[0036] Next, relocation processing is performed on the second relocation section file. For the indirect addressing relocation entry corresponding to the pcalau12i instruction in the call function group corresponding to the called function, the difference between the GOT entry address and the instruction address corresponding to the indirect addressing relocation entry is calculated to fill the immediate field of the pcalau12i instruction and the immediate field of the ld.d instruction. The high 20 bits of this difference are written to the immediate field of the instruction corresponding to the indirect addressing relocation entry, and the low 12 bits of this difference are written to the immediate field of another instruction in the call function group corresponding to the called function, namely the ld.d instruction.
[0037] For example, for the indirect addressing relocation entry corresponding to the pcalau12i instruction, the difference between the GOT entry address and the instruction address of the pcalau12i instruction is calculated. The high 20 bits of this difference are written to the immediate field of the pcalau12i instruction, and the low 12 bits are written to the immediate field of the ld.d instruction, thus implementing the relocation processing for the indirect addressing relocation entry corresponding to the ld.d instruction. For example, referring to the previous example, the GOT entry address can be 0xffff900000002000. Assuming the instruction address of the pcalau12i instruction is 0xffff900000001100, the calculated difference can be 0x00000000000000F00. The high 20 bits of 0x00000000000000F00 can be written to the immediate field of the pcalau12i instruction, and the low 12 bits can be written to the immediate field of the ld.d instruction. In this way, by executing the pcalau12i instruction after padding and the ld.d instruction, the GOT entry address is written to the register. Then, by executing the jirl instruction, the actual function address stored in the GOT entry address in the register is read, and execution jumps to the actual function address. This is equivalent to first finding the GOT entry address, then obtaining the absolute address of the called function based on the GOT entry address, and jumping to the execution based on the absolute address. This allows for jumps to any function's actual address, solving the problem of limited address jump range.
[0038] In this embodiment of the invention, the difference between the GOT entry address and the instruction address corresponding to the indirect addressing relocation entry is calculated, and relocation padding is performed in the immediate field of the call instruction group based on the difference. Since the GOT table is located in the data segment inside the hot patch file, the distance between the GOT and the code section file to which the function call instruction belongs is often no greater than a preset upper limit. Therefore, the distance between GOT_base and the module load address is often no greater than a preset upper limit. This ensures that the distance between the GOT entry address and the instruction address corresponding to the indirect addressing relocation entry is no greater than the preset upper limit. Even if the distance between the module load address and the kernel base address is greater than the preset upper limit, since the difference used in the indirect addressing relocation method is the difference between the GOT entry address and the instruction address corresponding to the indirect addressing relocation entry, the difference used in the relocation padding in this embodiment of the invention does not exceed the preset upper limit. For any allocated module load address, this will not cause the difference used in this embodiment of the invention to exceed the preset upper limit. In this embodiment of the invention, by executing the instructions corresponding to the padded indirect addressing relocation entries, the address of the GOT entry is found first, and then the absolute address of the called function is obtained based on the GOT entry address. The function is then executed by jumping based on the absolute address. This allows for jumping to the actual address of any function, thereby avoiding data overflow, which could lead to loading errors, failure to load normally, kernel crashes, and other problems.
[0039] Optionally, in this embodiment of the invention, the steps of obtaining the compiled original kernel code file and the repaired kernel code file may specifically include: Step 1011: Obtain the original kernel source code and the kernel source code after repairing the original kernel source code.
[0040] Step 1012: Call the target compilation tool to compile the original kernel source code and the repaired kernel source code respectively, to obtain the compiled original kernel code file and the repaired kernel code file; the target compilation tool is used to generate indirect addressing relocation entries based on the Global Offset Table (GOT).
[0041] In this embodiment of the invention, the original kernel source code and the repaired kernel source code can be obtained through a hot patch generation tool. For example, the hot patch generation tool can be the kpatch tool. In this embodiment, the original kernel source code and the repaired kernel source code input by a technician are received to achieve the acquisition. Alternatively, the original kernel source code and the repaired kernel source code can be automatically downloaded from a code repository to achieve the acquisition. The original kernel source code is consistent with the version of the operating system kernel currently running on the abnormal device; that is, the kernel code file running on the abnormal device is the same as the original kernel code file. The repaired kernel source code can be obtained in the following way: obtaining the patch source code generated for the abnormal device's kernel anomaly. The patch source code can be written by a technician or automatically generated by a code generation tool; this embodiment of the invention does not impose any restrictions on this. Next, a repair patch is applied to the original kernel source code, that is, the patch source code is applied to the original kernel source code for code merging. For example, the patch command can be used to merge the patch source code into the original kernel source code to obtain the repaired kernel source code.
[0042] Given the original kernel source code, a target compilation tool can be used to compile the original kernel source code, resulting in a compiled original kernel code file. Alternatively, given a repaired kernel source code, a target compilation tool can be used to compile the repaired kernel source code, resulting in a compiled repaired kernel code file. The execution order of compiling the original kernel source code and compiling the repaired kernel source code is not unique. For example, the original kernel source code can be compiled first, followed by the repaired kernel source code; or, the repaired kernel source code can be compiled first, followed by the original kernel source code; or, the compilation can be performed in parallel. This embodiment of the invention does not impose any restrictions on this.
[0043] In this embodiment of the invention, the original kernel source code and the repaired kernel source code are obtained. A target compilation tool is called to compile the original kernel source code and the repaired kernel source code respectively, resulting in the compiled original kernel code file and the repaired kernel code file. Since the target compilation tool is used to generate GOT-based indirect addressing relocation entries, it is ensured that GOT-based indirect addressing relocation entries are generated during the compilation process. This ensures that the final hot patch file uses GOT-based indirect addressing relocation entries, ensuring that long-distance address jumps can be achieved through GOT, and thus ensuring that the hot patch file can be loaded normally at any legal address.
[0044] For example, in this embodiment of the invention, a compiler parameter deletion mechanism (i.e., deleting specified compiler parameters from the default compiler parameter set, for example, deleting the -mdirect-extern-access and -fdirect-access-external-data parameters) is used to control the compiler to generate GOT-based indirect addressing relocation entries. The specific method by which the compiler generates GOT-based indirect addressing relocation entries is determined by the compiler's internal implementation, and this embodiment of the invention does not impose any restrictions on this. GOT-based indirect addressing relocation entries can be stored in the relocation section file using a `rela` structure.
[0045] Taking the GCC compiler as the target compilation tool as an example, given the original kernel source code, the target compilation tool is invoked. The original kernel source code is input into the target compilation tool, and the tool is run to obtain the original kernel code file output by the target compilation tool. For example, assume the storage path of the original kernel source code is / linux / <version>Then enter / linux / in the target compilation tool. <version>Provide the target compilation tools with the path / linux / <version>The original kernel source code stored in the directory is compiled to obtain the original kernel code file. Then, given the repaired kernel source code, a target compilation tool is invoked. The repaired kernel source code is input into the target compilation tool, and the tool is run to obtain the repaired kernel code file output by the target compilation tool. For example, assume the repaired kernel source code is stored in / linux / . <version>With the option `-fixed`, you can input ` / linux / ` into the target compilation tool. <version>-fixed, to allow target compilation tools to work with / linux / <version>The repaired kernel source code stored under -fixed is compiled to obtain the repaired kernel code file.
[0046] Optionally, embodiments of the present invention may further include the following steps: Step S21: Obtain the default compilation parameter set of the default compilation tool, and iterate through the compilation parameters corresponding to the default compilation parameter set.
[0047] Step S22: When the current compilation parameter is the specified compilation parameter, filter the current compilation parameter until all compilation parameters have been traversed to obtain the target compilation tool; the specified compilation parameter is used to instruct the compilation tool to generate direct addressing relocation items.
[0048] The default compilation tool can be the one used by the hot patch generation tool by default. The default compilation tool can be set as needed; for example, it can be the GCC compiler, but this embodiment of the invention does not limit this. The compilation parameters corresponding to the default compilation parameter set are the compilation parameters included in the default compilation parameter set. The default compilation parameter set of the default compilation tool is a series of parameters passed to the compiler. The default compilation parameter set includes multiple compilation parameters, and each compilation parameter corresponds to a compilation control item of the default compilation tool. In related technologies, the default compilation parameter set often includes specified compilation parameters used to instruct the compilation tool to generate relocation items in the direct addressing mode. These specified compilation parameters suppress the compilation tool from generating relocation items in the indirect addressing mode based on GOT, and need to be removed from the default compilation parameter set. The specified compilation parameters are determined by the compiler design. The compiler-supported compilation parameters used to instruct the compiler not to use GOT or to instruct the compiler to use the direct addressing relocation mode can be pre-determined as the specified compilation parameters. For example, specified compilation parameters may include the -mdirect-extern-access and -fdirect-access-external-data parameters, which are used to instruct the compiler not to use GOT and to instruct the compiler to use direct addressing relocation, respectively.
[0049] In this embodiment of the invention, specified compilation parameters can be extracted from the default compilation parameter set and filtered to control the compiler from generating relocation entries representing direct addressing relocation. Specifically, the compilation parameters included in the default compilation parameter set can be traversed. For example, traversal can be performed in a forward-to-back order, comparing the parameter name of the currently traversed compilation parameter with the parameter name of the specified compilation parameter. If the parameter names match, for example, if the parameter name of the currently traversed compilation parameter is -mdirect-extern-access or fdirect-access-external-data, then the currently traversed compilation parameter is filtered, thereby preventing the compiler from generating relocation entries representing direct addressing relocation. For example, the currently traversed compilation parameter is deleted from the default compilation parameter set, and traversal of the next compilation parameter begins. If the parameter names do not match, traversal of the next compilation parameter begins directly. After all compilation parameters included in the default compilation parameter set have been traversed, the default compilation parameter set is passed to the default compilation tool, and the default compilation tool is used as the target compilation tool to compile the original kernel source code and the repaired kernel source code respectively.
[0050] In this embodiment of the invention, the default compilation parameter set of the default compilation tool is obtained, and the compilation parameters in the default compilation parameter set are traversed. If the currently traversed compilation parameter is a specified compilation parameter, it is filtered to prevent the compiler from generating relocation entries representing direct addressing relocation, until all compilation parameters have been traversed. Then, all parameters except the specified compilation parameter are passed to the default compilation tool to obtain the target compilation tool; the specified compilation parameter is used to instruct the compilation tool to generate direct addressing relocation entries. In this way, by filtering out the specified compilation parameter through traversal, the generation of indirect addressing relocation entries based on GOT can be controlled directly during the compilation process, resulting in high control efficiency.
[0051] When specifying compilation parameters for the compiler, the compilation process can generate relocation entries using direct addressing. This can lead to data overflow and loading errors when the module load address is too far from the kernel base address. In this embodiment, by filtering specified compilation parameters from the default compilation parameter set, the default compiler is forced to generate GOT-based indirect addressing relocation entries during compilation. This ensures that the final hot patch file uses GOT-based indirect addressing relocation entries, preventing data overflow and loading errors, and improving the compatibility of the hot patch file.
[0052] Optionally, in this embodiment of the invention, the step of comparing the repaired kernel code file with the original kernel code file and extracting the difference file from the repaired kernel code file may specifically include: Step 1021: For the first function in the repaired kernel code file, compare the code section file corresponding to the first function with the code section file corresponding to the second function in the original kernel code file.
[0053] Step 1022: If there is no second function that is consistent with the code section file corresponding to the first function, then the first function is determined as the repair function corresponding to the exception function, and the relevant content of the repair function is used as the difference file; The relevant content includes the code section file, relocation section file, stack frame index section file, and metadata corresponding to the repair function; the relocation section file includes the GOT-based indirect addressing relocation entry corresponding to the repair function.
[0054] The first function is the function in the repaired kernel code file, the second function is the function in the original kernel code file, the code section file of the repaired kernel code file includes the instruction sequence corresponding to each function in the repaired kernel code file, and the code section file of the original kernel code file also includes the instruction sequence corresponding to each function in the original kernel code file. The instruction sequence corresponding to each function is the code section file corresponding to each function.
[0055] An exception function is a function in the original kernel code file that causes an exception. A repair function is a function used to fix the exception function. For example, suppose the original kernel code file includes functions A, B, C, and D. Function C has a calculation error exception during execution. Function C's execution involves adding a first value to the input value and then outputting it. However, the correct processing logic for function C is to add a second value to the input value and then output it; therefore, it is an exception function. Correspondingly, the repaired kernel code file includes functions A, B, C', and D. Function C' loads the second value and adds it to the input value before outputting it, thus achieving the repair. Therefore, function C' is the repair function corresponding to the exception function C. Because the logic implemented by the repair function (e.g., function C') is different from that implemented by the exception function (e.g., function C), their corresponding code section files are different.
[0056] Specifically, for any function in the repaired kernel code file (hereinafter referred to as the first function), the code section file corresponding to the first function is compared with the code section file corresponding to the reference function in the original kernel code file. The function name of the first function may include the function name of the reference function; for example, in practical applications, the function name of the `new_exception` function can be used as the name of the repaired function. For any second function in the original kernel code file, if the function name of the first function includes the function name of the second function, then the second function is used as the reference function for the first function.
[0057] Each first function and its reference function are traversed. If their corresponding code section files are identical, it indicates the existence of a second function with the same code section file as the first function, and this second function has not been repaired. Conversely, if their corresponding code section files are inconsistent, it can be assumed that no second function exists with the same code section file as the first function. This indicates that the first function is a repair function used for exception handling, and it can be identified as a repair function, while its reference function is identified as an exception function.
[0058] Furthermore, the sections in the difference file are the sections corresponding to the repair functions. Specifically, the difference file can include the code section file, relocation section file, stack frame index section file, and metadata corresponding to the repair function. Specifically, based on the function name of the repair function, the differences between the repaired kernel code file and the original kernel code file can be extracted. Specifically, the instruction sequence corresponding to the function name of the repair function can be extracted from the code section file of the repaired kernel code file to obtain the code section file corresponding to the repair function. From the relocation section file of the repaired kernel code file, the GOT-based indirect addressing relocation entry corresponding to the repair function can be extracted to obtain the relocation section file corresponding to the repair function. From the stack frame index section file of the repaired kernel code file, the stack frame index address entry corresponding to the repair function can be extracted to obtain the stack frame index section file corresponding to the repair function, and the name of the exception function and the entry point of the repair function can be obtained as metadata.
[0059] For example, assuming the function name of the repair function is `new_meminfo`, the part corresponding to the section index of `new_meminfo` can be extracted from the code section file of the repaired kernel code file to obtain the code section file corresponding to the repair function. The instructions in the code section file corresponding to the repair function constitute the repair function. Next, assuming the address range of the code section file corresponding to the repair function is 0x1000 to 0x1100, relocation entries with offsets belonging to 0x1000 to 0x1100 can be extracted from the relocation section file of the repaired kernel code file. These relocation entries with offsets belonging to 0x1000 to 0x1100 form the relocation section file corresponding to the repair function. From the stack frame index section file of the repaired kernel code file, stack frame index address entries with offsets belonging to 0x1000 to 0x1100 are extracted to obtain the stack frame index section file corresponding to the repair function. Assuming the entry point of the fix function is 0xffff900000001000, the name of the exception function (meminfo) and the entry point 0xffff900000001000 can be written into a predefined metadata structure to obtain the metadata corresponding to the fix function. The code section file, relocation section file, stack frame index section file, and metadata corresponding to the fix function can then be packaged according to the format required by the kernel module to obtain a kernel hot patch containing the fix function.
[0060] Of course, the difference file may also include other section files, and this embodiment of the invention does not limit this.
[0061] The relocation section file corresponding to the repair function includes: the first relocation entry and the second relocation entry corresponding to the function called in the repair function. The second relocation entry corresponding to the function called in the repair function forms the second relocation entry section file corresponding to the repair function. The first relocation entry corresponding to the function called in the repair function forms the first relocation entry section file corresponding to the repair function. The first relocation entry section file corresponding to the repair function can form the data segment corresponding to the repair function. Of course, the data segment can also include other data required by the repair function. In this embodiment of the invention, by comparing and identifying the repair function corresponding to the abnormal function in the repaired kernel code file, and extracting the relevant content of the repair function from the repaired kernel code file, the difference file can be obtained, which can ensure the efficiency of obtaining the difference file to a certain extent.
[0062] Furthermore, the relevant content includes the code section file, relocation section file, stack frame index section file, and metadata corresponding to the repair function. The relocation section file corresponding to the repair function includes the GOT-based indirect addressing relocation entry for the repair function. This ensures that the hot patch file generated from the difference file uses GOT-based indirect addressing relocation entries. Since relocation processing for relocation entries using indirect addressing is unaffected by the distance between the module load address and the kernel base address, module loading failures can be avoided, ensuring that the hot patch file can be loaded normally.
[0063] In this embodiment of the invention, the original kernel source code and the repaired kernel source code are compiled using the same compilation parameters and compilation tools. This avoids the differences introduced by the compilation parameters and compilation tools being the original kernel code file and the repaired kernel code file, thereby ensuring the comparability of the two and ensuring that the differences are all related to the repair functions, thus ensuring the accuracy of the final generated hot patch file.
[0064] Optionally, in this embodiment of the invention, the step of performing symbol substitution operations on all section files in the difference file except for the specified section file may specifically include: Step 1031: Traverse the section files in the difference files.
[0065] Step 1032: If the name of the current section file matches the specified name, skip the current section file and start traversing the next section file of the current section file.
[0066] Step 1033: Otherwise, replace the section symbol address in the current section file with the symbol of the function pointed to by the section symbol address, and after the replacement is completed, start traversing the next section file of the current section file until all section files in the difference file have been traversed.
[0067] The specified name refers to the name of the specified section file. Specified section files within the difference file can be identified and skipped. Specifically, the section files in the difference file can be traversed. The name of the currently traversed section file (i.e., the current section file) is compared with the specified name. If they match, the currently traversed section file is the specified section file, which is used to record stack frame indices. Accordingly, processing can be skipped, and the next section file can be traversed directly. If they do not match, the current section file is not the specified section file. Accordingly, a symbol substitution operation can be performed by replacing the section symbol addresses in the current section file with the symbols of the functions pointed to by those addresses. Then, the next section file is traversed until all section files in the difference file have been traversed. After traversing all section files in the difference file, a hot patch file is generated based on the replaced difference file.
[0068] The specified section file can be named "orc_unwind_ip". This specified section file is used to record stack frame indices, and its name can be predefined by technical personnel.
[0069] The `.orc_unwind_ip` section is a special segment generated by the Linux kernel during compilation. It works in conjunction with the `.orc_unwind` section to locate stack state information. The `.orc_unwind_ip` section stores stack frame index addresses, each representing an instruction address. Each stack frame index address in `.orc_unwind_ip` corresponds to a structure in the `.orc_unwind` section. This structure describes the stack state at that instruction address (e.g., stack pointer offset), allowing the kernel to quickly locate stack state information. For example, taking the stack frame index address `code section base address + 0x800` as an example, assuming the instruction at code section base address + 0x800 is a `Read` instruction, the structure corresponding to this stack frame index address can represent the stack state of the `Read` instruction.
[0070] Stack frame index address entries are also represented using section symbol addresses (section symbol + offset). During compilation, when the compiler encounters a reference to a code location (e.g., a function call), it sometimes uses a section symbol address to represent the symbol of the called function. This results in section symbol address representations in other section files. For example, the value of the Symbol parameter in the relocation entry of the relocation section is represented by a section symbol address, and section symbol addresses are defined in the instructions of the code section file. To ensure that the hot patch module loads and runs correctly, the section symbol addresses in other section files of the difference file need to be modified to the symbol of the function they point to. In this embodiment of the invention, by optimizing the symbol relocation logic and skipping specified section files, unnecessary replacement operations can be avoided, processing resources can be wasted, and production efficiency can be improved. At the same time, the accuracy of the specified section files is ensured, and the correct content of the specified section files is preserved, thereby ensuring the accuracy of the debugging information generated during subsequent runtime.
[0071] For example, by parsing compilation and debugging information, the symbol of the function pointed to by the section symbol address can be determined, and the section symbol address can be bound to the symbol of the function it points to. This establishes a binding relationship between each section symbol address and the symbol of the function it points to, making it easier to determine the symbol of the function pointed to by the section symbol address. During symbol relocation, if the name of the current section file is "orc_unwind_ip", then that current section file is skipped. If the name of the current section file is not "orc_unwind_ip", then that current section file is determined to be a non-specified section file. Symbol substitution is performed only for any non-specified section file, replacing the section symbol address in that non-specified section file with the symbol bound to that section symbol address. Since non-specified section files containing section symbol addresses are often relocation section files, and after replacing the section symbol address with the function symbol, the relocation entry directly points to the called function, the Addend parameter in the replaced relocation entry can also be adjusted to 0. For example, suppose the address of a section symbol in the unspecified section file is: code section base address + 0x100. By querying the binding relationship, it is found that the symbol bound to this code section base address + 0x100 is: printk. Specifically, the section symbol address is represented by Info and Addend in the relocation entry, where the value of Info is the section symbol (e.g., the code section base address), and the value of Addend is the offset (e.g., 0x100). When performing symbol replacement, the value of Addend can be set to 0 using an assignment instruction. The value of Info can be modified to printk using a write instruction, thus achieving symbol replacement. After replacement, the location can be directly determined based on the relocation entry in the relocation section file. Correspondingly, if symbol replacement is performed on the section symbol address in the specified section file, since there is no relocation entry corresponding to the stack frame index address, it will trigger the generation of a corresponding relocation entry for the stack frame index address in the specified section file. In this embodiment of the invention, by skipping the processing of the specified section file and only processing other section files, redundant content can be avoided. For example, unnecessary relocation section files (e.g., .klp.rela.vmlinux..orc_unwind_ip) can be avoided, thus avoiding unnecessary increase in module size, which would lead to prolonged module loading time and reduced system maintenance efficiency.
[0072] Optionally, in this embodiment of the invention, the step of generating the hot patch file may specifically include: Step 1034: Link the replaced difference file with the preset callback code file, and encapsulate the linked file into a kernel module format to obtain the hot patch file; wherein, the callback code file is used to insert a jump instruction into the exception function, and the jump instruction is used to jump to the repair function in the hot patch file.
[0073] The preset callback code file is a pre-provided stub code used to insert jump instructions into exception functions to redirect to the fix function in the hot patch file. Specifically, the linker can be called to link the replaced difference file with the preset callback code file. Then, the linker outputs the linked file according to the kernel module format layout, resulting in a hot patch file that conforms to the kernel module format.
[0074] In practical applications, hot patch files are sent to the faulty device running the original kernel code. The kernel loader on the faulty device loads the hot patch file into its operating system kernel and, if the faulty function is executed, jumps to the hot patch file for execution. Specifically, after the faulty device loads the hot patch file, the callback code file within it determines the name of the faulty function and the entry point of the repair function based on metadata. A jump instruction is inserted at the entry point of the faulty function in the operating system kernel of the faulty device. This jump instruction defines the entry point of the repair function in the hot patch file. When the operating system kernel of the faulty device executes the faulty function, it first executes this jump instruction, modifying the execution path of the current code to the entry point of the repair function, and then jumps to the entry point of the repair function to begin execution. This ensures that the correct processing logic is executed, avoiding the execution of the faulty function's processing logic, thus achieving fault repair. For example, assuming the name of the found abnormal function is "meminfo" and the entry point of the found repair function is "0xffff900000001000", a jump instruction defined with "0xffff900000001000" can be generated. When the function to be executed is named "meminfo", this jump instruction is executed, thereby jumping to "0xffff900000001000" and starting the execution of the repair function.
[0075] In this embodiment of the invention, a hot patch file is obtained by linking the replaced difference file with a preset callback code file and encapsulating the linked file into a kernel module format. Since the callback code file is used to insert jump instructions into the exception function, these jump instructions are used to jump to the repair function in the hot patch file. This ensures that when the hot patch file is loaded and executed, the repair function can be run to execute the correct processing logic, thereby achieving exception repair.
[0076] Figure 2 This is a schematic diagram of a processing flow provided by an embodiment of the present invention, such as... Figure 2 As shown, the original kernel source code can be obtained first, and then compiled. Specifically, the specified compilation parameters of the default compilation tool can be filtered, and the filtered default compilation tool (i.e., the target compilation tool) can be called for compilation. Next, the patched source code is applied to the original kernel source code to obtain the repaired kernel source code. The repaired kernel source code is then compiled to obtain the repaired kernel code file. Specifically, the specified compilation parameters of the default compilation tool can be filtered, and the filtered default compilation tool (i.e., the target compilation tool) can be called for compilation. In practical applications, since filtering has already been implemented in the aforementioned process, the target compilation tool can be directly called to compile the repaired kernel source code.
[0077] Next, the original kernel code file obtained from compilation and the repaired kernel code file are compared to determine the difference file. Specifically, section symbol addresses can be bound to the symbols of the functions they point to, the difference file can be extracted, and the section symbol addresses in all other section files in the difference file (excluding the specified section file) can be replaced with the functions pointed to by those section symbol addresses. Finally, a hot patch file is generated based on the difference file. This ensures that GOT-based indirect addressing relocation entries are generated during compilation, so that the final hot patch file uses GOT-based indirect addressing relocation entries. This ensures that long-distance address jumps can be achieved through GOT, and that the hot patch file can be loaded normally at any legal address, improving the compatibility of the hot patch file. At the same time, by skipping the symbol replacement operation of the specified section file, redundant content can be avoided, while also considering the loading efficiency of the hot patch file.
[0078] Reference Figure 3 The diagram shows a block diagram of a data processing apparatus provided in an embodiment of the present invention, such as... Figure 3 As shown, the data processing device may specifically include: The first acquisition module 201 is used to acquire the compiled original kernel code file and the repaired kernel code file; both the original kernel code file and the repaired kernel code file are relocated through indirect addressing relocation. Comparison module 202 is used to compare the repaired kernel code file with the original kernel code file, and extract the difference file from the repaired kernel code file; The processing module 203 is used to perform symbol replacement operations on the section files other than the specified section file in the difference file, and generate a hot patch file; the specified section file includes a section file used to record the stack frame index.
[0079] Optionally, the first acquisition module 201 is specifically used for: Obtain the original kernel source code, and the kernel source code after repairing the original kernel source code; The target compilation tool is invoked to compile the original kernel source code and the repaired kernel source code respectively, to obtain the compiled original kernel code file and the repaired kernel code file; the target compilation tool is used to generate indirect addressing relocation entries based on the Global Offset Table (GOT).
[0080] Optionally, the device further includes: The second acquisition module is used to acquire the default compilation parameter set of the default compilation tool and traverse the compilation parameters corresponding to the default compilation parameter set; The filtering module is used to filter the current compilation parameters when the current compilation parameters are specified compilation parameters, until all compilation parameters have been traversed to obtain the target compilation tool; the specified compilation parameters are used to instruct the compilation tool to generate direct addressing relocation items.
[0081] Optionally, the processing module 203 is specifically used for: The section files in the difference file are traversed; If the name of the current section file matches the specified name, skip the current section file and begin traversing the next section file. Otherwise, the section symbol address in the current section file is replaced with the symbol of the function pointed to by the section symbol address, and after the replacement is completed, the next section file of the current section file is traversed until all section files in the difference file have been traversed.
[0082] Optionally, the comparison module 202 is specifically used for: For the first function in the repaired kernel code file, the code section file corresponding to the first function is compared with the code section file corresponding to the second function in the original kernel code file; If there is no second function that matches the code section file corresponding to the first function, then the first function is identified as the repair function corresponding to the exception function, and the relevant content of the repair function is used as the difference file; The relevant content includes the code section file, relocation section file, stack frame index section file, and metadata corresponding to the repair function; the relocation section file includes the GOT-based indirect addressing relocation entry corresponding to the repair function.
[0083] Optionally, the processing module 203 is further configured to: The replaced difference file is linked with a preset callback code file, and the linked file is encapsulated in kernel module format to obtain the hot patch file; The callback code file is used to insert jump instructions into the exception function, and the jump instructions are used to jump to the fix function in the hot patch file.
[0084] Optionally, the relocation entries in both the original kernel code file and the repaired kernel code file are indirect addressing relocation entries based on GOT; The indirect addressing relocation entry is used to instruct the kernel loader to use indirect addressing processing. The indirect addressing processing includes: writing the actual address of the function to the GOT address corresponding to the called function in the GOT, and filling the function call instruction with the instruction address difference between the GOT address and the function call instruction, so as to jump to the actual address of the function written at the GOT address through the function call instruction.
[0085] In summary, the data processing apparatus provided in this embodiment of the invention acquires both the compiled original kernel code file and the repaired kernel code file. Both the original and repaired kernel code files undergo relocation processing via indirect addressing relocation. The repaired kernel code file is compared with the original kernel code file, and a difference file is extracted from the repaired kernel code file. Symbol substitution operations are performed on all section files in the difference file except for a specified section file, and a hot patch file is generated. The specified section file includes a section file used to record stack frame indices. In this embodiment of the invention, since the relocation processing for relocation items using indirect addressing relocation is not affected by the distance between the module load address and the kernel base address, the problem of module loading failure can be avoided, ensuring that the hot patch file can be loaded normally. Furthermore, by performing symbol substitution operations on section files other than the specified section file, unnecessary operations can be avoided, thereby avoiding the generation of redundant code in the hot patch file, allowing the hot patch file to be efficiently loaded by the operating system kernel.
[0086] Reference Figure 4 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. For example... Figure 4 As shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus.
[0087] The processor, the memory, and the communication interface communicate with each other via the communication bus; the memory stores executable instructions, which cause the processor to execute the data processing method of the aforementioned embodiments. The executable instructions can form a program.
[0088] This invention provides a machine-readable medium storing instructions that, when executed by one or more processors, enable the processors to perform the data processing method described in the foregoing embodiments. The machine-readable medium may be one or more processors.
[0089] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0090] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0091] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.
[0092] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will 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 program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0093] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0094] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0095] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.
[0096] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0097] Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0098] The above provides a detailed description of a data processing method, a data processing device, an electronic device, and a readable medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.< / version> < / version> < / version> < / version> < / version> < / version>
Claims
1. A data processing method, characterized in that, The method includes: Obtain the original compiled kernel code file and the repaired kernel code file; both the original kernel code file and the repaired kernel code file are relocated using an indirect addressing relocation method; The repaired kernel code file is compared with the original kernel code file, and the difference file is extracted from the repaired kernel code file; Symbol substitution operations are performed on all section files in the difference file except for the specified section file, and a hot patch file is generated; the specified section file includes a section file used to record the stack frame index.
2. The method according to claim 1, characterized in that, The process of obtaining the compiled original kernel code file and the repaired kernel code file includes: Obtain the original kernel source code, and the kernel source code after repairing the original kernel source code; The target compilation tool is invoked to compile the original kernel source code and the repaired kernel source code respectively, to obtain the compiled original kernel code file and the repaired kernel code file; the target compilation tool is used to generate indirect addressing relocation entries based on the Global Offset Table (GOT).
3. The method according to claim 2, characterized in that, The method further includes: Obtain the default compilation parameter set of the default compilation tool, and iterate through the compilation parameters corresponding to the default compilation parameter set; When the current compilation parameters are specified, the current compilation parameters are filtered until all compilation parameters have been traversed to obtain the target compilation tool; the specified compilation parameters are used to instruct the compilation tool to generate direct addressing relocation items.
4. The method according to claim 1, characterized in that, The symbol substitution operation performed on all section files in the difference file except for the specified section file includes: The section files in the difference file are traversed; If the name of the current section file matches the specified name, skip the current section file and begin traversing the next section file. Otherwise, the section symbol address in the current section file is replaced with the symbol of the function pointed to by the section symbol address, and after the replacement is completed, the next section file of the current section file is traversed until all section files in the difference file have been traversed.
5. The method according to claim 1, characterized in that, The comparison of the repaired kernel code file with the original kernel code file, and the extraction of the difference file from the repaired kernel code file, includes: For the first function in the repaired kernel code file, the code section file corresponding to the first function is compared with the code section file corresponding to the second function in the original kernel code file; If there is no second function that matches the code section file corresponding to the first function, then the first function is identified as the repair function corresponding to the exception function, and the relevant content of the repair function is used as the difference file; The relevant content includes the code section file, relocation section file, stack frame index section file, and metadata corresponding to the repair function; the relocation section file includes the GOT-based indirect addressing relocation entry corresponding to the repair function.
6. The method according to claim 5, characterized in that, The generation of the hot patch file includes: The replaced difference file is linked with a preset callback code file, and the linked file is encapsulated in kernel module format to obtain the hot patch file; The callback code file is used to insert jump instructions into the exception function, and the jump instructions are used to jump to the fix function in the hot patch file.
7. The method according to any one of claims 1-6, characterized in that, The relocation entries in both the original kernel code file and the repaired kernel code file are indirect addressing relocation entries based on GOT. The indirect addressing relocation entry is used to instruct the kernel loader to use indirect addressing processing; the indirect addressing processing includes: writing the actual address of the function to the GOT address corresponding to the called function in the GOT, and filling the function call instruction with the instruction address difference between the GOT address and the function call instruction.
8. A data processing apparatus, characterized in that, The device includes: The first acquisition module is used to acquire the compiled original kernel code file and the repaired kernel code file; both the original kernel code file and the repaired kernel code file are relocated through indirect addressing relocation. The comparison module is used to compare the repaired kernel code file with the original kernel code file, and extract the difference file from the repaired kernel code file; The processing module is used to perform symbol replacement operations on the section files other than the specified section file in the difference file, and generate a hot patch file; the specified section file includes a section file used to record the stack frame index.
9. An electronic device, characterized in that, include: The processor, memory, communication interface, and communication bus are provided, wherein the processor, memory, and communication interface communicate with each other via the communication bus. The memory is used to store executable instructions that cause the processor to perform the method as described in any one of claims 1 to 7.
10. A machine-readable medium, characterized in that, It stores instructions that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1 to 7.
