Mode switching method, initialization method of virtual machine and related equipment

By storing and backing up virtual machine register status data into the virtual machine state save area during virtual machine mode switching, and verifying its authenticity when switching back to virtual machine mode, the security risks that the virtual machine exist during mode switching are solved. Resist replay attacks and reduce the security risks of virtual machines.

CN118916867APending Publication Date: 2024-11-08HYGON INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411029220.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-29
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

Existing virtual machines have security risks during operation, especially when mode switching is vulnerable to replay attacks. Attackers can forge virtual machine register status data to control the execution flow of the virtual machine, thereby obtaining confidential information.

Method used

When the processor core switches from virtual machine mode to host mode, the virtual machine register status data is stored in the virtual machine state save area, and the status data of the target register is backed up as verification data in the memory pointed to by the target memory address; When switching back to virtual machine mode, obtain backup data from the target memory address and verify its authenticity to determine whether the virtual machine register status data is forged.

Benefits of technology

Through this mode switching method, it can resist replay attacks, ensure the authenticity of the virtual machine register status data, thereby reducing the security risks of the virtual machine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916867A_ABST
    Figure CN118916867A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a mode switching method, a virtual machine initialization method and related equipment, and the mode switching method comprises the steps: storing virtual machine register state data in a virtual machine state storage area when a processor core is switched from a virtual machine mode to a host mode; taking the state data of the target register stored in the virtual machine state storage area as verification data, and backing up the verification data in a memory pointed by the target memory address as backup data; when the processor core is switched from the host mode to the virtual machine mode, obtaining verification data and a target memory address in the virtual machine register state data from the virtual machine state storage area; acquiring backup data from a memory pointed by the target memory address; and based on the backup data, determining whether the verification data passes verification, and if yes, loading virtual machine register state data of a virtual machine state storage area. According to the mode switching method, the security risk of the virtual machine can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of virtual machine security, and specifically to a mode switching method, a virtual machine initialization method, and related equipment. Background Art

[0002] With the development of new technologies such as cloud computing and big data, virtualization technology is being used more and more widely. Through virtualization technology, a physical host can be virtualized into multiple virtual machines (VMs), thereby efficiently utilizing the hardware resources of the physical host.

[0003] However, existing virtual machines have security risks during operation. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a mode switching method, a virtual machine initialization method and related devices, which can reduce the security risks of the virtual machine.

[0005] To achieve the above objectives, the embodiments of the present application provide the following technical solutions.

[0006] In a first aspect, an embodiment of the present application provides a mode switching method, including:

[0007] When the processor core switches from the virtual machine mode to the host mode, the virtual machine register state data is stored in the virtual machine state saving area, wherein the virtual machine register state data includes the state data of the target register and the target address register, the state data of the target register changes dynamically based on the operation of the virtual machine, and the state data of the target address register is used to indicate the target memory address; the state data of the target register stored in the virtual machine state saving area is used as the verification data, and the verification data is backed up in the memory pointed to by the target memory address as the backup data;

[0008] When the processor core switches from host mode to virtual machine mode, the verification data and target memory address in the virtual machine register state data are obtained from the virtual machine state saving area; the backup data is obtained from the memory pointed to by the target memory address; based on the backup data, it is determined whether the verification data passes the verification, and if so, the virtual machine register state data in the virtual machine state saving area is loaded.

[0009] Optionally, the status data stored in the target register is data used to indicate the running status of the virtual machine during the running of the virtual machine; the target address register is used to indicate a target memory address that is fixed or changes during the running of the virtual machine; the memory pointed to by the target memory address is system memory or virtual machine memory.

[0010] Optionally, the processor core is further configured with an enable register, which is used to store an enable flag, and the enable flag includes an enable state and a disable state, the enable state is used to indicate enabling the verification process of the verification data, and the disable state is used to indicate skipping the verification process of the verification data.

[0011] Optionally, the target register is used to store the automatic exit cumulative value, and the storing the virtual machine register state data into the virtual machine state saving area includes:

[0012] Add 1 to the automatic exit cumulative value in the target register;

[0013] Storing the state data in the target register and the enable register into a virtual machine state saving area;

[0014] Determine whether the target memory address in the target address register is non-zero, and whether the enable flag in the enable register is in an enabled state;

[0015] When the target memory address is non-zero and the enable flag is in an enabled state, the state data of the target address register is stored in a virtual machine state saving area.

[0016] Optionally, obtaining the backup data from the memory pointed to by the target memory address includes:

[0017] Determine whether the enable flag is in an enabled state;

[0018] If so, determining whether the target memory address in the target address register is non-zero;

[0019] If so, read the backup data in the memory pointed to by the target memory address.

[0020] Optionally, the loading of the virtual machine register state data of the virtual machine state saving area includes:

[0021] The verification data is loaded into the target register, the target memory address is loaded into the target address register, and the enable flag is loaded into the enable register.

[0022] Optionally, when switching from virtual machine mode to host mode,

[0023] Before storing the virtual machine register state data in the virtual machine state saving area, the method further includes: configuring exit information to the virtual machine control block, wherein the exit information includes the address of the virtual machine state saving area;

[0024] The method further includes: loading the host virtual machine register state data to the processor core after using the state data of the target register stored in the virtual machine state saving area as verification data and backing up the verification data in the memory pointed to by the target memory address as backup data.

[0025] In a second aspect, an embodiment of the present application provides a computing device, including:

[0026] A processor core, used to execute the mode switching method described in the first aspect; wherein the processor core is configured with a target register and a target address register for indicating a target memory address; wherein the state data of the target register is verification data, and the memory pointed to by the target memory address is used to back up the verification data as backup data; the state data of the target register changes dynamically based on the operation of the virtual machine;

[0027] A virtual machine state saving area is configured in the memory, and the virtual machine state saving area is used to store virtual machine register state data, and the virtual machine register state data includes state data of a target register and a target address register.

[0028] Optionally, the status data stored in the target register is data used to indicate the running status of the virtual machine during the running of the virtual machine; the target address register is used to indicate a target memory address that is fixed or changes during the running of the virtual machine; the memory pointed to by the target memory address is system memory or virtual machine memory.

