Method for switching execution environment and related device thereof
AssigneeHuawei Technologies Co., Ltd.
InventorsYingjun Zhang, Ji Wang, Yingliang Yao
Life of this patent
Estimating the term…
Abstract
The present disclosure discloses a method for switching an execution environment and a related device thereof, to effectively prevent a hacker from maliciously accessing a TEE through ATF. The method in the present disclosure includes: After writing a first virtual address into a return address register of the TEE, the ATF determines whether the first virtual address is within a valid address range, and switches to the TEE based on the first virtual address only when determining that the first virtual address is within the valid address range.
Claims12
A method for switching an execution environment, comprising:
- receiving, by ARM trusted firmware (ATF), a switching request from a rich execution environment (REE);
- writing, by the ATF, a first virtual address into a return address register of a trusted execution environment (TEE) based on the switching request;
- writing, by the ATF, a base address of a page table of the TEE into a page table base address register of the TEE;
- reading, by the ATF, the first virtual address from the return address register of the TEE when the ATF determines that the first virtual address in the return address register of the TEE is within a valid address range;
- reading, by the ATF, the base address of the page table of the TEE from the page table base address register of the TEE, and obtaining a page table directory of the TEE based on the base address of the page table of the TEE, the page table directory recording a one-to-one correspondence between a plurality of virtual addresses of the TEE and physical addresses of a plurality of page table entries of the TEE;
- determining, by the ATF in the page table directory of the TEE, a physical address of a first page table entry corresponding to the first virtual address, wherein the first virtual address is one of the plurality of virtual addresses of the TEE;
- obtaining, by the ATF, the first page table entry based on the physical address of the first page table entry, and determining the physical address recorded in the first page table entry;
- and
- switching, by the ATF, to the TEE based on the physical address recorded in the first page table entry.
An apparatus for switching an execution environment, comprising a rich execution environment (REE), ARM trusted firmware (ATF), and a trusted execution environment (TEE), wherein the ATF is configured to:
- receive a switching request from the REE;
- write a first virtual address into a return address register of the TEE based on the switching request;
- write a base address of a page table of the TEE into a page table base address register of the TEE;
- read the first virtual address from the return address register of the TEE when the ATF determines that the first virtual address in the return address register of the TEE is within a valid address range;
- read the base address of the page table of the TEE from the page table base address register of the TEE, and obtain a page table directory of the TEE based on the base address of the page table of the TEE, wherein the page table directory of the TEE records a one-to-one correspondence between a plurality of virtual addresses of the TEE and physical addresses of a plurality of page table entries of the TEE;
- determine, in the page table directory of the TEE, a physical address of a first page table entry corresponding to the first virtual address, wherein the first virtual address is one of the plurality of virtual addresses of the TEE;
- obtain the first page table entry based on the physical address of the first page table entry, and determine the physical address recorded in the first page table entry;
- and
- switch to the TEE based on the physical address recorded in the first page table entry.
Dependencies are inferred from the claim text.