Memory access management methods and systems for target TEE applications
By managing the memory access behavior of TEE applications through virtualization technology, and by using the virtual machine manager and operating system to jointly manage the security page table and memory table, the problems of high cost and insufficient security of hardware TEE solutions are solved, and efficient management and protection of secure memory are achieved.
Patent Information
- Application Number
- CN202310576391.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-19
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2043-05-19
AI Technical Summary
Existing hardware TEE solutions are costly and vulnerable to attacks on secure memory, especially when relying on untrusted modules to manage TEE page tables, making it difficult to guarantee the integrity and privacy of secure memory.
Virtualization technology is used to create a trusted execution environment. The secure page table and secure memory table are jointly managed by the virtual machine manager and the operating system to ensure the memory access behavior of TEE applications, including dynamically adding, modifying and deleting secure memory pages.
While reducing costs, it improves the security of secure memory, avoids attacks on TEE applications by untrusted modules, and enhances memory isolation capabilities and security levels.
Smart Images

Figure CN116595539B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of security technology, and in particular to a memory access management method and system for a target TEE application. Background Technology
[0002] A Trusted Execution Environment (TEE) is generally a secure environment or zone provided by hardware or software for program developers. Hardware or software outside the zone cannot access the true content of the data within. Program developers can run critical program code that generates and processes sensitive / privacy data within the TEE, while other parts run in a Rich Execution Environment (REE). Even if the program code outside the TEE contains vulnerabilities that can be exploited by attackers, the security of the program and data within the TEE is guaranteed. A TEE typically provides security features such as data privacy, data integrity, and identity verification for programs that process sensitive / privacy data.
[0003] In traditional approaches, the creation of a Trusted Execution Environment (TEE) relies on specialized hardware, known as a hardware TEE solution. However, this specialized hardware is expensive and requires a platform capable of supporting it, thus increasing the cost of using a TEE. Furthermore, in hardware TEE solutions, the TEE page tables are typically managed by an untrusted module within the REE, which increases the risk of attacks on secure memory. Summary of the Invention
[0004] This specification describes one or more embodiments of a memory access management method for a target TEE application, which can effectively manage TEE applications running in a simulated trusted execution environment, thereby ensuring the security of secure memory while reducing the cost of using the trusted execution environment.
[0005] Firstly, a memory access management method for a target TEE application is provided, wherein the target TEE application runs in a Trusted Execution Environment (TEE) of a virtual machine; the method includes:
[0006] The virtual machine manager obtains the first page fault exception information generated during the execution of the target TEE application, which indicates the first virtual page;
[0007] In response to the fact that no binding relationship corresponding to the first virtual page is found in the target security page table corresponding to the target TEE application, the virtual machine manager injects the first page fault information into the operating system in the normal execution environment REE;
[0008] In response to the first page fault information, the operating system binds the first physical page to the first virtual page and provides the corresponding first binding relationship and the first metadata of the first physical page to the virtual machine manager.
[0009] The virtual machine manager adds the first binding relationship to the target security page table, and adds a first record to the security memory table used to record security memory information of each TEE application. The first record includes the first physical page and the first metadata.
[0010] Secondly, a memory access management system for a target TEE application is provided, wherein the target TEE application runs in a Trusted Execution Environment (TEE) of a virtual machine; the system includes:
[0011] The virtual machine manager is used to obtain the first page fault information generated during the execution of the target TEE application, wherein the first virtual page is indicated.
[0012] The virtual machine manager is also configured to inject the first page fault information into the operating system in the normal execution environment REE in response to the fact that no binding relationship corresponding to the first virtual page is found in the target security page table corresponding to the target TEE application;
[0013] The operating system is configured to, in response to the first page fault information, bind the first physical page to the first virtual page, and provide the corresponding first binding relationship and the first metadata of the first physical page to the virtual machine manager;
[0014] The virtual machine manager is further configured to add the first binding relationship to the target security page table, and add a first record to the security memory table used to record security memory information of each TEE application, the first record including the first physical page and the first metadata.
[0015] Thirdly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of the first aspect.
[0016] Fourthly, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement the method of the first aspect.
[0017] The memory access management method for a target TEE application provided in one or more embodiments of this specification allows the target TEE application to run in a simulated trusted execution environment. The memory access behavior of the target TEE application (including dynamically adding / modifying / deleting secure memory pages) is managed jointly by a trusted virtual machine manager and the operating system in the REE based on secure page tables and secure memory tables. This ensures the security of secure memory while reducing the cost of using the trusted execution environment. Attached Figure Description
[0018] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic diagram illustrating an implementation scenario of one embodiment disclosed in this specification;
[0020] Figure 2 This diagram illustrates an interaction diagram of a memory access management method for a target TEE application according to one embodiment.
[0021] Figure 3 An interaction diagram of a memory access management method for a target TEE application according to another embodiment is shown;
[0022] Figure 4 An interaction diagram of a memory access management method for a target TEE application according to yet another embodiment is shown;
[0023] Figure 5 A schematic diagram of a memory access management system for a target TEE application is shown according to one embodiment. Detailed Implementation
[0024] The solution provided in this specification will now be described with reference to the accompanying drawings.
[0025] As mentioned earlier, traditional technologies typically create trusted execution environments (TEEs) based on specialized hardware. In this hardware-based TEE solution, TEE application memory access operations are usually controlled by hardware modules such as the Memory Management Unit (MMU) (a computer hardware component responsible for handling memory access requests from the Central Processing Unit (CPU)). Specifically, when the CPU accesses memory via a virtual address, the MMU first configures the current memory access behavior based on the access permissions of the corresponding page table entry in the TEE page table, performing a validity check. After passing the check, the MMU queries the TEE page table (a data table used to record the binding relationship between virtual pages / virtual addresses and physical pages / physical addresses) to translate the virtual address into a physical address, and then the memory controller and other related hardware load the data from memory into the processor.
[0026] To reduce implementation complexity, hardware TEE solutions typically manage the TEE page table through an untrusted module (e.g., the operating system) within the REE. However, when the TEE page table is managed by an untrusted module, it becomes vulnerable to attack. To detect instances where untrusted modules maliciously modify the TEE page table, compromising the confidentiality and integrity of secure memory, a new hardware module is needed: the reverse page table. This module records metadata about the secure memory mapping within the TEE. Untrusted modules cannot access the reverse page table, and its metadata initialization and dynamic modification require authorization and verification from the TEE application. Utilizing the reverse page table mechanism, the memory security of the TEE application can be guaranteed. The reverse page table can be implemented using two structures: the SGX (Software Guard Extension) technology based on the Secure Page Cache Map (EPCM) structure, and the AMD SEV-SNP technology based on the Reverse Map Table (RMP) structure.
[0027] Taking the EPCM structure in SGX technology as an example, the EPCM can record secure memory mapping information. It also extends the MMU's mechanism for handling TEE applications' access to secure memory: during memory access, after address translation using the TEE page table managed by the untrusted module, the EPCM is used for further checks. Since the initialization and modification of EPCM content must be authorized by the TEE application, the secure memory mapping and configuration information of the TEE application are securely guaranteed. In SGX technology, all operations involving secure memory by TEE applications must be checked by the EPCM, including secure memory initialization, secure memory access and dynamic management, and secure memory paging operations.
[0028] In addition, SGX technology extends the page fault register by adding an SGX bit to indicate that the page fault originated from safe memory. SGX technology also expands the operating system kernel's page fault handling logic: based on the SGX bit in the exception register, page faults caused by safe memory are handled specially.
[0029] However, the above-mentioned scheme using the reverse page table mechanism has at least the following drawbacks:
[0030] Poor versatility: This solution requires expansion of existing hardware, such as introducing a new hardware module: EPCM. Therefore, it can only be used on a small number of hardware platforms that support SGX functionality.
[0031] Slow iteration and lack of auditability: The slow iteration speed of hardware means that support for new features and bug fixes cannot keep up with the ever-increasing demands of software development. Furthermore, because SGX technology does not open-source its implementation details, developers and users of its TEE applications must trust the correctness of the hardware design.
[0032] Page fault side-channel attack: In this scheme, the TEE page table used by the TEE application is directly controlled by an untrusted module. Although the TEE application can ensure the data integrity of secure memory by controlling the EPCM, this architecture provides an opportunity for the untrusted module to exploit side-channel attacks on the TEE application. For example, the untrusted module can modify the attributes of the page table entries corresponding to secure memory pages in the TEE page table without the TEE application's knowledge, causing the TEE application's access to secure memory to become abnormal. By obtaining this abnormal information, the module can obtain the TEE application's memory access behavior and achieve the attack objective.
[0033] To address this, this solution proposes creating a Trusted Execution Environment (TEE) using virtualization technology based on general-purpose hardware. Furthermore, the memory access behavior of target TEE applications running in the simulated TEE (Trusted Execution Environment) (including dynamically adding / modifying / deleting secure memory pages) is managed jointly by a trusted virtual machine manager and the operating system within the REE (Reliable Execution Environment) based on secure page tables and secure memory tables. This approach ensures the security of secure memory while reducing the cost of using the TEE.
[0034] Figure 1 This is a schematic diagram illustrating an implementation scenario of one of the embodiments disclosed in this specification. Figure 1In this architecture, the operating system and various TEE applications within the REE run on different virtual machines. The hypervisor runs on the physical machine and has the highest privileges. This hypervisor maintains a Secure Memory Table (SecMT). This Secure Memory Table is shared by all TEE applications and records their secure memory information. Based on this Secure Memory Table, the hypervisor can check and configure the Secure Page Table. The Secure Page Table (SecPT) corresponds to each TEE application and records the mapping information of the secure regions bound to the TEE application (i.e., the binding relationship between virtual pages / virtual addresses and physical pages / physical addresses). It should be noted that the Secure Memory Table and Secure Page Table can only be managed and accessed by the hypervisor.
[0035] The virtual machine manager can also manage the extended page tables (EPTs) for each virtual machine (a data table used to record the binding relationship between the physical addresses of virtual machines and the physical addresses of the physical machine). In one embodiment, for a first virtual machine running an operating system, a binding relationship can be established between the physical address of the first virtual machine and the physical address of ordinary memory, while for a second virtual machine running a TEE application, a binding relationship can be established between the physical address of the second virtual machine and the physical address of secure memory, thereby controlling the operating system from accessing secure memory.
[0036] Furthermore, since the security page table corresponds to the TEE application, that is, it only records the mapping information of the security zone bound to the TEE application, this solution can also control the TEE application to only access the security zone bound to it, and not to access other security zones bound to other TEE applications.
[0037] Figure 1 In a REE (Run-Electronic Execution Environment), a page fault occurs when a TEE application accesses a virtual page that is not bound to a physical page during execution. After a page fault occurs, the virtual machine manager can obtain the page fault information and inject it into the operating system within the REE. The operating system then binds the physical page to the page and requests the virtual machine manager to add the safe memory information of that physical page to the safe memory table. Based on the modified safe memory table, the virtual machine manager configures the corresponding safe page table.
[0038] Furthermore, when a physical page in secure memory (referred to as a secure memory page) is in certain states and types (such as an uninitialized or pending destruction state, or a metadata type), accessing that secure memory page by a TEE application will also trigger an exception. Specifically, for secure memory pages that are being added or modified, the virtual machine can set them to an inaccessible state. For example, for a secure memory page being added, the virtual machine manager can set it to the PENDING state (a state indicating that the corresponding physical page has been added by the operating system but has not yet been accepted by the TEE application). As another example, for a secure memory page being modified, the virtual machine manager can set it to the MODIFIED state (a state indicating that the corresponding physical page has been modified by the operating system but has not yet been accepted by the TEE application). When a TEE application accesses these inaccessible secure memory pages, the hardware interrupts the execution of the TEE application, and the virtual machine manager injects the exception into the operating system within the REE, allowing the operating system to handle the exception. After exception handling, the operating system can request the virtual machine manager to resume the execution of the TEE application.
[0039] It should be noted that the above process of binding virtual pages to physical pages can also be understood as the process of adding secure memory pages to TEE applications. In practical applications, a trusted virtual machine manager can also work with the operating system to modify or delete the secure memory pages of a TEE application.
[0040] In summary, in this solution, the memory access behavior of TEE applications (including dynamically adding / modifying / deleting secure memory pages, etc.) is managed jointly by a trusted virtual machine manager and the operating system in the REE, based on secure page tables and secure memory tables. This will be explained in detail later.
[0041] Figure 2 This diagram illustrates an interaction diagram of a memory access management method for a target TEE application according to one embodiment. Figure 2 As shown, the method may include the following steps:
[0042] In step S202, the virtual machine manager obtains the first page fault exception information generated during the execution of the target TEE application, which indicates the first virtual page.
[0043] The target TEE application here can be any application running in a virtual trusted execution environment.
[0044] It should be noted that the aforementioned target TEE application can be bound to a target memory region in secure memory. Specifically, before the target TEE application begins execution, it sends a memory allocation request to the operating system running in the REE. In response to this memory allocation request, the operating system, according to a predetermined allocation strategy, and in conjunction with the virtual machine manager, allocates the corresponding target memory region for the target TEE application. This predetermined allocation strategy is at least used to ensure that different memory regions are allocated for different TEE applications.
[0045] In one embodiment, the secure memory table records the initial memory information of each physical page in the secure memory, or in other words, the secure memory table records the initial memory information of each secure memory page. This initial memory information includes at least an owner field. Therefore, the above-mentioned allocation of the target memory region includes the operating system first allocating a target memory region for the target TEE application according to a predetermined allocation strategy. Then, the operating system provides the information of this target memory region (e.g., address information) to the virtual machine manager, which sets the owner field of each target physical page contained in that target memory region to the target TEE application in the secure memory table.
[0046] Of course, in practical applications, the initial memory information mentioned above can also include: physical address (i.e., physical page), permissions, page type, and page status bits, etc. Except for the physical address, all other information can be set to default values.
[0047] It should be understood that after allocating the target memory region for the target TEE application, the virtual machine manager can also initialize the corresponding target security page table. Specifically, it can establish binding relationships between at least a portion of the virtual pages maintained by the target TEE application and the physical pages in the target memory region, and record these binding relationships between the virtual pages and physical pages in the target security page table.
[0048] In step S202, if the target TEE application accesses a virtual page (i.e., the aforementioned first virtual page) that has not yet been bound to a physical page during execution, the MMU generates a first page fault exception and writes it to a predetermined register. Afterwards, when control flow is transferred to the virtual machine manager, the virtual machine manager can read the first page fault exception information from the predetermined register.
[0049] In one embodiment, the aforementioned first page fault information may include a ProtectionViolation bit and a User Mode bit. The ProtectionViolation bit indicates that the application's access behavior does not match the page information, and the User Mode bit indicates that the fault occurred in user mode.
[0050] It should be noted that the aforementioned unauthorized access bits and user mode bits are both disabled by default.
[0051] In step S204, in response to the fact that no binding relationship corresponding to the first virtual page is found in the target security page table corresponding to the target TEE application, the virtual machine manager injects the first page fault exception information into the operating system in the normal execution environment REE.
[0052] After obtaining the first page fault information, the virtual machine manager can query the target security page table corresponding to the target TEE application based on the first virtual page.
[0053] If the binding relationship corresponding to the first virtual page is not found, the virtual machine manager does not correct the above first page fault information, but directly injects it into the operating system, so that the operating system executes the default page fault handling logic.
[0054] In step S206, in response to the first page fault information, the operating system binds the first physical page to the first virtual page and provides the corresponding first binding relationship and the first metadata of the first physical page to the virtual machine manager.
[0055] It should be understood that the aforementioned first physical page is contained within the target memory region corresponding to the target TEE application.
[0056] In one embodiment, the first metadata of the first physical page includes at least one of the following: virtual address, page type, and permissions. Here, the virtual address can be understood as a virtual address range consisting of a start virtual address and an end virtual address, often referred to as a virtual page. The page type can include ordinary types and special types, where special types can be, for example, TRIM type (a page type that is about to be reclaimed) and TCS type, etc. Permissions can include, but are not limited to, read-only, read-write, and executable, etc.
[0057] Of course, in practical applications, the operating system can also provide the virtual machine manager with the first physical page, or a physical address range consisting of a start physical address and an end physical address, etc. This specification does not limit this.
[0058] In step S208, the virtual machine manager adds the first binding relationship to the target security page table and adds a first record to the security memory table used to record security memory information of each TEE application. The first record includes the first physical page and the first metadata.
[0059] The above-mentioned addition of the first binding relationship to the target security page table can also be understood as adding the correspondence between the first virtual page (i.e., virtual address range) and the first physical page (physical address range) to the target security page table.
[0060] In one embodiment, the target security page table may further include a flag bit (Present bit) for indicating whether the binding relationship is valid, so that adding the first binding relationship to the target security page table as described above also includes setting the flag bit of the first binding relationship to invalid.
[0061] It should be noted that the reason for setting the flag of the first binding relationship to invalid is that the first metadata is provided to the virtual machine manager by the operating system in the REE, which is untrusted and needs to be verified by the TEE application.
[0062] In one embodiment, if the initial memory information of each physical page in the safe memory is already recorded in the safe memory table, adding the first record may include updating the initial memory information of the first physical page based on the first metadata. For example, using the page type in the first metadata to replace the default value of the page type in the initial memory information, etc.
[0063] Furthermore, if the initial memory information also includes page status bits, the above-mentioned addition of the first record also includes setting the page status bits of the first physical page to represent an intermediate state in the processing. For example, setting it to the PENDING state.
[0064] It should be noted that physical pages in an intermediate state cannot be accessed by TEE applications.
[0065] In another embodiment, if the initial memory information is not recorded in the secure memory table, a corresponding first record can be added directly using the first physical page as an index. The first record includes the first physical page and the first metadata, and may also include page status bits, etc.
[0066] After adding the first binding relationship and the first record as described above, the virtual machine manager can send a notification to the operating system indicating that the addition is complete, so that the operating system can request the virtual machine manager to resume the execution of the target TEE application.
[0067] In summary, after binding a physical page to a virtual page that does not currently have a binding relationship, the virtual machine manager can set the status bit of that physical page in the secure memory table to indicate an intermediate state during processing. Simultaneously, it can set the flag bit corresponding to the binding relationship in the secure page table to invalid, thus preventing TEE applications from accessing the security memory page being added. Only after the TEE application verifies the addition of the security memory page (i.e., permissions and page type, etc.) can the page status bit be modified to indicate the final ready state, and the invalid flag bit be cleared.
[0068] It should be noted that if a TEE application accesses a safe memory page that is being added, a page fault will occur. Upon a page fault, the virtual machine manager first intercepts the exception, corrects the page fault information using the safe memory table, and then controls the operating system to execute the user-defined page fault handling logic: the operating system calls the TEE application to verify the correctness of the addition. After successful verification, it requests the virtual machine manager to update the corresponding page status bit in the safe memory table, as well as update the flag bits in the safe page table. Finally, the TEE application can access the newly added safe memory page normally.
[0069] The following provides a detailed explanation of the handling process for a page fault that occurs when a TEE application accesses a security memory page that is being added.
[0070] Figure 3 An interaction diagram of a memory access management method for a target TEE application according to another embodiment is shown. Figure 3 As shown, the method may include the following steps:
[0071] In step S302, the virtual machine manager obtains the second page fault exception information generated during the execution of the target TEE application, which indicates the aforementioned first virtual page.
[0072] It should be understood that because the flag corresponding to the first binding relationship in the target security page table is invalid, when the target TEE application resumes execution and accesses the first virtual page, the MMU will generate a page fault exception again (hereinafter referred to as the second page fault exception). The virtual machine manager then reads this second page fault exception from a predetermined register.
[0073] The second page fault information here is defined in the same way as the first page fault information mentioned above, that is, it may include access violation bits and user mode bits, etc.
[0074] In step S304, in response to finding the first binding relationship in the target security page table and the corresponding flag being invalid, the virtual machine manager corrects the second page fault information and injects the corrected fault information into the operating system.
[0075] It should be noted that since the second page fault is not caused by the failure to find the binding relationship corresponding to the first virtual page, but by the invalidation of the binding relationship, the virtual machine manager needs to correct the second page fault to control the operating system to execute the user-defined page fault handling logic.
[0076] Specifically, after obtaining the second page fault information, the virtual machine manager can query the target security page table corresponding to the target TEE application based on the first virtual page. Since the corresponding first binding relationship can be found, and the corresponding flag should be invalid, the virtual machine manager determines that the second page fault information is caused by a binding relationship failure. Therefore, it sets the illegal access bit and user mode bit in the second page fault information to valid, obtaining corrected fault information. Afterwards, the operating system executes the user-defined page fault handling logic based on this corrected fault information.
[0077] As can be seen, this solution can control the page fault handling process of the operating system by injecting correction exception information into the operating system.
[0078] In step S306, in response to the error correction information, the operating system calls the target TEE application to verify the first metadata of the first physical page bound to the first virtual page.
[0079] Specifically, after receiving the correction exception information, the operating system injects a SIGSEGV signal into the target TEE application to execute the signal handling function for the SIGSEGV signal contained in the target TEE application. This executes the user-defined page fault handling logic, specifically including: the target TEE application sending a first verification request to the virtual machine manager, indicating the first description data of the first virtual page maintained by the target TEE application. In response to the first verification request, the virtual machine manager compares the first description data with the first metadata. If the comparison matches, the verification of the first metadata passes.
[0080] The aforementioned first description data may include at least one of the following: virtual address, page type, and permissions, etc.
[0081] It should be understood that through the above verification steps, the target TEE application can confirm whether the metadata added to the secure memory table is the data that the target TEE application expects to add.
[0082] In step S308, if the verification is successful, the virtual machine manager sets the flag of the first binding relationship to valid in the target secure page table and sets the page status bit of the first physical page to the final state indicating readiness in the secure memory table.
[0083] If the above verification passes, it confirms to the target TEE application that the metadata added to the secure memory table is the data it intended to add. Afterward, the target TEE application can send a verification success notification to the operating system, which then requests the virtual machine manager to resume the execution of the target TEE application.
[0084] It should be understood that after the execution of the target TEE application is restored, it will be able to access the first virtual page as described above, in other words, it will be able to access the corresponding target memory region normally.
[0085] In the memory access management method for the target TEE application provided in the embodiments of this specification, when a safe memory page is in an intermediate state, accessing the safe memory page by the TEE application will trigger an exception. For example, when the TEE program accesses a safe memory page that is in a PENDING state, the hardware interrupts the execution of the TEE application and transfers the control flow to the virtual machine manager. The virtual machine manager then corrects the exception information and injects the corrected exception information into the operating system, thereby controlling the operating system to execute user-defined page fault handling logic.
[0086] As mentioned above Figure 2 The process of handling page faults in this solution involves adding safe memory pages. In addition to adding safe memory pages, the trusted virtual machine manager can also work with the operating system in REE to manage the modification and deletion of safe memory pages, as detailed below.
[0087] Figure 4 This diagram illustrates an interaction diagram of a memory access management method for a target TEE application according to yet another embodiment, such as... Figure 4 As shown, the method may include the following steps:
[0088] In step S402, the operating system sends a first update request to the virtual machine manager based on the target request of the target TEE application, which indicates the update attribute value of the second virtual page and its target attributes.
[0089] Specifically, when a target TEE application wants to modify or delete a secure memory page, it can send the aforementioned target request to the operating system in the REE. That is, the target request includes either a modification request or a deletion request. When the target request is a modification request, it can include request parameters such as the virtual page (hereinafter referred to as the second virtual machine) corresponding to the secure memory page to be modified, the target attribute to be modified, and its updated attribute value. The target attribute here includes, but is not limited to, page type or permissions. Taking page type as an example, the updated attribute value could be of type TRIM (a page type that is about to be reclaimed) or type TCS, etc.
[0090] In addition, if the target request is a delete request, it may include a second virtual page, a page type (i.e., the target attribute), and a TRIM type (i.e., update attribute value).
[0091] Since the content of the above modification request and deletion request is similar, the following explanation will refer to the modification request and deletion request collectively as the target request.
[0092] Typically, the operating system maintains necessary metadata for the secure memory region corresponding to the TEE application at the page level (this metadata is mainly used to manage the memory access behavior of the TEE application). Therefore, after receiving the above target request, the operating system will modify the metadata of the second physical page bound to the second virtual page, and at the same time, the operating system will generate a first update request and send the first update request to the virtual machine manager.
[0093] In step S404, the virtual machine manager modifies the attribute value of the target attribute in the second record corresponding to the second physical page bound to the second virtual page in the secure memory table to the updated attribute value, sets the page status bit in it to represent the intermediate state in the processing, and sets the corresponding flag bit in the target secure page table to invalid.
[0094] Specifically, after receiving the first update request, the virtual machine manager first queries the target security page table to obtain the second physical page bound to the second virtual page. Then, based on this second physical page, the virtual machine manager can determine the corresponding second record from the security memory table and modify the target attribute value in that second record to the updated attribute value.
[0095] It should be noted that since the virtual machine manager's modifications are based on information sent by the operating system (including the second virtual page and target attributes), verification is required. In other words, the current second record is untrusted and cannot be accessed. Therefore, to prevent the target TEE application from accessing the modified secure memory page (i.e., the second physical page), the virtual machine manager sets the flag corresponding to the second binding relationship (i.e., the binding relationship between the second virtual page and the second physical page) to invalid in the target secure page table. Of course, in practical applications, the page status bit in the second record can also be set to represent an intermediate state during processing.
[0096] In step S406, the target TEE application sends a second verification request to the virtual machine manager, which indicates the expected attribute value of the target attribute of the second virtual page.
[0097] After the virtual machine manager completes the modifications to the target security page table and security memory table, the control flow is transferred to the target TEE application, which then sends the aforementioned second verification request.
[0098] In addition, the expected attribute value here can refer to the modified attribute value that the target TEE application expects for the target attribute.
[0099] In step S408, the virtual machine manager verifies the updated attribute value in the second record based on the expected attribute value, and after the verification is successful, sets the page status bit in the second record to the final state indicating readiness.
[0100] In one embodiment, the above-mentioned verification of the updated attribute value in the second record includes: comparing the expected attribute value of the target attribute with the updated attribute value; if the comparison matches, the verification of the updated attribute value is passed.
[0101] Taking the target attribute as page type as an example, since the modified page type is usually a special type that TEE applications cannot access, after the above verification is passed, the flag corresponding to the second binding relationship in the target security page table is not modified, that is, the flag corresponding to the second binding relationship in the target security page table remains invalid.
[0102] It should be understood that when the target request is a delete request, the expected attribute value is of type TRIM, and therefore the updated attribute value in the second record is verified to confirm whether the type of the safe memory page to be deleted is TRIM. After confirming that the safe memory page to be deleted is of type TRIM, the above method may further include the following steps:
[0103] Based on the confirmation deletion request from the target TEE application, the operating system sends a second update request to the virtual machine manager, indicating the second virtual page. The virtual machine manager removes the second record from the secure memory table and clears the binding relationship corresponding to the second virtual page in the target secure page table.
[0104] It should be understood that after completing the verification in step S408 above, the control flow is transferred back to the target TEE application, which can then send a confirmation deletion request to the operating system. This may include the aforementioned second virtual page. The operating system then generates a second update request based on the confirmation deletion request and sends the second update request to the virtual machine manager.
[0105] In response to the second update request, the virtual machine manager queries the target security page table to obtain the second physical page bound to the second virtual page. Based on this second physical page, it determines the second record from the security memory table, checks whether the first condition is met, and clears the second record if the first condition is met.
[0106] The first condition mentioned above may include that the page type in the second record is TRIM type, and that the page status bit therein is a final state indicating readiness.
[0107] In one embodiment, if the initial memory information of each physical page in the safe memory is recorded in the safe memory table, the above-mentioned clearing of the second record can be understood as restoring the initial memory information of the second physical page.
[0108] In summary, in this scheme, when a TEE application requests to modify or delete a secure memory page, the virtual machine manager sets the page status bit of that secure memory page in the secure memory table to an intermediate state indicating processing. Simultaneously, the virtual machine manager sets the corresponding flag bit in the secure page table to invalid, preventing the TEE application from accessing the secure memory page being modified or deleted. Only after the TEE application verifies the modification of the secure memory page can the page status bit be set to the final state indicating readiness. This completes the modification of the secure memory page, or allows subsequent deletion operations to proceed.
[0109] The above describes the process of adding, modifying, and deleting secure memory pages. In practical applications, the target TEE application can also request the destruction of the corresponding target memory region, as detailed below:
[0110] Based on the target TEE application's destruction request, the operating system sends a third update request to the virtual machine manager. The virtual machine manager then removes data records from the secure memory table that are owned by the target TEE application, and deletes the target secure page table.
[0111] Specifically, when a target TEE application wants to exit execution, it can send a destruction request to the operating system, which includes the application identifier of the target TEE application. Based on this destruction request, the operating system generates a third update request and sends the third update request to the virtual machine manager.
[0112] In response to this third update request, the virtual machine manager queries the security memory table and clears the data records owned by the target TEE application. This means clearing the data records of each physical page in the corresponding target memory region, thus unbinding the target TEE application from the target memory region. Additionally, it can also delete the target security page table corresponding to the target TEE application.
[0113] In summary, the memory access management method for target TEE applications provided in the embodiments of this specification, based on general-purpose hardware and utilizing virtualization technology and an innovative secure memory table, can achieve access control of secure memory by TEE applications. Furthermore, by correcting exception information and injecting it into the operating system within the REE, the exception handling process of the operating system can be controlled.
[0114] It should be noted that this solution has at least the following advantages: First, it has good versatility, does not depend on special hardware, and can support various general-purpose hardware platforms. Second, the mechanisms for configuring the secure page table and correcting page fault information in this solution are implemented in software, offering greater flexibility compared to hardware TEE solutions. Third, compared to hardware TEE solutions, the secure page table in this solution is isolated from the ordinary page table and managed by the virtual machine manager. Therefore, the operating system in the REE cannot modify the secure page table, which fundamentally prevents most side-channel attacks based on memory access. In summary, this solution provides stronger memory isolation capabilities and a higher level of security compared to hardware TEE solutions.
[0115] Corresponding to the memory access management method for the target TEE application described above, one embodiment of this specification also provides a memory access management system for the target TEE application, such as... Figure 5 As shown, the system may include:
[0116] Virtual machine manager 502 is used to obtain the first page fault exception information generated during the execution of target TEE application 504, which indicates the first virtual page.
[0117] The virtual machine manager 502 is also configured to inject the first page fault information into the operating system 506 in the normal execution environment REE in response to the fact that the binding relationship corresponding to the first virtual page is not found in the target security page table corresponding to the target TEE application 504.
[0118] Operating system 506 is used to respond to the first page fault information, bind the first physical page to the first virtual page, and provide the corresponding first binding relationship and the first metadata of the first physical page to the virtual machine manager 502.
[0119] The virtual machine manager 502 is also used to add the first binding relationship to the target security page table and to add a first record to the security memory table used to record security memory information of each TEE application, the first record including the first physical page and the first metadata.
[0120] In one embodiment, the target secure page table further includes a flag bit for indicating whether the binding relationship is valid, and each physical page in the secure memory table has a page status bit.
[0121] The virtual machine manager 502 is specifically used to: set the flag of the first binding relationship to invalid; and set the page status bit of the first physical page to indicate an intermediate state in the processing.
[0122] In one embodiment, the virtual machine manager 502 is further configured to obtain second page fault information generated during the execution of the target TEE application 504, wherein the first virtual page is indicated;
[0123] The virtual machine manager 502 is also used to correct the second page fault information in response to finding the first binding relationship in the target security page table and the corresponding flag bit being invalid, and to inject the obtained corrected fault information into the operating system 506.
[0124] Operating system 506 is also used to respond to the correction exception information by calling the target TEE application 504 to verify the first metadata;
[0125] The virtual machine manager 502 is also configured to, upon successful verification, set the flag of the first binding relationship to valid in the target secure page table and set the page status bit of the first physical page to a final state indicating readiness in the secure memory table.
[0126] In one embodiment, the target TEE application 504 is configured to send a first verification request to the virtual machine manager 502, wherein the first description data of the first virtual page maintained by the target TEE application 504 is indicated.
[0127] The virtual machine manager 502 is also used to respond to the first verification request by comparing the first description data with the first metadata. If the comparison matches, the verification of the first metadata is successful.
[0128] In one embodiment, the virtual machine manager 502 is further configured to:
[0129] The violation access bit and user mode bit in the second page fault error message are set to valid to obtain the corrected error message.
[0130] In one embodiment, the operating system 506 is further configured to send a first update request to the virtual machine manager 502 based on the target request of the target TEE application 504, wherein the update attribute value of the second virtual page and its target attribute is indicated.
[0131] The virtual machine manager 502 is also used to modify the attribute value of the target attribute in the second record corresponding to the second physical page bound to the second virtual page in the secure memory table to the updated attribute value, set the page status bit in it to represent the intermediate state in the processing, and set the corresponding flag bit in the target secure page table to invalid.
[0132] The target TEE application 504 is used to send a second verification request to the virtual machine manager 502, which indicates the expected attribute value of the target attribute of the second virtual page;
[0133] The virtual machine manager 502 is also used to verify the updated attribute value based on the expected attribute value, and after the verification is successful, to set the page status bit in the second record to the final state indicating readiness.
[0134] In one embodiment, the virtual machine manager 502 is specifically used for:
[0135] The expected value of the target attribute is compared with the updated attribute value. If the comparison matches, the verification of the updated attribute value is successful.
[0136] In one embodiment, the target request is a modification request, and the target attribute is a page type.
[0137] In another embodiment, the target request is a deletion request, the target attribute is a page type, and the desired attribute value is of type TRIM.
[0138] Operating system 506 is also configured to send a second update request to virtual machine manager 502 based on the confirmation deletion request of target TEE application 504, wherein the second virtual page is indicated;
[0139] Virtual machine manager 502 is also used to clear the second record from the secure memory table and clear the binding relationship corresponding to the second virtual page in the target secure page table.
[0140] In one embodiment, each data record in the secure memory table includes an owner field;
[0141] Operating system 506 is also used to send a third update request to virtual machine manager 502 based on the destruction request of target TEE application 504;
[0142] The virtual machine manager 502 is also used to remove data records from the secure memory table whose owner is the target TEE application 504, and to delete the target secure page table.
[0143] The functions of each functional unit of the apparatus in the above embodiments of this specification can be implemented through the steps of the above method embodiments. Therefore, the specific working process of the apparatus provided in one embodiment of this specification will not be repeated here.
[0144] This specification provides an embodiment of a memory management system for a target TEE application that can ensure the security of secure memory while reducing the cost of using a trusted execution environment.
[0145] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform a combination Figure 2 , Figure 3 or Figure 4 The method described.
[0146] According to another embodiment, a computing device is also provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements a combination... Figure 2 , Figure 3 or Figure 4 The method described.
[0147] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device and medium embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0148] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0149] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of this specification. It should be understood that the above description is only a specific embodiment of this specification and is not intended to limit the scope of protection of this specification. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of this specification should be included within the scope of protection of this specification.
Claims
1. A memory access management method for a target TEE application, wherein the target TEE application runs in a Trusted Execution Environment (TEE) of a virtual machine; the method includes: The virtual machine manager obtains the first page fault exception information generated during the execution of the target TEE application, which indicates the first virtual page; In response to the fact that no binding relationship corresponding to the first virtual page is found in the target security page table corresponding to the target TEE application, the virtual machine manager injects the first page fault information into the operating system in the normal execution environment REE; In response to the first page fault information, the operating system binds the first physical page to the first virtual page and provides the corresponding first binding relationship and the first metadata of the first physical page to the virtual machine manager. The virtual machine manager adds the first binding relationship to the target security page table, and adds a first record to the security memory table used to record security memory information of each TEE application. The first record includes the first physical page and the first metadata.
2. The method according to claim 1, wherein, The target secure page table also includes a flag bit for indicating whether the binding relationship is valid, and each physical page in the secure memory table has a page status bit.
3. The method according to claim 2, wherein, Adding the first binding relationship to the target security page table includes: setting the flag of the first binding relationship to invalid; Adding the first record includes setting the page status bit of the first physical page to represent an intermediate state in the processing.
4. The method according to claim 3, further comprising, after adding the first record: The virtual machine manager obtains the second page fault information generated during the execution of the target TEE application, wherein the first virtual page is indicated; In response to finding the first binding relationship in the target security page table and the corresponding flag being invalid, the virtual machine manager corrects the second page fault information and injects the corrected fault information into the operating system; In response to the corrected anomaly information, the operating system invokes the target TEE application to verify the first metadata. If the verification is successful, the virtual machine manager sets the flag of the first binding relationship to valid in the target secure page table and sets the page status bit of the first physical page to a final state indicating readiness in the secure memory table.
5. The method according to claim 4, wherein, The verification of the first metadata includes: The target TEE application sends a first verification request to the virtual machine manager, which indicates the first description data of the first virtual page maintained by the target TEE application; In response to the first verification request, the virtual machine manager compares the first description data with the first metadata. If the comparison matches, the verification of the first metadata is successful.
6. The method according to claim 4, wherein, The correction of the second page fault information includes: The illegal access bit and user mode bit in the second page fault error information are set to valid to obtain the corrected error information.
7. The method according to claim 1, wherein, The first metadata includes at least one of the following: virtual address, page type, and permissions.
8. The method according to claim 2, further comprising: The operating system sends a first update request to the virtual machine manager based on the target request of the target TEE application, wherein the update attribute value of the second virtual page and its target attribute is indicated. The virtual machine manager modifies the attribute value of the target attribute in the second record corresponding to the second physical page bound to the second virtual page in the secure memory table to the updated attribute value, and sets the page status bit in it to represent an intermediate state in the processing; and sets the corresponding flag bit to invalid in the target secure page table. The target TEE application sends a second verification request to the virtual machine manager, indicating the expected attribute value of the target attribute of the second virtual page; The virtual machine manager verifies the updated attribute value based on the expected attribute value, and after the verification is successful, sets the page status bit in the second record to the final state indicating readiness.
9. The method according to claim 8, wherein, The verification of the updated attribute value includes: The expected attribute value of the target attribute is compared with the updated attribute value. If the comparison is consistent, the verification of the updated attribute value is successful.
10. The method according to claim 8, wherein, The target request is a modification request, and the target attribute is the page type.
11. The method according to claim 8, wherein, The target request is a delete request, the target attribute is a page type, and the expected attribute value is of type TRIM; the method further includes: The operating system sends a second update request to the virtual machine manager based on the confirmation deletion request of the target TEE application, wherein the second virtual page is indicated; The virtual machine manager removes the second record from the secure memory table and clears the binding relationship corresponding to the second virtual page in the target secure page table.
12. The method according to claim 1, wherein, Each data record in the secure memory table includes an owner field; the method further includes: The operating system sends a third update request to the virtual machine manager based on the destruction request of the target TEE application; The virtual machine manager removes data records from the secure memory table whose owner is the target TEE application, and deletes the target secure page table.
13. A memory access management system for a target TEE application, wherein the target TEE application runs in a Trusted Execution Environment (TEE) of a virtual machine; the system comprises: The virtual machine manager is used to obtain the first page fault information generated during the execution of the target TEE application, wherein the first virtual page is indicated. The virtual machine manager is also configured to inject the first page fault information into the operating system in the normal execution environment REE in response to the fact that no binding relationship corresponding to the first virtual page is found in the target security page table corresponding to the target TEE application; The operating system is configured to, in response to the first page fault information, bind the first physical page to the first virtual page, and provide the corresponding first binding relationship and the first metadata of the first physical page to the virtual machine manager; The virtual machine manager is further configured to add the first binding relationship to the target security page table, and add a first record to the security memory table used to record security memory information of each TEE application, the first record including the first physical page and the first metadata.
14. The system according to claim 13, wherein, The target secure page table also includes a flag bit for indicating whether the binding relationship is valid, and each physical page in the secure memory table has a page status bit.
15. The system according to claim 14, wherein, The virtual machine manager is specifically used to: set the flag of the first binding relationship to invalid; and set the page status bit of the first physical page to represent an intermediate state in the processing.
16. The system according to claim 15, wherein, The virtual machine manager is also used to obtain second page fault information generated during the execution of the target TEE application, wherein the first virtual page is indicated; The virtual machine manager is also configured to, in response to finding the first binding relationship in the target security page table and the corresponding flag bit being invalid, correct the second page fault exception information and inject the obtained corrected exception information into the operating system; The operating system is also configured to, in response to the corrected anomaly information, invoke the target TEE application to verify the first metadata; The virtual machine manager is further configured to, upon successful verification, set the flag of the first binding relationship to valid in the target secure page table and set the page status bit of the first physical page to a final state indicating readiness in the secure memory table.
17. The system according to claim 16, wherein, The target TEE application is used to send a first verification request to the virtual machine manager, wherein the first description data of the first virtual page maintained by the target TEE application is indicated. The virtual machine manager is further configured to, in response to the first verification request, compare the first description data with the first metadata; if the comparison is consistent, the verification of the first metadata is successful.
18. The system according to claim 16, wherein, The virtual machine manager is also specifically used for: The illegal access bit and user mode bit in the second page fault error information are set to valid to obtain the corrected error information.
19. The system according to claim 14, wherein, The operating system is further configured to send a first update request to the virtual machine manager based on the target request of the target TEE application, wherein the update attribute value of the second virtual page and its target attribute is indicated; The virtual machine manager is further configured to modify the attribute value of the target attribute in the second record corresponding to the second physical page bound to the second virtual page in the secure memory table to the updated attribute value, and set the page status bit therein to represent the intermediate state in the processing; and set the corresponding flag bit in the target secure page table to invalid. The target TEE application is used to send a second verification request to the virtual machine manager, wherein the expected attribute value of the target attribute of the second virtual page is indicated. The virtual machine manager is further configured to verify the updated attribute value based on the expected attribute value, and after the verification is successful, set the page status bit in the second record to the final state indicating readiness.
20. The system according to claim 19, wherein, The virtual machine manager is specifically used for: The expected attribute value of the target attribute is compared with the updated attribute value. If the comparison is consistent, the verification of the updated attribute value is successful.
21. The system according to claim 19, wherein, The target request is a modification request, and the target attribute is the page type.
22. The system according to claim 19, wherein, The target request is a deletion request, the target attribute is a page type, and the expected attribute value is of type TRIM. The operating system is further configured to send a second update request to the virtual machine manager based on the confirmation deletion request of the target TEE application, wherein the second virtual page is indicated; The virtual machine manager is also configured to clear the second record from the secure memory table and clear the binding relationship corresponding to the second virtual page in the target secure page table.
23. The system according to claim 13, wherein, Each data record in the secure memory table includes an owner field; The operating system is also configured to send a third update request to the virtual machine manager based on the destruction request of the target TEE application; The virtual machine manager is also used to remove data records owned by the target TEE application from the secure memory table, and to delete the target secure page table.
24. A computer-readable storage medium having a computer program stored thereon, wherein, When the computer program is executed in the computer, it causes the computer to perform the method according to any one of claims 1-12.
25. A computing device comprising a memory and a processor, wherein, The memory stores executable code, and when the processor executes the executable code, it implements the method of any one of claims 1-12.
Citation Information
Patent Citations
Page table management method and device for safely isolating virtual machine and related equipment
CN114201752A
Testing storage protection hardware in a secure virtual machine environment
US20200285493A1