[0029] Optionally, the virtual machine state saving area is a preset area divided in the virtual machine memory when the virtual machine is initialized; the virtual machine state saving area is configured with one or more security protection mechanisms of physical isolation, access permission isolation, data encryption or integrity verification.

[0030] Optionally, the virtual machine state saving area is configured with a verification data field and a target memory address field, wherein the verification data field is used to store the verification data in the target register, and the target memory address field is used to store the target memory address.

[0031] Optionally, also include:

[0032] An enable register configured to the processor core, the enable register is used to store an enable flag, the enable flag includes an enable state and a disable state, the enable state is used to indicate enabling the verification process of the verification data, and the disable state is used to indicate skipping the verification process of the verification data.

[0033] Optionally, the virtual machine state saving area is further configured with an enable flag field, and the enable flag field is used to store the enable flag.

[0034] Optionally, both the target register and the target address register are only accessible to a virtual core of a virtual machine.

[0035] In a third aspect, an embodiment of the present application provides a method for initializing a virtual machine, which is applied to the computing device described in the second aspect, and includes: a host configuration stage and a virtual machine configuration stage, wherein the host configuration stage is used to allocate a virtual machine state save area for the virtual core, and the virtual machine configuration stage is used to configure target registers and target address registers for the virtual core.

[0036] Optionally, the host configuration stage includes:

[0037] Allocating a virtual machine state saving area for a virtual core of the virtual machine; wherein the virtual machine state saving area is configured with a verification data field corresponding to the verification data and a target address field corresponding to the target memory address;

[0038] Configuring an initial value for the virtual machine register state data in the virtual machine state saving area, and notifying the security processor to encrypt the virtual machine register state data;

[0039] The address of the virtual machine state saving area is configured to the virtual machine control block.

[0040] Optionally, in the step of allocating a virtual machine state saving area for the virtual core of the virtual machine, the virtual machine state saving area is also configured with an enable flag field corresponding to the enable flag, the enable flag includes an enable state and a disable state, the enable state is used to indicate enabling the verification process of the verification data, and the disable state is used to indicate skipping the verification process of the verification data.

[0041] Optionally, the virtual machine configuration stage includes:

[0042] Allocating a target memory address for a virtual core of the virtual machine, and writing the target memory address into a target address register;

[0043] Write the state data in the target register into the memory pointed to by the target memory address.

[0044] Optionally, the virtual machine is configured with multiple virtual cores, the multiple virtual cores including a startup virtual core and at least one application virtual core;

[0045] In the virtual machine configuration stage, before allocating the target memory address for the virtual core of the virtual machine, the method further includes: configuring a virtual core identifier at a first preset position in the shared memory area of ​​the virtual core;

[0046] When the virtual core is a startup virtual core, the target memory address is allocated to the virtual core of the virtual machine, and the target memory address is written into the target address register, specifically: a target memory address is allocated to the startup virtual core based on a preset mechanism, and the target memory address is used as the initial target memory address, and the allocated target memory address is written into the target address register;

[0047] After executing the allocating the target memory address for the virtual core of the virtual machine and before writing the state data in the target register into the memory pointed to by the target memory address, the method further includes: configuring an initial target memory address at a second preset position of the shared memory area;

[0048] When the virtual core is an application virtual core, the target memory address is allocated to the virtual core of the virtual machine, and the target memory address is written into the target address register, specifically: based on the virtual core identifier of the first preset position and the initial target memory address of the second preset position, the target memory address of the application virtual core is calculated, and the calculated target memory address is written into the target address register.

[0049] In a fourth aspect, an embodiment of the present application provides a computer program product, comprising one or more computer executable instructions, which, when executed, implement the mode switching method as described in the first aspect above, or, when executed, implement the virtual machine initialization method as described in the third aspect above.

[0050] The embodiment of the present application provides a mode switching method, a virtual machine initialization method and related equipment, the mode switching method comprising: when a processor core switches from a virtual machine mode to a host mode, storing virtual machine register state data into a virtual machine state saving area, wherein the virtual machine register state data comprises state data of a target register and a target address register, the state data of the target register changes dynamically based on the operation of the virtual machine, and the state data of the target address register is used to indicate a target memory address; using the state data of the target register stored in the virtual machine state saving area as verification data, backing up the verification data in a memory pointed to by the target memory address as backup data; when the processor core switches from the host mode to the virtual machine mode, obtaining the verification data and the target memory address in the virtual machine register state data from the virtual machine state saving area; obtaining the backup data from the memory pointed to by the target memory address; based on the backup data, determining whether the verification data passes the verification, and if so, loading the virtual machine register state data of the virtual machine state saving area.

[0051] It can be seen that in the mode switching scheme described in the embodiment of the present application, when switching from the virtual machine mode to the host mode, the virtual machine register state data is stored in the virtual machine state saving area, and the state data of the target register in the virtual machine register state data is backed up as verification data in the memory pointed to by the target memory address as backup data, and the target memory address is indicated by the state data of the target address register in the virtual machine register state data. It can be understood that the verification data in the target register is based on the dynamic changes of the operation of the virtual machine, which is difficult to predict for the attacker, and the corresponding target memory address is unknown information for the attacker, making it difficult for the attacker to forge the virtual machine register state data when he wants to forge the virtual machine register state data during the replay attack. Accordingly, when the processor core switches from the host mode to the virtual machine mode, based on the backup data obtained from the memory pointed to by the target memory address, it is determined whether the verification data saved in the virtual machine state saving area passes the verification to determine whether the virtual machine register state data is real data or forged data. If it passes the verification, it indicates that the virtual machine register state data saved in the virtual machine state saving area is the real virtual machine register state data of the virtual machine, rather than the virtual machine register state data forged by the attacker, so that the virtual machine register state data in the virtual machine state saving area can be loaded. Therefore, the mode switching method provided in the embodiment of the present application can determine whether the virtual machine register state data is forged, thereby resisting replay attacks and reducing the security risks of the virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0053] Figure 1 is a schematic diagram of an optional architecture of a computing device using virtualization technology;

[0054] Figure 2 It is a schematic diagram of an optional architecture of a computing device using a virtualization technology provided in an embodiment of the present application;

[0055] Figure 3 It is a schematic diagram of an optional structure of a virtual machine state storage area provided in an embodiment of the present application;

