A method, device, equipment and storage medium for configuring mirrored memory
By detecting and turning off the KASLR function, modifying the BIOS option parameters for memory mirroring, it solves the problem that ARMM technology is difficult to cover the kernel memory space, and achieves efficient memory resource utilization and system security improvement.
Patent Information
- Application Number
- CN202411947634.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-27
AI Technical Summary
The existing memory address range mirroring (ARMM) technology is difficult to effectively cover the kernel memory space, which results in the mirroring settings that cannot guarantee the kernel space coverage when the kernel address space layout randomization (KASLR) function is enabled, and may lead to waste of memory resources.
By detecting whether the KASLR function needs to be turned off, the instructions are compiled in the system boot manager configuration file to turn off the function, and by modifying the Basic Input and Output System (BIOS) option parameters, the preset memory address space is mirrored to ensure that the kernel's memory address is stored within a specified range.
It realizes that the kernel address is stored within the preset capacity range without sacrificing too much memory space, simplifies memory management, improves the overall security and stability of the system, and avoids waste of memory resources.
Smart Images

Figure CN119377015B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for configuring mirrored memory. Background Art
[0002] The Address Range Memory Mirroring (ARMM) technology has features such as memory reliability, availability, and serviceability (RAS), and it provides finer-grained control on some platforms (such as Haswell EX) to determine how much memory resources are used for redundancy. The ARMM technology allows the definition of mirror ranges of primary and secondary memory on each home agent (HA), and can be selectively enabled to reduce the amount of memory lost due to mirroring.
[0003] In traditional channel mirroring, the memory behind each HA in the system is configured as a mirror, which means that half of the installed memory is reserved for redundancy. Address range mirroring allows the size of the primary and secondary images to be defined on each HA, which can be set in intervals of 64MB. On HAs with address range mirroring enabled, the defined range will be used for redundancy and will not be included in the total system memory size. Although ARRM provides a high-reliability memory technology, it does not provide an effective method for mirroring critical data or code areas. If the kernel address space layout randomization technology is enabled in the default kernel configuration, the kernel load address will be randomized to improve the security of the system. This randomization is achieved through the kernel address space layout randomization (ASLR) technology, which can select a random load address for the kernel at each boot, thereby increasing the difficulty for attackers to predict the kernel address.
[0004] Currently, in the ARMM setting stage, no matter how the value of the kernel address storage is set, it cannot be guaranteed that it can cover the kernel memory space. The larger the value is set, the greater the probability of covering the kernel space, but it will also lead to an increase in the sacrificed memory space. Summary of the invention
[0005] In view of this, the present invention provides a method, apparatus, device and storage medium for configuring mirror memory to solve the problem that memory address range mirroring ARMM technology covers kernel memory space.
[0006] In a first aspect, the present invention provides a method for configuring mirrored memory, the method comprising:
[0007] Under the operating system, detecting whether a kernel address space layout randomization function needs to be turned off, wherein the system defaults the kernel address space layout randomization function to be turned on;
[0008] If yes, inputting a compile instruction for shutting down the function into a system boot manager configuration file, and compiling the configuration file, wherein the configuration file is used to control one or more of the startup items and startup parameters loaded when the system starts;
[0009] By modifying the option parameters of the basic input and output system, the memory address space of the first preset capacity is mirrored, wherein the first preset capacity needs to cover the memory address space of the kernel;
[0010] Based on the compiled system boot manager configuration file and the modified option parameters, the operating system is restarted to implement an image of a first preset capacity size, and the memory address of the kernel is stored within the range of the first preset capacity.
[0011] In combination with the first aspect, in a possible implementation, the inputting of the compilation instruction for turning off the function into the system boot manager configuration file includes: searching for a target startup item in the system boot manager configuration file, setting a field in the target startup item with the function of turning off the system boot manager, and modifying the field.
[0012] In combination with the first aspect, in another possible implementation manner, the modifying the option parameters of the basic input and output system includes:
[0013] In the BIOS setup interface, find options related to memory;
[0014] Use the modification tool to modify the memory-related option parameters.
[0015] In combination with the first aspect, in another possible implementation, before using the modification tool to modify the memory-related option parameters, the method further includes: backing up the current memory-related option parameters.
[0016] In combination with the first aspect, in another possible implementation, the first preset capacity size is 4G; and storing the memory address of the kernel within the first preset capacity size range includes:
[0017] The memory address of the kernel is stored in an address space with 0x1000000 as the base address, and the address space with 0x1000000 as the base address is within the range of 0~4G.
[0018] In combination with the first aspect, in yet another possible implementation, the method further includes: using a debugging tool to view a memory address of the kernel within the first preset capacity range.
[0019] In combination with the first aspect, in another possible implementation, the target startup item is a Bootloader startup item; the option parameters of the basic input and output system include: an image tag field, a unified extensible firmware interface field, and a memory address image range field;
[0020] The step of modifying the option parameters of the basic input and output system includes:
[0021] Modify the image tag field to Enabled, modify the unified extensible firmware interface field to Enabled, and modify the memory address image range field to 0;
[0022] After the modification is completed, use the command to import the modified option parameters above.
[0023] In combination with the first aspect, in another possible implementation, the detecting whether it is necessary to disable the kernel address space layout randomization function further includes:
[0024] If not, obtaining a random number through a random number tool under the operating system, wherein the value range of the random number is between the first preset capacity and the second preset capacity, and the first preset capacity is smaller than the second preset capacity;
[0025] Assigning the random number to a kernel address space layout randomization seed, and inserting the random number into the kernel as a kernel startup parameter;
[0026] By modifying the option parameters of the basic input and output system, memory mirroring is performed on the memory address space in the range from the first preset capacity to the second preset capacity, wherein the range from the first preset capacity to the second preset capacity needs to cover the memory address space of the kernel;
[0027] Restart the operating system, store the memory address of the kernel in the range from the first preset capacity to the second preset capacity according to the kernel startup parameter in the kernel, and implement memory mirroring in the range from the first preset capacity to the second preset capacity.
[0028] In combination with the first aspect, in another possible implementation, assigning the random number to a kernel address space layout randomization seed and inserting it into the kernel as a kernel startup parameter includes:
[0029] Get the device tree source file;
[0030] Edit the device tree source file, find a selection node in the device tree source file, insert the kernel address space layout randomization seed into the selection node, compile and generate a device tree binary file, wherein the selection node is used to provide additional information required when the kernel is started;
[0031] Configure the bootloader to load the device tree binary.
[0032] In combination with the first aspect, in yet another possible implementation, the method further includes:
[0033] If the selected node is not found in the device tree source file, a new node is created, the kernel address space layout randomization seed is inserted into the new node, and a new device tree binary file is compiled to generate the new node, where the new node is used to provide additional information required when the kernel is started.
[0034] In combination with the first aspect, in another possible implementation, obtaining a random number by using a random number tool under the operating system includes: using the random number tool to input a first command under the operating system to generate the random number.
[0035] In a second aspect, the present invention provides a device for configuring mirrored memory, the device comprising:
[0036] A detection module, used for detecting whether a kernel address space layout randomization function needs to be turned off under an operating system, wherein the system defaults the kernel address space layout randomization function to be turned on;
[0037] A compiling module, used for inputting a compiling instruction for shutting down the function into a system boot manager configuration file, and compiling the configuration file, when the detection module detects that the function is shut down, and the configuration file is used for controlling one or more of the startup items and startup parameters loaded when the system is started;
[0038] A processing module, configured to perform mirroring processing on a memory address space of a first preset capacity by modifying an option parameter of a basic input / output system, wherein the first preset capacity needs to cover the memory address space of a kernel;
[0039] A restart module is used to restart the operating system based on the compiled system boot manager configuration file and the modified option parameters to realize an image of a first preset capacity size and store the memory address of the kernel within the range of the first preset capacity.
[0040] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method for configuring mirrored memory of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0041] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method for configuring mirrored memory of the first aspect or any corresponding embodiment thereof.
[0042] In addition, the present invention provides a computer program product, including computer instructions, which are used to enable a computer to execute the method for configuring mirrored memory of the above-mentioned first aspect or any corresponding embodiment thereof.
[0043] The present invention provides a method, device, equipment and storage medium for configuring mirror memory. On the one hand, when the kernel address space layout randomization (KASLR) function is turned off, a compilation instruction is input into a system boot manager configuration file, the configuration file is compiled, and a basic input and output system (BIOS) option parameter is modified to achieve mirroring of a memory address space of a first preset capacity. Finally, after the operating system is restarted, a mirror of the first preset capacity size is achieved, and when performing memory mirroring, it is ensured that the kernel address is stored within the first preset capacity size range, which not only simplifies the complexity of memory management, but also facilitates operations in scenarios such as security analysis and troubleshooting, and improves the overall security and stability of the system.
[0044] In addition, by accurately calculating and setting the memory address space of the first preset capacity for mirroring, the capacity just covers the kernel's memory address space, avoiding unnecessary waste of memory resources. This refined memory management strategy enables system resources to be used more efficiently, which is particularly important in an environment with limited memory resources.
[0045] On the other hand, when the kernel address space layout randomization (KASLR) function is turned on, the present invention performs mirroring by accurately calculating and setting the memory address space in the range of the first preset capacity to the second preset capacity, which just covers the memory address space of the kernel and makes full use of memory resources. By introducing random numbers, even when the KASLR function is turned on, the effective mapping and access of the kernel address can be ensured, and the system kernel is mirrored at a relatively low cost, thereby avoiding kernel failures caused by memory and also avoiding the waste of memory resources.
[0046] The present invention closely combines the steps of KASLR function detection, random number generation and assignment, memory mirror processing, and system restart to form an automated configuration process. The automated technology accurately defines the memory address range of the kernel space. This not only simplifies the cumbersome manual configuration steps in the traditional method, but also realizes the update of the memory mirror and kernel address space mapping through the restart operation, thereby improving the efficiency of system deployment and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 is a flow chart of a method for configuring mirrored memory according to an embodiment of the present invention;
[0049] Figure 2 is a flowchart of another method for configuring mirrored memory according to an embodiment of the present invention;
[0050] Figure 3 is a schematic diagram of storing a memory address of a kernel in a first preset capacity range according to an embodiment of the present invention;
[0051] Figure 4 is a flowchart of another method for configuring mirrored memory according to an embodiment of the present invention;
[0052] Figure 5 is a schematic diagram of storing a memory address of a kernel in a range from a first preset capacity to a second preset capacity according to an embodiment of the present invention;
[0053] Figure 6 is a flowchart of another method for configuring mirrored memory according to an embodiment of the present invention;
[0054] Figure 7 is a structural block diagram of a configuration mirror memory device according to an embodiment of the present invention;
[0055] Figure 8 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0057] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0058] Furthermore, the terms “first” and “second” are used for descriptive purposes only and should not be understood as indicating or implying relative importance.
[0059] The technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0060] First, the application scenarios and related background of the technical solutions of the embodiments of the present invention are introduced.
[0061] Address Range Memory Mirroring (ARMM) is a technology that copies data in a specific memory address range to another memory address range or maps it to another physical address space. This technology can be used in application scenarios such as data backup, fast access, and memory protection.
[0062] Among them, the advantages of memory address range mirroring ARMM are:
[0063] Reduce memory redundancy: Compared with traditional full mirroring, address range mirroring can reduce the amount of memory reserved for redundancy, thereby providing more available memory. Flexible memory management: Allows system administrators to decide which data needs to be protected by mirroring and which data can be protected without mirroring based on business needs and the importance of the data, thereby achieving more refined memory management. Improve memory utilization: By mirroring only critical data or code areas, memory utilization can be improved while maintaining high system reliability. Support hot swapping and online maintenance: Address range mirroring usually supports hot swapping and online maintenance, which means that memory modules can be replaced without restarting the system, reducing system maintenance time and cost.
[0064] For the enabling of ARMM, on each Home Agent (HA), ARMM can be enabled through specific configuration registers, such as the Target Address Decoder 0 (TAD0) register. TAD0 enables memory mirroring below the 4G address, and the TAD1 register enables memory mirroring above 4G. Mirrored AmountAbove4GB is a configuration parameter related to ARMM. In ARMM, this parameter is used to specify the amount of memory that needs to be mirrored in the available memory above 4GB, measured in basis points (1% percentage point, i.e. 0.01%). For example, if the total memory in the system is 48GB, if 12GB of memory is requested to be mirrored above 4GB, and assuming TOLM (Top of Low Memory) is 2GB, then the total memory above 4GB is 46GB, and the amount of memory that needs to be mirrored is 10GB (because 12GB - 2GB = 10GB), so the percentage that needs to be mirrored is 10÷46≈0.21739, and correspondingly, the value of MirroredAbove4GB is 2173.
[0065] Among them, Home Agent is the component inside the CPU that manages memory access and cache consistency. It is mainly responsible for processing data exchange between cache lines and memory, ensuring data consistency between multiple processor cores.
[0066] Although ARRM provides a high-reliability memory technology, it does not provide an effective method for mirroring critical data or code areas. An embodiment of the present invention provides a method for configuring mirrored memory, which provides a method for mirroring critical data or code areas of an operating system to greatly improve the reliability of the system.
[0067] Machine Check Architecture Recovery (MCA Recovery) is an advanced RAS (Reliability, Availability, and Serviceability) feature that allows the software layer to assist in system recovery when the hardware cannot correct certain errors. This recovery mechanism specifically targets some hardware-unrecoverable faults to provide software with an opportunity to isolate and recover. When the processor identifies an error that the hardware cannot correct, it marks the data as corrupted data and triggers an error event that can be captured by the firmware and / or the operating system.
[0068] Then, it determines whether there is a redundant copy of the data; if so, it can correct the error, which can be reported via CMCI (corrected machine check interrupt) or MCE (Machine Check Exception).
[0069] Among them, CMCI is a hardware interrupt that is triggered when the processor detects a correctable error (such as a single-bit error in ECC memory). This interrupt allows the operating system or hardware management system to capture and handle the error, usually by recording an error log, trying to correct the error, or taking other recovery measures. In addition, MCE is a serious hardware error that is triggered when the processor detects an uncorrectable error (such as a multi-bit error in ECC memory, an internal error in the processor, etc.). This exception usually causes the system to crash or restart because it indicates a serious problem at the hardware level and the operating system usually cannot continue to run safely.
[0070] In addition, if the above errors occur in user space, the operating system can notify the application with events, allowing further recovery or interruption of the application while keeping the operating system running. If the error occurs in kernel space, the operating system will trigger a kernel panic.
[0071] Therefore, the use of ARMM technology can successfully mirror to the kernel's memory space, which can prevent kernel failures caused by memory UCE (Uncorrectable Error). During the boot process of the Linux system kernel, the starting position of the kernel code is determined by the kernel configuration option, generally CONFIG_PHYSICAL_START. According to the search results, this option is set to 0x1000000 by default, which is 16MB. This means that without enabling the KASLR (Kernel Address Space Layout Randomization) function, the kernel will be loaded at the physical address 0x1000000 and start executing.
[0072] However, the KASLR function is enabled in the default kernel configuration, so the kernel load address will be randomized to improve the security of the system. This randomization is achieved through the kernel address space layout randomization (KASLR) technology, which can select a random load address for the kernel at each boot, thereby increasing the difficulty for attackers to predict the kernel address. Therefore, ARMM sets that no matter how the value of MirroredAmountAbove4GB is set, it cannot guarantee that it can cover the kernel memory space. The larger the setting value, the greater the probability of covering the kernel space, but the larger the memory space is sacrificed.
[0073] In order to solve the above problems, an embodiment of the present invention provides a method for configuring mirrored memory. The method can use the memory address range mirroring ARMM technology to cover the kernel memory space when setting a sufficiently small MirroredAmountAbove4GB value, thereby improving the utilization of memory resources while avoiding sacrificing a larger memory space.
[0074] It should be noted that 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, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0075] In addition, the technical solution of the present invention is applicable to all server products that support memory address range mirroring technology, and its purpose is to protect the kernel space, accurately locate and mirror the kernel space, thereby solving the problem of server or server cluster downtime caused by memory.
[0076] Embodiment 1
[0077] In this embodiment, a method for configuring mirror memory is provided, which can be used in an operating system, such as a Linux system or a software or functional module having a Linux system. Figure 1 is a flowchart of a method for configuring mirrored memory according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0078] Step S101: Under the operating system, detecting whether it is necessary to disable the kernel address space layout randomization function.
[0079] Among them, the kernel address space layout randomization function is the KASLR function. When the system is running, the kernel address space layout randomization KASLR function will be turned on by default. Whether to turn off the KASLR function can be set by the user or by the system custom setting, and this embodiment does not limit this.
[0080] Optionally, the operating system is a Linux operating system.
[0081] Step S102: If yes, input the compile instruction for shutting down the function into the system boot manager configuration file, and compile the configuration file.
[0082] The configuration file is used to control one or more of the startup items and startup parameters loaded when the system starts. Optionally, the configuration file can be a system boot manager configuration file, also known as a "Grub configuration file". The Grub configuration file is a key file related to the GRand Unified Bootloader (GRUB) and is used to control the behavior of Grub, including which operating systems are loaded when the system starts, the loading order, the startup parameters, etc.
[0083] The functions of the Grub configuration file include the following: Define the boot menu: set which operating systems and kernel versions appear in the boot menu. Set the default boot item: specify which operating system or kernel is loaded by default when the system starts. Configure the boot parameters: specify the parameters used at boot time for each operating system or kernel, such as kernel boot parameters (such as root=, init=, etc.). Load Grub modules: load additional Grub modules as needed to support more functions. In this embodiment, compiling the Grub configuration file is mainly to determine whether to turn off the KASLR function.
[0084] Furthermore, if the user chooses to turn off the KASLR function, one implementation is to configure GRUB_CMDLINE_LINUX="nokaslr" in the system boot manager configuration file. The "nokaslr" field is used to turn off the KASLR function.
[0085] Step S103: mirroring the memory address space of the first preset capacity by modifying the option parameters of the basic input / output system.
[0086] The first preset capacity needs to cover the memory address space of the kernel. Optionally, the first preset capacity is 4G.
[0087] The first preset capacity size can be determined according to the size of the kernel address space. In this embodiment, for the ARRM technology of the Linux operating system, the first preset capacity size range is generally set to 0~4G. The first preset capacity size 4G is pre-configured by the KASLR function. The memory address space of the kernel can be 2G~4G, and the first preset capacity size 0~4G covers the memory address space 2G~4G of the kernel, thereby ensuring that all the memory addresses of the kernel are stored within the first preset capacity range.
[0088] The option parameters of the basic input and output system BIOS include but are not limited to: a mirror tag field (Mirror TAD0), a unified extensible firmware interface field (UEFI ARM Mirror), and a memory address mirror range field (ARM Mirrorpercentage).
[0089] Modify the option parameters of the basic input and output system BIOS, including: modify the mirror tag field (Mirror TAD0) to Enabled, modify the unified extensible firmware interface field (UEFI ARM Mirror) to Enabled, and modify the memory address mirror range field (ARM Mirror percentage) to 0;
[0090] After the modification is completed, use the command to import the modified option parameters. For example, a command statement is:
[0091] # . / SCELNX_64 / i / s bios.txt.
[0092] Step S104: based on the compiled system boot manager configuration file and the modified option parameters, restart the operating system to implement an image of a first preset capacity size, and store the memory address of the kernel within the range of the first preset capacity.
[0093] Specifically, storing the memory address of the kernel within the first preset capacity size range includes: storing the memory address of the kernel in an address space with 0x1000000 as the base address, and the address space with 0x1000000 as the base address is within the range of 0~4G. The address space of the entire kernel of the Linux operating system is within the range of 0~TOP, 0 represents the starting address of the address space, and TOP represents the end address of the address space.
[0094] In this embodiment, the first preset capacity range is within 0~4G.
[0095] like Figure 2 As shown in the figure, it is a schematic diagram of the kernel address space before and after the KASLR function is turned off by using the command detection. Before the kernel image is made, the kernel address is stored in the address space between 4G and TOP (maximum capacity); after the BIOS configuration file is modified and the Grub configuration file is compiled, the Linux operating system is restarted to store the kernel memory address within the first preset capacity range, such as the range below 4G. Among them, the kernel code is stored in the address space of 0x1000000, and the kernel rodata, kernel data, kernel bss and other data are also stored within the first preset capacity range.
[0096] Among them, Kernel bss (Block Started by Symbol). In the context of programming and computer science, BSS usually refers to the uninitialized data segment. During compilation, all uninitialized global variables and static variables are generally placed in the BSS segment. In this embodiment, Kernelbss refers to the uninitialized data segment used in the kernel. Kernel data is kernel data; Kernel rodata is the kernel read-only data segment, where the abbreviation of read-only data means rodata; Kernel code is kernel code.
[0097] Optionally, in a possible implementation, step S102 inputs a compilation instruction for shutting down the function into a system boot manager configuration file, including: searching for a target startup item in the system boot manager configuration file, setting a field in the target startup item with a function of shutting down the system boot manager, and modifying the field.
[0098] Among them, the target startup item is the Bootloader startup item. The Bootloader is mainly responsible for completing a series of initialization tasks during the device startup process and preparing the environment for the loading and running of the operating system or user application. For example, hardware initialization: The Bootloader will first initialize the hardware components of the device, such as memory, CPU, storage devices, and peripherals (such as UART, GPIO, etc.). Boot loading: Load the operating system image into the memory and jump to the entry address of the operating system to start execution. This usually includes reading the operating system image from a storage device (such as Flash, hard disk, etc.).
[0099] Optionally, in another possible implementation, step S103 modifies option parameters of the basic input / output system, including: searching for memory-related options in a setting interface of the basic input / output system; and changing the memory-related option parameters using a modification tool.
[0100] Furthermore, before using the modification tool to change the memory-related option parameters, the method further includes: backing up the current memory-related option parameters to prevent the parameters from being destroyed or lost due to errors or failures when modifying the memory-related option parameters.
[0101] In addition, after step S104, the method further includes: using a debugging tool to check the memory address of the kernel within the first preset capacity range. For example, the debugging tool can be an Intel debugging tool, and it is checked that the memory space below 4G is indeed mirrored. Figure 2 shown.
[0102] In this embodiment, when the Linux kernel address space layout randomization (KASLR) function is turned off, the solution is simple to set up and saves memory image space. The method provided in this embodiment is suitable for customers who do not have high requirements for kernel security and want simple operation.
[0103] The present invention provides a method for configuring mirror memory. When the KASLR function is turned off, a compile instruction is input into a system boot manager configuration file, the configuration file is compiled, and a basic input and output system (BIOS) option parameter is modified to achieve mirroring of a memory address space of a first preset capacity. Finally, after the operating system is restarted, the mirroring of the first preset capacity is achieved, and when performing memory mirroring, it is ensured that the kernel address is stored within the first preset capacity range. This not only simplifies the complexity of memory management, but also facilitates operations in scenarios such as security analysis and troubleshooting, and improves the overall security and stability of the system.
[0104] In addition, by accurately calculating and setting the memory address space of the first preset capacity for mirroring, the capacity just covers the kernel's memory address space, avoiding unnecessary waste of memory resources. This refined memory management strategy enables system resources to be used more efficiently, which is particularly important in an environment with limited memory resources.
[0105] See also Figure 3 In a specific implementation manner, the method provided in this embodiment specifically includes:
[0106] Step S201: boot up the computer and enter the system, and modify the Grub configuration file to disable the KASLR function.
[0107] Specifically, a Grub configuration file of the current Linux operating system is obtained, a Grub configuration parameter is searched in the Grub configuration file, and a GRUB_CMDLINE_LINUX="nokaslr" field is configured in the Grub file. The Nokaslr field is used to disable the KASLR function.
[0108] The purpose of this step is to disable the kernel address space randomization KASLR function, which can fix the kernel address space below 4G. Among them, 4G is the first preset capacity, which is set by the system.
[0109] Step S202: Compile the Grub configuration file, change the Bootloader startup item, and disable the KASLR function.
[0110] After the change is completed, use the command. For example, in this embodiment, a RedHat system using the Unified Extensible Firmware Interface (UEFI) is used as an example. RedHat is an open source operating system provider, and its operating system is widely used in servers, cloud computing, and desktop environments.
[0111] Specifically, after inputting the compilation instruction to the Grub configuration file of "nokaslr", the compilation operation is performed to generate the compiled grub.cfg file. Optionally, the compilation instruction is # grub2-mkconfig–o / boot / efi / EFI / redhat / grub.cfg. After compilation, enter the system.
[0112] Step S203: Use the tool to change the BIOS parameters and enable the mirror function below 4G.
[0113] Specifically, use the SCE tool or H20UVE to modify the BIOS parameters to enable the memory mirroring function below 4G. For example, using Intel's Eagle Stream platform as an example, modify the Mirror TAD0 field to Enabled, modify the UEFI ARM Mirror field to Enabled, and modify the ARM Mirror percentage field to 0. After the modification is completed, use the command to import the parameters, such as the command: # . / SCELNX_64 / i / s bios.txt.
[0114] Step S204: After restarting the Linux system, automatically implement the mirroring below the first preset capacity of 4G and check the kernel address range. Figure 2 shown.
[0115] In this embodiment, the system address space is stored in the addressing space with 0x1000000 as the base address, and 0x1000000 is the base address within 0~4G. Optionally, it also includes: using a command to detect the kernel address space before and after shutdown, it can be seen that the kernel address space is indeed allocated below 4G, and the Intel debugging tool can be used to check that the memory space below 4G is indeed mirrored. In this embodiment, the kernel's memory address can be stored in the first preset capacity range, such as 2G~4G memory address space.
[0116] Embodiment 2
[0117] This embodiment limits the random address of the kernel address space layout randomization (KASLR) function to a certain low address range of more than 4G, and only mirrors the low address range of more than 4G, thereby effectively controlling the size of the mirror address range and saving memory mirror space.
[0118] The difference from the aforementioned embodiment 1 is that, in the embodiment 1, when the KASLR function is turned off, the memory address of the kernel is stored in a first preset capacity range of 0 to 4G; while in this embodiment, when the KASLR function is turned on, the memory address of the kernel is stored in a low address range of more than 4G.
[0119] like Figure 4 As shown, in the above step S101: detecting whether it is necessary to disable the kernel address space layout randomization function, the method further includes:
[0120] Step S105: If not, a random number is obtained through a random number tool in the operating system, and the value range of the random number is between the first preset capacity and the second preset capacity.
[0121] The first preset capacity is smaller than the second preset capacity. Further, the second preset capacity is determined according to a user acceptable range, and generally the second preset capacity is much smaller than the maximum value TOP of the memory address space. In this embodiment, the second preset capacity is set to 5GB-64MB.
[0122] Specifically, whether to turn on or off the KASLR function can be selected and determined by the user.
[0123] Step S106: assigning a random number to the kernel address space layout randomization seed, and inserting it into the kernel as a kernel startup parameter.
[0124] Specifically, one implementation includes:
[0125] Step S106 - 1 : Obtain the device tree source file.
[0126] The device tree source file (Device Tree) is a data structure used to describe the hardware configuration. It is passed to the kernel by the boot loader (such as U-Boot or Grub) when the system starts. In the Device Tree, the / chosen selection node is a special node used to provide additional information required for kernel startup, such as startup parameters, file system location, and kernel address space layout randomization seed (kaslr-seed).
[0127] Step S106-2: edit the device tree source file, find the selection node in the device tree source file, insert the kernel address space layout randomization seed into the selection node, compile and generate the device tree binary file, and the selection node is used to provide additional information required when the kernel is started.
[0128] Step S106 - 3 : Configure the boot loader to load the device tree binary file.
[0129] It should be noted that, in this embodiment, an example is given of using a method of changing the device tree source file (Device Tree) to limit the value range of kaslr-seed and insert kernel startup parameters into the kernel, including but not limited to this method. Other methods may also be used, and this embodiment does not limit this.
[0130] In addition, step S106-2 also includes: if the selected node is not found in the device tree source file, a new node is created, the kernel address space layout randomization seed (kaslr-seed) is inserted into the new node, and a new device tree binary file is compiled and generated. The new node is used to provide additional information required when the kernel is started.
[0131] Step S107: performing memory mirroring processing on the memory address space in the range of the first preset capacity to the second preset capacity by modifying the option parameters of the basic input and output system.
[0132] The range from the first preset capacity to the second preset capacity needs to cover the memory address space of the kernel.
[0133] Step S108: restarting the operating system, storing the memory address of the kernel in the range from the first preset capacity to the second preset capacity according to the kernel startup parameters in the kernel, and implementing memory mirroring in the range from the first preset capacity to the second preset capacity.
[0134] like Figure 5 As shown, after restarting the Linux operating system, the kernel's memory address storage Kernel code, Kernel rodata, Kernel data, and Kernel bss are stored in the range of the first preset capacity (4G) to the second preset capacity (5GB-64MB).
[0135] Further, in step S106, a random number is assigned to a kernel address space layout randomization seed and inserted into the kernel as a kernel startup parameter, specifically including: in one possible implementation, step S105, obtaining a random number through a random number tool under the operating system, including: under the operating system, using the random number tool to input a first command to generate a random number.
[0136] Optionally, the first command is a shuf command, and a random number in the range of 4GB (4294967296) to 5GB (5301600256) is generated according to the shuf command.
[0137] The method provided in this embodiment, when the KASLR function is turned on, performs mirroring by accurately calculating and setting the memory address space in the range of the first preset capacity to the second preset capacity, which just covers the memory address space of the kernel and makes full use of the memory resources. By introducing random numbers, even when the KASLR function is turned on, the effective mapping and access of the kernel address can be ensured, and the system kernel is mirrored at a relatively low cost, thereby avoiding kernel failures caused by the memory and avoiding the waste of memory resources.
[0138] The present invention closely combines the steps of KASLR function detection, random number generation and assignment, memory mirror processing, and system restart to form an automated configuration process. The automated technology accurately defines the memory address range of the kernel space. This not only simplifies the cumbersome manual configuration steps in the traditional method, but also realizes the update of the memory mirror and kernel address space mapping through the restart operation, thereby improving the efficiency of system deployment and maintenance.
[0139] In a specific implementation, the value range of kaslr-seed is limited in the operating system, for example, to 4GB~5GB-64MB, thereby limiting the layout address range of the KASLR function, and then using the system tool SCE or H2OUVE to modify the BIOS parameters to enable the memory mirroring function below 4G, and at the same time enable the memory address space mirroring function of 4GB~5GB. This ensures system security and enables kernel space mirroring at the expense of a small amount of memory space, reducing the risk of downtime caused by memory UCE.
[0140] like Figure 6 As shown, the specific process of the method includes:
[0141] Step S301: boot up the computer and enter the system, and use a random number tool to obtain a random number within a certain range, such as obtaining a random number within the range of 0x1000000 to 0x13C000000.
[0142] In this embodiment, it is assumed that the range of random number values is limited to 4GB~(5GB-64MB). Correspondingly, the kernel size of this example is 0x37FFFFF-0x1000000=0x27FFFFF, which is less than 64MB. Therefore, the random number is limited to the range of 5GB-64MB=5056MB, where 5056MB is the second preset capacity size.
[0143] Further, an implementation of this step is: using the shuf command to generate a random number within a specified range. For example, the following command will generate a random number n1 within the range of 4 GB to 5 GB.
[0144] The command is: shuf -i 4294967296-5301600256-n1.
[0145] Use the shuf command to generate a random number in the range of 4GB (4294967296) to 5GB (5301600256). This step can be automated by modifying the device tree source file through a script.
[0146] Optionally, in this step, assume that the selected random number is 4500000000.
[0147] Step S302: Use the obtained random number as a random seed (kaslr-seed) to edit the device tree source file.
[0148] This step corresponds to the aforementioned step S106, assigning the random number obtained in S301 to kaslr-seed, and inserting the assigned kaslr-seed into the kernel as a kernel startup parameter, so that KASLR uses the kernel address space layout randomization seed (kaslr-seed) as the base address of the address.
[0149] The device tree source file (Device Tree) is a data structure used to describe the hardware configuration. It is passed to the kernel by the boot loader (such as U-Boot or Grub) when the system starts. In the Device Tree, the / chosen selection node is a special node used to provide additional information required for kernel startup, such as startup parameters, file system location, and kaslr-seed. Among them, the selection node is a node in the device tree source file.
[0150] When configuring / chosen a node, you need to edit the device tree source file, usually a .dts or .dtsi file, and then recompile the device tree source file to generate a new device tree binary file, usually a .dtb or .itb file.
[0151] Further, a process of editing a device tree source file includes: opening a device tree source file (.dts or .dtsi), finding or creating a / chosen selection node. If the / chosen selection node does not exist, a new node needs to be created first as the selection node.
[0152] Step S303: Recompile the device tree source file.
[0153] Use a device tree compilation tool (such as dtc) to compile the device tree source file to generate a new device tree binary file. For example, if the device tree source file is mydevice.dts, the compiled device tree binary file is mydevice.dtb.
[0154] Step S304: configure the boot loader to load a new device tree.
[0155] Depending on the boot loader, the configuration method may vary. For example, in U-Boot, you can set an environment variable to specify the location of the device tree. In the Grub configuration file, you need to update the GRUB configuration file to specify the new device tree file.
[0156] Step S305: Use the SCE or H2OVE tool to modify the BIOS parameters and enable the mirror function below 5G.
[0157] The purpose of this step is to enable the memory mirroring function below 5G. One implementation method is to use Intel's platform Eagle Stream as an example. The total system memory MemTotal can be viewed through cat / proc / meminfo, and the value of MirroredAmount Above4GB is 1÷(MemTotal-TOLM)×10000. Among them, fill the value of MirroredAmountAbove4GB into ARM Mirror percentage. Use SCE or H2OUVE tools to modify the Mirror TAD0 field to Enabled, modify UEFI ARM Mirror to Enabled, and modify ARM Mirrorpercentage to the above calculation result. After the modification is completed, use the command to import the parameters.
[0158] Step S306: Restart the system and check the kernel address range.
[0159] like Figure 5 As shown, after restarting the Linux operating system, the memory address of the kernel is stored in the range of the first preset capacity 4G to the second preset capacity 5056MB according to the kernel startup parameters in the kernel, and memory mirroring is implemented in the range of the first preset capacity 4G to the second preset capacity 5056MB.
[0160] The method provided in this embodiment uses automation technology to accurately limit the memory address range of the kernel space, and performs memory mirroring on the system kernel at a relatively low cost, thereby avoiding kernel panic caused by memory UCE.
[0161] In this embodiment, a device for configuring mirror memory is also provided, which is used to implement the above embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0162] This embodiment provides a device for configuring mirror memory, such as Figure 7 As shown, the device includes: a detection module 710, a compilation module 720, a processing module 730 and a restart module 740, wherein the device may also include other more or fewer modules, which is not limited in this embodiment.
[0163] The detection module 710 is used to detect whether the kernel address space layout randomization function needs to be turned off under the operating system, wherein the system defaults the kernel address space layout randomization function to be turned on.
[0164] The compilation module 720 is used to input the compilation instruction for shutting down the function into the system boot manager configuration file and compile the configuration file when the detection module detects the shutdown function. The configuration file is used to control one or more startup items and startup parameters loaded when the system starts.
[0165] The processing module 730 is used to perform mirroring processing on the memory address space of the first preset capacity by modifying the option parameters of the basic input and output system, wherein the first preset capacity needs to cover the memory address space of the kernel.
[0166] The restart module 740 is used to restart the operating system based on the compiled system boot manager configuration file and the modified option parameters to realize an image of a first preset capacity size and store the memory address of the kernel within the first preset capacity range.
[0167] In some optional implementations, the compiling module 720 is specifically used to search for a target startup item in a system boot manager configuration file, set a field in the target startup item that has a function of shutting down the system boot manager, and modify the field.
[0168] In some other optional implementations, the processing module 730 is further used to search for memory-related options in the basic input and output system setting interface; and use a modification tool to modify memory-related option parameters.
[0169] In some further optional implementations, the processing module 730 is further configured to back up current memory-related option parameters before using a modification tool to modify the memory-related option parameters.
[0170] Optionally, the first preset capacity size is 4G.
[0171] In some further optional implementations, the restart module 740 is specifically used to store the memory address of the kernel in an address space with 0x1000000 as the base address, and the address space with 0x1000000 as the base address is in the range of 0 to 4G.
[0172] The processing module 730 is specifically configured to use a debugging tool to view the memory address of the kernel within a first preset capacity range.
[0173] Optionally, in some other optional implementations, the target startup item is a Bootloader startup item; the option parameters of the basic input and output system include: an image tag field, a unified extensible firmware interface field, and a memory address image range field;
[0174] The processing module 730 is specifically used to modify the image tag field to Enabled, modify the unified extensible firmware interface field to Enabled, and modify the memory address image range field to 0; after the modification is completed, use the command to import the above modified option parameters.
[0175] Optionally, in some other specific implementations, the processing module 730 is also used to obtain a random number through a random number tool under the operating system when the detection module 710 detects that the KASLR function is not turned off, and the value range of the random number is between a first preset capacity and a second preset capacity, and the first preset capacity is smaller than the second preset capacity; the random number is assigned to a kernel address space layout randomization seed and inserted into the kernel as a kernel startup parameter.
[0176] The processing module 730 is also used to perform memory mirroring processing on the memory address space in the range of the first preset capacity to the second preset capacity by modifying the option parameters of the basic input and output system, wherein the range of the first preset capacity to the second preset capacity needs to cover the memory address space of the kernel.
[0177] The restart module 740 is also used to restart the operating system, store the memory address of the kernel in the range of the first preset capacity to the second preset capacity according to the kernel startup parameters in the kernel, and implement memory mirroring in the range of the first preset capacity to the second preset capacity.
[0178] Optionally, in some other specific implementations, the processing module 730 is further used to obtain a device tree source file; edit the device tree source file, find a selection node in the device tree source file, insert a kernel address space layout randomization seed into the selection node, compile and generate a device tree binary file, and the selection node is used to provide additional information required for kernel startup; configure the boot loader to load the device tree binary file.
[0179] The processing module 730 is also used to create a new node if the selected node is not found in the device tree source file, insert the kernel address space layout randomization seed into the new node, compile and generate a new device tree binary file, and the new node is used to provide additional information required when the kernel is started.
[0180] In some further specific implementations, the processing module 730 is further configured to use a random number tool to input a first command in the operating system to generate a random number.
[0181] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0182] The memory mirroring device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0183] The embodiment of the present invention also provides a computer device having the above Figure 7 The configuration shown mirrors the memory devices.
[0184] See also Figure 8 , is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses for communication, and can be installed on a common motherboard or in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface).
[0185] In some optional embodiments, if desired, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8 A processor 10 is taken as an example.
[0186] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0187] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method for configuring the mirror memory shown in the above embodiment.
[0188] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0189] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0190] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 8 The example of connecting through bus is taken in the following.
[0191] The input device 30 can receive input digital or character information, and generate signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0192] In addition, the computer device also includes a communication interface, which is used for the computer device to communicate with other devices or a communication network.
[0193] The computer device provided in this embodiment includes but is not limited to a server, a server cluster, a client or other network devices.
[0194] The computer device provided by the present invention, on the one hand, when the KASLR function is turned off, inputs a compilation instruction into the system boot manager configuration file, compiles the configuration file, and mirrors the memory address space of a first preset capacity by modifying the basic input and output system (BIOS) option parameters. Finally, after restarting the Linux operating system, the mirror of the first preset capacity size is realized, and when performing memory mirroring, it is ensured that the kernel address is stored within the first preset capacity size range, which not only simplifies the complexity of memory management, but also facilitates operations in scenarios such as security analysis and troubleshooting, and improves the overall security and stability of the system.
[0195] On the other hand, when the KASLR function is turned on, the present invention performs mirroring by accurately calculating and setting the memory address space in the range of the first preset capacity to the second preset capacity, and this range just covers the memory address space of the kernel, while making full use of memory resources. By introducing random numbers, even when the KASLR function is turned on, the effective mapping and access of the kernel address can be ensured, and the system kernel is mirrored at a relatively low cost, thereby avoiding kernel failures caused by memory and also avoiding waste of memory resources.
[0196] An embodiment of the present invention also provides a computer-readable storage medium, and the above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented by downloading through a network and originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware.
[0197] The storage medium may be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid state drive, etc.; further, the storage medium may also include a combination of the above-mentioned types of memories. It is understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by the computer, processor or hardware, the method shown in the above embodiment is implemented.
[0198] Embodiments of the present application may also provide a computer program product, including computer program instructions, which, when executed by a processor, cause the processor to perform the steps in the above method. Wherein, the computer program product may be written in any combination of one or more programming languages to perform program codes for performing the operations of the disclosed embodiments, wherein the programming languages include object-oriented programming languages, such as Java, C++, etc., and also include conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on a user computing device, partially on a user device, as an independent software package, partially on a user computing device, partially on a remote computing device, or entirely on a remote computing device or server.
[0199] The above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the embodiments of the present invention are described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for configuring mirrored memory, characterized in that: The method comprises: Under the operating system, detecting whether a kernel address space layout randomization function needs to be turned off, wherein the system defaults the kernel address space layout randomization function to be turned on; If yes, inputting a compile instruction for shutting down the function into a system boot manager configuration file, and compiling the configuration file, wherein the configuration file is used to control one or more of the startup items and startup parameters loaded when the system starts; By modifying the option parameters of the basic input and output system, the memory address space of the first preset capacity is mirrored, wherein the first preset capacity needs to cover the memory address space of the kernel; Based on the compiled system boot manager configuration file and the modified option parameters, the operating system is restarted to implement an image of a first preset capacity size, and the memory address of the kernel is stored within the range of the first preset capacity.
2. The method according to claim 1, characterized in that The step of inputting the compilation instruction for shutting down the function into the system boot manager configuration file comprises: The target boot item is searched in the system boot manager configuration file, a field having a function of shutting down the system boot manager in the target boot item is set, and the field is modified.
3. The method according to claim 1, characterized in that The step of modifying the option parameters of the basic input and output system includes: In the BIOS setup interface, find options related to memory; Use the modification tool to modify the memory-related option parameters.
4. The method according to claim 3, characterized in that Before using the modification tool to modify the memory-related option parameters, the method further includes: Back up the current memory-related option parameters.
5. The method according to claim 1, characterized in that The first preset capacity size is 4G; The step of storing the memory address of the kernel within the first preset capacity range includes: The memory address of the kernel is stored in an address space with 0x1000000 as the base address, and the address space with 0x1000000 as the base address is within the range of 0~4G.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Use a debugging tool to view the memory address of the kernel within the first preset capacity range.
7. The method according to claim 2, characterized in that The target startup item is a Bootloader startup item; the option parameters of the basic input and output system include: an image tag field, a unified extensible firmware interface field and a memory address image range field; The step of modifying the option parameters of the basic input and output system includes: Modify the image tag field to Enabled, modify the unified extensible firmware interface field to Enabled, and modify the memory address image range field to 0; After the modification is completed, use the command to import the modified option parameters above.
8. The method according to claim 1, characterized in that The detecting whether the kernel address space layout randomization function needs to be disabled also includes: If not, obtaining a random number through a random number tool under the operating system, wherein the value range of the random number is between the first preset capacity and the second preset capacity, and the first preset capacity is smaller than the second preset capacity; Assigning the random number to a kernel address space layout randomization seed, and inserting the random number into the kernel as a kernel startup parameter; By modifying the option parameters of the basic input and output system, memory mirroring is performed on the memory address space in the range from the first preset capacity to the second preset capacity, wherein the range from the first preset capacity to the second preset capacity needs to cover the memory address space of the kernel; Restart the operating system, store the memory address of the kernel in the range from the first preset capacity to the second preset capacity according to the kernel startup parameter in the kernel, and implement memory mirroring in the range from the first preset capacity to the second preset capacity.
9. The method according to claim 8, characterized in that The step of assigning the random number to a kernel address space layout randomization seed and inserting the random number into the kernel as a kernel startup parameter includes: Get the device tree source file; Edit the device tree source file, find a selection node in the device tree source file, insert the kernel address space layout randomization seed into the selection node, compile and generate a device tree binary file, wherein the selection node is used to provide additional information required when the kernel is started; Configure the bootloader to load the device tree binary.
10. The method according to claim 9, characterized in that The method further comprises: If the selected node is not found in the device tree source file, a new node is created, the kernel address space layout randomization seed is inserted into the new node, and a new device tree binary file is compiled to generate the new node, where the new node is used to provide additional information required when the kernel is started.
11. The method according to claim 8, characterized in that The obtaining of a random number by using a random number tool under the operating system includes: Under the operating system, a first command is inputted using the random number tool to generate the random number.
12. A device for configuring mirrored memory, characterized in that: The device comprises: A detection module, used for detecting whether a kernel address space layout randomization function needs to be turned off under an operating system, wherein the system defaults the kernel address space layout randomization function to be turned on; a compiling module, for inputting a compiling instruction for shutting down the function into a system boot manager configuration file, and compiling the configuration file, when the detection module detects that the function is shut down, and for controlling one or more of the startup items and startup parameters loaded when the system is started; A processing module, configured to perform mirroring processing on a memory address space of a first preset capacity by modifying an option parameter of a basic input / output system, wherein the first preset capacity needs to cover the memory address space of a kernel; A restart module is used to restart the operating system based on the compiled system boot manager configuration file and the modified option parameters to realize an image of a first preset capacity size and store the memory address of the kernel within the range of the first preset capacity.
13. A computer device, characterized in that: comprising a memory and a processor, wherein the memory and the processor are connected; The memory stores computer instructions, and the processor executes the method for configuring mirrored memory according to any one of claims 1 to 11 by executing the computer instructions.
14. A computer-readable storage medium, characterized in that: The computer readable storage medium has computer instructions stored thereon; The computer instructions are used to enable a computer to execute the method for configuring mirrored memory according to any one of claims 1 to 11.
15. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the method for configuring a mirrored memory according to any one of claims 1 to 11.
Citation Information
Patent Citations
Starting method, and method and device for generating kernel image
CN107688474A
Implementation method and device for kernel address space layout randomization and terminal
CN117370266A