Memory management
The implementation of a guard control stack data structure with translation hardening mechanisms and restricted access controls in data processing systems addresses ROP attacks by securing return status information, enhancing system security and preventing unauthorized access.
Patent Information
- Application Number
- CN202380036310.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2022-04-28
- Filing Date
- 2023-03-17
- Publication Date
- 2024-12-06
AI Technical Summary
Existing data processing systems are vulnerable to attacks based on return-oriented programming (ROP) that manipulate return status information stored in memory, as attackers can tamper with stage 1 translation table entries to bypass protection mechanisms.
Implement a guard control stack (GCS) data structure protected by a translation hardening mechanism, which restricts write access to certain instructions and uses hardened stage 1 translation table entries defined by a more privileged execution state, and enforces anti-aliasing properties to prevent unauthorized access.
Enhances security by preventing unauthorized modification of return status information, reducing the attack surface and effectively thwarting ROP attacks through stringent access controls and hardened translation table entries.
Smart Images

Figure CN119096231A_ABST
Abstract
Description
[0001] The present technology relates to the field of data processing.
[0002] In a data processing apparatus, memory management circuitry is provided to control access to a memory system. The memory management circuitry is responsible for performing address translation to convert a target virtual address specified based on an operand of an instruction executed by the processing circuitry into a target physical address identifying a memory system location to be accessed. The memory management circuitry may also implement access permissions, for example based on information specified in a translation table structure that specifies a mapping from a target virtual address to a target physical address.
[0003] At least some examples provide an apparatus comprising: a processing circuit for executing instructions in one of a plurality of execution states; and a memory management circuit for, in response to a memory access request specifying a target virtual address corresponding to a target memory region to be accessed, translating the target virtual address into a target physical address, wherein a mapping from the target virtual address to the target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure, the stage 1 translation table structure being accessible using a stage 1 base address that can be set by an instruction executed by the processing circuit in a first execution state; wherein: at least when the memory access request is a write request, the memory management circuit is configured to deny the memory access request in response to determining that the following two conditions are satisfied: the stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is a guard control stack (GCS) data structure for storing a GCS data structure, the GCS data structure being used to protect return status information returned from a function call or an exception; and the The memory access request is a request other than a GCS memory access request triggered by one of a restricted subset of instructions of a GCS access type; the memory management circuitry is configured to support a translation hardening mechanism, the translation hardening mechanism being used to define at least one hardened stage 1 translation table entry based at least on translation hardening information that can be set by an instruction executed by the processing circuitry in a second execution state having a higher privilege than the first execution state, the at least one hardened stage 1 translation table entry being protected by the translation hardening mechanism from being tampered with by the instruction executed in the first execution state; when the anti-aliasing property is specified for the target memory region, the memory management circuitry is configured to deny the memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism; and in at least one operating state of the processing circuitry, the memory management circuitry is configured to deny the memory access request in response to determining that the memory access request is the GCS memory access request and that the anti-aliasing property is not specified for the target memory region.
[0004] At least some examples provide a method comprising: executing an instruction in one of a plurality of execution states; and responsive to a memory access request specifying a target virtual address corresponding to a target memory region to be accessed, converting the target virtual address to a target physical address, wherein a mapping from the target virtual address to the target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure, the stage 1 translation table structure being accessible using a stage 1 base address set by an instruction that can be executed by the processing circuit in a first execution state; wherein: at least when the memory access request is a write request, denying the memory access request in response to determining that the following two conditions are satisfied: the stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is a GCS region for storing a guard control stack (GCS) data structure, the GCS data structure being used to protect return status information returned from a function call or an exception; and the memory access request is denied. The memory access request is a request other than a GCS memory access request triggered by one of a restricted subset of instructions of a GCS access type; a translation hardening mechanism is supported for defining at least one hardened stage 1 translation table entry based at least on translation hardening information that can be set by instructions executed in a second execution state having a higher privilege than the first execution state, and the at least one hardened stage 1 translation table entry is protected by the translation hardening mechanism from being tampered with by instructions executed in the first execution state; and the method includes: when anti-aliasing properties are specified for the target memory region, rejecting the memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism; and in at least one operating state of the processing circuit, rejecting the memory access request in response to determining that the memory access request is the GCS memory access request and the anti-aliasing property is not specified for the target memory region.
[0005] At least some examples provide a computer program comprising instructions that, when executed by a host data processing device, control the host data processing device to provide an instruction execution environment for executing a target code, the computer program comprising: a handler logic for simulating instructions for executing the target code in one of a plurality of execution states; and a memory manager logic for, in response to a memory access request specifying a target virtual address corresponding to a target memory region to be accessed, translating the target virtual address into a simulated target physical address, wherein a mapping from the target virtual address to the simulated target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure, the stage 1 translation table structure being accessible using a stage 1 base address that can be set by the instruction simulated to be executed in a first execution state; wherein: at least when the memory access request is a write request, the memory manager logic is configured to deny the memory access request in response to determining that the following two conditions are satisfied: the stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is for storing a guard control stack (GCS) data structure; a GCS region, the GCS data structure being used to protect return status information returned from a function call or an exception; and the memory access request being a request other than a GCS memory access request triggered by one of a restricted subset of instructions of a GCS access type; the memory manager logic being configured to support a translation hardening mechanism, the translation hardening mechanism being used to define at least one hardened stage 1 translation table entry based at least on translation hardening information that can be set by an instruction simulated to be executed in a second execution state having a higher privilege than the first execution state, the at least one hardened stage 1 translation table entry being protected by the translation hardening mechanism from being simulated as instruction tampering executed in the first execution state; when the anti-aliasing property is specified for the target memory region, the memory management program logic is configured to reject the memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism; and in at least one operating state of the processing circuit, the memory management circuit is configured to reject the memory access request in response to determining that the memory access request is the GCS memory access request and the anti-aliasing property is not specified for the target memory region.
[0006] The computer program may be stored on a computer readable storage medium. The storage medium may be a non-transitory storage medium.
[0007] Additional aspects, features, and advantages of the present technology will be apparent from the following description of examples read in conjunction with the accompanying drawings, in which:
[0008] Figure 1 An example of a data processing apparatus having processing circuitry and memory management circuitry is shown;
[0009] Figure 2 An example of an execution state of a processing circuit is shown;
[0010] Figure 3 A two-stage address translation is shown;
[0011] Figure 4 and Figure 5 Examples of translation table traversals for stage 1 and stage 2 address translations are shown, respectively;
[0012] Figure 6 shows the table lookups performed for a full translation table traversal for both stage 1 and stage 2 translations when considering that each table base address and final intermediate address determined in stage 1 will be translated into a physical address using a corresponding stage 2 translation;
[0013] Figure 7 An example of a memory management circuit and control registers for controlling memory management is shown;
[0014] Figure 8 shows examples of translation table entries for stage 1 and stage 2 address translation;
[0015] Fig. 9 shows the types of write requests that are allowed and prohibited to write to a portion of the read-only memory region defined by a stage 2 translation table entry;
[0016] Fig.10 A method for performing address translation and permission checking is shown;
[0017] Fig.11 is a flow chart illustrating a check based on partial read-only permission;
[0018] Fig.12 , Fig.13 and Fig.14 The processing of different variants of a read-check-write instruction of a protected entry check type is shown;
[0019] Fig.15 Aliasing of virtual addresses onto the same intermediate address is shown;
[0020] Fig.16 Anti-aliasing check is shown;
[0021] Fig.17 shows the stage 1 top-level table existence check and the stage 1 top-level portion read-only check;
[0022] Fig.18 shows permission information indirectly specified by a translation table entry;
[0023] Fig.19 An example of a function call and return is shown;
[0024] Fig. 20 shows registers used to control access to a guard control stack (GCS) data structure;
[0025] Fig.21 shows the use of a GCS data structure for protecting return status information returned from a function call or exception;
[0026] Fig. 22 is a flow chart showing the processing of a return status push instruction;
[0027] Fig.23 is a flow chart showing the processing of a return status pop-up instruction;
[0028] Fig.24 shows an access permission check performed by the memory management circuitry for a memory access request issued when the GCS mode is enabled; and
[0029] Fig.25 A specific implementation of a simulator that can be used is shown.
[0030] An apparatus has: processing circuitry for executing instructions in one of a plurality of execution states; and memory management circuitry for translating a target virtual address corresponding to a target memory region to be accessed into a target physical address in response to a memory access request specifying the target virtual address. A mapping from the target virtual address to the target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure. The stage 1 translation table structure is accessible using a stage 1 base address set by an instruction executable by the processing circuitry in a first execution state.
[0031] Attacks based on return-oriented programming (ROP) are common categories of attacks on data processing systems. ROP attacks attempt to make a program behave in an unexpected manner by destroying the return status information for returning from a function call or an exception. Typically, software will save the return status information in a memory, such as to facilitate the nesting of function calls or exceptions, wherein the return status information for an external function call or exception (in a nested function call or exception set) is saved in a memory, so that the return status information can be overwritten in a register using the return status information for an internal function call or an exception before saving the return status information. When the return status information is stored in a memory, a ROP attack can attempt to tamper with the return status information, and then restore the return status information to a register and use it to control function returns or exception returns. A successful ROP attack can cause a function return or an exception return to return the program flow to an instruction other than the next instruction after a function is called or an exception occurs, which can allow an attacker to control the processing circuit to perform any operation other than the sequence of operations expected by the programmer.
[0032] To prevent ROP-based attacks, it may be useful to provide a guard control stack (GCS) data structure for protecting return status information returned from a function call or an exception. The stage 1 translation table entry specifies whether the memory region corresponding to a given virtual address is a GCS region for storing a GCS data structure. In response to a memory access request specifying a target virtual address, at least when the memory access request is a write request, the memory management circuit denies the memory access request in response to determining that the following two conditions are met:
[0033] The stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is a guard control stack (GCS) region for storing a GCS data structure that is used to protect return status information returned from a function call or an exception;
[0034] as well as
[0035] - The memory access request is other than a GCS memory access request triggered by one of a restricted subset of instructions of GCS access type.
[0036] Therefore, the area of memory can be designated as a GCS area for protecting the return status information for function calls or exceptions by the corresponding stage 1 translation table entry. The information stored in the area can be used to verify whether the return status information is appropriate before continuing the function return or exception return. If the write to the area designated as the GCS area is made in response to an instruction other than a restricted subset of instructions of the GCS access type, the write is rejected. By limiting the write access to the GCS area to certain instruction types, this reduces the attack surface available to attackers who attempt to destroy the return status information, because write requests triggered by other types of memory access instructions included in the executed program code (if tricked into accessing the GCS area after modifying its address operand) will not be used to successfully update the information stored in the GCS area. It is not necessary to apply this restriction to read requests, because read requests cannot update the protected return status stored in the GCS area, but optionally, some specific implementations can also choose to signal a fault when the target memory area for the read request is designated as a GCS area by the stage 1 permission information and the read request is not triggered by one of the restricted subsets of the GCS access type instructions.
[0037] However, because the stage 1 translation table entries are used to specify the GCS region, and the stage 1 translation table structure is accessed via a base address register that can be controlled by instructions executed in a first execution state (e.g., this can be a state in which an operating system is executed), if an attacker is able to compromise the operating system or other software executing in the first execution state, they may be able to modify the stage 1 translation table entries corresponding to the GCS region such that the memory region is no longer designated as a GCS region, and / or create aliased stage 1 translation table entries that map different virtual addresses to translated addresses of the GCS region without designating the corresponding memory region as a GCS region, in an attempt to circumvent the protection provided by the stage 1 translation table entries that specify the GCS region.
[0038] In an example discussed below, memory management circuitry supports a translation hardening mechanism for defining at least one hardened stage 1 translation table entry based at least on translation hardening information that can be set by instructions executed by processing circuitry in a second execution state having higher privileges than a first execution state, the at least one hardened stage 1 translation table entry being protected by the translation hardening mechanism from being tampered with by instructions executed in the first execution state. When anti-aliasing properties are specified for a target memory region, the memory management circuitry denies a memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism. In at least one operating state of the processing circuitry, the memory management circuitry denies the memory access request in response to determining that the memory access request is a GCS memory access request and that anti-aliasing properties are not specified for the target memory region.
[0039] Therefore, the following combination of measures was implemented:
[0040] - Writes to GCS regions (indicated using stage 1 permission information) are restricted to being performed using instructions of certain specified GCS access types;
[0041] - a stage 1 translation table entry may be specified to be hardened based on information that may be set by an instruction executed in a more privileged execution state than a first execution state that is capable of controlling a base address of a stage 1 translation table structure;
[0042] - memory regions designated as having anti-aliasing properties are not accessible based on unhardened stage 1 translation table entries; and
[0043] - If the anti-aliasing properties have not been set for the target memory region, the GCS memory access request is rejected.
[0044] This combination of measures allows for a more secure protection of the GCS data structures from tampering, since this enforces the requirement that the anti-aliasing property be applied to any GCS memory region (otherwise a GCS memory access request will not succeed), while the anti-aliasing property is enforced when the anti-aliasing property is defined for a GCS region, no unhardened translation table entries (which may be susceptible to modification by an attacker, or may be aliased translation table entries that an attacker has defined to circumvent hardened translation table entries) may be used to enable access to the GCS region. Thus, this approach provides a stronger protection against attacks based on return-oriented programming.
[0045] GCS memory access requests may include read requests and write requests. GCS read requests may be triggered by one or more types of GCS access load instructions, and GCS write requests may be triggered by one or more types of GCS access store instructions that trigger write requests. As described above, in at least one operating state, GCS memory access requests are subject to the following requirement: if anti-aliasing properties are not specified for the target memory area, a fault is signaled. Regardless of whether the GCS memory access request is a read request or a write request, the fault may be signaled. Therefore, if anti-aliasing properties are not specified for the target memory area, both GCS access load instructions and GCS access store instructions may trigger checks for anti-aliasing properties and faults (even if a read request to a GCS area of memory would not trigger a fault if caused by an instruction other than an instruction of the GCS access type).
[0046] The memory management circuitry may support two-stage address translation, wherein a stage 1 address mapping includes a mapping from a target virtual address to a target intermediate address, and the address mapping from the target virtual address to the target physical address is further dependent on a stage 2 address mapping from the target intermediate address to the target physical address specified by a target stage 2 translation table entry in a stage 2 translation table structure for the target intermediate address. The stage 2 translation table structure may be accessed using a stage 2 base address set by instructions executable by the processing circuitry in a second execution state. The two-stage address translation may be used to support virtualization, wherein multiple guest operating systems may coexist on the same hardware platform. The second execution state may be an execution state for executing a hypervisor for controlling virtualization of the guest operating systems.
[0047] The anti-aliasing properties may be set by instructions executed in the second execution state.The anti-aliasing properties may be specified for a target memory region in a data structure maintained by software executing in the second execution state, the data structure being separate from the stage 2 translation table structure.
[0048] However, since the stage 2 translation table structure may in any case be managed by software executing in the second execution state, it may be most efficient for the target stage 2 translation table entry to specify whether anti-aliasing properties are specified for the target memory region.
[0049] Similarly, while the translation hardening information may include information defined by software executing in the second execution state using a data structure separate from the stage 2 translation table structure, it may be more efficient to reuse the stage 2 translation table structure to define permission information including the translation hardening information. Thus, for a given stage 1 translation table entry stored at a given memory region corresponding to a given intermediate address, the translation hardening information for specifying whether the given stage 1 translation table entry is a hardened stage 1 translation table entry includes the stage 2 permission information specified by the corresponding stage 2 translation table entry corresponding to the given intermediate address.
[0050] It is not necessary to provide any architectural mechanism for implementing software that has set appropriate access permissions or address mappings to ensure that stage 2 translation table entries are protected from being updated by software executed in the first execution state or a less privileged state. The hypervisor software responsible for the stage 2 translation table structures executed in the second execution state typically takes measures to protect those structures from being modified by operating system software or other software executed in the first execution state (or an execution state that is less privileged than the first execution state). For example, the hypervisor can achieve this by assigning entries of the stage 2 translation table structures to memory areas corresponding to physical addresses that are not mapped to any intermediate physical addresses in the stage 2 translation table structures used by software executed in the first execution state (or a less privileged state), so that software in the first execution state cannot access those areas (alternatively, read-only permissions can be used to protect the stage 2 translation table structures). The responsibility for defining appropriate translation table mappings and / or perhaps ensuring that memory areas storing stage 2 translation table structures are protected from being accessed by software executed in the first execution state may lie with the software executed in the second execution state that controls the stage 2 translation table structures. Thus, while it may be preferred that, when the device is in use, the hypervisor (or other software executing in the second execution state) configure the stage 2 translation table structures with address mappings and access permissions appropriate to the needs of the software itself, such that anti-aliasing properties and translation hardening information specified using stage 2 translation table entries may be restricted to being set by instructions executed in the second execution state (or more privileged execution state), and may not be set by instructions executed in the first execution state (or less privileged execution state), the hardware architecture of the device need not provide any special architectural measures to implement that those mappings / access permissions have actually been set to protect the stage 2 translation table structures from modification by software executing in the first execution state or less privileged execution state. For example, no architecturally defined checks are required to verify that the stage 2 translation table entries used to define anti-aliasing properties (or translation hardening information) themselves have been protected from tampering. It can be assumed that the hypervisor software will set the appropriate stage 2 address mappings / permissions to protect its own operation.
[0051] The conversion hardening mechanism can be implemented in different ways. In general, the conversion hardening mechanism can be any architectural mechanism that allows certain hardened stage 1 conversion table entries to be provided with stronger anti-tamper protection than unprotected stage 1 conversion table entries. For example, a stage 1 conversion table entry can be provided with a specific encoding that marks the entry as hardened, and the processing circuit or memory management circuit can check whether the data to be written has the hardened encoding of the stage 1 conversion table entry on a write to the memory, in which case the write can be suppressed. However, in practice, implementing such a check on every write to the memory (including writes to memory areas that do not store conversion table entries) can be extremely performance intensive and consume a lot of power.
[0052] A more efficient mechanism for the translation hardening mechanism may be to use a stage 2 translation table entry to specify stage 2 permission information, the stage 2 translation table entry being used to provide a stage 2 address mapping for a region storing a hardened stage 1 translation table entry, wherein the stage 2 permission information has at least one encoding indicating a permission type that limits the ability of data in the corresponding region to be modified. For example, the permission type may be a read-only permission indicating that write requests are prohibited and / or a partial read-only permission type indicating that write requests are only allowed for a restricted subset of write request types.
[0053] For example, each hardened stage 1 translation table entry may include a stage 1 translation table entry for which a given memory region storing the stage 1 translation table entry is indicated by the stage 2 permission information of the corresponding stage 2 translation table entry as one of:
[0054] prohibiting writes to the requested read-only memory region; and
[0055] a partial read-only memory region for which write requests to the partial read-only memory region are allowed for a restricted subset of write request types, and
[0056] Write request types other than the restricted subset are prohibited, the restricted subset of write request types including at least metadata update write requests generated by the memory management circuitry to update access tracking metadata in the translation table entries.
[0057] Some implementations may only support a read-only option for hardened stage 1 translation table entries. This may simplify the implementation, since read-only permission may already be supported in stage 2, and implementing read-only permission may require less complex control logic.
[0058] Other specific implementations may choose to support partial read-only permissions, which may be useful because full read-only permissions prevent access tracking metadata in the translation table entries from being updated by the memory management circuitry. Such metadata update write requests can be used to enable tracking of access frequencies to corresponding memory regions, which can be used, for example, for software (such as an operating system) to make decisions about which memory regions should be paged out to external storage devices and which memory regions should be retained in faster access on-chip memory. Since the access tracking metadata may not affect the permissions that define which memory accesses are allowed to the corresponding address region, these access tracking metadata can be safely updated even if write access to other parts of the stage 1 translation table entries is not allowed. Therefore, by supporting partial read-only permissions, this can provide software developers with a better balance between security and ease of programming.
[0059] In some implementations, the only type of permission allowed at stage 2 for hardened stage 1 translation table entries can be partial read-only permissions.
[0060] However, in other specific implementations, a given stage 1 translation table entry may be considered a hardened stage 1 translation table entry if read-only permissions or partial read-only permissions are defined in the stage 2 permissions information of the corresponding stage 2 translation table entry, which defines the stage 2 address mapping of the memory region for storing the given stage 1 translation table entry. Therefore, it may be useful that the stage 2 permissions information has encodings for indicating both read-only memory regions and partial read-only memory regions, and both encodings allow the corresponding stage 1 translation table entry (stored in the memory region to which the stage 2 permissions information applies) to be considered hardened. This gives the programmer of the hypervisor or other software executing in the second execution state the option of selecting whether read-only permissions or partial read-only permissions are preferred for preventing tampering with the corresponding stage 1 translation table entry.
[0061] Setting the stage 2 permissions to read-only or partially read-only can be used to harden the stage 1 translation table entries stored in the corresponding memory area, but in practice, the stage 2 permissions are set at the granularity of the page and a single page can store many stage 1 translation table entries. It may not be necessary to protect all stage 1 translation table entries stored in a given page from tampering by a damaged operating system or other software executed in the first execution state. However, once any stage 1 translation table entry stored in a given page needs to be hardened, the read-only or partially read-only stage 2 permissions set for the page can cause a write request (or at least in the case of a partial read-only permission, a write request other than a restricted subset of the write request) to fail, thereby causing an exception handler to be executed. This may not be a problem, because even if it is still desired to allow the operating system to update the stage 1 translation table entries associated with non-sensitive information, although the corresponding memory area is set to have a read-only or partially read-only permission in the stage 2 access permissions to protect other entries in the area from tampering, then one method may be to capture each update to a hypervisor that can decide whether the update is allowed. However, such update requests may be relatively frequent, and therefore capturing each legitimate translation table entry update to the hypervisor may result in performance loss.
[0062] Such capture to the hypervisor may be avoided in one implementation that:
[0063] - Support for defining partial read-only permissions in stage 2 permission information, as described above;
[0064] - providing each stage 1 translation table entry with an encoding specifying whether the stage 1 translation table entry is a protected entry whose updates are restricted compared to unprotected stage 1 translation table entries that are not designated as protected entries, and
[0065] -Support for a write request type that is included as one of a restricted subset of write request types that allow writing to a partially read-only region of memory, the write request type being allowed to update at least a subset of bits of unprotected stage 1 translation table entries but being prohibited from updating protected stage 1 translation table entries.
[0066] Using this method, a memory region marked with partial read-only permissions using stage 2 permission information can contain a mixture of protected entries and unprotected entries, so that the hardware of the memory management circuit can prevent at least a subset of bits protected within the protected stage 1 translation table entries from being updated, while the unprotected entries can still be updated by software even if they are stored in the partial read-only region. This avoids the need to capture every update of the unprotected entries to the hypervisor, thereby improving performance.
[0067] For example, a restricted subset of write request types (permitted to update unprotected stage 1 translation table entries stored in a partially read-only area of memory) may include a write request issued in response to a read check write instruction of a protected entry check type. The apparatus may have a protected entry check circuit for, in response to the processing circuit executing a read check write instruction of a protected entry check type for requesting an update to a given memory system location: reading data from the given memory system location, checking whether the data read from the given memory system location has a value consistent with a stage 1 translation table entry designated as a protected entry, and in response to determining that the data read from the given memory system location has a value consistent with the stage 1 translation table entry designated as a protected entry, preventing an update restricted bit subset of the stage 1 translation table entry from being updated in response to the read check write instruction. The update restricted bit subset may be all bits of the stage 1 translation table entry, or may be a suitable bit subset (less than all bits) of the stage 1 translation table entry. The update restricted bit subset may be defined as a fixed bit subset of the stage 1 translation table entries, or as a programmably defined bit subset of the stage 1 translation table entries that is protected (e.g., using control information stored in a control register indicating which bits are the programmably defined bit subset). By defining a special type of write request triggered by a particular type of read-check-write instruction that is allowed to update unprotected entries (and optionally, unprotected bits of protected entries) in a partially read-only region of memory (whereas other types of write requests triggered by other load / store operations may not be considered to be one of the restricted subset of write request types that are allowed to update data stored in a partially read-only region), this may avoid the need to trigger an exception on every write to a partially read-only region of memory to trap a hypervisor (for checking whether the data to be updated for a given write request is a protected entry).
[0068] In a specific implementation that supports defining stage 1 translation table entries as protected, information indicating whether a given stage 1 translation table entry is designated as a protected entry may also be considered as part of the translation hardening information. When the stage 2 permission information specified by the corresponding stage 2 translation table entry specifies that a given memory region is a partial read-only memory region, the memory management circuitry may treat an unprotected stage 1 translation table entry as an unhardened stage 1 translation table entry (unprotected entries stored in a read-only memory region may still be considered hardened). Thus, each hardened stage 1 translation table entry may include one of the following: a stage 1 translation table entry for which the given memory region is indicated by the stage 2 permission information as a read-only memory region to which write requests are prohibited; and a stage 1 translation table entry designated as a protected entry for which the given memory region is indicated by the stage 2 permission information as a partial read-only memory region. Unprotected stage 1 translation table entries may be modified in any manner by software operating in the first execution state performing read-check-write instructions of the protected entry check type, and it is therefore safest to treat them as unhardened even if they are stored in a portion of the read-only memory area defined by the stage 2 permission information. If the unprotected entries are stored in the read-only memory area, then these unprotected entries will not be modifiable, so there is no need to impose the requirement that the entries stored in the read-only memory area be protected entries.
[0069] It should be understood that designating translation table entries as protected or unprotected is not a required feature, and some implementations may not support this. For example, an implementation that is restricted to hardening stage 1 translation table entries with stage 2 read-only permissions (rather than partial read-only permissions) may not need to support protected entry encoding, and even if partial read-only permissions are supported, an implementation that does not support protected / unprotected stage 1 translation table entry encoding may only assign translation table entries intended to be hardened to specific pages marked with partial read-only permissions at stage 2, or may trap all writes to the corresponding region to the hypervisor, which may then determine whether to allow an update requested by the operating system in the first execution state based on whether the data being updated is a stage 1 translation table entry intended to be hardened against tampering.
[0070] The above-described conversion hardening mechanisms and anti-aliasing properties may be general architectural mechanisms that are not specific to protecting conversion entries for accessing GCS data structures, but may also be used to protect other stage 1 conversion table entries for other data structures from tampering and aliasing, which provide sensitive information that is desired to be protected from tampering by a compromised operating system. An alternative approach would be to define in the stage 2 permission information a dedicated encoding that identifies the corresponding memory area as a GCS memory area reserved for providing a protection control stack structure. In this alternative approach, the GCS stage 2 permission would be applied to the memory area that actually stores the GCS data structure, in contrast to the above-described conversion hardening information (e.g., read-only or partially read-only permission) that would be applied in stage 2 (by software when the device is in use) to the memory area that stores the stage 1 conversion table entries that grant access to the GCS data structure. However, a disadvantage of defining a dedicated GCS permission at stage 2 is that the amount of coding space available for defining permission information for a given stage 2 conversion table entry is limited, and therefore defining a dedicated GCS permission may waste valuable coding space that may be more useful for other purposes. To protect the GCS structures, by reusing the common architectural mechanisms for hardening stage 1 address translations to prevent general tampering, but rejecting GCS memory access requests where anti-aliasing properties have not been specified for the target memory region (to prevent GCS access where there is a risk that the translation hardening mechanisms have not been applied), this can avoid the need to consume encoding space in the stage 2 translation table entries for dedicated protection of the guard control stack data structure used to protect return state information, and therefore can result in a more efficient encoding of the translation table structures.
[0071] The anti-aliasing property need not be checked for GCS memory access requests issued in all operating states of the processing circuitry. A GCS transition hardening check enable control parameter may be provided (e.g., in a control register) which may be set to an enabled state and a disabled state. At least one operating state of the processing circuitry (in which the GCS memory access request is rejected if the anti-aliasing property is not set for the target memory region) may include an operating state in which the GCS transition hardening check enable control parameter is set to an enabled state, the enabled state indicating that the GCS memory access request will be subject to a check as to whether the anti-aliasing property is specified for the target memory region. If the GCS transition hardening check enable control parameter is in a disabled state, then whether the GCS memory access request is allowed may be determined independently of whether the anti-aliasing property is set for the target memory region (thus, when the GCS transition hardening check is disabled, the GCS memory access request may be allowed even if the anti-aliasing property is not set for the target memory region). Providing an enable / disable control for the GCS transition hardening check may be used to enable backward compatibility when executing legacy software that may have been written for an architecture that does not support the anti-aliasing property, in which case the GCS anti-aliasing check may be disabled.
[0072] As described above, if a write request to a GCS region is not triggered by one of the restricted subset of instructions of the GCS access type, the write request is denied (optionally, if a read request is not triggered by an instruction of the GCS access type, the read request may be denied, but this is not necessary). The memory management circuitry may also deny the memory access request (including both write and read requests) in response to determining that the memory access request is a GCS memory access request and the stage 1 permission information does not specify that the memory region corresponding to the target virtual address is a GCS region. This reduces the attack surface available to an attacker because it means that GCS memory access requests can only be used to access GCS regions and cannot be used to access conventional memory regions used to store other data. This means that if the address operand of an instruction of the GCS access type is modified by an attacker (or is incorrect due to the attacker forcing an incorrect program flow sequence) so as to cause the GCS memory access request to access a non-GCS region, this is detected as an error and the request to access the memory will be denied.
[0073] A variety of different types of instructions may be supported as part of a restricted subset of instructions of the GCS access type.
[0074] For example, a restricted subset of instructions of the GCS access type may include a return status push instruction, which is used to control the processing circuit to push the return status information obtained based on the information indicated in one or more registers of the processing circuit to the GCS data structure. In some examples, the return status push instruction may be a dedicated GCS specific instruction, which is dedicated to controlling the return status information to be pushed to the GCS data structure. However, at least one variant of the return status push instruction may also be an instruction that controls the processing circuit to perform another operation (e.g., an operation usually performed by software when calling a function or handling an exception) in addition to pushing the return status information to the GCS data structure. For example, the other operation may be a function call branch operation that triggers a branch to a target address and also controls the function return address to be saved to a register (e.g., a register called a "link register"). For example, a "branch with link" instruction (used to control the processing circuit to perform such a function call branch operation) may also act as a return status push instruction when executed in the GCS mode of the processing circuit to support the use of the GCS data structure. When the GCS mode is disabled, the branch with link instruction may cause the processing circuit to perform a function call branch operation, but not perform the operation of pushing the return status information to the stack data structure. When GCS mode is enabled, the branch with link instruction may cause the processing circuitry to both perform a function call branch operation and push return state information to a stack data structure (for this particular example, the return state information may include a function return address saved to a link register in response to the branch with link instruction).
[0075] A restricted subset of instructions of the GCS access type may also include a return status pop instruction for controlling the processing circuit to pop return status information from the GCS data structure. In some examples, the return status pop instruction may also control the processing circuit to signal a fault condition in response to determining a mismatch between the return status information popped from the GCS data structure and the current return status information determined based on information indicated in one or more registers of the processing circuit. Other examples may define a separate return status verification instruction that does not itself pop return status information from the GCS data structure, but verifies whether the protected return state popped from the GCS data structure by an earlier return status pop instruction matches the current return status information determined based on the information in the register. Multiple variants of the return status push and pop instructions may be supported in an instruction set architecture supported by the processing circuit, for example including variants dedicated to push / pop exception return status information and function (procedure) return status information, respectively.
[0076] Likewise, the return status pop-up instruction may be a dedicated GCS specific instruction, or may be a reused variant of another type of instruction that also performs another operation. For example, the return status pop-up instruction may also control the processing circuit to perform an exception return. For example, when the exception return instruction is executed when the GCS mode is disabled, the exception return instruction may control the processing circuit to perform an exception return based on the expected exception return status information defined in the register (but without popping up the protected return status information from the GCS data structure and verifying the expected exception return status information against the protected return status information). When the exception return instruction is executed in the GCS mode, the exception return instruction may control the processing circuit to perform an exception return and pop up the protected return status information from the GCS data structure, and verify the expected exception return status information against the protected return status information.
[0077] The apparatus may have at least one GCS pointer register for storing a stack pointer indicating an address of a guard control stack data structure. Instructions of a GCS access type may reference the stack pointer stored in the GCS pointer register to determine their target virtual address. In some examples, there may be more than one GCS pointer register, each GCS pointer register indicating a stack pointer to be used in a corresponding execution state of the processing circuit.
[0078] In the case where information is specified by a specific conversion table entry (whether it is a stage 1 conversion table entry or a stage 2 conversion table entry), the information can be directly specified in the encoding of the conversion table entry, or indirectly specified with reference to information stored in a register referenced by the conversion table entry. For example, for indirect reference, a license indirect register can be provided, the license indirect register includes a plurality of fields that can be set by software to indicate a specific license type, and the conversion table entry can specify field selection information, which indicates which fields of the license indirect register specify the license to be applied to the corresponding memory area. The indirect licensing method can be used for a variety of different license types, including read-only or partially read-only licenses provided in stage 2 as discussed above, and / or defining a specific memory area as a GCS area in stage 1, and / or defining anti-aliasing properties for a target memory area. For example, the stage 1 license information specifying whether the target memory area is a GCS area can be specified in a field of a license indirect register referenced by a target stage 1 conversion table entry. Similarly, stage 2 license information (specifying whether the target memory area is read-only or partially read-only) can also be specified in a field of a license indirect register referenced by a target stage 2 conversion table entry. Due to many reasons, the indirect permission using the license indirect register can be useful.For example, the indirect permission specification allows software to use a single write to register to update the permission type applied to two or more different memory areas (the same field of the license indirect register is all quoted), without the need to update each independent conversion table entry corresponding to those memory areas.In addition, in some conversion table entry formats, there may not be enough coding space to encode each possible permission type that is expected to be encoded, and therefore the use of the license indirectly can allow a limited number of bits in the entry encoding itself to reference the larger field of the license indirect register, which can be selected from the permission range wider than the possible permission range in the entry itself.However, other methods can directly specify the relevant permission in the encoding of the conversion table entry.Therefore, it should be understood that when the application indicates that information is "specified" by the conversion table entry, this information can be directly specified in the encoding of the conversion table entry, or indirectly specified (or the direct specification of information and the mixing of indirect specification) via the license indirect register.
[0079] In addition, in some embodiments, certain bits of a translation table entry or permission information specified directly or indirectly by a translation table entry may be interpreted in different ways depending on a control state specified in a control register of the device. For example, a control parameter stored in a control register may control whether a particular bit (or bit field) of permission information is interpreted in a first manner or in a second manner. This may help enable legacy software to operate according to a legacy encoding scheme and enable newer software to interpret the same bit according to a different encoding scheme. Therefore, when a statement is made that permission information specifies some information (or has an encoding that identifies the information), the permission information need not specify the information in all operating modes of the device, because in some cases, whether the permission information is considered to specify the information may depend on the current setting of at least one control parameter stored in at least one control register.
[0080] The techniques discussed above may be implemented within a data processing apparatus having hardware circuitry provided for implementing the processing circuitry and memory management circuitry discussed above.
[0081] However, the same technique may also be implemented in a computer program that is executed on a host data processing device to provide an instruction execution environment for executing the target code. Such a computer program may control the host data processing device to simulate an architectural environment that will be provided on a hardware device that actually supports the target code according to a specific instruction set architecture, even if the host data processing device itself does not support the architecture. The computer program may have a processing program logic and a memory management program logic that simulates the functions of the processing circuits and memory management circuits discussed above, including support for GCS regions, conversion hardening mechanisms, anti-aliasing properties, and whether the control of anti-aliasing properties has been specified for the target memory region (for GCS memory access requests), as discussed above. For example, such a simulation program may be useful when executing legacy code written for one instruction set architecture on a host processor that supports a different instruction set architecture. In addition, simulation may allow software development for a newer version of the instruction set architecture to begin before the processing hardware that supports the new architecture version is ready, because the execution of the software on the simulated execution environment may allow software testing to be carried out in parallel with the ongoing development of the hardware device that supports the new architecture. The simulation program may be stored on a storage medium, which may be a non-transitory storage medium.
[0082] Specific examples of data processing devices
[0083] Figure 1An example of a data processing apparatus 2 is schematically shown. The data processing apparatus has a processing pipeline 4 including a plurality of pipeline stages. In this example, the pipeline stages include: a fetch stage 6 for fetching instructions from an instruction cache 8; a decode stage 10 for decoding the fetched program instructions to generate micro-operations (decoded instructions) to be processed by the remaining stages of the pipeline; an issue stage 12 for checking whether operands required for a micro-operation are available in a register file 14, and issuing the micro-operation for execution once the operands required for a given micro-operation are available; an execute stage 16 for executing a data processing operation corresponding to the micro-operation by processing the operands read from the register file 14 to generate a result value; and a write-back stage 18 for writing the result of the processing back to the register file 14. It should be understood that this is only one example of a possible pipeline architecture, and other systems may have additional stages or different stage configurations. For example, in an out-of-order processor, a register renaming stage may be included that is used to map architectural registers specified by program instructions or micro-operations to physical register designators that identify physical registers in register file 14. In some examples, there may be a one-to-one relationship between program instructions decoded by decode stage 10 and corresponding micro-operations processed by execution stage 10. It is also possible that there may also be a one-to-many or many-to-one relationship between program instructions and micro-operations, such that, for example, a single program instruction may be split into two or more micro-operations, or two or more program instructions may be fused and processed as a single micro-operation.
[0084] The execution stage 16 includes a plurality of processing units for performing different categories of processing operations. For example, the execution units may include a scalar arithmetic / logic unit (ALU) 20 for performing arithmetic or logic operations on scalar operands read from the register 14; a floating point unit 22 for operating on floating point values; a branch unit 24 for evaluating the results of branch operations and adjusting the program counter representing the current execution point accordingly; and a load / store unit 26 for performing load / store operations to access data in the memory system 8, 30, 32, 34. A memory management unit (MMU) 28 is provided as an example of a memory management circuit for performing address translation between a virtual address specified by the load / store unit 26 based on an operand of a data access instruction and a physical address identifying a storage location of the data in the memory system. The MMU has a translation lookaside buffer (TLB) 29 for caching address translation data from page tables stored in the memory system, wherein page table entries of the page tables define address translation mappings and access permissions that govern whether a given process executing on the pipeline is allowed to read, write, or execute instructions in a given memory region.
[0085] In this example, the memory system includes a level 1 data cache 30, a level 1 instruction cache 8, a shared level 2 cache 32, and a main system memory 34. It should be understood that this is only one example of a possible memory hierarchy, and other cache arrangements may also be provided. The specific type of processing units 20 to 26 shown in the execution stage 16 is only one example, and other implementations may have a different set of processing units or may include multiple instances of the same type of processing unit so that multiple micro-operations of the same type can be processed in parallel. It should be understood that Figure 1 This is only a simplified representation of some components of a possible processor pipeline implementation, and the processor may include many other elements that are not shown for the sake of brevity. Figure 1 A single processor core is shown having access to the memory 34 , but the device 2 may also have one or more further processor cores that share access to the memory 34 , with each core having a respective cache 8 , 30 , 32 .
[0086] Figure 2 1 is a diagram illustrating different execution states (also referred to as exception levels) in which processing circuitry 4 may operate when executing instructions. In this example, there are four exception levels EL0, EL1, EL2, EL3, with exception level EL0 being the least privileged exception level and exception level EL3 being the most privileged exception level. Generally speaking, when executing in a more privileged exception level, the processing circuitry may access some memory locations or registers 14 that are not accessible to lower, less privileged exception levels.
[0087] In this example, exception level EL0 is used to execute applications managed by a corresponding operating system or virtual machine executed at exception level EL1. In the case where multiple virtual machines coexist on the same physical platform, a hypervisor operating at EL2 may be provided to manage the corresponding virtual machines. Figure 2 An example is shown in which a hypervisor manages virtual machines and the virtual machines manage applications, but it is also possible for the hypervisor to directly manage applications at EL0.
[0088] Although not required, some implementations may implement separate hardware partitions for secure and non-secure operating domains for processing circuitry. The data processing system 2 may have hardware features implemented within the processor and memory systems to ensure that data and code associated with software processes operating in the secure domain are isolated from access by processes operating in the non-secure domain. For example, a hardware partition such as that provided by Cambridge, England, may be used. Provided by Co., Ltd. Alternatively, other hardware-enforced security partitioning architectures may be used. Secure applications (trusted services) may operate in exception level EL0 in the secure domain, and secure (trusted) operating systems or virtual machines may operate in exception level EL1 in the secure domain. In some implementations, there is no support for EL2 in the secure state, and the hypervisor may only execute in the non-secure EL2. In other implementations, secure hypervisors executing in the secure EL2 may be supported, such as Figure 2 In some examples, a security monitoring program for managing transitions between non-secure domains and secure domains may be provided, which executes in the exception level EL3. Other specific implementations may regulate transitions between secure domains in hardware so that a security monitoring program may not be required.
[0089] Address Translation
[0090] One task performed by the MMU 28 is address translation between virtual addresses (VA) and physical addresses (PA). Software executed on the processing circuit 4 uses virtual addresses to specify memory locations, but these virtual addresses can be translated by the MMU 28 into physical addresses that identify the memory system locations to be accessed. The benefit of using virtual addresses is that it allows management software (such as an operating system (OS)) to control the view of memory presented to the software. The OS can control what memory is visible, the virtual addresses at which the memory is visible, and what access is allowed to the memory. This allows the OS to sandbox applications (hide the resources of one application from another application) and provide abstraction from the underlying hardware. Another benefit of using virtual addresses is that the OS can present multiple segmented physical areas of memory to the application as a single continuous virtual address space. Virtual addresses are also beneficial to software developers, who will not know the exact memory addresses of the system when writing their applications. With virtual addresses, software developers do not need to pay attention to physical memory themselves. The application knows that the OS and the hardware work together to perform address translation.
[0091] In practice, each application can use its own set of virtual addresses, which will be mapped to different locations in the physical system. When the operating system switches between different applications, it reprograms the mapping. This means that the virtual address of the current application will be mapped to the correct physical location in memory.
[0092] The virtual address is converted to a physical address through mapping. The mapping between the virtual address and the physical address is stored in a translation table (sometimes called a page table). The translation table is stored in memory and managed by software (usually an OS or hypervisor). The translation table is not static and can be updated as needed by software changes. This changes the mapping between the virtual address and the physical address.
[0093] For memory accesses performed while processing circuitry 4 is in a particular subset of execution states (specifically, while processing circuitry 4 is in non-secure EL0 or non-secure EL1), such as Figure 3 As shown, two-stage address translation is used (for other execution states, one address translation level using the stage 1 page table is sufficient). Therefore, two sets of tables are used to translate virtual addresses from non-secure EL0 and non-secure EL1. These tables support virtualization and allow the hypervisor to virtualize the view of physical memory seen by a given virtual machine (VM) (corresponding to the virtual machine of the guest operating system and the application controlled by the guest operating system). We refer to the translation set controlled by the OS as stage 1. The stage 1 table converts virtual addresses to intermediate physical addresses (IPA-an example of the intermediate address mentioned previously). In stage 1, the OS considers IPA to be a physical address space. However, the hypervisor controls a second translation set, which is called stage 2. This second translation set converts IPA to a physical address.
[0094] The stage 1 and stage 2 conversion tables are implemented as a hierarchical table structure that includes Figure 4 and Figure 5 1 and 2 respectively. In this example, both the stage 1 table and the stage 2 table may have up to 4 page table levels, namely level 0 (L0), level 1 (L1), level 2 (L2), and level 3 (L3).
[0095] To locate the physical address mapping for a given address, a translation table walk is performed, including one or more translation table lookups. A translation table walk is the set of lookups required to convert a virtual address to a physical address. For the non-secure EL1 and 0 translation hierarchy, this set includes lookups for both stage 1 translations and stage 2 translations (see the table below). Figure 6 ). The information returned by a successful translation table traversal using phase 1 and phase 2 lookups is:
[0096] - Required physical address (translated based on stage 1 mapping to intermediate addresses and stage 2 mapping to physical addresses).
[0097] The access permissions and / or memory attributes of the target memory region, which provide information about how to control access to the memory region. These may include the stage 1 access permissions and / or attributes defined in the stage 1 table structure and the stage 2 access permissions and / or attributes defined in the stage 2 table structure.
[0098] To traverse a given one of the stage 1 and stage 2 structures, the traversal begins with a read of the top level (L0) translation table for an initial lookup, based on the address specified in the translation table base address register (TTBR for stage 1, VTTBR_EL2 for stage 2). Each translation table lookup returns a descriptor that indicates one of the following:
[0099] ●The entry is the final entry of a traversal of the stage 1 or stage 2 structure that provides the address mapping being sought. If the entry is in the final L3, the entry is called a page descriptor (D_Page), and if the entry providing the final entry of the traversal is at one of the higher levels, it is called a block descriptor (D_Block). The last entry of the traversal contains the output address (OA, i.e., IPA for stage 1 or PA for stage 2) and permissions and attributes for the access. If a block descriptor is found at a higher level of the translation table structure, this means that the block descriptor represents a memory region that is larger in size than the 4kB memory page represented by the single entry at the L3 (the specific size represented by the block descriptors at the L1 and L2 depends on the number of index bits used to index into the L1 or L2 tables - in this example, the L1 and L2 block descriptors represent 1GB and 2MB regions, respectively).
[0100] ● An additional lookup level is required. In this case, the entry is called a table descriptor (D_Table) because it provides the translation table base address for a lookup in another level of the table. The table descriptor may also optionally provide other hierarchical attributes that may be applied to the final translation. The encoding of the translation table entries at levels 1 and 2 distinguishes block descriptors from table descriptors.
[0101] • The descriptor is invalid. In this case, the memory access generates a translation fault.
[0102] Figure 4 The stage 1 translation table is shown indexed using corresponding bits of the virtual address provided as an input address for a table lookup. The base address of the top-level table L0 is read from the TTBR, and the base addresses of the L1, L2, L3 tables are indicated by the addresses stored in the index table descriptors in the L0, L1, L2 tables, respectively (if no block descriptor is identified in the L1 or L2 tables - if a block descriptor is found in the index entry for L1 or L2, then the traversal stops at that level because the output address mapping has been found). The specific entry to be selected within a given level of the stage 1 translation table is determined based on the index value a, b, c, d corresponding to a specific subset of bits of the virtual address provided as the input address for the lookup. Figure 4It is shown which bits of the input address in one specific example are used for each index value a, b, c, d. The address of the associated entry in a given table is obtained by adding a multiple of the index bits a, b, c, or d to the base address of the given table as determined based on the TTBR or the address specified in the table descriptor at the previous level (the multiplier is applied to the index value corresponding to the size of one translation table entry).
[0103] Similarly, Figure 5 shows indexing the stage 2 translation table using corresponding bits of the intermediate address provided as the input address for the stage 2 table lookup. The indexing is similar to Figure 4 The same indexing as shown for stage 1 is used, but a different base address register, VTTBR_EL2, is used to provide the base address of the L0 table. Figure 5 As shown in the example of , for stage 2 lookup, the starting level at which the traversal of the stage 2 translation table begins can be changed based on the value stored in the control register VTCR_EL2.SL0 (which can specify that the lookup should start at L0 or L1). If the stage 2 lookup starts at L0, the indexes for levels 0, 1, 2, and 3 are similar to those for stage 1. Figure 4 If the stage 2 search starts at L1, indexing is performed in a similar manner, but now a larger number of index bits b2 is used at the top level of the search (L1), such as Figure 5 . Providing a variable starting level is not a necessary feature and may be omitted if desired. Although Figure 4 Not shown, but a variable starting level for the search at stage 1 may also be provided.
[0104] like Figure 6 As shown, in practice, when a full translation table walk including both stage 1 and stage 2 translations is performed, then each stage 1 table base address obtained from the TTBR and the table descriptors accessed in the stage 1 L0, L1, L2 translation tables will be an intermediate address, which itself needs to be translated using the stage 2 translation tables. Therefore, in the case where the translation table walk does not encounter any block descriptors, but proceeds all the way to L3 where a page descriptor is found, then the full page table walk process may include accessing multiple levels of the page table in the following order:
[0105] ● Stage 2 translation of the base address of the stage 1L0 page table to a physical address (the stage 1L0 base address is usually an intermediate physical address, since the stage 1 translation is configured by the operating system). The stage 2 translation consists of 4 lookups (stage 2L0; stage 2L1; stage 2L2; stage 2
[0106] L3).
[0107] ● Stage 1 L0 lookup of the entry at the address obtained based on the L0 index portion "a" of the target virtual address and the translated stage 1 L0 base address to obtain the stage 1 L1 base address (intermediate physical address)
[0108] ●Stage 2 translation to make the stage 1 L1 base address a physical address (also includes 4 lookups).
[0109] ● Stage 1 L1 lookup of the entry at the address obtained based on the L1 index portion "b" of the target virtual address and the translated stage 1 L1 base address to obtain the stage 1 L2 base address (intermediate physical address)
[0110] ● Stage 2 translation to make the stage 1 L2 base address a physical address (also includes 4 lookups)
[0111] ● Stage 1 L2 lookup of the entry at the address obtained based on the L2 index portion "c" of the target virtual address and the translated stage 1 L2 base address to obtain the stage 1 L3 base address (intermediate physical address)
[0112] ●Stage 2 translation to make the stage 1 L3 base address a physical address (also includes 4 lookups).
[0113] - A stage 1 L3 lookup of an entry at an address obtained based on the L3 index portion "d" of the target virtual address and the translated stage 1 L3 base address to identify a target intermediate physical address corresponding to the target virtual address.
[0114] - Stage 2 translation that makes the target intermediate physical address a target physical address representing the location in memory to be accessed that corresponds to the original target virtual address (again involving 4 lookups).
[0115] Thus, without any cache, and assuming that the starting level of stage 2 is L0, the translation will include a total of 24 lookups. If the starting level of stage 2 is L1, this can reduce the number of lookups to 19 (one less for each of the 5 stage 2 translations performed). However, as can be seen from the above sequence, performing the entire page table traversal process can be very slow, because for each stage in the stage of address translation, it may require a large number of accesses to memory to step through each of the levels of the page table. This is why it is generally desirable to cache information derived from the translation table traversal in the TLB 29 of the MMU 28. The cached information may include not only the final stage 1 address mapping from VA to IPA, the final stage 2 mapping from IPA to PA, or the combined stage 1 and stage 2 mapping from VA directly to PA (derived from the previous lookup of the stage 1 and stage 2 structures), but also entries from higher level page tables of the stage 1 and stage 2 tables may be cached in the TLB 29 of the MMU 28. This may allow at least some steps of the full page table walk to be bypassed even if the last level address mapping for a given target address is not currently in the address translation cache.
[0116] Figure 6 Annotate by specifying the information of specific permission or property, this specific permission or property can be defined for some of the translation table entries involved in two-phase address translation.Once these permissions and properties have been explained below, this will be described in more detail later.
[0117] Memory Management Unit Example
[0118] Figure 7 The memory management unit 28 is shown in more detail. Although for the sake of brevity, Figure 1 and Figure 7 A single MMU 28 is shown, but separate instruction-side and data-side MMUs may be provided to handle memory management operations for instruction fetch accesses initiated by the fetch stage 6 and data accesses initiated by the load / store unit 26, respectively—in which case both the instruction-side and data-side MMUs may have Figure 7. Like the TLB 29, the MMU 28 includes access control circuitry 50 for checking the access permissions specified in the translation table entry being looked up and controlling the processing of memory access requests based on those access permissions. For example, the access control circuitry 50 may be implemented to determine whether a particular type of memory access request (e.g., based on whether the request is a read, write, or instruction fetch request, or based on the type of instruction executed that caused the request to be issued) satisfies a check of the permissions specified in the corresponding translation table entry for a given memory region being accessed. The MMU also includes translation table walk control circuitry 52, which issues a memory access request to the memory to request that the translation table entry be read during the translation table walk process if the required information from the translation table is not yet available in the TLB 29, as described above in Figures 4 to 6 As shown in . The translation table traversal control circuit 52 may be responsible for generating the address of the memory system location to be read to obtain the relevant translation table entry in the stage 1 or stage 2 translation table structure. In addition, when performing a translation table traversal, the translation table traversal control circuit 52 may generate metadata update write requests, which request updates to the access tracking metadata within a particular translation table entry that is being traversed in the translation table traversal. These metadata update write requests can update the access tracking metadata to reflect that a particular memory area has been accessed, which can be used to manage operations such as paging. The metadata update write requests are generated in hardware to specify an address that is not directly specified as an instruction fetch address, or a load / store target address derived from an operand of a load / store instruction executed by the processing circuit 4, because the address of the metadata update write request is the address of the translation table entry accessed in the translation table traversal, rather than the address of the data or instruction being accessed.
[0119] The MMU 28 has access to various control registers for controlling translation table walks and other aspects of memory management operations. For example, the control registers may include the stage 1 and stage 2 base address registers TTBR_EL1, VTTBR_EL2, as previously described with respect to Figure 4 and Figure 5Mentioned. In response to instructions executed at exception levels EL1, EL2 or EL3 (i.e., in a first execution state or an execution state with higher privileges than the first execution state), the stage 1 base address in register TTBR_EL1 is writable. In response to instructions executed at exception levels EL2 or EL3 (i.e., in a second execution state or an execution state with higher privileges than the second execution state), the stage 2 base address in register TTBR_EL2 is writable. In some cases, a control value can be set to indicate that writes to TTBR_EL1 triggered by instructions executed at EL1 should be captured to EL2, so that the hypervisor operating at EL2 can check updates being requested by the operating system and prevent updates if necessary. The control registers also include registers TCR_EL1, VTCR_EL2 for specifying various control state values that affect the manner in which stage 1 and stage 2 conversions and access permission checks are performed. For example, a control value specifying the starting level for stage 2 traversal can be specified in VTCR_EL2. In addition, the TCR_EL1 or VTCR_EL2 control register can specify a control value, which specifies which type of security check is enabled / disabled. As discussed in more detail below, the control register may also include a mask register (labeled as RCWMask_Valid_EL2 and RCWMask_Invalid_EL2) for specifying a limited bit subset for updating, for which the limited bit subset is updated, the update is limited to the protected stage 1 conversion table entry for valid and invalid entries respectively. It should be understood that other control registers may also be provided, and the markings for the control registers may vary. For example, one or more license indirect registers may be provided to specify indirect access permission information, which may be referenced by a given conversion table entry to specify access permission information for a given conversion table entry. It is also possible that the same information is arranged in a control register in different formats, so that the specific allocation of information to one control register or another control register is not a necessary feature.
[0120] like Figure 7 As shown, the device may have protected entry check circuitry 54 for performing a protected entry check when an update to a stage 1 translation table entry that is encoded as a protected entry is requested (this will be described in more detail below). Figure 7, the protected entry checking circuit 54 may be implemented at various locations within the processing system. For example, the protected entry checking circuit 54 may be part of the access control circuit 50 of the MMU 28. Alternatively, the protected entry checking circuit may be implemented within a memory system component 56, which is closer to the physical memory system location accessed by a given memory access request to be checked using the protected entry checking circuit 54. For example, the memory system component 56 may be a cache 30, 32, an interconnect for managing access to shared memory by multiple processor cores, or a memory controller associated with a particular memory storage unit. Furthermore, the protected entry checking circuit 54 may include distributed logic at multiple locations in the system (e.g., the MMU 28, the load / store unit 26, and / or the memory system component 56).
[0121] Convert table access permissions and attributes
[0122] Figure 8 An exemplary format of a translation table entry in a stage 1 and stage 2 translation table structure is shown. It should be understood that the same information may be represented in different arrangements and thus the specific ordering and layout of the fields within a descriptor may vary. Figure 8 The difference shown in .
[0123] In this example, a valid translation table descriptor has a least significant bit set to 1 and an invalid translation table descriptor has a least significant bit set to 0. For a valid descriptor read at one of the levels 0, 1, 2 of the translation table structure, the second least significant bit distinguishes whether the descriptor is a table descriptor (the second least significant bit is set to 1) or a block descriptor (the second least significant bit is set to 0). A page descriptor at L3 of a stage 1 or stage 2 structure may have the second least significant bit set to 1 to allow for the distinction between page descriptors and block descriptors. Of course, valid / invalid entries and table / block / page descriptors may also be distinguished by other encoding methods.
[0124] For both stage 1 and stage 2 entries, the valid table descriptor provides a next level table address 60, which indicates the base address of the translation table at the next level of the stage 1 or stage 2 translation table structure. The valid stage 1 block or page descriptor provides an intermediate address mapping 62 corresponding to the virtual address used to index the stage 1 translation table structure. The valid stage 2 block or page descriptor provides a physical address mapping 64 corresponding to the intermediate address used to index the stage 2 translation table structure.
[0125] The stage 1 block and page descriptors also provide stage 1 access permissions 66 for controlling access to the corresponding memory region. For example, the stage 1 access permissions 66 (typically set by the OS at EL1) may specify whether reading, writing, and / or using the region is allowed for instruction fetching of executable instructions.
[0126] Similarly, stage 2 block and page descriptors provide stage 2 access permissions 68 for controlling access to corresponding memory regions. Likewise, stage 2 access permissions 68 (typically set by a hypervisor at EL2) may specify whether a region is allowed to be read, written, and / or used for instruction fetching of executable instructions. If there is a conflict between stage 1 access permissions 66 and stage 2 access permissions 68, the more restrictive set of attributes may take precedence.
[0127] A stage 1 or stage 2 block / page descriptor may also specify other attributes associated with the memory region ( Figure 8 For example, these attributes may specify properties such as whether caching of data from the corresponding memory region is allowed, whether the region is defined as device memory such that reordering or merging of different memory accesses to the device memory is not allowed, and the like.
[0128] The stage 1 block / page descriptor may also specify access tracking metadata, which may be used by the operating system to track the frequency of accesses to a given memory region. For example, the metadata may include an access flag (AF) 70 and a dirty bit modifier (DBM) 72.
[0129] The operating system may periodically clear the access flags in the entries corresponding to the set of memory regions to be monitored. When a read access is made to one of these memory regions, the access flag 70 may be set in the corresponding stage 1 block or page descriptor (if it has not been set after an earlier access) (the memory access request that causes the access flag 70 to be set may be one of the metadata update write requests generated by the earlier mentioned translation table traversal control circuit 52). After the monitoring period, the operating system may then check the access flag 70 to assist operations that may benefit from information about the frequency of access to certain pages. For example, the operating system may maintain an additional tracking data structure in memory in which an entry for each memory region tracks how many times the memory region has been accessed, and therefore at the end of each monitoring period, the entry of the additional tracking structure corresponding to the memory region for which the access flag 70 is set may be incremented. After multiple monitoring periods, the additional tracking structure will therefore provide an indication of the relative frequency of accesses to the corresponding memory region. This may provide useful information for controlling operations such as paging, where it may be useful to know the least frequently accessed page of memory for which corresponding data may be prioritized for paging to external storage compared to other more frequently accessed pages.
[0130] Similarly, DBM 72 assists in tracking which pages have been subject to writes. If the operating system wishes to track whether a given page has been written to, then when the page is mapped or at the beginning of a monitoring period, the operating system may set the access permissions for that page to "read-only" (even if the page is intended to be write-enabled) and set DBM bit 72. When DBM bit 72 is set, for an access permission fault caused by a write to a read-only page, the operating system may determine from the DBM bit 72 being set that this is not a "real" violation of the read-only permissions, and instead cause the operating system to update a data structure stored in memory that tracks the pages subject to write requests, and also update the page's write access permissions to indicate that the page can now be written to without triggering a fault. After the monitoring period, software can use the tracking data structure in memory to determine whether it is necessary to write the modified data from a particular region back to external storage when the region is paged out, or (if no write occurred) whether the data stored in the on-chip memory can simply be discarded when the region is paged out, because if the data is clean, it can be assumed that the corresponding data in the external memory is still the same.
[0131] The access flags 70 and dirty bit modifiers 72 are only some examples of possible access tracking data that may be stored within a translation table entry, and other examples may provide other types of access tracking metadata. For example, in another example, a multi-bit access counter may be provided as access tracking metadata. Also, in another example, instead of the DBM bit 72 being used to modify the handling of read-only access permission violations for write requests and trigger an update of write permissions, the DBM flag 72 may instead be directly updated in response to the first write to the page after the DBM flag 72 is cleared, in a manner similar to the manner in which the access flag 70 is updated upon the first access to the page as previously described.
[0132] like Figure 8 As shown in , the various translation table descriptors may also include a number of other pieces of information that can be used to protect stage 1 translation table entries from being corrupted by operating system code under attack by an attacker. Typical operating system code may include many lines of code that may be difficult to fully verify as safe from attack, and it is therefore desirable to provide architectural mechanisms for protecting against the possibility that an attacker may be able to modify the behavior of the operating system code to cause writes to memory areas used to store translation table entries (thereby attempting to modify address mappings or permissions in these entries so as to give the attacker access to memory areas in an unauthorized manner).
[0133] like Figure 8 As shown, in order to provide a transformation hardening mechanism, the additional properties and permissions described below for hardening the phase 1 transformation table to prevent attacks include the following:
[0134] = A stage 2 block / page descriptor specifies stage 2 access permissions 68, which have an encoding indicating whether the corresponding memory region has partial read-only (PRO) permissions (partial read-only permissions may also be referred to as "primary read-only" permissions);
[0135] Valid stage 1 descriptors at all levels of the stage 1 translation table structure (including table descriptors and block / page descriptors) have an encoding that specifies whether the translation table entry is a "protected" entry, which provides additional protection against unauthorized updates compared to non-protected entries. For example, a bit field 76 within the valid stage 1 descriptor may indicate whether an entry is a protected entry.
[0136] Invalid stage 1 descriptors at all levels of the stage 1 translation table structure may also have an encoding that specifies whether the translation table entry is a "protected" entry. This may be indicated using a bit field 78, which may be at a different location within the translation table entry encoding than the bit field 76 used to indicate a protected entry for a valid stage 1 translation table entry.
[0137] A stage 2 block / page descriptor may have an indicator 79 that specifies whether the corresponding memory region has anti-aliasing properties. In some examples, the presence or absence of the anti-aliasing property may be encoded in a combined bit field that may also signal other types of properties, or alternatively, the anti-aliasing bit field may be a separate bit field that does not signal any other information. If specified, the anti-aliasing property indicates that for access to the corresponding physical address to be allowed, all stage 1 translation table entries accessed in the translation table traversal to obtain the intermediate address used to access the stage 2 descriptor will need to be designated as protected entries using bit field 76 and will be stored in the memory region that indicates partial read-only permission 74 for its corresponding stage 2 block / page descriptor.
[0138] The stage 2 block / page descriptor may also specify in the stage 2 access permissions 68 a stage 1 top-level entry presence permission 80, which indicates whether the corresponding memory region is allowed to hold the top-level translation table for stage 1 translation (i.e., Figure 4 and Figure 6 In one example, the encoding of stage 2 access permissions 68 may be such that the stage 1 top-level entry presents another attribute that the permission is encoded as a PRO permission, such that the values allowed to be encoded for stage 2 access permissions 68 may include values indicating the following:
[0139] ○ PRO licenses where no Phase 1 top-level entry exists;
[0140] ○ A PRO license with a Phase 1 Top-Level Entry Existence License; or
[0141] o One or more other types of permissions (eg, read-only permissions, read / write permissions, and / or execute permissions) that do not have a PRO permission or a stage 1 top-level entry presence permission.
[0142] In this case, it may not be possible to specify the stage 1 top-level entry presence permission independently of the PRO permission. However, other implementations may encode the stage 1 top-level entry presence permission independently of the PRO permission, such that the stage 1 top-level entry presence permission may be specified even if the PRO permission is not provided.
[0143] The use of these attributes and permissions is discussed in more detail below. It should be understood that not all of these attributes and permissions need to be supported in every implementation. Figure 8 An example of directly specifying S1 and S2 access permissions in the encoding of the conversion table entry is shown, but the same information can also be indirectly specified using the permissions specified in the permission register. For example, the S1 or S2 permission field 66, 68 can specify an index value, which selects which of the multiple permission fields of the permission register specifies the access permission for the corresponding conversion table entry. Depending on the control state stored in the control register, some fields of the conversion table entry can also be interpreted in different ways. For example, when the control value stored in the control register has a first value, the protected entry field 76 of the stage 1 conversion table entry can be interpreted as indicating whether the stage 1 conversion table entry is protected, and when the control value has a second value, the protected entry field can be interpreted in different ways. Similarly, when the control value stored in the control register has a first value, the anti-aliasing property field 79 of the stage 2 conversion table entry can be interpreted as indicating whether the stage 2 conversion table entry has anti-aliasing properties, and when the control value has a second value, the anti-aliasing property field can be interpreted in different ways.
[0144] Although S1 permission 66 and S2 permission 68 are shown as being directly specified by the corresponding S1 descriptor or S2 descriptor, these permissions (or other information specified by the translation table entries) may also be specified indirectly using indirect registers, as described below with respect to Fig.18 shown.
[0145] Partial read-only permission
[0146] Fig. 9 The write access control behavior of a memory region marked by the stage 2 access permission 68 as having a partial read-only (PRO) permission is summarized. At least for write requests issued when the current execution state is EL1 (a state in which operating system code is expected to be executed), a memory region with PRO permission is writable for a restricted subset of write request types, but is treated as read-only for the write request types. Since only some write request types treat the memory region as read-only, this permission is described as a partial read-only permission.
[0147] Fig. 9 Summarizing the types of write requests that are allowed and prohibited to write to a memory region for which a corresponding stage 2 translation table entry defines the region as having PRO permissions. A restricted subset of the types of write requests that are allowed to write to a PRO region when a write is issued at EL1 includes a metadata update write request generated by the MMU 28 to update access tracking metadata (such as access flags 70 or write permissions) in a translation table entry when the dirty bit modifier 72 is set, as discussed above. In addition, the restricted subset may include at least one predetermined type of translation table entry update instruction executed at the exception state EL1, which may be a dedicated type of instruction intended for updating translation table entries to express the intent of the program code to distinguish such writes for updating translation table entries from writes for updating data other than the translation table entries. For example, a predetermined type of translation table entry update instruction may include the following with respect to Figure 12 to Figure 14 A variant of the protected entry check read check write (RCW) instruction discussed above. Fig. 9 As shown, write requests issued in response to at least one other type of storage instruction executed in one of the exception states EL0 and EL1 are prohibited from writing to the PRO region of memory. For example, the prohibited write request types may include most storage instructions in the instruction set architecture supported by the processing circuit 4. By limiting the ability to update the translation table entries to a limited set of instruction types when marking the region with PRO permissions, this reduces the attack surface available to attackers in attempting to corrupt the stage 1 translation table entries, for example, tampering with the address operand of a general storage that is not one of the restricted subset of write requests will not allow access to the PRO region of memory.
[0148] Optionally, write requests issued in response to storage instructions executed in one of execution states EL2 or EL3 may be allowed to write to a portion of the read-only region, even if they are a type of storage instruction that would be prohibited from writing to that region if executed at execution state EL0 or EL1. However, as described above, this is not required.
[0149] Fig.10is a flow chart illustrating a method of processing instructions and controlling memory management operations. At step 500, processing circuit 4 processes instructions in one of a plurality of execution states EL0-EL3 associated with different privilege levels. At step 502, in response to a memory access request, MMU 28 performs a two-stage address translation of a target virtual address (VA) specified by the memory access request to a target physical address (PA), wherein the mapping of the target VA to the target PA depends on a stage 1 address mapping from the target VA to a target intermediate address (IPA) and a stage 2 address mapping from the target IPA to the target PA. At step 504, access control circuit 50 of MMU 28 performs a permission check for the memory access request based at least on stage 2 access permission information 68 specified in a corresponding stage 2 translation table entry. The permission check may also be based on stage 1 access permission information 66. Stage 2 access permission information 66 has an encoding that specifies whether a memory region corresponding to the target IPA has PRO permission. At step 506, MMU 28 denies the memory access request when the memory access request is a write request issued in a predetermined execution state (e.g., EL1), the stage 2 access permission information specifies PRO permission, and the write request is a write request type other than a restricted subset of write request types permitted to write to the PRO region of memory. Optionally, MMU 28 may also deny the memory access request when the memory access request is a write request issued in an execution state other than the predetermined execution state (e.g., EL0), the PRO permission is specified by the stage 2 access permission information, and the write request type is not one of the restricted subset of write request types.
[0150] Fig.11 The partial read-only check performed by the access control circuit 50 of the MMU 28 is shown in more detail. At step 600, a write memory access request is issued when the processing circuit 4 is in a predetermined execution state (EL1). The write request specifies a target VA. The write request may be issued by the load / store unit 26 of the processing circuit 4 in response to a load / store instruction executed by the processing circuit, or by the fetch stage 6 when an instruction fetch is requested. The write request may also be a metadata update write request issued by the MMU 28 to update access tracking metadata in the translation table entries during the translation table traversal process.
[0151] At step 602, the target VA is translated into a target PA identifying the memory system location to be accessed. To perform the translation, MMU 28 may look up the target VA within TLB 29, and if a mapping from the target VA to the target PA is already available in TLB 29, no translation table walk is required. Otherwise, a translation table walk may be required. Figure 6, although some portions may be able to be skipped if information derived from corresponding translation table entries for that portion of the translation table traversal is already cached in TLB 29. For write memory access requests issued from non-secure EL1, the translation is performed as a two-stage address translation based on mappings defined in both the stage 1 and stage 2 translation tables, although this does not necessarily mean that two separate translations need to be performed, as it is possible to provide a combined stage 1 / stage 2 TLB that caches mappings directly from the target VA to the target PA (depending on both the stage 1 and stage 2 mappings) together with corresponding stage 1 and stage 2 permission information to avoid the need to explicitly determine the target IPA.
[0152] At step 604, the access control circuitry checks whether the corresponding stage 2 (S2) translation table entry (the stage 2 entry that specifies the mapping from the target IPA to the target PA) specifies PRO permission. If so, then at step 606, the access control circuitry checks whether the write request being processed is one of a restricted subset of write request types. If the current write request is not one of a restricted subset of write request types (including at least metadata update write requests), then at step 608, the memory access request is denied and a failure is signaled. If the write request is one of a restricted subset of write request types, the partial read-only check passes and therefore the method proceeds to step 610. Moreover, if at step 604, the corresponding stage 2 translation table entry does not specify PRO permission, then the partial read-only check at step 606 can be omitted and therefore the method proceeds directly from step 604 to step 610.
[0153] At step 610, the access control circuitry determines whether any other checks necessary to allow the write memory access request to proceed are satisfied. For example, these checks may include checks to use stage 1 access permissions 66, checks to use other stage 2 access permissions 68 if no PRO permissions are specified, security checks based on whether the request was issued from a secure or non-secure state (in implementations that support secure states), and other checks specific to particular instruction types, such as the following with respect to Figure 12 to Figure 14 The discussed checks regarding whether the data at the target memory location is a protected translation table entry. If any of these other checks are not met, the memory access request is again denied at step 608 and a fault is signaled. Fault symptom information may be provided to distinguish the cause of the fault. If the checks performed at step 610 are met, then at step 612, the memory access request may be allowed to proceed and the memory system location associated with the target PA may therefore be updated with the write data specified by the write request.
[0154] Therefore, as discussed previously Figure 6As shown in , PRO permissions may be specified in the stage 2 access permissions 68 of the stage 2 translation table entries, which are used to provide physical addresses of memory system locations at various levels of the stage 1 translation table that are maintained for use in traversal of the stage 1 table structure to obtain intermediate addresses of memory regions containing sensitive information. This protects those stage 1 translation entries from being corrupted by erroneous functioning code or operating system code under attack by malicious parties, because the PRO permissions limit the ability to write to the corresponding memory region to a limited subset of instruction types, thereby greatly reducing the number of lines of code that may be susceptible to corruption of the stage 1 translation table. However, hardware-generated write requests for updating access tracking metadata in the translation table entries may still be allowed for such regions to avoid compromising the efficiency of the operating system's paging operations.
[0155] although Fig.11 It is shown that a partial read-only check is performed for a write memory access request issued in a predetermined execution state EL1, but a partial read-only check may also be performed for other execution states. However, this may not be necessary, because for a write request issued in the least privileged execution state EL0, it is possible that the memory area holding the stage 1 translation table will in any case be marked by the stage 1 access permission 66 as inaccessible to the application-level code operating at EL0, so the stage 1 permission check may have prevented such write requests from destroying the stage 1 translation table. In addition, for code executed at EL2 or EL3, the translation table will not use two-stage address translation, and it is unlikely to restrict writing to the area storing the stage 1 translation table entries, because the management program or monitoring code may be the code that is controlling the restrictions on allowing updates to the stage 1 translation table. Therefore, some specific implementations may limit the partial read-only check to be performed only when the current execution state is EL1. Regardless of which execution state is the current execution state, other specific implementations may apply the partial read-only check.
[0156] Protected entry encoding for stage 1 translation table entries
[0157] Using PRO permissions to mark specific memory regions as read-only for write requests other than a restricted subset of write types helps protect the Stage 1 table from corruption. Figure 6 As shown in , typically, a given translation table at a given level of the translation table structure occupies an entire page in memory, and thus the PRO license will apply to the entire translation table at a given level of the stage 1 translation table structure, which may include translation table entries for various memory regions, which may include some memory regions for sensitive information that need to be protected from unauthorized access, and other memory regions that contain only non-sensitive information that does not require such protection.
[0158] It is possible to provide a specific implementation that does not support encoding protected entries for stage 1 translation table entries, as discussed further below. In this case, in order to allow the operating system to update a specific stage 1 translation table entry associated with a non-protected area containing non-sensitive information, a fault generated when a write access to the PRO area is not one of the write request types allowed to write to the PRO area can cause a capture to the hypervisor operating at EL2, and the hypervisor can then determine in software whether the area for which the operating system wishes to update the stage 1 translation table entry should be protected from being updated by the operating system, and if the area does not need to be protected, the update requested by the operating system can be allowed to proceed. However, in practice, the operating system may need to change the translation table entries for non-protected areas of memory relatively frequently, and therefore the capture of the hypervisor each time an update is required may be slow in performance.
[0159] The protected entry encoding for the stage 1 translation table entries (e.g., using bits 76, 78) helps allow the operating system to update non-protected entries without hypervisor intervention (and optionally for some specific implementations, update the non-update restricted bits of protected entries without hypervisor intervention). This helps improve performance because hypervisor involvement can be avoided more frequently even when a given stage 1 translation table is stored in the PRO area of memory because it contains a mixture of protected entries and non-protected entries. The instruction decoder 10 and execution stage 16 of the processing circuit 4 support at least one type of instruction, referred to as a protected entry check type read check write (RCW) instruction, which can be used to request an update to a given memory system location, where the update is conditioned on a protected entry check that checks the data stored at the accessed memory system location to check whether it has a value consistent with the encoding of the protected stage 1 translation table entry. If the data at the accessed memory system location is found to have a value consistent with the data as a protected stage 1 translation table entry, then the update of at least a subset of the update restricted bits of the given memory system location is suppressed. The RCW instruction is allowed to be executed by an operating system executing at EL1. The RCW instruction is one of a restricted subset of instructions that are allowed to update data in a memory region marked with PRO permission through a corresponding stage 2 translation table entry.
[0160] The protected entry check is performed in hardware by the protected entry check circuit 54, such as Figure 7As shown in , the protected entry check circuitry may be implemented within the MMU 28 or implemented closer to the memory system location where the data is stored (e.g., within a memory system component 56 such as a cache, interconnect, or memory controller). A distributed set of logic may also be used, with some portions of the protected entry check circuitry 54 implemented in the MMU 28 (or the execution stage 16 of the pipeline) and other portions implemented closer to the memory storage device. The read, check, and write operations performed in the protected entry check are performed as atomic (indivisible) operations, so that when an access to a given memory system location is requested by another thread executing on the same processor circuit as the thread executing the RCW instruction or by another processor core, the other access sees the value of the given memory system location before the RCW instruction is processed or the value of the given memory system location after the RCW instruction is processed, rather than any partial effects of the RCW instruction, and it is also not possible for a write to the given memory system location to update the given memory system location in the period between the protected entry check reading the data at the given memory system location and the subsequent update of the data at the given memory system location in response to the RCW instruction. Any known technique for implementing atomic read / write operations on memory system locations may be used to enforce atomicity (e.g., locking the memory location from access by other operations in the period between the read and write, or allowing conflicting accesses in the period but restarting the RCW operation if a conflicting access is detected in the period between the read and write). By enforcing atomicity of the read, check, and write, this avoids race conditions that may lead to incorrect processing results. When performing read, check, and write operations in an atomic manner, it may be useful to implement the protected entry check circuit 54 within the memory system component 56 closer to the storage location being updated to reduce the duration of the period between the read and write, compared to the duration if the read data must be returned all the way to the MMU 28 or another element of the processor pipeline 4 for performing the check before the write can proceed and the write data is returned to the memory system location where the data is stored.
[0161] exist Figure 8In the example shown in, both valid and invalid stage 1 conversion table entries have encodings that allow entries to be designated as protected entries. However, it is not necessary that invalid entries can be designated as protected, and other examples can omit protected entry encoding bit fields 78 from the invalid entry format. In addition, different specific implementations can select different options for how many bits of protected entries are suppressed in response to RCW instructions to update them. Some specific implementations can prevent any update to protected entries in response to RCW instructions, wherein updates are allowed in response to RCW instructions only when data at a given memory system location is not encoded as protected entries. Other specific implementations can specify update-restricted bit subsets and non-update-restricted bit subsets, and therefore even for protected entries, updates to non-update-restricted bit subsets can be allowed. For example, there may be some fields that are not critical to security, such as access flags 70 and dirty bit modifiers 72, which can be allowed to be updated even in protected entries. Which bits are update-restricted or non-update-restricted can be fixed in a non-programmable manner for a given architecture, or can be programmed by software using a selection value stored in a control register. For example, the select value may be selected from one of several different modes, each mode being associated with a different setting of which bits are update restricted. Figure 7 In the example of , the selection value is encoded as a bit mask identifying the positions of update restricted bits, where the selection value is stored in a mask register (e.g., Figure 7 RCWMask_Valid_EL2 and RCWMask_Invalid_EL2 registers are shown for selecting update restricted bits for valid and invalid entries, respectively—in a specific implementation where invalid entries cannot be encoded as protected entries, the RCW_Mask_Invalid_EL2 register may be omitted). Updates to the selected value may be limited to program instructions executed at a threshold privilege level or higher, e.g., only instructions executed at EL2 or EL3 may be allowed to update the selected value. Regardless of the state of the selected value, there may be some bits that are forced to be update restricted. For example, bit fields 76, 78 for encoding whether an entry is a protected entry may not be allowed to be updated, regardless of which other bits can be updated. In general, RCW instructions may be prohibited from changing the state of whether a particular entry is protected or unprotected. The setting of bit fields 76, 78 would instead be controlled by program code executing at a higher privilege level (such as EL2 or EL3), which could access memory using a different set of stage 2 translation tables that did not mark the memory region storing the protected entries as partially read-only, and which could therefore use standard general purpose storage instructions to set bit fields 76, 78 of the protected stage 1 entries.
[0162] There are multiple ways to implement the protected entry check. In one example, if the entry stored at the accessed memory system location is valid and protected, it cannot be changed, and if it is invalid, it can be changed, including making it valid (as long as the entry is not also protected). Alternatively, there may be a protected bit field 76 in the valid entry, and a protected bit field 78 in the invalid entry, and changes to the protected entry may not be allowed, otherwise non-protected (valid or invalid) entries are allowed to be updated (except changing the state of whether the entry is protected). Another example may provide a protected bit field 76 in the valid entry, and a protected bit field 78 in the invalid entry, and the RCW instruction may be allowed to make any changes to the entry (except making it protected) if it is not protected, and if it is protected, the RCW instruction may make changes to some bits as described for the valid entry, and make changes to some bits in the invalid entry. In some examples, the mechanism for describing which bits are protected is a hard-wired architectural selection of any field other than the protection or valid field. Alternatively, the mechanism for describing which bits are protected in valid entries may use a mask register owned by EL2, and / or the mechanism for describing which bits are protected in invalid entries is a mask register owned by EL2. Different choices for defining the update restricted bits are possible for valid and invalid entries respectively - for example, one approach may be to define a mask register for defining the update restricted bits for valid entries, but hardwire the update restricted bits for invalid entries.
[0163] When updating some fields in a protected entry is allowed, there may also be variations on how the check is applied, two example options are:
[0164] A) Protected entry check circuit 54 reads the current entry to check whether the entry is valid and / or protected, and then only stores bits that are allowed to be written (without checking whether the RCW instruction is attempting to change an update restricted bit that is not allowed to be written).
[0165] B) The protected entry check circuit 54 reads the current entry to check whether the entry is valid and / or protected. If it is protected, and the RCW instruction does not attempt to change any bits that are not allowed to be written, then the write can occur, but if the RCW instruction attempts to update any update restricted bits, then the write fails and nothing is written.
[0166] Both A and B are viable alternatives.
[0167] In response to the RCW instruction, an indication of whether the write was successful or failed may be written to a conditional status flag stored in a control register of the processing circuit 4. For example, the conditional status register may include a plurality of conditional flags (e.g., a negation flag N, a zero flag Z, a carry flag C, and an overflow flag V) that may be set depending on the result of the processing operation and may be tested by a conditional instruction, which may then conditionally trigger an operation (such as a branch operation or an arithmetic / logical operation) depending on the state of the conditional status flag. Therefore, it may be useful to update the conditional status flag based on whether any portion of the write requested by the RCW instruction was unsuccessful to allow subsequent instructions to take actions depending on the result of the write without requiring the memory system location to be re-read to check whether the write was successful.
[0168] Fig.12 , Fig.13 and Fig.14 The processing of multiple variations of the protected entry check RCW instruction is shown. Fig.12 An example of processing of a store variant or a swap variant of an instruction is shown (most of the processing steps are the same for both instructions, except for the final step 726 or 728 depending on the variant). Both the store variant and the swap variant specify a register Xd that provides an address operand for generating the address of a given memory system location to be updated, and a source register Xs that provides new data to be written to the given memory system location. At least the swap variant also specifies a destination register Xt to which the old data read from the given memory system location will be written. The store variant does not need to specify any destination register because the store variant differs from the swap variant in that the old data is not written to any destination register. However, in one example, the store variant and the swap variant may be encoded using the same encoding, except that the instruction may be treated as a store variant when the field used to specify the destination register Xt has a predetermined value. For example, some instruction set architectures may define a particular register designator (e.g., register 31) to correspond to a "zero" register that, when specified as an operand of an instruction, causes the operand to be treated as if it has a value of zero, without actually reading the operand from a register provided in hardware. Thus, in some examples, when the destination register Xt is specified as the "zero" register X31, the instruction may be considered a store variant. In other examples, the store instruction may be encoded as a completely different instruction type than the exchange instruction.
[0169] exist Fig.12At step 700, the address operand and new data ("NewData") to be written are read from the registers identified by the register designators Xd and Xs, respectively. At step 702, the target address for memory access is determined based on the address operand. For example, the address operand may be viewed as an absolute address that directly specifies the target address, or may define an offset relative to a reference address (such as a value in another base register or a program counter value that identifies the address of the RCW instruction itself). The target address calculated based on the address operand is a virtual address and may be converted to a physical address by the MMU 28. At step 704, assuming that any MMU check (except the protected entry check) for whether the target address is accessible to the current instruction is passed, a read request is issued to the memory system to obtain data ("ReadData") read from the memory system location corresponding to the (converted) target address. This corresponds to a "read" of the RCW instruction.
[0170] At step 706, the protected entry check circuit 54 determines whether ReadData has a value consistent with the encoding of the protected stage 1 (S1) conversion table entry. This corresponds to the "check" portion of the RCW instruction. If ReadData does not have a value consistent with being a protected stage 1 conversion table entry, then at step 708, the protected entry check circuit checks whether NewData is encoded as a protected stage 1 conversion table entry. If so, then at step 710, the write requested by the RCW instruction is rejected, or alternatively, the non-update restricted bits of the stage 1 conversion table entry designated as NewData by the RCW instruction can be written to the corresponding bits of the memory system location, wherein at least the bits used to encode whether the entry is protected are regarded as unwritten update restricted bits. In either case, at step 712, the conditional status flag is set to report that the write requested by the RCW instruction was not fully executed.
[0171] If at step 706, it is determined that the ReadData is encoded as a protected stage 1 translation table entry, then at step 716, the protected entry check circuit 54 determines whether the read data has a value consistent with a stage 1 translation table entry that is valid or invalid. If the read data has a value consistent with a protected stage 1 translation table entry that is invalid, then at step 718, the protected entry check circuit 54 determines whether NewData attempts to change any invalid entry update restricted bits of the stage 1 translation table entry (including at least any bits used to encode whether the entry is protected), and if so, the method proceeds to steps 710 and 712 again to suppress updates of at least the invalid entry update restricted bits and set the conditional status flag (again, this can be done by completely rejecting writes or by writing only to non-update restricted bits).
[0172] On the other hand, if at step 716, it is determined that ReadData has a value consistent with a valid stage 1 translation table entry that is encoded as a protected entry, then at step 720, the protected entry check circuit 54 determines whether NewData attempts to change any valid entry update restricted bits (including at least any bits for encoding whether the entry is protected) of the stage 1 translation table entry read from the memory system location corresponding to the target address. If so, then writing to non-update restricted bits is again denied or allowed at step 710, and the conditional status flag is set at step 712 to report the failure of the write.
[0173] In implementations that do not support encoding of invalid translation table entries as protected entries, steps 716 and 718 may be omitted, and the method may proceed directly from step 706 to step 720 in the case where the ReadData is encoded as a protected entry.
[0174] If at step 708, NewData is to be written if ReadData is not a protected entry, or at steps 718 or 720, NewData (to be written if ReadData is a protected entry) does not attempt to change any update restricted bits, then at step 714, the writing of the RCW instruction is allowed and NewData is therefore written to the memory system location corresponding to the target address.
[0175] Regardless of whether the write is successful or rejected (at least in part), at step 724, the operation varies depending on whether the current RCW instruction being executed is a store variant or a swap variant. If the instruction is a store variant, no further action is required at step 726, and the ReadData is not written to any destination register. If the instruction is a swap variant, then at step 728, the ReadData is written to the destination register Xt. Some implementations may not support both store variants and stop variants, in which case step 724 may be omitted, and the method may proceed directly from step 714 to the relevant steps in steps 726 and 728.
[0176] The read at step 704, the write at step 714, and the various check operations performed between steps 704 and 714 are performed atomically, as an indivisible set of operations for which it is not possible for an intervening write to the memory system location to occur between the read at step 704 and the write at steps 710 or 714, or for another execution thread to see a partial result of executing the set of operations.
[0177] Fig.13 is a flow chart showing the processing of a compare and swap (CAS) variant of a protected entry check RCW instruction. Fig.12The same reference numerals as shown in Fig.13 The steps are the same as those discussed above. It should be noted that Fig.12 In contrast, the symbols for the registers used to store ReadData and provide NewData are already in Fig.13 Swap in - Xt is now the register providing NewData and Xs is the destination register that was written with the old value of ReadData before the write. Fig.13 and Fig.12 The difference is that step 700 is replaced by step 750 because the CAS variant specifies an additional source operand called compare data ("CompareData"). In this example, in order to reduce the number of register fields required in the instruction encoding, at step 728, CompareData is specified in the same register X used as the destination register for writing ReadData, but this is not necessary, and other examples may specify CompareData in another register separate from X.
[0178] Steps 702 and 704 are Fig.12 The steps in are the same as in . After step 704, an additional step 752 is performed to compare the ReadData read from the given memory system location corresponding to the target address with the CompareData specified by the RCW instruction in register Xs. The protected entry check circuit 54 determines whether the comparison condition is met based on the comparison. For example, the comparison condition may be whether CompareData is equal to ReadData, or may be based on another comparison condition, such as less than, greater than, not equal, etc. Some specific implementations may fix the comparison condition to an equality condition, while other embodiments may allow parameters of the instruction to select which type of comparison to perform. If the comparison condition is not met, then at step 754, the write requested by the RCW instruction is rejected and the conditional status flag is set to report a write failure caused by a comparison condition failure (for example, a negation flag N is set on a comparison condition failure). If the comparison condition is met, the write is reported as equal to the write condition. Fig.12 Steps 706, 708, 710, 714, 716, 718, 720 are performed in the same manner as in the above to check the protected entry status of the data read from the memory system location corresponding to the target address, and based on the result of the check, control whether to allow writing. If writing is allowed, step 714 is the same as the steps discussed previously to allow writing to proceed, thereby writing NewData to the memory system location. If writing is denied or only partially performed at step 710, then Fig.12 The subsequent step 712 is Fig.13, which is identical in that it sets the conditional status flags to report a write failure, but in the case of the compare and swap variant, this distinguishes that the failure was caused by a protected entry check failure, thereby setting the conditional status flags to a different value than that used at step 754 in the event of a compare condition failure.
[0179] Regardless of whether the comparison condition is satisfied or the protected entry check is successful, steps 724, 726, and 728 are performed in conjunction with Fig.12 The same is used to optionally write the ReadData to the destination register Xs (when the destination register designator specifies a predetermined value (e.g., 31), the update of the destination register Xs can be suppressed again).
[0180] Fig.13 A situation is shown in which the comparison condition evaluation takes precedence over the protected entry check, so if the comparison condition fails but the entry is also protected and the check at steps 708, 718, 720 fails, the condition status code will indicate a CAS failure. The protected entry check may also take precedence, such that if the entry is protected and the check at steps 708, 718, or 720 fails, the condition status code will indicate a write failure due to the protected entry check even though the comparison condition has failed. For example, Fig.13 It may be modified to implement steps 752 and 754 after step 714 instead of before step 706 .
[0181] Fig.14 is a flow chart showing the processing of the bit set / clear variant of the protected entry check RCW instruction. Fig.14 In steps 700-728 and Fig.12 The difference is that Fig.14 In , NewData is not specified directly in the source register, but is calculated based on the bit mask ("BitMask") provided in the source register Xs, which encodes the position of the bit to be set or cleared within the addressed memory system location. Fig.12The only difference is that at step 700, register Xs defines the BitMask instead of specifying NewData directly, and additional steps 770, 772, 774 are performed between steps 704 and 706. At step 770, the method differs depending on whether a bit setting instruction or a bit clearing instruction is being executed (it is not necessary to support both types of instructions, so if only one of these instructions is supported, step 770 can be omitted and the relevant one of steps 772, 774 is performed after step 704). If a bit setting instruction is being executed, then at step 774, NewData is set to the result of a bitwise OR operation of the ReadData read from the addressed memory system location and the BitMask specified by the RCW instruction (thus, for a bit setting instruction, the position of the bit marked with "1" in the request BitMask is set to 1 within the addressed memory system location). In contrast, at step 772, if a bit clear instruction is being executed, NewData is set to the result of the inverse bitwise AND operation of ReadData and BitMask (thus, for a bit clear instruction, the positions of the bits marked with "1" in the request BitMask are cleared to 0 within the addressed memory system location). For both the bit set variant and the bit clear variant, the bits of ReadData corresponding to the "0" bits of the BitMask retain their original values in NewData and are therefore not changed by the RCW instruction. After NewData is calculated at steps 772 or 774, Fig.14 All subsequent steps are related to Fig.12 Same as in.
[0182] For all flow charts in this application, it should be understood that the same functions can also be implemented in a different order, so that although the flow chart shows a sequential sequence of steps, for any steps that are not dependent on each other, these steps can be reordered or at least partially performed in parallel.
[0183] Therefore, if Figure 6As shown in , various stage 1 translation table entries for traversing a translation table tree structure to arrive at an intermediate address mapping corresponding to a sensitive memory page (e.g., a page intended for sensitive data or instructions) may be set to have a protected entry encoding. This may be the case even if one of these entries is temporarily set to invalid to prohibit access to the page (e.g., as a result of a paging operation). At the same time, other entries in the same page table as the protected entry may be non-protected entries whose updates are less restricted. By supporting protected entry encoding, this enables a given page table stored in a PRO region of memory to contain a mix of protected and non-protected entries, wherein the non-protected entries can be updated by operating system code executing at EL1 without the intervention of the hypervisor, by executing RCW instructions according to any of the variations discussed above, while the protected entries may have more stringent restrictions imposed on them. Because a dedicated type of instruction (e.g., one or more of the variations of the RCW instruction described above) is provided for triggering the protected entry check, and the PRO license prevents other types of instructions (such as most store instructions) from being able to update the PRO region of memory, this avoids the need to perform a protected entry check on every write to memory, which would be very expensive in terms of performance.
[0184] Anti-aliasing check
[0185] The mechanisms discussed above are useful for protecting specific stage 1 transformation entries from being corrupted (either intentionally by a malicious party hacking the code or accidentally by poorly written code). Fig.15 As shown in , by defining stage 1 translation table entries that specify the same intermediate address mapping 62, it is possible for several different virtual addresses to alias to the same intermediate address. To prevent an attacker from being able to circumvent the protection provided by the PRO permission and protected entry encoding discussed above for the first set of stage 1 translation entries mapping VA1 to IPA by defining aliasing stage 1 entries that map different virtual addresses VA2 to the same intermediate address IPA, as shown in Figure 8As shown, the stage 2 translation table entry may have a bit field 79 that specifies whether the corresponding region of memory has anti-aliasing properties (alternatively, the anti-aliasing properties 79 may be indirectly specified by the stage 2 translation table entry reference to an indirect register). If the region is indicated as having anti-aliasing properties, an additional anti-aliasing check is performed for accesses to the region to check whether all traversed stage 1 translation table entries (which will be accessed in the translation table traversal to locate the corresponding stage 1 translation table entry that specifies the stage 1 address mapping from the virtual address of the region to the physical address) are: (a) stored in the PRO or read-only area of the memory and encoded as protected entries, or (b) stored in the read-only area of the memory. It should be noted that this does not necessarily require that a page table traversal of those traversed stage 1 translation table entries be actually performed on each access to the memory region associated with the stage 2 translation table entry having anti-aliasing properties. It is possible to cache information in the TLB 29 to indicate whether the antialiasing check passed (or for certain traversed stage 1 translation table entries to indicate whether it has been determined to be stored in the PRO region and / or is a protected entry) to avoid the need to perform a full translation table traversal each time.
[0186] Fig.16 8 is a flow chart illustrating a method of performing anti-aliasing checking. At step 800, a memory access request is issued that specifies a particular target virtual address VAx. At step 802, the MMU 28 initiates an address translation from the target virtual address VAx to the target physical address PAz based on the stage 1 mapping from VAx to the intermediate address IPAy and the stage 2 mapping from the intermediate address IPAy to the target physical address PAz (it is not necessary to perform two separate actions for the stage 1 and stage 2 translations, although this is an option, other examples may have a combined stage 1 and stage 2 TLB that may map directly from VAx to PAz for cached translations, but upon a miss in the TLB, by performing a Figure 6 The Phase 1 and Phase 2 traversals shown are used to identify new VA to PA mappings).
[0187] At step 804, the MMU 28 checks whether the stage 2 translation table entry (block or page descriptor) corresponding to IPAy indicates anti-aliasing properties. If so, then at step 806, the MMU checks whether all traversed stage 1 translation table entries meet the anti-aliasing condition. If a full translation table traversal corresponding to virtual address VAx is performed, then the traversed stage 1 translation table entry is the entry that will be accessed in the translation table traversal to locate the corresponding S1 translation table entry that specifies the S1 address mapping from VAx to IPAy (depending on what is already cached in the TLB 29, the current memory access may not actually require a traversal). For example, in Figure 6The traversed stage 1 translation table entries will be the entries labeled D_Table in the L0, L1, and L2 stage 1 page tables, and the entries labeled D_Page in the L3 stage 1 page table. The antialiasing condition is met for a given traversed stage 1 translation table entry when any of the following conditions are met:
[0188] a) the given traversed stage 1 translation table entry is designated as a protected entry, and the given traversed stage 1 translation table entry is stored at physical address PAj for which PRO permission or read-only permission is specified by the associated stage 2 translation table entry that provides the stage 2 address mapping used to derive PAj; or
[0189] b) Read-only permission is specified by the associated stage 2 translation table entry that provides the stage 2 address mapping used to derive the physical address PAj of the given traversed stage 1 translation table entry.
[0190] for Figure 6 For the specific example of , the relevant stage 2 translation table entry for the L1 stage 1 entry that derives the PA of the accessed page would be Figure 6 The stage 2L3 entry indicated as "D_Page" in Figure 6 For the other traversals of the stage 1 entries shown in , there will similarly be associated stage 2 L3 entries (or stage 2 L1 or L2 entries if a stage 2 block descriptor is found to correspond to IPAy) that should be marked with PRO or read-only permissions in order to satisfy the anti-aliasing condition (these are the entries at the end of each stage 2 translation traversal shown to obtain the physical address of the stage 1 translation table for each traversal).
[0191] If in Fig.16 If, at step 806, MMU 28 determines that any one or more of the traversed stage 1 translation table entries do not satisfy the antialiasing condition, the memory access is denied at step 808. A fault may be signaled, which may trigger an exception handler (e.g., executing at EL2) to perform error handling actions.
[0192] If all traversed stage 1 translation table entries meet the anti-aliasing condition, step 808 is omitted. In this case, at step 810, the MMU 28 also checks whether any other checks are met (e.g., any checks based on PRO permissions set for access to the memory region, protected entry checks whether the memory access request is issued in response to the RCW instruction, or any other specific checks for preventing other inappropriate accesses, such as checks based on secure / non-secure states in embodiments that support this). If any other checks are not met, the memory access is again denied at step 808 (the type of fault generated may depend on the reason for the access check failure). Otherwise, the memory access request is allowed to proceed at step 812.
[0193] Therefore, if Figure 6 As shown in , the anti-aliasing property can be set in the stage 2 translation table entry that provides the physical address mapping of the memory region being accessed (this can be a page descriptor or a block descriptor). If the anti-aliasing property is set, then for valid access to the corresponding memory location, this will require that all traversed stage 1 translation table entries on the path to the entry that provides the intermediate address mapping for the memory region be (a) marked as protected and the stage 2 entry that provides the physical address mapping of the region storing those traversed stage 1 translation table entries be assigned PRO permissions, or (b) be stored at a PA that is assigned read-only permissions by the stage 2 entry that provides the PA mapping for the PA. This means that an attacker cannot easily establish a new aliasing stage 1 address mapping to circumvent the protection applied to the trusted address mapping intended for accessing the corresponding region of memory. An attacker who can affect the behavior of operating system code at EL1 will not be able to control the stage 2 entries used to control memory access because this will be based on the base address in the VTTBR_EL2 register, which cannot be updated by code executed at EL1 (and therefore cannot cause PRO or read-only permissions to be set for the area storing the attacker's newly created aliased stage 1 address mapping). In addition, since the mechanism for code executed at EL1 to update stage 1 translation table entries can be to execute a RCW instruction of the protected entry check type discussed above (other instructions are prohibited from writing to the PRO area of memory), and this instruction cannot change the protected state of any translation table entry, the attacker cannot cause the stage 1 entry to become protected. In addition, the read-only area cannot be written by any write instruction. Therefore, any new entry that the attacker can create should not pass at least one of the anti-aliasing checks used to obtain whether the stage 1 entries of the VA-IPA mapping are protected and / or whether those entries are stored in the PRO or read-only area of memory.
[0194] Prevent inappropriate updates to the stage 1 top-level base address
[0195] Another attack that an attacker capable of affecting the behavior of operating system code executing at EL1 might attempt could be to modify the stage 1 top-level base address indicated by the base address register TTBR_EL1 (identifying the location in memory of the L0 stage 1 page table). For example, the attacker could substitute the addresses of a new set of stage 1 tables defined by the attacker in place of the addresses of the authorized page table structures that are correctly formed and behave correctly as verified by the hypervisor. Furthermore, the attacker could attempt to force the MMU 28 to use an existing authorized stage 1 page table in an unintended manner, such as by replacing the base address of one of the L1, 2, or 3 page tables in place of the correct L0 base address, such that a next level table pointer or address mapping for a different memory region may be incorrectly used for the memory region being accessed due to the table being accessed being used at the wrong level of the tree that is different than the expected level, such that different bits of the virtual address are used to select the relevant entry from the table.
[0196] Fig.17 Shown is a stage 1 top-level base address check, which can be performed to prevent these types of attacks. At step 1000, a page table walk is required for a memory access request that specifies a specific target virtual address (for a memory access request that does not require a page table walk, because the required address mapping is already available from the TLB, then when those address mappings are allocated to the cache after an earlier page table walk, any required stage 1 top-level base address check will have been completed, and therefore another check does not have to be implemented). At step 1002, the stage 1 top-level base address is determined based on the value in the stage 1 translation table base address register TTBR_EL1. The base address is designated as the intermediate address IPA_base. At step 1004, MMU 28 obtains information that is specified by the associated stage 2 translation table entry to provide a mapping from IPA_base to PA_base. For example, if already cached in the TLB, this information can be obtained from TLB 29, or this information can be obtained by performing a stage 2 translation table walk using the stage 2 base address specified in the stage 2 translation table base address register VTTBR_EL2.
[0197] At step 1006, the MMU 28 determines whether the stage 1 top-level table portion read-only check is enabled. For example, this can be determined based on a stage 1 top-level table portion read-only check enable control value stored in a control register (e.g., stage 2 translation control register VTCR_EL2, whose updates are restricted to code executed at exception level EL2 or higher). Alternatively, other specific implementations may consider the stage 1 top-level table portion read-only check to be permanently enabled. If the stage 1 top-level table portion read-only check is enabled, then at step 1008, the MMU 28 checks whether the associated stage 2 translation table entry specifies PRO permission, and if not, then at step 1010, the memory access is denied and a fault is signaled. This means that if an attacker attempts to modify the stage 1 translation table base address register TTBR_EL1 to point to a new L0 page table created by the attacker, access based on the modified base address will fail because the attacker will not be able to modify the PRO area of memory and must therefore write to the non-PRO area, so the stage 1 top-level table PRO check will fail.
[0198] If the stage 1 top-level table PRO check is disabled at step 1006, or is enabled but passes at step 1008, then at step 1012 the MMU 28 determines whether the stage 1 top-level table existence check is enabled. Again, this can be determined based on the stage 1 top-level table existence check enable control value stored in a control register (e.g., stage 2 translation control register VTCR_EL2). The enable control value used to determine whether to enable the check at step 1012 may be the same as the enable control value mentioned above for step 1006 (e.g., in some embodiments, the checks at steps 1008 and 1014 may be viewed as two steps of a single check that is enabled as a whole or disabled as a whole). If the stage 1 top-level table existence check is enabled, then at step 1014, the MMU 28 determines whether the associated stage 2 translation table entry specifies a stage 1 top-level entry existence permission 80. As described above with respect to Figure 8As mentioned, the stage 1 top-level entry presence permission may be encoded as an alternative variant of the PRO permission (so that a memory region with the stage 1 top-level entry presence permission is also assumed to have the PRO permission), or alternatively encoded as an independent attribute separate from the indication of whether the PRO permission is provided. If the associated stage 2 translation table entry does not specify the stage 1 top-level entry presence permission, then the memory access is again denied and a failure is signaled at step 1010. This can be used to prevent a valid and trusted L1, L2, or L3 table from replacing the L0 table by modifying the stage 1 top-level base address to point to an address of the L1, L2, or L3 table, because the stage 2 entry corresponding to the memory region used to hold the L1, L2, or L3 table can be defined as not having the stage 1 top-level entry presence permission. Memory regions used only to hold any valid and trusted stage 1 L0 table can be marked as having the stage 1 top-level entry presence permission in the corresponding stage 2 entry to limit which addresses can be used as the stage 1 L0 base address for valid memory accesses.
[0199] If the stage 1 top-level table existence check is disabled at step 1012, or is enabled but passes at step 1014, then at step 1016 the MMU performs any other checks required to access the memory region identified by the PA_base, and if those checks fail, the memory access is again denied at step 1010. If any other checks pass, then at step 1018 the stage 1 top-level base address IPA_base can be effectively used to perform a page table search. Thus, the address of the stage 1 top-level translation table entry is obtained by applying an index offset to the determined PA_base, where the index offset is determined based on a subset of the bits of the target VA to be translated. The page table traversal then continues as previously discussed.
[0200] Therefore, if Figure 6As shown, in intended use defined by software (and therefore not enforced as a requirement of hardware), in a stage 1 entry accessed on a page table walk, to obtain a PA map 64 for a memory region to which protection is desired, a stage 2 page / block descriptor identifying a storage location for a stage 1 L0 page table is provided that specifies PRO and stage 1 top-level presence permissions, and a stage 2 page / block descriptor identifying a storage location for a stage 1 L1, L2, or L3 page table is provided that specifies PRO permissions but does not specify stage 1 top-level presence permissions. This prevents the base address replacement attack described above. An alternative to avoiding the need to implement a base address check may be to trap any access to the stage 1 base address register TTBR_EL1 to a hypervisor executing at EL2, which may then check whether the update requested by the operating system code executing at EL1 is valid and reject the update if necessary. However, in practice, the operating system may frequently need to switch the address in the base address register TTBR_EL1 upon context switch, and thus trapping each update may be expensive in terms of performance. By implementing Fig.17 This can avoid the need for such a capture of the base address register update to TTBR_EL1 to improve performance.
[0201] In some examples, a single variant of the Stage 1 top-level presence license may be supported, in which case Fig.17 The check at step 1014 may simply be a check whether a stage 1 top level permission exists that has been specified.
[0202] Other examples may support multiple variants of the stage 1 top-level presence permission to allow finer control over the address in the memory region to which a particular stage 1 translation table base register may specify a corresponding address. For example, some implementations may support two stage 1 base address registers:
[0203] TTBR0_EL1, when the most significant bits of a configurable number (N) of virtual addresses to be translated are all set to 0 (N can be defined in the control value specified in the control register)
[0204] , is selected for Phase 1 conversion in EL0 or EL1; and
[0205] - TTBR1_EL1, selected for stage 1 translation in EL0 or EL1 when any of the N most significant bits of the virtual address to be translated is not zero.
[0206] Several variations of the Stage 1 top-level existence permission can then be defined, including:
[0207] ● Toplevel0: indicates a memory area that allows for top-level translation tables accessed via TTBR0_EL1 instead of top-level translation tables accessed via TTBR1_EL1;
[0208] ● Toplevel1: indicates a memory area that allows for the top-level translation table accessed via TTBR1_EL1 instead of the top-level translation table accessed via TTBR0_EL1;
[0209] ●Toplevel01: Indicates the memory area allowed for the top-level translation table accessed via TTBR0_EL1 or TTBR1_EL1.
[0210] In this case, a specific implementation of the check at step 1014 may be such that if any of the following conditions are met: Fig.17 The fault is signaled at step 1010:
[0211] ●TTBR0_EL1 is used to provide a base address for a corresponding memory region that does not have Toplevel0 or Toplevel01 permissions; or
[0212] ●TTBR1_EL1 is used to provide a base address for a corresponding memory region that does not have Toplevel1 or Toplevel01 permissions.
[0213] In some implementations, additional controls set in control registers controlled by software at EL2 may control whether TTBR0_EL1 is prohibited from giving access to Toplevel1 pages, and whether TTBR1_EL1 is prohibited from giving access to Toplevel0 pages. In this case, the check at step 1014 may cause a fault to be signaled at step 1010 if any of the following conditions are met:
[0214] TTBR0_EL1 is used to provide a base address for which the corresponding memory region has no Toplevel01 permission or has Toplevel1 permission when the TTBR0 / Toplevel1 fault enable control is set so that a fault can be triggered when a Toplevel1 page is accessed using TTBR0_EL1; or
[0215] ●TTBR1_EL1 is used to provide a base address for which the corresponding memory region has no Toplevel01 permission or has Toplevel0 permission when the TTBR1 / Toplevel0 fault enable control is set so that a fault can be triggered when accessing a Toplevel0 page using TTBR1_EL1.
[0216] These features allow finer-grained control over the memory address regions that can be used to provide the top-level stage 1 translation tables, but enable controls allow these finer-grained checks to be disabled if it is deemed acceptable that any top-level page can be used to provide the base address for both TTBR0 and TTBR1.
[0217] In some implementations, the encodings of the various top-level presence permissions Toplevel0, Toplevel1, Toplevel01 may be combined with the encodings of the PRO permission, such that these are considered to be Toplevel0 PRO permissions, Toplevel1 PRO permissions, and Toplevel01 PRO permissions. In such implementations, it would not be possible to define a Toplevel0, Toplevel1, or Toplevel01 memory region as not having PRO permissions. However, a PRO region may be defined as not having any Toplevel0, Toplevel1, or Toplevel01 permissions, since there is a separate PRO permission encoding that is not considered to have any stage 1 top-level table presence permissions.
[0218] exist Figure 8 In the example of , PRO permissions and S1 top-level entry presence permissions are shown as specified in S2 permissions field 68, which is directly specified as part of the encoding of the stage 2 translation table entry itself. Similarly, the stage 1 translation table entry is shown as encoding the stage 1 permissions directly in field 66 of the entry itself.
[0219] However, if Fig.18 As shown, the license information may also be indirectly specified by the stage 2 conversion table entry in the license indirect register. In this case, the stage 2 conversion table entry can specify a field identifier, which field of the license indirect register identifies the stage 2 license for the entry, and the reference field of the license indirect register is encoded to indicate the license type. The method can be used for, for example, PRO license 74, S1 top-level entry existence license 80, anti-aliasing properties 79 described above, or GCS attributes described below. The indirect license specification using registers can be used to allow software to quickly update the licenses for many conversion table entries that all reference the same license field by a single update to the register field, without the need to update many different conversion table entries in the memory. In addition, in the specific implementation where each field of the license indirect register has more bits than the corresponding license field of the conversion table entry, it can indirectly help support more license types than the limited encoding space of the license in the entry that may support.
[0220] Guarded control stack to prevent return-oriented programming attacks
[0221] Fig.19An example of calling a function (labeled fn1 for ease of reference) and returning from the function is shown. A function (also called a procedure) is a sequence of instructions that can be called from another part of a program and when completed returns processing to the part of the program flow from which the function was called. The same function can be called from multiple different locations in a program, and therefore the function return address is stored when the function is called so that the function return can distinguish which address the program flow should be returned to.
[0222] For example, Fig.19 As shown, the branch with link instruction BLR can be executed when a function is about to be called to cause the program flow to branch to the instruction at the branch target address specified by the operand of the branch with link instruction. The branch with link instruction also causes the processing circuit to set the link register (a designated register for tracking the return address of the function) to the address of the next instruction after the branch with link instruction. After the branch has been made, multiple instructions (e.g., LD, MUL, ADD, etc.) are executed within the function code, and a return branch instruction RET is executed when the function is completed, which causes the instruction indicated by the return address stored in the link register to be branched.
[0223] If no other functions are called from within fn1, and no exception occurs before the return branch at the end of fn1 is reached, the address in the link register should still be the same as it was set when fn1 was called.
[0224] However, the first function fn1, which is usually called by the background code, may itself call another function (e.g., fn2) in a nested manner, and in this case, the function call to fn2 will overwrite the return address stored in the link register, and therefore before calling the other function, the function code of the first function fn1 should include instructions for saving the return address from the link register to a data structure in memory (e.g., a stack structure operating in a last-in-first-out (LIFO) manner), and after returning from fn2, the function code of fn1 should restore the return address to the link register before executing the return branch. The responsibility for saving and restoring function return states (such as return addresses) usually lies with software (there may be no architecturally implemented hardware mechanism for saving return addresses).
[0225] However, when the function return address is stored in memory, it may be vulnerable to an attacker modifying that data, for example using another thread executing on another processor core, or by interrupting the called function and concurrently executing other code that overwrites the return address stored in memory. Alternatively, an attacker may execute some instructions designed to modify the address operand of the instruction that restores the return address from memory to a register so that the data loaded from memory is different from the return address that was originally saved to memory before calling the nested function. If an attacker can cause the return branch to branch to a point in the program flow other than the instruction after the function call branch ( Fig.19 #add1+4 in the example), the attacker may be able to cause the software to behave incorrectly and may be able to circumvent certain security protections or cause undesired operations to be performed.
[0226] Function call is an example of an operation that generates return status information, and this return status information provides information about the state that the processing circuit will restore to later.Another scenario that can capture return status information can be when an exception occurs, at this time, the exception handling circuit or software exception handler provided in the hardware can capture exception return status information, such as indicating the exception return address of the address of the instruction to be executed after returning from the handling exception, and / or indicating the processor state information of the mode or execution state that the processor will execute after returning from the exception.For example, the processor state information saved can indicate which exception level in the exception level EL0-EL3 the exception occurs, and other information about the operating state of the processor when the exception occurs.As with function call, exception can be nested, and therefore the exception return state captured for an exception can be saved to memory (automatically saved in hardware, or saved by software exception handler) when another exception occurs, and therefore it may be easily tampered by attackers when it is stored in memory.These types of attacks can be referred to as return-oriented programming (ROP) attacks.It is desirable to provide an architectural countermeasure for such attacks.
[0227] Fig. 20 and Fig.21 A method for preventing ROP attacks using a protected data structure in memory called a "Guard Control Stack" (GCS) is shown. The location of the GCS data structure within the memory address space is selectable by software, but the hardware provides a number of architectural features designed to protect the GCS data structure from tampering by a malicious attacker, including by an operating system (operating at exception level EL1) that has been compromised by the attacker.
[0228] like Fig. 20As shown, registers 14 include control registers 1050, which may include one or more registers that specify (among other parameters) a GCS enable parameter 1052 for specifying whether the GCS mode is enabled or disabled and a stage 1 GCS hardening check enable control parameter 1054, which controls (when the GCS mode is enabled) whether a GCS memory access request is subject to a check as to whether the anti-aliasing property 79 discussed above is set for a memory region accessed by the GCS memory access request. Registers 14 also include one or more guard control stack pointer (GCS pointer) registers 1056, which are used to store a stack pointer indicating an address on a GCS data structure. In some examples, the GCS pointer register 1056 may be a set of grouped registers provided separately for at least two of the execution states (exceptions levels EL0-EL3) to enable software operating in different execution states to reference different GCS structures within the memory without having to reprogram a shared stack pointer register after each transition of the execution state. Other examples may use a single GCS pointer register, and software may update the stack pointer stored in the GCS pointer register 1054 when transitioning between execution states. Fig. 20 Not shown, the GCS enablement parameter 1052 and the stage 1 GCS hardening check enablement control parameter 1054 may also be specified separately for two or more different execution states.
[0229] like Fig.21 As shown, GCS data structure 1058 is stored in a memory region designated as a GCS region of memory (by the stage 1 permissions 66 specified by the corresponding stage 1 address translation table entry). The GCS region permissions may be specified directly within the encoding of the corresponding stage 1 address translation table entry, or may be referenced indirectly within the permissions indirect register, such as Fig.18 As shown. When a memory region is identified as a GCS region, then write access to the region is restricted to write requests triggered by the processing circuit 4 when a certain subset of GCS access instructions are executed. General storage instructions used by software for general storage operations that are not intended to access GCS structures are not considered to be one of the restricted subset of GCS access instructions. The MMU 28 may still allow the use of general load instructions to read GCS structures, which general load instructions cause read requests that are not GCS memory access requests to be issued. When a memory access request is requesting access to a GCS region, the request is a write request, and the request is not a GCS memory access request triggered by one of the restricted subset of GCS access instructions, then the memory access request is denied and a fault is signaled.
[0230] like Fig.21As shown, a subset of GCS access instructions may include at least a GCS push instruction that causes return state information (such as a function return address from a link register, or an exception return address or a saved processor state captured when an exception occurs) to be pushed to a location on a GCS structure determined using a stack pointer corresponding to the current execution state ELx indicated in GCS pointer register 1056. The GCS access instructions also include at least one form of a GCS pop instruction that pops protected return information from a GCS structure.
[0231] The GCS structure is separate from any data structure used by software to maintain saved return state information in memory to handle nesting of function calls or exceptions. Thus, the GCS structure is not intended to eliminate the need for software itself to track the saving and restoration of return state information when function calls or exceptions are nested (software-triggered saving of return state can continue in the same manner as on processors that do not support the architectural measures for GCS protection discussed above). Instead, the GCS structure provides an area of protected memory that is protected from tampering by compromised code operating at exception levels EL0 or EL1, which can be used to provide information for verifying return state information intended to be used by software to return from the handling of function calls or exceptions.
[0232] Thus, in some implementations, a GCS pop instruction that causes protected return state information to be popped from the GCS structure may also cause processing circuitry 4 to compare the popped return state with current return state information stored in a register (e.g., a link register for a function return, or an exception return address register and / or a saved processor state register for an exception return), and signal a fault if there is a mismatch between the return state information popped from GCS structure 1058 and the expected return state information intended by the software for a function / exception return. Thus, software may be protected from tampering by including instances of GCS push instructions and GCS pop instructions within program code that will be executed around a function call / return or exception entry / return.
[0233] Other implementations may define separate instructions for verifying that the expected return status information is valid, separate from the instructions for popping the return status information from GCS structure 1058.
[0234] Alternatively, a GCS pop instruction may pop the protected return state from the GCS directly into one or more registers of the return state for specifying an exception return or function return (or may be combined with an exception / function return instruction to pop the protected return state and use that state to control the exception / function return), in which case it is not necessary to perform the step of verifying that the expected return state information provided by the software is valid, since in this specific implementation, the GCS protected return state is used directly to control the exception / function return.
[0235] Additionally, other types of GCS access instructions may also be supported.Some instructions having other functions when GCS mode is disabled using GCS enable control parameter 1052 may cause processing circuitry 4 to perform additional functions (such as additional GCS mode specific security checks) when executed when GCS mode is enabled.
[0236] In general, by providing architectural support for defining GCS memory region types for use by GCS structure 1058, and restricting write access to GCS region types to a limited subset of GCS access instructions (which may not be allowed to access memory regions other than GCS region types), this reduces the attack surface available to attackers attempting to tamper with protected return status information stored on GCS structure 1058.
[0237] However, because the stage 1 permissions associated with the stage 1 translation table entry corresponding to the region storing GCS structure 1058 are used to specify properties that indicate the region is a GCS region, a compromised operating system may attempt to modify the stage 1 translation table entry to remove the GCS permission type, or define Fig.15 to allow access to the same region of physical memory using different stage 1 translation table entries that do not specify a GCS permission type.
[0238] To prevent such attacks, the previously described translation hardening mechanism may be used to protect the stage 1 translation table entries that specify the GCS region for storing the GCS data structure 1058. Thus, the stage 1 translation table entries that specify the GCS region type may be protected from tampering by storing the stage 1 translation table entries in a read-only region or a partially read-only region specified by stage 2 permission information, which is specified (directly or indirectly) by the corresponding stage 2 translation table entry of the memory region for storing the stage 1 translation table entries. Note that the read-only or partially read-only region type should not be specified in the stage 2 permissions of the stage 2 entry corresponding to the GCS region itself, because pushing the return status information to the GCS region will require writing the data to the GCS region. In addition, if protected entry encoding is supported as discussed above, the stage 1 translation table entry corresponding to the GCS region may also be indicated as a protected entry to protect it from being modified by a protected entry check type RCW instruction executed at EL1 as previously discussed. Additionally, anti-aliasing properties 79 may be specified for stage 2 translation table entries corresponding to GCS regions to enforce that the stage 1 translation table entries that will be used for all traversals of address mappings for GCS regions must be hardened stage 1 translation table entries stored in a read-only or partially read-only area of memory (and, if the stage 1 translation table entries support protected entry encoding and the translation table entries are stored in a partially read-only area, they also need to be encoded as protected entries). These mechanisms mean that attempts to modify the stage 1 translation table entry to remove the GCS region designation or to circumvent the entry using an aliased stage 1 translation table entry will fail.
[0239] In order to ensure that the stage 1 translations corresponding to the GCS region are protected using the above-described translation hardening mechanism, and thus give confidence that an attacker who provides an aliased stage 1 translation entry does not make a GCS access to an alternative GCS structure that replaces the intended GCS structure, when the stage 1 GCS translation hardening enable parameter 1054 is set to an enabled state and the GCS mode is enabled by the GCS enable parameter 1052, if the stage 2 translation table entry corresponding to the target memory region attempted to be accessed by the GCS memory access does not specify the anti-aliasing property 79, then the GCS memory access (including both read access and write access) is denied (and thus causes a fault). This ensures that the protection that will cause a fault to be generated is appropriate if any access to the GCS region is attempted using an unhardened stage 1 translation table entry that is neither (a) stored in an area designated as read-only by a stage 2 translation table entry, nor (b) stored in an area designated as partially read-only by a stage 2 translation table entry, and (in a specific implementation that supports encoding of protected entries) is encoded as an unprotected entry. The need to check anti-aliasing properties 79 in response to GCS memory accesses may be disabled by setting the stage 1 GCS transition hardening enable parameter 1054 to a disabled state (this may be useful for legacy code written for systems that do not support anti-aliasing properties 79 or transition hardening mechanisms).
[0240] The enable control values 1052 , 1054 for controlling the operation of the GCS mode may be restricted to being updated by instructions executed in execution levels EL2 or EL3 to prevent update by an operating system at EL1 or an application at EL0 .
[0241] Fig. 221 is a flow chart showing the processing of a GCS return status push instruction, which may be a GCS specific instruction dedicated to pushing a return status to the GCS, or may be a reused function call branch instruction (with link branch instruction) that also acts as a GCS return status push instruction when executed in the GCS mode. At step 1100, when the GCS mode is indicated as enabled by the GCS enable parameter 1052, the instruction decoding circuit 10 decodes the return status push instruction. If the GCS mode is indicated as disabled, this type of instruction may be regarded as an undefined instruction and may therefore cause a fault, or may be regarded as a no-operation (NOP) instruction that has no architectural effect but does not cause a fault. Assuming that the GCS mode is enabled, in response to the GCS return status push instruction, the instruction decoding circuit 10 controls the execution stage 16 of the processing circuit 4 to obtain the return status information based on information in a register (e.g., a link register for storing a function return address, or an exception return status register for storing exception return information such as an exception return address and a saved processor state (e.g., a mode / execution state indication value)). At step 1104, the load / store unit 26 of the processing circuit 4 issues one or more GCS memory access requests to push the return status information obtained at step 1102 to a location on the guard control stack determined based on the GCS pointer for the current execution state (ELx) stored in the GCS pointer register 1056, and the processing circuit 4 updates the GCS pointer register 1056 to update the stack pointer, thereby advancing the stack pointer to the next location on the stack. Any known stack pointer update mechanism may be used (e.g., the stack may be an incrementing or decrementing stack, and the stack pointer may point to the next location to which information is to be pushed, or to the last location to which information was pushed).
[0242] Fig.2311 is a flow chart illustrating the processing of a GCS return status pop instruction, which in this example also serves as a return status verification instruction, which is decoded at step 1120 when the GCS mode is enabled. The GCS return status pop instruction may be a GCS specific instruction dedicated to popping the return status to the GCS, or may be a reused exception return instruction that also serves as a GCS return status pop instruction when executed in the GCS mode. Similarly, if the GCS mode is disabled, the instruction may be treated as an undefined instruction or a NOP instruction. In response to decoding the GCS return status pop instruction, at step 1122, the instruction decoder 10 controls the execution stage 16 (load / store unit 26) of the processing circuit 4 to issue one or more GCS memory access requests to pop the return status information from a location on the protection control stack determined based on the stack pointer for the current execution state ELx stored in the GCS pointer register 1056, and the processing circuit 4 updates the stack pointer to take into account the pop operation.
[0243] At step 1124, processing circuitry 4 obtains current return state information based on information in a return status register (e.g., a link register or an exception return status register as described above). At step 1126, processing circuitry 4 compares the current return state information with the popped return state information obtained from GCS data structure 1058 at step 1122, and determines whether the compared states match. If a mismatch is detected between the current return state information and the popped (GCS-protected) return state information, then a fault condition is signaled at step 1128, as a mismatched return state may be a sign that a ROP attack has been attempted. If the current return state matches the popped return state obtained from GCS structure 1058, then at step 1130, the software is allowed to proceed with the return from the function / exception. Note that the return state may be returned to the GCS structure 1058 by executing a separate instruction (such as an exception return instruction or a GCS protected return state instruction). Fig.19 ) to trigger a function return or exception return, so this does not need to be triggered directly by the GCS pop / return status verification instruction.
[0244] Although Fig.23A combined instruction for popping return status information from the GCS and verifying the current return status against the popped return status is shown, but these operations may also be separated into separate instructions (one instruction for popping the return status from the GCS, and a second instruction for verifying the popped return status against the current return status). In addition, a separate GCS pop instruction may be provided to allow the return status information to be removed from the GCS structure 1058 in scenarios where the corresponding function / exception return is no longer needed. In addition, if the GCS return status pop instruction directly controls the function / exception return status for a function / exception return (because the GCS return status pop instruction is combined with the exception return instruction, as described above, or because the GCS return status pop instruction pops the GCS protected return status directly into a register used to provide a return status for controlling a function / exception return), then the verification steps 1126, 1128 may not need to be performed.
[0245] Fig.24 1 is a flow chart illustrating an access permission check performed by the MMU 28 for memory accesses issued when the GCS mode is enabled by the GCS enable parameter 1052. At step 1200, a memory access request is issued that specifies a target virtual address corresponding to a target memory region. The memory access request may be issued by Fig. 22 and Fig.23 1204. The MMU 28 may be a GCS memory access request triggered by one of the GCS push / pop instructions shown in FIG. 1205 (or by another type of GCS access instruction), or may be another type of memory access request not triggered by an instruction of the GCS access type. At step 1202, the MMU 28 initiates an address translation based on the relevant stage 1 and stage 2 address mappings defined in the stage 1 and stage 2 address translation structures. At step 1203, the MMU 28 determines whether the stage 1 permission information directly or indirectly specified by the target stage 1 translation table entry that provides an address mapping for the target virtual address specifies that the target memory region is a GCS region.
[0246] If the target memory region is a GCS region, then at step 1204, the MMU 28 determines whether the memory access request is a GCS memory access request triggered by one of the restricted subset of instructions of the GCS access type. If not, then at step 1205, the MMU 28 determines whether the memory access request is a write request. If the memory access request is a write request, then at step 1206, a fault is signaled to prevent other general storage instruction types from being able to write to the GCS structure 1058 stored in the GCS region.
[0247] If the memory access request is a GCS memory access request or a read request, then at step 1208, the MMU 28 determines whether the stage 1 GCS hardening check enable parameter 1054 indicates that the stage 1 GCS hardening mode is enabled. When the stage 1 GCS hardening mode is enabled, then at step 1210, an additional check is performed on the GCS memory access request to check whether the anti-aliasing property 79 is specified for the target memory region by the stage 2 translation table entry corresponding to the target memory region. If the anti-aliasing property 79 is not specified for the target memory region, a fault is again signaled at step 1206.
[0248] If it is determined at step 1208 that the stage 1 GCS hardened mode is disabled, or at step 1210 that the target memory region does have the anti-aliasing property 79 defined in the corresponding stage 2 translation table entry, then at step 1212, the MMU 28 determines whether the memory access request satisfies any other access permissions. For example, this may be based on other parameters specified in the stage 1 or stage 2 translation table entry corresponding to the target region, or other security conditions, such as based on the security state, exception level, or other operating mode of the processing circuit 4. If no other access permissions are satisfied, then a fault is signaled again at step 1206. If all other access permissions are satisfied, then the memory access request may be allowed at step 1214.
[0249] If the MMU 28 determines at step 1203 that the target memory region is not a GCS region, then at step 1220, the MMU 28 determines whether the memory access request is a GCS memory access request triggered by one of a restricted subset of instructions of the GCS access type. This is the same check as the check performed at step 1204, but has a different result compared to step 1204. At step 1220, if the memory access request is a GCS memory access request, a fault is signaled at step 1206 (which can be triggered for both read requests and write requests). This ensures that GCS memory access requests cannot be used to access non-GCS regions of memory, which will avoid inducing software developers to use GCS access type instructions for non-GCS access (which will increase the attack surface available to attackers), and allows attacks to be detected based on the address operands of GCS access type instructions that are being modified by an attacker to point to an area other than GCS. Security can be improved by restricting instructions of the GCS access type to access GCS regions and restricting instructions of the non-GCS access type to access non-GCS regions.
[0250] If it is determined at step 1220 that the memory access request is not a GCS memory access request, then at step 1222, the MMU 28 determines whether the memory access request satisfies any other access permissions. For example, this may include checks based on security state, exception level, or operating mode as discussed above, and may also include checks based on the previously mentioned partial read-only region type or anti-aliasing properties 79. In addition, if the memory access request is triggered by an RCW instruction of the previously mentioned protected entry check type, whether access is allowed may also depend on a check of old data read from the target location corresponding to the target VA. If all required access conditions are met, the memory access request is allowed at step 1224. If any access permissions are violated, a fault is signaled at step 1206.
[0251] Although Fig.24 A single step 1206 is shown for signaling a fault in response to multiple different check failures, but it is understood that some implementations may signal different fault types depending on the cause of the fault.
[0252] In addition, although Fig.24 An example is shown in which no fault is required when a non-GCS read request targets a GCS region, but other examples may omit step 1205 and may proceed from step 1204 to step 1206, thereby signaling a fault when a memory access request targeting a GCS region of memory is not a GCS memory access request, regardless of whether the memory access request is a read request or a write request.
[0253] In the case where GCS mode is currently disabled using GCS enable parameter 1052, then GCS access instructions may trigger a fault (e.g., an undefined instruction fault) or be treated as a no operation (NOP) instruction. In addition, memory access requests other than GCS access requests may cause execution Fig.24 The checks shown at step 1212 or 1222 may be omitted, but when the GCS mode is disabled, the checks at steps 1203, 1204, 1208, 1210 and 1220 may be omitted.
[0254] Fig.25A simulator that can be used is shown as being implemented. Although the previously described embodiments implement the present invention in terms of the apparatus and method for operating the specific processing hardware supporting the technology involved, an instruction execution environment according to the embodiments described herein can also be provided, which is implemented by using a computer program. Such computer programs are generally referred to as simulators, to a certain extent because such computer programs provide a software-based implementation of the hardware architecture. The types of simulator computer programs include emulators, virtual machines, models, and binary converters, which include dynamic binary converters. Typically, the simulator is implemented to run on a host processor 1330 that supports the simulator program 1310, optionally running a host operating system 1320. In some arrangements, multiple simulation layers may exist between the hardware and the provided instruction execution environment and / or multiple different instruction execution environments provided on the same host processor. Historically, powerful processors were required to provide a simulator that was executed at a reasonable speed, but this approach may be reasonable in certain circumstances, such as when it is desired to run another processor local code for compatibility or reuse reasons. For example, the simulator implementation may provide additional functionality that is not supported by the host processor hardware to the instruction execution environment, or provide an instruction execution environment that is generally associated with different hardware architectures. An overview of simulation is given in: "Some Efficient Architecture Simulation Techniques", Robert Bedichek, Winter 1990 USENIX Conference, pp. 53-63.
[0255] To the extent that embodiments have been previously described with reference to specific hardware constructs or features, in simulated embodiments, equivalent functionality may be provided by suitable software constructs or features. For example, specific circuits may be implemented as computer program logic in simulated embodiments. Similarly, memory hardware such as registers or cache memory may be implemented as software data structures in simulated embodiments. One or more of the hardware elements referenced in the previously described embodiments are present in an arrangement on host hardware (e.g., host processor 1330), and some simulated embodiments may utilize host hardware where appropriate.
[0256] The simulator program 1310 may be stored on a computer-readable storage medium (which may be a non-transitory medium) and provide a program interface (instruction execution environment) to the target code 1300 (which may include applications, operating systems, and hypervisors), which is the same as the interface of the hardware architecture modeled by the simulator program 1310. Therefore, the program instructions of the target code 1300 (including the above-mentioned protected entry check RCW instructions and GCS access instructions) can be executed from within the instruction execution environment using the simulator program 1310, so that the host computer 1330 that does not actually have the hardware features of the above-mentioned device 2 can simulate these features. Similarly, the memory management program logic 1318 of the simulator program 1310 can be used to simulate the various memory management check functions described above, including support for PRO region types, anti-aliasing properties, and GCS memory region types.
[0257] Therefore, the simulator program 1310 may have a handler logic 1312 that simulates the state of the processing circuit 4 described above. For example, the handler logic 1312 may control the transition of the execution state EL0-EL3 in response to events occurring during the simulated execution of the target code 1300. The instruction decoding program logic 1314 decodes the instructions of the target code 1300 and maps these instructions to corresponding instruction sets in the native instruction set of the host device 1330. The register emulation program logic 1316 maps the register access requested by the target code to the access to the corresponding data structure maintained on the host hardware of the host device 1330, such as by accessing the register of the host device 1330 or the data in the memory 1332. The memory management program logic 1318 implements address translation, page table traversal and access control checking in a manner corresponding to the MMU 28 described in the above hardware implementation embodiment, but also has the additional function of mapping the simulated physical address obtained by the stage 2 mapping in the address translation based on the page table defined for the target code 1300 to the host virtual address for accessing the host memory 1332. These host virtual addresses themselves can be converted to host physical addresses using standard address translation mechanisms supported by the host (the conversion of host virtual addresses to host physical addresses is outside the scope of control by the simulator program 1310).
[0258] In this application, the words "configured to..." are used to mean that elements of a device have a configuration that enables the performance of a defined operation. In this context, "configuration" means the arrangement or manner of interconnection of hardware or software. For example, the device may have dedicated hardware that provides the defined operation, or a processor or other processing device may be programmed to perform the function. "Configured to" does not mean that the device elements need to be changed in any way in order to provide the defined operation.
[0259] Although exemplary embodiments of the present invention have been described in detail herein with reference to the accompanying drawings, it should be understood that the invention is not limited to those precise embodiments and that various changes and modifications may be effected therein by those skilled in the art without departing from the scope of the invention as defined in the appended claims.
Claims
1. A device, comprising: processing circuitry for executing instructions in one of a plurality of execution states; and memory management circuitry for, in response to a memory access request specifying a target virtual address corresponding to a target memory region to be accessed, translating the target virtual address into a target physical address, wherein a mapping from the target virtual address to the target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure accessible using a stage 1 base address settable by an instruction executable by the processing circuitry in a first execution state; wherein: At least when the memory access request is a write request, the memory management circuit is configured to deny the memory access request in response to determining that the following two conditions are satisfied: the stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is a guard control stack (GCS) region for storing a GCS data structure, the GCS data structure being used to protect return status information returned from a function call or an exception; and The memory access request is a request other than a GCS memory access request triggered by one of a restricted subset of instructions of a GCS access type; the memory management circuitry being configured to support a translation hardening mechanism for defining at least one hardened stage 1 translation table entry based at least on translation hardening information that can be set by instructions executed by the processing circuitry in a second execution state having a higher privilege than the first execution state, the at least one hardened stage 1 translation table entry being protected by the translation hardening mechanism from tampering by instructions executed in the first execution state; When anti-aliasing properties are specified for the target memory region, the memory management circuitry is configured to deny the memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism; and In at least one operating state of the processing circuitry, the memory management circuitry is configured to deny the memory access request in response to determining that the memory access request is the GCS memory access request and the anti-aliasing property is not specified for the target memory region.
2. An apparatus according to claim 1, wherein the memory management circuit is configured to support two-stage address translation, wherein the stage 1 address mapping includes a mapping from the target virtual address to a target intermediate address, and the address mapping from the target virtual address to the target physical address is also dependent on a stage 2 address mapping from the target intermediate address to the target physical address specified for the target intermediate address by a target stage 2 translation table entry in a stage 2 translation table structure, the stage 2 translation table structure being accessible using a stage 2 base address set by an instruction executable by the processing circuitry in the second execution state.
3. The apparatus of claim 2, wherein the target stage 2 translation table entry specifies whether the anti-aliasing property is specified for the target memory region.
4. The device according to any one of claims 2 and 3, wherein: For a given stage 1 translation table entry stored at a given memory region corresponding to a given intermediate address, the translation hardening information for specifying whether the given stage 1 translation table entry is a hardened stage 1 translation table entry includes stage 2 permission information specified by a corresponding stage 2 translation table entry corresponding to the given intermediate address.
5. The apparatus of claim 4 , wherein each hardened stage 1 translation table entry comprises a stage 1 translation table entry for which the given memory region storing the stage 1 translation table entry is indicated by the stage 2 permission information of the corresponding stage 2 translation table entry as one of: prohibiting writing to the requested read-only memory area; and A partial read-only memory area, for which write requests to the partial read-only memory area are allowed for a restricted subset of write request types and are prohibited for write request types other than the restricted subset, and the restricted subset of write request types at least includes a metadata update write request generated by the memory management circuit to update access tracking metadata in a translation table entry. 6 . The apparatus according to claim 5 , wherein the phase 2 permission information has a code for indicating both the read-only memory area and the partial read-only memory area.
7. The apparatus of claim 4, wherein the stage 2 permission information specifies whether the given memory region is a partial read-only memory region for which write requests to the partial read-only memory region are allowed for a restricted subset of write request types and are prohibited for write request types other than the restricted subset, the restricted subset of write request types comprising at least a metadata update write request generated by the memory management circuitry to update access tracking metadata in a translation table entry; The memory management circuitry is configured to support each stage 1 translation table entry of the first translation table structure having an encoding that specifies whether the stage 1 translation table entry is a protected entry whose updates are restricted compared to an unprotected stage 1 translation table entry that is not designated as a protected entry, the restricted subset of write request types including write request types for which at least a subset of bits are permitted to update the unprotected stage 1 translation table entries but are prohibited from updating the protected stage 1 translation table entries.
8. The apparatus of claim 7, the apparatus comprising protected entry check circuitry, the protected entry check circuitry responsive to the processing circuitry executing a read check write instruction of a protected entry check type for requesting an update to a given memory system location: reading data from said given memory system location, checking whether the data read from the given memory system location has a value consistent with a stage 1 translation table entry designated as a protected entry, and responsive to determining that the data read from the given memory system location has a value consistent with a stage 1 translation table entry designated as a protected entry, preventing a subset of update restricted bits of the stage 1 translation table entry from being updated in response to the read check write instruction; The restricted subset of write request types includes write requests issued in response to read-check-write instructions of the protected entry check type.
9. An apparatus according to any one of claims 7 and 8, wherein the translation hardening information includes information indicating whether a given stage 1 translation table entry is designated as the protected entry, and the memory management circuit is configured to treat an unprotected stage 1 translation table entry as an unhardened stage 1 translation table entry when the stage 2 permission information specified by the corresponding stage 2 translation table entry specifies that the given memory region is the partial read-only memory region.
10. The apparatus of any one of claims 7 to 9, wherein each hardened stage 1 translation table entry comprises one of the following: a stage 1 translation table entry for which the given memory region is indicated by the stage 2 permission information as a read-only memory region to which write requests are prohibited; and A stage 1 translation table entry designated as a protected entry, for which the given memory region is indicated by the stage 2 permission information as being the partial read-only memory region.
11. An apparatus according to any preceding claim, wherein the at least one operating state of the processing circuit comprises an operating state in which a GCS transition hardening check enable control parameter is set to an enabled state, the enabled state indicating that a GCS memory access request is to be subject to a check on whether the anti-aliasing property is specified for the target memory region.
12. An apparatus according to any preceding claim, wherein the memory management circuit is configured to deny the memory access request in response to determining that the memory access request is the GCS memory access request and the stage 1 permission information does not specify that the memory region corresponding to the target virtual address is the GCS region.
13. An apparatus according to any preceding claim, wherein the restricted subset of instructions of the GCS access type includes a return status push instruction, the return status push instruction being used to control the processing circuit to push return status information obtained based on information indicated in one or more registers of the processing circuit to the GCS data structure.
14. Apparatus according to any preceding claim, wherein the restricted subset of GCS access type instructions comprises a return status pop instruction for controlling the processing circuitry to pop return status information from the GCS data structure.
15. An apparatus as claimed in any preceding claim, comprising at least one GCS pointer register for storing a stack pointer indicating an address of the guard control stack data structure.
16. Apparatus according to any preceding claim, wherein the stage 1 permission information specifying whether the target memory region is the GCS region is specified in a field of a permissions indirect register referenced by the target stage 1 translation table entry.
17. A method comprising: executing instructions in one of a plurality of execution states; as well as responsive to a memory access request specifying a target virtual address corresponding to a target memory region to be accessed, translating the target virtual address into a target physical address, wherein a mapping from the target virtual address to the target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure accessible using a stage 1 base address set by an instruction executable by the processing circuitry in a first execution state; wherein: At least when the memory access request is a write request, the memory access request is denied in response to determining that the following two conditions are satisfied: the stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is a guard control stack (GCS) region for storing a GCS data structure, the GCS data structure being used to protect return status information returned from a function call or an exception; and The memory access request is a request other than a GCS memory access request triggered by one of a restricted subset of instructions of a GCS access type; a translation hardening mechanism supported for defining at least one hardened stage 1 translation table entry based at least on translation hardening information capable of being set by instructions executed in a second execution state having a higher privilege than the first execution state, the at least one hardened stage 1 translation table entry being protected by the translation hardening mechanism from tampering by instructions executed in the first execution state; and The method comprises: When antialiasing properties are specified for the target memory region, denying the memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism; and In at least one operational state of the processing circuitry, the memory access request is denied in response to determining that the memory access request is the GCS memory access request and the anti-aliasing property is not specified for the target memory region.
18. A computer program, the computer program comprising instructions, which when executed by a host data processing device, control the host data processing device to provide an instruction execution environment for executing a target code, the computer program comprising: Processor logic for simulating execution of instructions of the target code in one of a plurality of execution states; and memory manager logic to, in response to a memory access request specifying a target virtual address corresponding to a target memory region to be accessed, translate the target virtual address into an emulated target physical address, wherein a mapping from the target virtual address to the emulated target physical address depends at least on a stage 1 address mapping specified for the target virtual address by a target stage 1 translation table entry in a stage 1 translation table structure accessible using a stage 1 base address that can be set by the emulated instruction to be executed in a first execution state; wherein: At least when the memory access request is a write request, the memory manager logic is configured to deny the memory access request in response to determining that the following two conditions are satisfied: the stage 1 permission information specified by the target stage 1 translation table entry specifies that the target memory region is a guard control stack (GCS) region for storing a GCS data structure, the GCS data structure being used to protect return status information returned from a function call or an exception; and The memory access request is a request other than a GCS memory access request triggered by one of a restricted subset of instructions of a GCS access type; the memory manager logic being configured to support a translation hardening mechanism for defining at least one hardened stage 1 translation table entry based at least on translation hardening information capable of being set by instructions simulated to be executed in a second execution state having a higher privilege than the first execution state, the at least one hardened stage 1 translation table entry being protected by the translation hardening mechanism from tampering by instructions simulated to be executed in the first execution state; when antialiasing properties are specified for the target memory region, the memory manager logic is configured to deny the memory access request in response to detecting that the target stage 1 translation table entry or another stage 1 translation table entry used to locate the target stage 1 translation table entry is an unhardened translation table entry that is not protected by the translation hardening mechanism; and In at least one operating state of the processing circuitry, the memory management circuitry is configured to deny the memory access request in response to determining that the memory access request is the GCS memory access request and the anti-aliasing property is not specified for the target memory region.
19. A storage medium storing the computer program according to claim 18.