[0056] Figure 4 It is a schematic diagram of an optional flow chart of the mode switching method provided in an embodiment of the present application when the processor core switches from the virtual machine mode to the host mode;

[0057] Figure 5is an optional flow chart of step S100 provided in an embodiment of the present application;

[0058] Figure 6 is an optional flow chart of a processor core switching from a virtual machine mode to a host mode provided in an embodiment of the present application;

[0059] Figure 7 It is a schematic diagram of an optional flow chart of the mode switching method provided in an embodiment of the present application when the processor core switches from the host mode to the virtual machine mode;

[0060] Figure 8 is an optional flow chart of step S210 provided in an embodiment of the present application;

[0061] Fig. 9 It is a schematic diagram of the initialization process of the host stage provided in an embodiment of the present application;

[0062] Fig.10 It is a schematic diagram of the initialization process of the virtual machine stage provided in an embodiment of the present application;

[0063] Fig.11 It is a flowchart of a method for initializing a virtual machine provided in an embodiment of the present application. DETAILED DESCRIPTION

[0064] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0065] In virtualization technology, each virtualized virtual machine can be allocated memory (space) and processor resources. The memory allocated to each virtual machine is mainly used for task consumption and virtualization support, and the processor resources allocated to each virtual machine (also called virtual core vCPU) realize process execution.

[0066] refer to Figure 1 An optional architecture diagram of a computing device using virtualization technology is shown, such as Figure 1 As shown, the architecture may include: a CPU (Central Processing Unit) core 1, a memory controller 2, a memory 3 and a security processor 4.

[0067] The CPU core 1 (also called a processor core) can virtualize multiple virtual machines 12 and virtual core vCPUs running corresponding virtual machines through the host operating system (hereinafter referred to as the host) 10 running therein. A virtual machine can allocate one or more virtual cores as computing resources of the virtual machine. Among them, multiple virtual machines 12 can allocate, manage and schedule virtual machine resources based on the virtual machine manager (VMM, Virtual Machine Manager) 13 in the host 10.

[0068] The memory controller 2 is hardware that controls the memory 3 and exchanges data between the memory 3 and the CPU core 1. Part of the memory space or all of the memory space in the memory 3 can be allocated as a virtual machine memory used by the virtual machine. In order to improve the security of the virtual machine data, the virtual machine memory can also be protected, for example, security protection measures such as encryption or isolation can be provided for the virtual machine memory.

[0069] The security processor 4 is a specially configured processor responsible for handling security-related operations of the virtual machine. For example, the security processor 4 can configure an encryption mechanism for the virtual machine memory before the virtual machine runs. The encryption mechanism can encrypt and decrypt data based on the virtual machine key assigned to the virtual machine. Accordingly, the virtual machine memory can also be called encrypted memory; the CPU core 1 can be configured with an interface to communicate with the security processor 4 to realize the interaction of security information related to the virtual machine.

[0070] During system operation, the processor core presents two operating modes, namely host mode and virtual machine mode. In host mode, the processor core is used to execute host code, and in virtual machine mode, the processor core is used to execute virtual machine code. In virtual machine mode, the processor resources allocated to the virtual machine for processing virtual machine code are virtual cores. The two modes will switch based on a preset mechanism in some scenarios.

[0071] For example, the operation of a virtual machine may involve hardware and software configuration matters, such as the configuration of peripheral devices. Accordingly, the virtual machine will generate an AE (Automatic Exits) event to notify the VMM to simulate the peripheral IO behavior of the virtual machine. At this time, the CPU core switches from the virtual machine mode to the host mode to execute the corresponding configuration tasks; after the corresponding configuration tasks are completed, it will switch from the host mode to the virtual machine mode.

[0072] In the corresponding mode switching process, in order to completely restore the running state of the virtual machine, when the virtual machine mode is switched to the host mode, the virtual machine register state data of the processor core in the virtual machine mode (i.e., the parameters of each register when the processor core is running) can be saved to the VMSA (Virtual Machine State Save Area), and when the host mode is switched to the virtual machine mode, the corresponding virtual machine register state data is read from the VMSA and loaded into each register of the processor core. Among them, the VMSA is configured with a security protection mechanism, which can be, for example, one or more of encryption, physical isolation or integrity verification.

[0073] However, this architecture has security risks. Specifically, attackers can use possible state data for analysis and simulate the behavior of the original virtual machine through replay attacks, injecting their forged virtual machine register state data into VMSA, so that the virtual machine loads the forged virtual machine register state data, and achieves the purpose of controlling the execution flow of the virtual machine to obtain confidential information.

[0074] For example, during the operation of a virtual machine, an AE event will be generated to notify the VMM to simulate the virtual machine's peripheral IO (input and output) behavior, giving the attacker the opportunity to deduce the target load of the virtual machine (such as a load that undertakes computing work with typical characteristics) by analyzing the behavior pattern of the virtual machine returning to the VMM, and indirectly achieve secret theft and malicious information injection by overloading the VMSA of the target load.

[0075] In view of this, an embodiment of the present application provides a mode switching method, a virtual machine initialization method and related equipment, the mode switching method comprising: when a processor core switches from a virtual machine mode to a host mode, storing virtual machine register state data into a virtual machine state saving area, wherein the virtual machine register state data comprises state data of a target register and a target address register, the state data of the target register changes dynamically based on the operation of the virtual machine, and the state data of the target address register is used to indicate a target memory address; using the state data of the target register stored in the virtual machine state saving area as verification data, backing up the verification data in a memory pointed to by the target memory address as backup data; when the processor core switches from the host mode to the virtual machine mode, obtaining the verification data and the target memory address in the virtual machine register state data from the virtual machine state saving area; obtaining the backup data from the memory pointed to by the target memory address; based on the backup data, determining whether the verification data passes the verification, and if so, loading the virtual machine register state data in the virtual machine state saving area.

[0076] It can be seen that in the mode switching scheme described in the embodiment of the present application, when switching from the virtual machine mode to the host mode, the virtual machine register state data is stored in the virtual machine state saving area, and the state data of the target register in the virtual machine register state data is backed up as verification data in the memory pointed to by the target memory address as backup data, and the target memory address is indicated by the state data of the target address register in the virtual machine register state data. It can be understood that the verification data in the target register is based on the dynamic changes of the operation of the virtual machine, which is difficult to predict for the attacker, and the corresponding target memory address is unknown information for the attacker, making it difficult for the attacker to forge the virtual machine register state data when he wants to forge the virtual machine register state data during the replay attack. Accordingly, when the processor core switches from the host mode to the virtual machine mode, based on the backup data obtained from the memory pointed to by the target memory address, it is determined whether the verification data saved in the virtual machine state saving area passes the verification to determine whether the virtual machine register state data is real data or forged data. If it passes the verification, it indicates that the virtual machine register state data saved in the virtual machine state saving area is the real virtual machine register state data of the virtual machine, rather than the virtual machine register state data forged by the attacker, so that the virtual machine register state data in the virtual machine state saving area can be loaded. Therefore, the mode switching method provided in the embodiment of the present application can determine whether the virtual machine register state data is forged, thereby resisting replay attacks and reducing the security risks of the virtual machine.

[0077] The following is a detailed description of the mode switching solution provided in the embodiment of the present application.

[0078] refer to Figure 2 An optional architecture diagram of a computing device using virtualization technology is shown, such as Figure 2 As shown, the architecture may include: a CPU (Central Processing Unit) core 1, a memory controller 2, a memory 3 and a security processor (PSP, Platform Secure Processor) 4. Figure 1 The architecture is different in that the computing device further includes: a target register configured to the processor core, and a target address register for indicating a target memory address; wherein the state data of the target register is verification data, and the memory pointed to by the target memory is used to back up the verification data.

[0079] The state data of the target register changes dynamically based on the operation of the virtual machine, so that during the mode switching process, when the state data of the target register is stored in the virtual machine state save area as part of the virtual machine register state data, the corresponding value is also uncertain, making it difficult for an attacker to predict the value of the state data in the target register as verification data.

[0080] The state data stored in the target register may be data indicating the running state of the virtual machine during the running of the virtual machine. In an optional implementation, the target register may be a register for storing an automatic exit cumulative value (AE_COUNTER), which may be named MSR_AE_COUNTER, for example, and the automatic exit cumulative value is the cumulative number of times the virtual machine executes automatic exit (AE). Each time the virtual machine executes an automatic exit, the automatic exit cumulative value is increased by "1".

[0081] The target address register is used to indicate the target memory address, which can be fixed or variable during the operation of the virtual machine. For example, it can be configured as a fixed memory address in the initialization process of the virtual machine, or it can be controlled by software / hardware to change regularly or randomly. This application does not make specific limitations here. The memory pointed to by the target memory address is used to store the state data (i.e., verification data) of the target register stored in the virtual machine state save area. When the verification data is an automatic exit cumulative value, the memory pointed to by the corresponding target memory address is used to back up the automatic exit cumulative value. Optionally, in this example, the target address register can be named MSR_AE_COUNTER_PTR based on the automatic exit cumulative value.

[0082] The memory pointed to by the target memory address may be, for example, a virtual machine memory, which is an encrypted memory allocated to the virtual machine. By configuring the target memory address to indicate the virtual machine memory, the security of the verification data backed up at the target memory address can be improved.

[0083] In a further optional example, the computing device may further include: an enable register configured to the processor core, the enable register is used to store an enable flag, the enable flag is used to indicate whether to enable the verification process of the verification data, thereby enabling control of the verification process. In a specific example, the enable register can be named MSR_REPLAY_DEFENSE.

[0084] Among them, the enable flag can include an enabled state and a disabled state. Taking the value "1" or "0" as an example, when the enable flag is "1", it can be defined as an enabled state, used to indicate enabling the verification process of the verification data. When the enable flag is "0", it can be defined as a disabled state, which is used to indicate skipping the verification process of the verification data.

[0085] Correspondingly, in an optional example, the virtual machine register state data simultaneously includes the verification data, the target memory address and the enable flag.

[0086] The memory 3 is configured with a virtual machine state saving area, which may be an area preset by the computing device for storing virtual machine register state data, or may be a preset area divided in the virtual machine memory when the virtual machine is initialized.

[0087] It is understandable that when the virtual machine state saving area is an area preset by the computing device for storing virtual machine register state data, a separate security protection mechanism can be configured for the area, such as one or more of physical isolation, access permission isolation, data encryption or integrity verification, so as to improve the security of the virtual machine register state data stored in this part. In a further optional example, the virtual machine state saving area is configured with an integrity verification mechanism, so as to further ensure the security of the data in the virtual machine state saving area.

[0088] refer to Figure 3 The optional structural diagram of the virtual machine state saving area shown in the figure has a preset structure for implementing the storage of virtual machine register state data based on the preset structure. In an embodiment of the present application, the virtual machine state saving area is configured with a verification data field and a target memory address field, wherein the verification data field is used to store the verification data in the target register, and the target memory address field is used to store the target memory address.

[0089] In a further example, when an enable register exists, an enable flag field is further configured in the virtual machine state saving area to store the enable flag in the enable flag field.

[0090] It should be noted that when the virtual machine is a multi-core virtual machine, the virtual machine is configured with multiple virtual cores. In the computing device, the target register and the target address register are both only allowed to be accessed by the virtual core of the virtual machine, thereby ensuring data security. Further, when there is an enable register, the enable register is also configured to only allow access by the virtual core of the virtual machine, thereby ensuring data security.

[0091] Based on the optional architecture of the above computing device, the embodiment of the present application further provides a mode switching method, which can be applied to the computing device of the above architecture, and can also be applied to other computing devices of other architectures that can implement the method. Figure 4 FIG. 1 shows an optional flow chart of the mode switching method provided in an embodiment of the present application when the processor core switches from the virtual machine mode to the host mode, with reference to FIG. Figure 4 , the method comprises the following steps:

[0092] Step S100: storing virtual machine register state data into a virtual machine state saving area;

[0093] It can be understood that when executing the switch from virtual machine mode to host mode, the virtual machine register state data is stored in the virtual machine state save area so that the state of the processor core can be quickly and stably restored in the subsequent switch from host mode to virtual machine mode, thereby making the corresponding mode switch faster and smoother.

[0094] In the case where there are target registers and target address registers in the embodiment of the present application, the virtual machine register state data includes state data corresponding to the target register and the target address register. The state data in the target register is used as verification data at the time of mode switching, and the state data in the target address register is used to back up the verification data to its designated memory.

[0095] In combination with the above description, the state data of the target register changes dynamically based on the operation of the virtual machine, so that when the state data of the target register is stored in the virtual machine state save area as part of the virtual machine register state data, the corresponding value is also uncertain, making it difficult for an attacker to predict the value of the state data in the target register serving as verification data.

[0096] The state data stored in the target register may be data indicating the running state of the virtual machine during the running of the virtual machine. In an optional implementation, the target register may be a register for storing an automatic exit cumulative value (AE_COUNTER), which may be named, for example, MSR_AE_COUNTER, and the automatic exit cumulative value is the cumulative number of times the virtual machine executes automatic exit (AE). Each time the virtual machine executes an automatic exit, the automatic exit cumulative value is increased by "1".

[0097] The target memory address indicated by the target address register may be fixed or variable. In a specific example, the target address register may be determined based on a preset mechanism, for example, a preset address may be specified as the target memory address stored in the target address register when initializing the virtual machine, or the target memory address may be periodically changed in sequence among several candidate memory addresses, or the target memory address in the target address register may be randomly updated based on the operation of the virtual machine.

[0098] Wherein, when the verification data is an automatic exit cumulative value, the memory pointed to by the corresponding target memory address is used to back up the automatic exit cumulative value.

[0099] In an optional example, if the computing device also includes an enable register configured to the processor core, the virtual machine register state data also includes an enable flag stored in the enable register to enable control of the verification process based on the enable flag.

[0100] In a specific example, the target register is used to store the automatic exit accumulated value, referring to Figure 5 The optional flow chart of step S100 is shown, and step S100 can be implemented based on the following process:

[0101] Step S101: adding 1 to the automatic exit cumulative value in the target register;

[0102] It can be understood that when the virtual machine mode is switched to the host mode, it indicates that the automatic exit event increases once, and accordingly, the automatic exit cumulative value in the target register increases by 1.

[0103] Step S102: storing the state data in the target register and the enable register into a virtual machine state saving area;

[0104] Step S103: determining whether the target memory address in the target address register is non-zero, and whether the enable flag in the enable register is in an enabled state;

[0105] Wherein, when the target memory address is non-zero and the enable flag is in the enabled state, the subsequent steps S110 and S104 are executed, otherwise, the subsequent steps are skipped.

[0106] Step S104: storing the state data of the target address register into the virtual machine state saving area.

[0107] Wherein, when it is necessary to execute step S110 and step S104, the order of step S110 and step S104 is not limited, and step S110 may be executed first, or step S104 may be executed first. In an optional example, step S110 may be executed first, and after step S110 is successfully executed, step S104 is executed.

[0108] It should be noted that when there is an integrity verification mechanism in the virtual machine state saving area, integrity verification can be performed based on the virtual machine register state data after being stored in the target memory address in step S104, thereby ensuring data integrity.

[0109] Step S110: using the state data of the target register stored in the virtual machine state saving area as verification data, backing up the verification data in the memory pointed to by the target memory address as backup data;

[0110] After the virtual machine register state data is stored in the virtual machine state saving area, the state data of the target register is further backed up as verification data to the memory pointed to by the target memory address as backup data, so that the verification data can be verified based on the backup data.

[0111] Wherein, when the target memory address points to a virtual machine memory with an encryption mechanism, the data stored at the target memory address (i.e., backup data) can be encrypted based on the virtual machine key, thereby ensuring data security. Wherein, a virtual machine configured with the mode switching solution of the present application can be called a state encrypted virtual machine.

[0112] In a specific example, in the process of switching the processor core from the virtual machine mode to the host mode, refer to Figure 6 The optional flow chart of the processor core switching from the virtual machine mode to the host mode shown may further include, before executing step S100:

[0113] Step S201: configuring the virtual machine exit information to the virtual machine control block (VMCB);

[0114] By configuring the exit information to the VMCB, the exit information may include, for example, the control information and processing information of the virtual machine, so that when the virtual machine is started, the virtual machine can be quickly started based on the exit information.

[0115] It is understandable that the exit information of the virtual machine control block includes the address of the virtual machine state saving area, so that the virtual machine state saving area can be addressed.

[0116] Furthermore, after executing step S110, the following steps may be further included:

[0117] Step S202: Loading host virtual machine register state data to the processor core;

[0118] After executing step S110 , the host mode can be restored to the processor core by loading the host virtual machine register state data.

[0119] It can be seen that in the mode switching scheme described in the embodiment of the present application, when switching from the virtual machine mode to the host mode, the virtual machine register state data is stored in the virtual machine state saving area, and the state data of the target register in the virtual machine register state data is backed up as verification data in the memory pointed to by the target memory address as backup data, wherein the target memory address is indicated by the state data of the target address register in the virtual machine register state data. It can be understood that the verification data in the target register changes dynamically based on the operation of the virtual machine, which is difficult for the attacker to predict, and the corresponding target memory address is unknown information to the attacker, so it is difficult for the attacker to forge the virtual machine register state data when he wants to forge the part of the data during the replay attack.

[0120] The following is a description of the process of switching the processor core from the host mode to the virtual machine mode in the embodiment of the present application, referring to Figure 7 The optional flow chart of the mode switching method provided in the embodiment of the present application when the processor core switches from the host mode to the virtual machine mode is shown, including the following steps:

[0121] Step S200: obtaining verification data and a target memory address in the virtual machine register state data from the virtual machine state saving area;

[0122] After storing the corresponding status data in the aforementioned step, the corresponding verification data and the target memory address may be obtained in this step to implement the verification process for the verification data.

[0123] It should be noted that when the virtual machine state saving area is configured with an encryption mechanism, the corresponding virtual machine register state data should be the decrypted virtual machine register state data; when the virtual machine state saving area is configured with an integrity verification mechanism, the virtual machine register state data should be the virtual machine register state data that has passed the integrity verification.

[0124] When the virtual machine register state data has an enable flag, this step also simultaneously obtains the enable flag to control the verification process based on the enable flag.

[0125] Step S210: Acquire the backup data from the memory pointed to by the target memory address;

[0126] By acquiring the backup data, the verification data can be verified. Figure 8 An optional flow chart of step S210 is shown, and step S210 may include the following process:

[0127] Step S211: determining whether the enabling flag is in an enabling state;

[0128] Through the judgment in step 211, it is determined whether to execute the verification process of the verification data.

[0129] If yes, execute step S212 , if no, execute step S230 to load the virtual machine register state data of the virtual machine state saving area.

[0130] Step S212: determining whether the target memory address in the target address register is non-zero;

[0131] If so, it indicates that the target memory address is valid, and step S213 is executed; otherwise, it indicates that there is an error in the data, and the mode switching process is exited.

[0132] Step S213: reading the backup data in the memory pointed to by the target memory address;

[0133] Wherein, when the backup data is stored in the virtual machine memory, if the virtual machine memory is configured with an encryption mechanism, the backup data is decrypted while reading the backup data.

[0134] Step S220: Based on the backup data, determine whether the verification data passes the verification;

[0135] Among them, based on the backup data being a backup of the verification data, correspondingly, the two can be compared to see if they are consistent. If so, the verification data passes the verification and step S230 is executed. If not, it indicates that there is an error in the data and the mode switching process is exited.

[0136] Step S230: Loading the virtual machine register state data of the virtual machine state saving area;

[0137] After confirming that the verification data is authentic original data, the virtual machine register state data may be loaded into the processor core.

[0138] Specifically, when the virtual machine register state data includes verification data and a target memory address, step S230 may specifically include: loading the verification data into the target register, and loading the target memory address into the target address register.

[0139] Furthermore, when the virtual machine register state data also includes an enable flag, step S230 may further include: loading the enable flag into an enable register.

[0140] It can be seen that when the processor core switches from the host mode to the virtual machine mode, based on the backup data obtained from the memory pointed to by the target memory address, it is determined whether the verification data saved in the virtual machine state saving area passes the verification to determine whether the virtual machine register state data is real data or forged data. If it passes the verification, it indicates that the virtual machine register state data saved in the virtual machine state saving area is the real virtual machine register state data of the virtual machine, rather than the virtual machine register state data forged by the attacker, so that the virtual machine register state data in the virtual machine state saving area can be loaded. Therefore, the mode switching method provided in the embodiment of the present application can determine whether the virtual machine register state data is forged, thereby resisting replay attacks and reducing the security risks of virtual machines.

[0141] In a further optional implementation, the embodiment of the present application further provides a method for initializing a virtual machine, the initialization method is used to implement the initialization of the virtual machine run by the processor core described in the embodiment of the present application, so as to provide a basis for the aforementioned mode switching method. Specifically, the initialization process includes a host configuration stage and a virtual machine configuration stage, the host configuration stage is used to allocate a virtual machine state save area for the virtual core, and the virtual machine configuration stage is used to configure a target register and a target address register for the virtual core. Among them, the host configuration stage is executed first, and the virtual machine configuration stage is executed thereafter.

[0142] refer to Fig. 9 The schematic diagram of the initialization process of the host stage is shown, and the initialization process of the host stage includes:

[0143] Step S300: Allocate a virtual machine state saving area for a virtual core of the virtual machine;

[0144] It is understandable that the virtual machine can be a single-core virtual machine or a multi-core virtual machine. When the virtual machine has one virtual core, a virtual machine state saving area is allocated to the virtual core. When the virtual machine has multiple virtual cores, a virtual machine state saving area corresponding to the virtual core can be allocated, or multiple virtual machine state saving areas with consecutive addresses can be allocated.

[0145] The virtual machine state storage area is configured with a verification data field corresponding to the verification data and a target address field corresponding to the target memory address. In a further example, the virtual machine state storage area is further configured with an enable flag field corresponding to the enable flag.

[0146] Step S310: configuring an initial value for the virtual machine register state data in the virtual machine state saving area, and notifying the security processor to encrypt the virtual machine register state data;

[0147] When there is a target register and a target address register, step S310 may include configuring the verification data field corresponding to the target register and the target memory address field corresponding to the target address register as initial values. When there is an enable flag field corresponding to the enable register, step S310 may also include configuring the enable flag field corresponding to the enable register as an initial value. In an optional example, the initial values ​​may all be 0.

[0148] After configuring the corresponding initial value, the virtual machine register state data in the virtual machine state saving area can also be encrypted to ensure data security. In a specific example, the host can notify the security processor to encrypt the virtual machine register state data. It can be understood that when the security processor encrypts the virtual machine register state data, a corresponding response message can be fed back to indicate that the virtual machine register state data has been encrypted.

[0149] Step S320: configuring the address of the virtual machine state saving area to VMCB;

[0150] After encrypting the virtual machine register state data, the memory address corresponding to the virtual machine state saving area may be configured in the VMCB, so as to address the virtual machine state saving area based on the address information.

[0151] Among them, reference Fig.10 The schematic diagram of the initialization process of the virtual machine stage is shown, and the initialization process of the virtual machine stage includes:

[0152] Step S400: allocating a target memory address to a virtual core of the virtual machine, and writing the target memory address into a target address register;

[0153] The virtual machine may allocate a target memory address based on a preset mechanism, so as to indicate the memory pointed to by the target memory address based on a target address register in a subsequent process.

[0154] The preset mechanism may be a virtual machine dynamic allocation mechanism, so that the virtual machine dynamically allocates the target memory address, thereby reducing the predictability of the target memory address.

[0155] Step S410: writing the state data in the target register into the memory pointed to by the target memory address;

[0156] By writing the status data in the target register into the memory pointed to by the target memory address as backup data, the verification process of the verification data can be executed when the virtual machine is running, and the verification data of the target memory address is compared with the verification data in the VMSA of the virtual core to ensure anti-replay attack.

[0157] When there is an enable register, the initialization process further includes:

[0158] Step S420: configuring the enable flag in the enable register to be in an enable state.

[0159] Wherein, based on the enabling flag, the verification process is enabled.

[0160] The above-mentioned initialization process of the virtual core can be understood as a general initialization process of the virtual core. In a multi-core virtual machine, multiple virtual cores are configured, including a BSP (bootstrap processor, a virtual core that starts the system, that is, a virtual core that is prepared for the initialization of other virtual cores) and at least one AP (application processor, an application virtual core, that is, a virtual core other than the BSP). In a further example, refer to Fig.11 In the flowchart of the method for initializing a virtual machine shown in the figure, the initialization process is compared with the aforementioned general initialization process in that the host configuration phase is the same and the virtual machine configuration phase is different, wherein the specific differences include:

[0161] Before step S400, the following steps are further performed:

[0162] Step S500: configuring a virtual core identifier at a first preset position of a shared memory area of ​​the virtual core;

[0163] The shared memory (also called critical area) of the virtual core is a memory that can be accessed by multiple virtual cores of the virtual machine, so that data interaction between different virtual cores is performed based on the shared memory. By configuring the virtual core identifier in the shared memory area, the target memory address corresponding to different virtual cores can be calculated based on the virtual core identifier.

[0164] In a specific example, the virtual core identifier of the virtual core of the BSP may be a preset value, such as "0", and the virtual core identifier of the virtual core of the AP may be the sum of the virtual core identifier of the previous virtual core and a preset value, which may be "1". For example, for the first AP after the BSP is initialized, the corresponding virtual core identifier may be based on the calculation of 0+1 to obtain the virtual core identifier "1" of the first AP, and so on. The first preset position may be workarea.offset1.

[0165] Next, step S400 is executed. In this example, when the virtual core is a startup virtual core, step S400 may specifically be:

[0166] Step S401: allocating a target memory address for the startup virtual core based on a preset mechanism, and using the target memory address as the initial target memory address; correspondingly, writing the target memory address into a target address register, specifically, writing the allocated target memory address into the target address register.

[0167] It is understandable that the preset mechanism may be a dynamic allocation mechanism for a virtual machine, so that the corresponding target memory address is obtained based on the dynamic allocation mechanism.

[0168] Afterwards, executing step S510: configuring an initial target memory address at a second preset position of the shared memory area;

[0169] It can be understood that the initial target address is used to indicate the target memory address configured for starting the virtual core; accordingly, based on the virtual core identifier of the first preset position and the initial target memory address of the second preset position, the target memory address of the application virtual core can be calculated. That is, when the virtual core is an application virtual core, the target memory address can be calculated based on the virtual core identifier of the first preset position and the initial target memory address of the second preset position.

[0170] After executing step S510, step S410 and step S420 may be continued to be executed to complete the initialization of starting the virtual core.

[0171] Afterwards, the initialization process of the application virtual core may be further performed. Different from the above-mentioned general initialization process, before step S400, step S500 is further performed: configuring the virtual core identifier at the first preset position of the shared memory area of ​​the virtual core;

[0172] In combination with the foregoing, the virtual core identifier of the AP can be the sum of the virtual core identifier of the previous virtual core and a preset value, and the preset value can be, for example, "1". For example, for the first AP after BSP initialization, the corresponding virtual core identifier can be based on calculating 0+1 to obtain the virtual core identifier "1" of the first AP, and so on. The first preset position can be workarea.offset1.

[0173] Next, step S400 is executed, wherein step S400 allocates a target memory address for the virtual core of the virtual machine, which may be specifically:

[0174] Step S402: Based on the virtual core identifier at the first preset position and the initial target memory address at the second preset position, a target memory address of the application virtual core is calculated, and the calculated target memory address is written into a target address register.

[0175] In a specific example, the second preset position may be workarea.offset2, wherein the calculation formula of the target memory address may be workarea.offset2+(workarea.offset1*c). In the formula, workarea.offset1 is used to indicate the virtual core identifier stored therein, workarea.offset2 is used to indicate the address within the initial target stored therein, c is the byte length (byte), or may be the word length (bit), in an optional example, c may be 8, in other examples, c may also be 16 or 64, etc., which is specifically determined by the capacity of the memory page in the hardware and the size of the backup data.

[0176] After executing step S400 , step S410 and step S420 may be continued to be executed to complete the initialization of the application virtual core.

[0177] An embodiment of the present application also provides a computer program product, which may include one or more computer executable instructions, and when the one or more computer executable instructions are executed, they implement the mode switching method described above, or when the one or more computer executable instructions are executed, they implement the virtual machine initialization method described above.

[0178] The above describes multiple implementation schemes provided by the embodiments of the present application. The various optional methods introduced in each implementation scheme can be combined and cross-referenced with each other without conflict, thereby extending a variety of possible implementation schemes, which can all be considered as implementation schemes disclosed and open in the embodiments of the present application.

[0179] Although the embodiments of the present application are disclosed above, the present application is not limited thereto. Any person skilled in the art may make various changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be subject to the scope defined by the claims.

Claims

1. A mode switching method, It is characterized in that include: When the processor core switches from the virtual machine mode to the host mode, the virtual machine register state data is stored in the virtual machine state saving area, wherein the virtual machine register state data includes the state data of the target register and the target address register, the state data of the target register changes dynamically based on the operation of the virtual machine, and the state data of the target address register is used to indicate the target memory address; Using the state data of the target register stored in the virtual machine state saving area as verification data, backing up the verification data in the memory pointed to by the target memory address as backup data; When the processor core switches from host mode to virtual machine mode, the verification data and target memory address in the virtual machine register state data are obtained from the virtual machine state saving area; the backup data is obtained from the memory pointed to by the target memory address; based on the backup data, it is determined whether the verification data passes the verification, and if so, the virtual machine register state data in the virtual machine state saving area is loaded.

2. The mode switching method according to claim 1, It is characterized in that The state data stored in the target register is data used to indicate the running state of the virtual machine during the running of the virtual machine; the target address register is used to indicate a target memory address that is fixed or changes during the running of the virtual machine; the memory pointed to by the target memory address is system memory or virtual machine memory.

3. The mode switching method according to any one of claims 1 to 2, It is characterized in that The processor core is further configured with an enable register, which is used to store an enable flag, the enable flag including an enable state and a disable state, the enable state is used to indicate enabling the verification process of the verification data, and the disable state is used to indicate skipping the verification process of the verification data.

4. The mode switching method according to claim 3, It is characterized in that The target register is used to store the automatic exit accumulated value, and the storing of the virtual machine register state data into the virtual machine state saving area includes: Add 1 to the automatic exit cumulative value in the target register; Storing the state data in the target register and the enable register into a virtual machine state saving area; Determine whether the target memory address in the target address register is non-zero, and whether the enable flag in the enable register is in an enabled state; When the target memory address is non-zero and the enable flag is in an enabled state, the state data of the target address register is stored in a virtual machine state saving area.

5. The mode switching method according to claim 3, It is characterized in that The acquiring the backup data from the memory pointed to by the target memory address includes: Determine whether the enable flag is in an enabled state; If so, determining whether the target memory address in the target address register is non-zero; If so, read the backup data in the memory pointed to by the target memory address.

6. The mode switching method according to claim 3, It is characterized in that The step of loading the virtual machine register state data of the virtual machine state saving area includes: The verification data is loaded into the target register, the target memory address is loaded into the target address register, and the enable flag is loaded into the enable register.

7. The mode switching method according to claim 1, It is characterized in that When switching from virtual machine mode to host mode, Before storing the virtual machine register state data in the virtual machine state saving area, the method further includes: configuring exit information to the virtual machine control block, wherein the exit information includes the address of the virtual machine state saving area; The method further includes: loading the host virtual machine register state data to the processor core after using the state data of the target register stored in the virtual machine state saving area as verification data and backing up the verification data in the memory pointed to by the target memory address as backup data.

8. A computing device, It is characterized in that include: A processor core, for executing the mode switching method according to any one of claims 1 to 7; wherein the processor core is configured with a target register and a target address register for indicating a target memory address; wherein the state data of the target register is verification data, and the memory pointed to by the target memory address is used to back up the verification data as backup data; the state data of the target register changes dynamically based on the operation of the virtual machine; A virtual machine state saving area is configured in the memory, and the virtual machine state saving area is used to store virtual machine register state data, and the virtual machine register state data includes state data of a target register and a target address register.

9. The computing device according to claim 8, It is characterized in that The state data stored in the target register is data used to indicate the running state of the virtual machine during the running of the virtual machine; the target address register is used to indicate a target memory address that is fixed or changes during the running of the virtual machine; the memory pointed to by the target memory address is system memory or virtual machine memory.

10. The computing device according to claim 8, It is characterized in that The virtual machine state storage area is a preset area divided in the virtual machine memory when the virtual machine is initialized; the virtual machine state storage area is configured with one or more security protection mechanisms of physical isolation, access permission isolation, data encryption or integrity verification.

11. The computing device according to claim 8, It is characterized in that The virtual machine state saving area is configured with a verification data field and a target memory address field, wherein the verification data field is used to store the verification data in the target register, and the target memory address field is used to store the target memory address.

12. The computing device according to any one of claims 8 to 11, It is characterized in that Also includes: An enable register configured to the processor core, the enable register is used to store an enable flag, the enable flag includes an enable state and a disable state, the enable state is used to indicate enabling the verification process of the verification data, and the disable state is used to indicate skipping the verification process of the verification data.

13. The computing device according to claim 12, It is characterized in that The virtual machine state saving area is further configured with an enable flag field, and the enable flag field is used to store the enable flag.

14. The computing device according to claim 8, It is characterized in that The target register and the target address register are both accessible only to the virtual core of the virtual machine.

15. A method for initializing a virtual machine, It is characterized in that The computing device applied to any one of claims 8 to 14 comprises: a host configuration stage and a virtual machine configuration stage, wherein the host configuration stage is used to allocate a virtual machine state save area for the virtual core, and the virtual machine configuration stage is used to configure a target register and a target address register for the virtual core.

16. The method for initializing a virtual machine according to claim 15, It is characterized in that The host configuration stage includes: Allocating a virtual machine state saving area for a virtual core of the virtual machine; wherein the virtual machine state saving area is configured with a verification data field corresponding to the verification data and a target address field corresponding to the target memory address; Configuring an initial value for the virtual machine register state data in the virtual machine state saving area, and notifying the security processor to encrypt the virtual machine register state data; The address of the virtual machine state saving area is configured to the virtual machine control block.

17. The method for initializing a virtual machine according to claim 16, It is characterized in that In the step of allocating a virtual machine state saving area for the virtual core of the virtual machine, the virtual machine state saving area is also configured with an enable flag field corresponding to the enable flag, the enable flag includes an enable state and a disable state, the enable state is used to indicate enabling the verification process of the verification data, and the disable state is used to indicate skipping the verification process of the verification data.

18. The method for initializing a virtual machine according to claim 15, It is characterized in that The virtual machine configuration stage includes: Allocating a target memory address for a virtual core of the virtual machine, and writing the target memory address into a target address register; Write the state data in the target register into the memory pointed to by the target memory address.

19. The method for initializing a virtual machine according to claim 18, It is characterized in that The virtual machine is configured with a plurality of virtual cores, the plurality of virtual cores including a startup virtual core and at least one application virtual core; In the virtual machine configuration stage, before allocating the target memory address for the virtual core of the virtual machine, the method further includes: configuring a virtual core identifier at a first preset position in the shared memory area of ​​the virtual core; When the virtual core is a startup virtual core, the target memory address is allocated to the virtual core of the virtual machine, and the target memory address is written into the target address register, specifically: a target memory address is allocated to the startup virtual core based on a preset mechanism, and the target memory address is used as the initial target memory address, and the allocated target memory address is written into the target address register; After executing the allocating the target memory address for the virtual core of the virtual machine and before writing the state data in the target register into the memory pointed to by the target memory address, the method further includes: configuring an initial target memory address at a second preset position of the shared memory area; When the virtual core is an application virtual core, the target memory address is allocated to the virtual core of the virtual machine, and the target memory address is written into the target address register, specifically: based on the virtual core identifier of the first preset position and the initial target memory address of the second preset position, the target memory address of the application virtual core is calculated, and the calculated target memory address is written into the target address register.

20. A computer program product, It is characterized in that The method comprises one or more computer executable instructions, which, when executed, implement the mode switching method as described in any one of claims 1 to 7, or the one or more computer executable instructions, when executed, implement the virtual machine initialization method as described in any one of claims 15 to 19.