Data processing device and method
By introducing memory access check and stack pointer verification mechanism into the processing circuit, the data processing security problem between multiple security domains is solved, ensuring the access control of the less secure domain to the secure domain, and improving the security of the system.
Patent Information
- Application Number
- CN201980064661.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2018-11-23
- Filing Date
- 2019-09-03
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2039-09-03
AI Technical Summary
Existing technologies are difficult to effectively perform data processing securely between multiple security domains and prevent code in less secure domains from inappropriately accessing sensitive data or code in secure domains.
A processing circuit is designed, including a memory access check circuit and a stack pointer register. It triggers faults or verification actions through gateway instructions to ensure that security checks are performed when the program flow transitions from a less secure domain to a secure domain to prevent unauthorized access. Memory access and stack pointer manipulation.
It effectively prevents attacks on the secure domain by codes in less secure domains, ensures safe conversion of data processing between different security domains, and improves the security and reliability of the system.
Smart Images

Figure CN112805710B_ABST
Abstract
Description
Technical Field
[0001] The present technology relates to the field of data processing. Background Art
[0002] The processing circuitry may support performing data processing in one of a plurality of security domains, the plurality of security domains comprising at least a secure domain and a less secure domain. This may allow sensitive data or code associated with the secure domain to be protected from inappropriate access by less secure code operating in the less secure domain. Summary of the invention
[0003] At least some examples provide a device comprising: a processing circuit for performing data processing in a security domain of a plurality of security domains, the plurality of security domains comprising at least a secure domain and a less secure domain; a memory access checking circuit for checking whether memory access is allowed based on security attribute data indicating which of the plurality of security domains is associated with a target address of the memory access; and at least one stack pointer register for storing a stack pointer indicating a stack data structure in a memory; wherein: in response to a given change in program flow from processing in a less secure domain to a target instruction having an instruction address associated with a secure domain: when the target instruction is an instruction other than a gateway instruction indicating a valid entry point to the secure domain, the processing circuit is configured to trigger a fault; and when the target instruction is a gateway instruction, the processing circuit is configured to trigger a stack pointer verification action to verify whether it is safe to use the selected stack pointer stored in the selected stack pointer register.
[0004] At least some examples provide a data processing method for a processing circuit capable of performing data processing in one of a plurality of security domains, the plurality of security domains including at least a secure domain and a less secure domain, for which a check is made as to whether memory access is allowed based on security attribute data, the security attribute data indicating which of the plurality of security domains is associated with a target address of the memory access; the method comprising: in response to a given change in program flow from processing in a less secure domain to a target instruction having an instruction address associated with a secure domain: determining whether the target instruction is a gateway instruction indicating a valid entry point to the secure domain; triggering a fault when the target instruction is an instruction other than a gateway instruction; and triggering a stack pointer verification action to verify whether it is safe to use a selected stack pointer stored in a selected stack pointer register when the target instruction is a gateway instruction.
[0005] At least some examples provide a computer program for controlling a host data processing apparatus to provide an instruction execution environment for instruction execution, the computer program comprising: a processing program logic for supporting data processing in a security domain of a plurality of security domains, the plurality of security domains comprising at least a secure domain and a less secure domain; a memory access checker logic for checking whether a memory access is permitted based on security attribute data indicating which of the plurality of security domains is associated with a target address of the memory access; and a cache emulation program logic for controlling access to a memory of the host data processing apparatus to simulate access to a memory accessed by a computer. Access to simulated architecture registers of a target architecture simulated by a program, these simulated architecture registers include at least one stack pointer register, this stack pointer register includes a stack pointer for storing an indication of a stack data structure in a memory; wherein: in response to a given change in program flow from processing in a less secure domain to a target instruction having an instruction address associated with a secure domain: when the target instruction is an instruction other than a gateway instruction indicating a valid entry point to the secure domain, the handler logic is configured to trigger a fault; and when the target instruction is a gateway instruction, the handler logic is configured to trigger a stack pointer verification action to verify whether it is safe to use a selected stack pointer associated with a selected stack pointer register among these simulated architecture registers.
[0006] A computer-readable storage medium can store the above-mentioned computer program. The storage medium can be a non-transitory storage medium. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] Other aspects, features and advantages of the present technology will become apparent from the following description of examples read in conjunction with the accompanying drawings, in which:
[0008] Figure 1 schematically illustrates an example of a data processing system having processing circuitry supporting a secure domain and a less secure domain;
[0009] Figure 2 Examples showing different domains and modes of operation of processing circuitry;
[0010] Figure 3 shows examples of registers of a processing circuit;
[0011] Figure 4 showing multiple examples of a first exception stack frame that omits architectural state associated with callee registers and omits an integrity signature;
[0012] Figure 5 showing an example of a second exception stack frame, the second exception stack frame including additional architectural state from the callee registers and including an integrity signature;
[0013] Figure 6 is a table illustrating different exception entry conversions supported by a data processing apparatus;
[0014] Figure 7 is a table showing a number of different exception return conversions supported by the data processing apparatus;
[0015] Figure 8 showing potentially inappropriate domain / mode switching sequences that one might wish to detect;
[0016] Fig. 9 illustrates an example of a reentry scenario in which a function is called for the first time, interrupted, and then called again without completing the remainder of the function code from the time the function was first called;
[0017] Fig.10 is a flow chart illustrating a method of data processing including triggering a stack pointer validation action in response to a gateway instruction;
[0018] Fig.11 An example of a simulator that can be used is shown. DETAILED DESCRIPTION
[0019] A data processing apparatus may have processing circuitry that supports performing data processing in a security domain of a plurality of security domains, the plurality of security domains including at least a secure domain and a less secure domain. Memory access checking circuitry may be provided to check whether memory access is permitted based on security attribute data, the security attribute data indicating which of the domains is associated with a target address of the memory access. For example, when operating in the less secure domain, the memory access checking circuitry may prevent memory access to addresses associated with the secure domain, and when operating in the secure domain, the processing circuitry may be allowed to access addresses associated with the secure domain and addresses associated with the less secure domain. At least one stack pointer register may be provided to store a stack pointer indicating a stack data structure in memory. For example, when handling an exception, the stack data structure may be used to save and restore an architectural state.
[0020] In the techniques discussed below, in response to a given change in program flow from processing in a less secure domain to a target instruction having an instruction address associated with a secure domain: when the target instruction is an instruction other than a gateway instruction indicating a valid entry point to the secure domain, the processing circuitry triggers a fault; and when the target instruction is a gateway instruction, the processing circuitry triggers a stack pointer verification action to verify whether it is safe to use a selected stack pointer stored in a selected stack pointer register.
[0021] Gateway instructions may be used to mark valid entry points to a secure domain. By triggering a fault if the target instruction is not a gateway instruction following a change in program flow from a less secure domain to a target instruction having an instruction address associated with a secure domain, this prevents an attacker who can control code processed in a less secure domain from violating security by triggering a branch to an arbitrary point within secure code stored in a secure area of memory. A given change in program flow that triggers a check to see if a target instruction is a gateway instruction may be a continuous change in program flow (where a series of instructions are executed without branching across a boundary between an address designated as less secure and an address designated as secure, no branching) or a discontinuous change in program flow (e.g., caused by a branch or other instruction, or caused by an abnormal entry or return event, which causes an update to a program counter indicating the address of an instruction representing the current execution point).
[0022] On the other hand, after a given change in program flow, when the target instruction is a gateway instruction, the processing circuit may trigger a stack pointer verification action to verify whether it is safe to use the selected stack pointer stored in the selected stack pointer register. This can prevent certain attacks that may attempt to manipulate the stack pointer used in the secure domain to attempt to allow unsafe code operating in a less secure domain to affect which instructions are executed in the secure domain. By triggering the stack pointer verification action in response to a gateway instruction, it can be ensured that the stack pointer verification action is triggered whenever the secure domain is entered from a less secure domain. Because after a given change in program flow, if the next instruction executed is any instruction other than a gateway instruction, a fault will occur, which means that the gateway instruction can be trusted to implement additional security checks, even if the remainder of the code to be executed in the secure domain after the gateway instruction is malicious code that has been called by an attacker. Therefore, the gateway instruction can trigger an action for verifying whether it is safe to use the selected stack pointer, thereby preventing attacks that attempt to misuse the stack pointer. Triggering the stack pointer verification action in response to a gateway instruction, rather than based on logic that is not directly triggered by instructions that monitor certain security domain conversions, can also be simpler for hardware system designers to implement in the microarchitecture.
[0023] In some examples, the device may include two or more stack pointer registers to store corresponding stack pointers. When stack access is required, which stack pointer register is accessed may depend on the current security domain and / or current operating mode of the processing circuit, and in some cases also based on an architectural state stored, for example, in a control register.
[0024] For example, in some cases, the system may include at least two stack pointer registers, including a secure stack pointer register accessible in the secure domain and a less secure stack pointer register accessible in both the secure domain and the less secure domain. When handling an exception, which stack pointer register is used to provide a stack pointer for saving / restoring the architectural state may be selected based on the domain involved in the exception entry or exception return conversion. By providing separate secure stack pointer registers and less secure stack pointer registers, this can prevent less secure code from being able to identify or modify which area of memory contains a stack structure used by the secure domain. Therefore, in some cases, the selected stack pointer register may be a secure stack pointer register.
[0025] More specifically, some examples may have processing circuitry that supports processing in one of a plurality of modes within a given security domain. These modes may include a handler mode for exception handling and a thread mode for background processing. Separating thread mode and handler mode is useful for simplifying management of which architectural state is accessible to the processing circuitry, which can simplify exception handling and ensure that certain states required for exception handling are not available for background processing, such as in thread mode. Thus, control over access to regions of memory and which architectural registers are accessible to the processing circuitry may be based on a combination of the current security domain and the current mode of the processing circuitry, and in some cases also based on other control parameters of the architecture.
[0026] In a system supporting thread mode and handler mode, the stack pointer registers may then include a process stack pointer register for storing a process stack pointer and a master stack pointer register for storing a master stack pointer. There may be secure and less secure grouped versions of the process stack pointer register and the master stack pointer register, so in some cases, there may be at least four different stack pointer registers (secure master stack pointer, secure process stack pointer, less secure master stack pointer, and less secure process stack pointer). Generally speaking, when operating in handler mode, the master stack pointer register may be selected. When in thread mode, one of the process stack pointer register and the master stack pointer register may be selected based on a stack pointer selection value stored in a control register. In an architecture providing a grouped stack pointer register including the four stack pointer registers described above, the selected stack pointer register (to which a stack pointer validation action is performed in response to a gateway instruction) may be a secure master stack pointer register or a secure process stack pointer register.
[0027] The stack pointer validation action may be performed in different ways. In one example, the stack pointer validation action may include triggering a permission check to check whether a load request is allowed, the load request requesting a target address load value derived from a selected stack pointer stored in a selected stack pointer register. In some implementations, this permission check may be triggered by issuing an actual load request to the target address. Alternatively, this permission check may be triggered by issuing another type of memory access request (such as a storage request) or by issuing a permission check request for a specified target address (which does not actually trigger access to the memory, but rather controls the memory access check circuit to return an indication of whether access to the target address is allowed).
[0028] This seems counter-intuitive: it is useful to trigger a memory permission check for an address derived from a stack pointer when a gateway instruction is encountered, because the function of the gateway instruction in marking a valid entry point to a security domain does not seem to require access to any value in memory. However, by triggering a permission check for a target address derived from a selected stack pointer stored in a selected stack pointer register, the permission check can be used as a check on whether it is safe to use the selected stack pointer. For example, the processing circuit can be configured to operate at one of several privilege levels. If the selected access permission set that can be used for the target address triggered in response to the gateway instruction specifies that the selected privilege level is prohibited from accessing the target address, the memory access check circuit can trigger a fault. Therefore, the gateway instruction can be used to cause a privilege-based memory permission check implemented by the memory access check circuit, thereby providing a way to verify whether the selected stack pointer is safe.
[0029] Specifically, the selected privilege level may be a privilege level associated with a process that is in a combination of a current operating mode and a security domain of the processing circuitry at a given change in program flow. For example, if the combination of the security domain and the current mode is defined as unprivileged, the memory access checking circuitry may check whether the selected set of access permissions indicates that unprivileged code will be allowed to execute a target address derived from a selected stack pointer, and may trigger a fault if the unprivileged code is not allowed to access the address. This may guard against attacks in which an attacker may attempt to use unprivileged code to manipulate a stack pointer that points to a stack data structure in a privileged area of memory.
[0030] The selected set of access permissions (used to check whether access to a target address derived from a selected stack pointer in response to a load request is allowed) may include a set of access permissions that can be used for the target address when the current domain of the processing circuit is the secure domain. In some examples, the memory access checking circuitry may maintain separate sets of access permission data for the secure domain and the less secure domain. Thus, even if a gateway instruction is executed when the current domain is still the less secure domain (although the gateway instruction is stored in a secure area of memory and a domain switch may not have been triggered), the gateway instruction may trigger a permission check using access permissions associated with the secure domain to provide verification as to whether it is safe to use a stack pointer that may later be accessed from the secure domain.
[0031] In some examples, the target address checked in the permission check triggered by the gateway instruction can be derived from the selected stack pointer by adding a certain offset to the selected stack pointer. In other examples, the target address can simply be equal to the selected stack pointer itself.
[0032] In one example, the processing circuit may also perform a reentry check in response to the gateway instruction. The reentry check may include triggering a fault when the value loaded from the target address derived from the selected stack pointer shows one of at least one integrity signature value. The integrity signature value may be a predetermined bit pattern that can be used to enable some integrity checks on the stack data structure in the memory. In some implementations, there may be support for two or more different integrity signature values (e.g., one for an exception stack frame and another for a function stack frame). In this case, the integrity signature value that causes the fault to be triggered may be a specific integrity signature value among these integrity signature values (e.g., an integrity signature value for an exception stack frame), or the fault may be triggered by any of these integrity signature values.
[0033] Such reentrancy checking can be used to provide architectural protection against reentrancy scenarios, in which a function has been called once, the function is interrupted midway, and then, after a certain sequence of events (e.g., events including domain transitions, mode transitions, exception entry or return events, function calls, function returns), the function ends and is called a second time without first completing the remaining portion of the function code from the first time the function was called. It may be unsafe to execute some types of function code in such reentrancy scenarios because these types of code may give erroneous results if the previous instance of the function is not fully completed before the function is called again. For example, a function may implement a set of operations that need to be completed atomically for other instances of the same function to be called. Although the function code itself can be redesigned to be safe against reentrancy, doing so can result in a significant increase in code complexity, can introduce additional security vulnerabilities, make maintenance more difficult, and increase code size, which may be undesirable. Alternatively, instead of designing the software to be safe even if reentrancy occurs, another approach may be to provide software that includes a sequence of instructions for detecting reentry and preventing the function from being executed again if reentry is detected. However, this may also be undesirable, because such software detection of reentry may be prone to errors, increase code size and reduce performance. Another option to prevent reentry may be to try to reduce the probability that a function will be interrupted midway, such as by raising the priority of a function during critical operations to prevent interruptions or preempt exceptions to the function. However, this may not work in all use cases, because priority raising may only be available for certain privilege levels, and such priority raising may significantly interfere with interrupt latency, which is undesirable.
[0034] It has been recognized that, typically in a reentry scenario, the reentry may typically be after a series of exceptional transitions that result in integrity signature values being present on the associated stack data structure indicated by the selected stack pointer in the selected stack pointer register. Thus, by triggering a load of an address derived from the selected stack pointer in response to a gateway instruction, and triggering a fault when the loaded value matches at least one of the at least one integrity signature value, an architectural defense against such reentry is provided. This can significantly reduce the burden on a programmer or compiler in providing software that achieves its intended results.
[0035] By using a load triggered by a gateway instruction to perform a reentry check, this ensures that a reentry check can be performed each time a secure domain is entered. Reentry checks are more relevant for secure domains than for less secure domains, which may be counterintuitive because reentry itself is not a problem of strengthening the boundary between secure and less secure domains (more precisely, the main risk of reentry is that the software code may not achieve its expected results, rather than security issues). However, it should be recognized that software repairs for reentry may lead to secondary risks of introducing security vulnerabilities, which may be exploited by attackers. Therefore, by providing such architectural support for reentry checks, this avoids the need for programmers or compilers to provide software repairs for preventing or detecting reentry, which reduces the chance of those software repairs accidentally introducing security vulnerabilities. Therefore, triggering a reentry check in response to a gateway instruction is particularly useful because it is due to the presence of a gateway instruction that marks a secure entry point in the secure domain, which ensures that any secure function can have a defense against reentry checks that is automatically triggered in the architecture.
[0036] When reentrancy checking is performed in response to a gateway instruction, a load request for reentrancy checking to obtain a value from a target address can also be used as a trigger for a permission check for a stack pointer validation action. Thus, triggering this load can be used for two purposes: stack pointer validation action and reentrancy checking.
[0037] However, such a reentry check may not always be needed. For some security functions, the program code may be able to safely prevent reentry, for example, because the program code does not rely on shared variables that need to be updated atomically. Therefore, in some examples, the architecture may provide a reentry check enable value (e.g., stored in a control register), which specifies whether to enable or disable the reentry check. In response to a given change in program flow, when the target instruction is a gateway instruction, the processing circuit may determine whether to perform a reentry check in response to a gateway instruction based on whether the reentry check is enabled or disabled by the reentry check enable value. Therefore, if the reentry check is not related to the specific function being executed, the reentry check can be disabled.
[0038] However, even when the reentrancy check enable value specifies that reentrancy checking is disabled, when a gateway instruction is retrieved from secure memory and is a target instruction executed after a given change in program flow from a less secure domain, the processing circuitry may still trigger a permission check in response to the gateway instruction to check whether a load request to the target address is permitted. Although it may be desirable that a permission check need not be performed for the target address if reentrancy checking is disabled, since there is no need to check whether the loaded value matches the integrity signature value, a permission check for the target address may still be used to verify whether it is safe to use the selected stack pointer, thereby providing protection against some forms of attacks on security, even if reentrancy checking is disabled.
[0039] In the case where reentrancy checking is disabled, there are different options for triggering a permission check for stack pointer validation to be performed. One approach could be to issue the load request anyway, even though the value loaded from memory is not needed because reentrancy checking has been disabled. This can be simpler to implement in the microarchitecture because it means that the request that triggers the stack pointer validation action to be performed can be the same regardless of whether reentrancy checking is enabled or disabled.
[0040] However, another option would be to trigger the permission check by issuing a load request when reentrancy checking is performed, but when reentrancy checking is not performed, a different type of request can be used to trigger a permission check for the stack pointer validation action. For example, a different type of request can be an address check request, which is used to request that a permission check be performed without triggering a memory access. This can improve performance because by eliminating the load of the actual target address, this can save time and power and save memory access bandwidth for other memory access operations.
[0041] The apparatus may have an exception control circuit for handling exceptions and exception returns. In response to an exception condition, the exception control circuit may execute one of at least a number of exception entry transitions, the exception entry transition being selected based at least on a current security domain of the processing circuit (and in some cases also based on a current mode). For at least a subset of the exception entry transitions, the exception control circuit may trigger saving a stack frame including one of the at least one integrity signature value to a stack data structure identified by a stack pointer stored in at least one stack pointer register. For example, the subset of exception entry transitions (for which a stack frame including an integrity signature value is saved) may include a transition from a secure domain to a less secure domain.
[0042] On the other hand, for an abnormal return condition, one of several abnormal return conversions may be selected based at least on a security domain associated with the abnormal return condition. For at least a subset of the abnormal return conversions, the abnormal control circuit may perform an integrity signature check for accessing a stack frame selected for this abnormal return conversion from a given stack data structure, and when a mismatch is detected between a value at a predetermined position in the accessed stack frame and the one integrity signature value of at least one integrity signature value, a fault is triggered. Therefore, for the abnormal return conversion, for at least some abnormal return conversions, an integrity signature may be required to be present on the stack data structure to avoid triggering a fault. Including integrity signature values in this way can provide protection against attacks, in which an attacker attempts to forge a series of abnormal entry or return conversions or function calls or returns in a manner that causes an inappropriate stack frame to be restored when returning to the security domain (here, the attacker may be trying to use a mismatch in the stack frame to trigger the security domain to process code from addresses in the security domain, which are selected based on information provided by less secure code controlled by the attacker). Using integrity signature values can allow detection of inappropriate conversion sequences to guard against such attacks.
[0043] Thus, at some exception return transitions, the integrity signature value may need to be presented as an indication that a valid exception and exception return sequence has been executed (the lack of an integrity signature value may trigger a fault at certain exception return transitions). In contrast, for reentry checks, a fault may be triggered when a value at a predetermined location on the stack does not match the integrity signature value, because in this case the integrity signature value may be a flag that marks that the same function has been called again after a previously interrupted instance of executing a certain secure function, without expecting a reentry. Thus, reentry checks may be viewed as counter-intuitive, because when an integrity signature (usually used as a sign that the stack has been properly disposed of) is detected, these reentry checks trigger a fault, which is the opposite of what one might expect. Although the present invention is described with respect to detecting reentry of a function after a previous interrupt called the same function, it should be appreciated that the present invention may also guard against different forms of reentry (where a second secure function is called after a previous interrupt called a first function). Because it is common for different functions to share and modify the same state, it may be desirable to protect against function reentry to any combination of security domains.
[0044] Where reentrancy checking is supported, deriving the target address from the selected stack pointer may be such that the target address corresponds to an address associated with the selected stack pointer at which the integrity signature value is desired to be stored. For example, if the integrity signature value is located at a point on the stack frame that is an offset from the stack pointer, then when the target address is derived in response to the gateway instruction, the same offset may be added to the selected stack pointer. However, in some architectures, to avoid the need to perform a summation of the stack pointer and the offset (which may increase latency), the integrity signature value may be stored at a location on the stack frame that corresponds to the stack pointer itself, and so in this case the target address may simply be equal to the selected stack pointer.
[0045] This technique of checking whether an integrity signature exists can be used in the case of a reentry scenario after a series of exception entry and return conversions. However, when a function call has been used at a point between the first call and subsequent calls of a function, a reentry scenario may also occur, and therefore, sometimes the load of the target address derived from the selected stack pointer may access the stack frame that has been saved to the memory in response to the function call being executed. For function calls, integrity signature values may not be saved at all, or integrity signature values different from those saved in response to a subset of exception entry conversions may be saved, or integrity signature values for function calls may be at different offsets relative to the stack pointer compared to integrity signature values for exceptions. In any of these cases, checking whether the loaded value matches a given integrity signature value for an exception may not be sufficient to detect all reentry scenarios. In some examples where there is no integrity signature for a function call, it may be desirable to ensure that the value at the target address cannot accidentally match the integrity signature value, because this may accidentally trigger a reentry check failure when reentry has not yet occurred. Such that some embodiments may place the function return address at the target address and select an integrity signature value that is not an executable address, thereby ensuring that the function return address may never accidentally match the integrity signature. In some embodiments, saving the stack frame to memory in response to a function call may be automatically performed by the processor and may occur only in response to a secure function call to a less secure function.
[0046] Thus, in some examples, reentrancy checking may also include triggering a fault when a stack pointer select value used to determine which stack pointer register to use to push or pop an architectural state has a predetermined value. The fact that the stack pointer select value has a predetermined value may be another indicator that a reentry is about to occur, and thus, when reentry checking is enabled, triggering a fault when the stack pointer select value has a predetermined value may then provide further protection against reentrancy checking.
[0047] For example, as discussed above, the processing circuit may support handler mode and thread mode. When in thread mode, the stack pointer selection value may control the selection between the process stack data structure and the main stack data structure. When the stack pointer selection value has a first value, the process stack data structure identified by the stack pointer stored in the process stack pointer register may be selected for use in response to an exception condition occurring in thread mode and saving the architecture state. When the exception condition occurs in thread mode and the stack pointer selection value has a second value, the main stack data structure identified by the stack pointer stored in the main stack pointer register may be selected. When the exception condition occurs in handler mode, then regardless of the current value of the stack pointer selection value, the main stack data structure may be used. It should be appreciated that, as described above, a secure version and a less secure version of the process stack data structure and the main stack data structure may be provided, and therefore which version to use may depend on the security domain associated with the background processing performed before the exception occurs.
[0048] Therefore, for reentry check, in some examples, a fault may be triggered when the stack pointer selection value has the second value described above, which indicates that the main stack data structure should be used for thread mode. Again, this may be a sign of an impending reentry. By triggering a fault in response to a gateway instruction when a reentry check is performed and the stack pointer selection value has the second value, this provides an architectural defense against reentry, thereby simplifying code development and thus reducing the chance of security vulnerabilities due to attempts to address reentry in software.
[0049] Specifically, this method may be used in the following architecture: wherein in response to at least one secure thread mode to secure handler mode exception entry transition, the exception control circuit may update the stack pointer selection value to a second value. This may be an action taken to defend against another type of security attack, which may exploit the fact that when an exception triggers a secure to secure domain transition, certain protective measures performed on the transition from the secure domain to the less secure domain may be omitted, such as saving / clearing architectural register states and saving integrity signature values as discussed above. Although omitting such protective measures may improve performance and is considered reasonable when transitioning from secure thread mode to secure handler mode because the system is already in the secure domain and can be trusted, this may introduce some security vulnerabilities if an attacker is able to forge an inappropriate sequence of function or exception entry and return conditions so that a stack frame lacking an integrity signature is accessed when returning to secure thread mode. Although it is expected that thread mode will normally access the process stack data structure, by switching the stack pointer select value to the second value in response to at least one secure thread mode to secure handler mode exception entry transition, this means that if the processing circuit returns to the secure thread mode via one of these inappropriate transition sequences and the stack pointer select value still has the second value, the main stack data structure may be accessed, rather than the process stack data structure, which may cause other security checks to fail. This setting of the stack pointer select value to the second value can be used for reentry checks because, typically in this case, when an intermediate function call is used as part of a chain of transitions, resulting in a reentry scenario (where this function is called again from a less secure domain before a previous instance of a secure function call is completed), the chain of transitions will also have included at least one secure thread mode to secure handler mode exception entry transition (where the stack pointer select value is set to the second value).
[0050] When there is a change in program flow from processing in a secure domain to a gateway instruction having an instruction address associated with a secure domain, the reentry check described above can be omitted. Therefore, a reentry check can be performed for a conversion from a less secure domain to a gateway instruction stored in a secure memory, but when the program flow switches from the secure domain to this gateway instruction, the reentry check is not required. As discussed above, the preservation of the integrity signature value can be performed only when there is a conversion from a secure domain to a less secure domain, and therefore when the program flow switches from the secure domain to the gateway instruction, the stack data structure may not include the integrity signature value. This means that when a secure function calls other secure functions, the value at the address derived from the selected stack pointer in the reentry check can show any value. By omitting the reentry check in response to a change in program flow from a secure domain to a gateway instruction stored in an address associated with a secure domain, this avoids accidentally triggering a fault when the value on the stack happens to match the integrity signature by chance.
[0051] In addition to triggering security checks, the gateway instruction may also have the function of triggering a switch of the current security domain from a less secure domain to a secure domain. Therefore, when the target instruction after a given change in program flow is a gateway instruction, at least one security check (e.g., a reentry check (if enabled), and / or any other security check for supervising the boundary between domains) may be performed in response to the gateway instruction, and if at least one security check is passed, the processing circuit may trigger a switch of the current security domain from a less secure domain to a secure domain.
[0052] In the example discussed above, a stack pointer validation action triggered in response to a gateway instruction after a given change in program flow may include triggering a permission check to check whether loading of a target address derived from a selected stack pointer is allowed. This approach has the advantage that some overhead may be shared with a reentry check when performing a stack pointer validation action (e.g., issuing a load request), which is useful for the reasons given above. In addition, this means that certain valid use cases in which the stack pointer selection value has a second value when called in secure thread mode may still be supported. In some embodiments, in the case of performing a reentry check, the stack pointer selection value may still be checked, and if the stack pointer selection value is the second value, a fault occurs. If the reentry check is disabled, the reentry check may not be performed. In addition, a reentry check may not be performed when the program flow changes from a secure domain to a secure region of memory for a gateway instruction stored therein.
[0053] However, in another example, when a given change in program flow is detected and the target instruction is a gateway instruction, the stack pointer verification action may include: if the stack pointer selection value has a second value, a fault is triggered. This can provide another way to prevent attacks that aim to manipulate the secure main stack pointer in an attempt to trigger the secure domain to execute an inappropriate code sequence. It should be noted that, unlike the first method discussed above (in the first method, when a reentry check is performed, the stack pointer selection value is checked, and when the reentry check is omitted, the stack pointer selection value is not checked), with this second method, the stack pointer selection value can be checked in response to a gateway instruction regardless of whether a reentry check is performed. Therefore, this provides an alternative embodiment for checking whether it is safe to use a selected stack pointer after a given change in program flow. By triggering this action in response to a gateway instruction (which is guaranteed to exist when the secure domain is effectively switched), if the gateway instruction is not present, a fault will be triggered before any subsequent instructions are executed, this makes the microarchitecture design simpler, because these actions require that the stack pointer selection value be checked, which can be triggered by the instruction decoder in response to the recognition of the gateway instruction.
[0054] No matter which variant of the stack pointer verification action is used, it is not necessary to trigger the stack pointer verification action for all instances of encountering a gateway instruction after a given change in the control flow. In some cases, when the processing circuit is in a predetermined operating mode at a given change in the program flow, the stack pointer verification action can be triggered. For example, the predetermined mode can be a thread mode. When the processing circuit is in an operating mode other than the predetermined operating mode, the stack pointer verification action can be omitted. This can be useful because the attacks based on the stack pointer of the type discussed above may be most likely when entering the thread mode, and may not be a problem when entering the handler mode. Although when in the handler mode, it may always be possible to pass the check associated with the stack pointer verification action (at least for the following embodiment: the stack pointer verification action includes triggering a permission check of the target address derived from the selected stack pointer, wherein the access from the handler mode can generally pass the access permission check based on privileges, because the handler mode can be defined as privileged by default), but for performance reasons, it may be desirable to omit the triggering of the stack pointer verification action to save processing power and enable the release of resources for other purposes. For example, in an embodiment where the stack pointer validation action includes triggering a load request, omitting the stack pointer validation action when the processing circuit is in handler mode may free up a slot in the load queue that may be used for other memory accesses. Therefore, limiting the stack pointer validation action to a predetermined mode (such as thread mode) may improve performance. Similarly, support for safe reentry may be required in handler mode due to the need to support multiple nested exception handlers. Some embodiments may therefore suppress reentry checks when in handler mode because for handler mode code, it may be expected that the code is already securely protected against reentry, and therefore no further protection against reentry at the architectural level is required.
[0055] A corresponding simulator computer program may be provided for controlling a host data processing device to provide an instruction execution environment for instruction execution. The computer program may include a processing program logic and a memory access check program logic, which functionally correspond to the processing circuit and the memory access check circuit discussed above. In addition, the program may have a register emulation program logic for controlling access to the memory of the host device to simulate access to the simulated architecture registers of the target architecture simulated by the computer program. The simulated architecture registers may include at least one stack pointer register as described above. The processing program logic may trigger a stack pointer verification action in response to a gateway instruction of the target code running on the simulator. Therefore, such a simulator computer program can present an instruction environment similar to the instruction environment provided by the actual hardware device to the software running on the simulator computer program (even if any actual hardware that may not provide these features may be provided in the host computer that is executing the simulator computer program).
[0056] The functionality of the hardware architecture discussed above may be emulated by providing program logic, such as an instruction set or data structure, which enables a general purpose host computer to run object code intended to be run on a device having those features in a manner compatible with the results achieved on a device actually having those features. The simulator computer program for controlling the host data processing device may be stored on a storage medium. This storage medium may be a non-transitory storage medium.
[0057] Figure 1 An example of a data processing system 2 is schematically illustrated, the data processing system 2 comprising a processing circuit 4 for performing data processing in response to instructions fetched from a memory system 6. The memory system 6 may include a cache (e.g., one or more levels of data cache and / or instruction cache) and a main memory. The processing circuit 4 comprises a processing pipeline comprising a plurality of pipeline stages including, for example, a fetch stage 8 for fetching instructions to be executed from the memory system 6, a decode stage 10 for decoding the fetched instructions to generate control signals for controlling the remaining pipeline stages to perform data processing, and an execute stage 12 for executing the decoded instructions to perform data processing operations. Registers 14 are provided for storing input operands of instructions processed by the pipeline 4. Registers 14 include multiple types of registers, including general purpose (GP) (integer) registers 16 for storing integer values, floating point (FP) registers 18 for storing floating point values, and control registers 20 for storing control parameters to control the processing circuit 4 to execute instructions and other operations (such as exception handling, security checks, etc.).
[0058] It should be understood that Figure 1 The pipeline stages shown in are simplified representations, and other types of pipeline stages may also be provided, such as a renaming stage for performing register renaming, an issue stage for queuing instructions waiting to be executed and issuing instructions when operands required by the instructions are available, and a write-back stage for handling instruction commit and writing results back to registers 14. The pipeline may be an in-order or out-of-order pipeline.
[0059] The system 2 also includes a memory access check circuit 22 for checking whether access to the memory system 6 is allowed based on attribute data specified for each region of the memory address space. The memory access check circuit includes a security attribute unit (SAU) 24 for storing security domain definition data, which defines the security domain associated with each corresponding region of the memory address space. Based on the security attribute data, the security attribute unit 24 can check whether the memory access is allowed, which depends on the current security domain in which the processing circuit operates and the security domain associated with the region including the target address of the memory access. In other embodiments, the SAU may not directly store the security domain definition data, but access the security domain definition data stored elsewhere to perform the memory access check. In some systems, the security domain definition data may be stored in the memory system 6, or may be a configuration register elsewhere in the system 2. The processing circuit 4 can operate in the current security domain of operation, which can generally correspond to the security domain associated with the address of the instruction currently being executed (although there may be some exceptions, such as when switching between processing domains). When an instruction branches from an address in an area designated by the SAU 24 as a domain to an address in an area associated with a different domain, this may trigger a transition of the current security domain in which the processing circuit 4 operates. In other embodiments, such a branch may not directly trigger a transition of the current security domain, but rather trigger an external security check, such as whether a gateway instruction exists, in which case it is the gateway instruction itself that triggers the change of the current security domain. Generally speaking, when operating in a secure domain, the processing circuit may access data in memory areas associated with the secure domain and the less secure domain, and when operating in a less secure domain, the processing circuit may access data in an area associated with the less secure domain, but the processing circuit may not be allowed to access data in an area of the address space designated by the SAU 24 as being associated with the secure domain. This protects sensitive data from unauthorized access by code running in a less secure domain.
[0060] In addition, the memory access check circuit may include a memory protection unit (MPU) 26, which checks whether memory access to the memory system 6 satisfies access permissions, which access permissions may specify, for example, which privilege levels of the processing circuit 4 are allowed to access a given area of the memory, or may specify whether a memory area of the address space is accessible by both read operations and write operations or whether it is a read-only area where writing is prohibited. The access permissions used by the MPU 26 are, for example, specified by a higher privileged process (such as a hypervisor or an operating system), which is used to control which areas of the memory are accessed by lower privileged processes (such as allowing applications to access) and how to access (read-only or read / write). The permissions provided by the MPU 26 may be orthogonal to the permissions provided by the SAU 24, so that for a given memory access to be allowed, it should pass a check based on the access permissions defined for both the MPU 26 and the SAU 24. Although the MPU 26 is Figure 1 Although shown as a single entity in the diagram, in some examples, separate secure and less secure MPUs 26 may be provided, each MPU 26 being associated with one of the security domains so that different memory access permissions may be specified for a given region of memory, depending on whether the current domain is a secure domain or a less secure domain (e.g., a region may be read-only in a less secure domain, but both readable and writable in a secure domain).
[0061] Therefore, if Figure 2 As shown, the processing circuit 4 can support data processing in one of a plurality of security domains, the plurality of security domains including at least a secure domain (S) and a less secure domain (NS). Figure 2 A system with only two security domains is shown, but three or more domains associated with different security levels may be provided.
[0062] In addition, within a given security domain, such as Figure 2As shown, the processing circuitry can perform data processing in one of a plurality of modes, including a handler mode (H) for exception handling and a thread mode (T) for background processing. An exception control circuit 28 can be provided to control exception handling operations, including exception entry conversion and exception return conversion and any preservation / restore of the architectural state during such conversion. Separating exception handling into a dedicated handler mode H can help simplify management of which registers the processing circuitry is allowed to access (e.g., some registers used for exception handling can be accessed in the handler mode H but cannot be accessed in the thread mode T). In general, when operating in the handler mode H, the processing circuitry 4 can default to being assumed to have a higher privileged operating mode so as to control access to memory according to a privilege level of a particular level other than the minimum privilege level, while in the thread mode T, the processing circuitry can have one of a plurality of different privilege levels, depending on other architectural states stored in the control register 20.
[0063] Therefore, if Figure 2 As shown, the combination of the security domain and mode in which processing circuit 4 is operating may determine how processing circuit 4 performs aspects of processing. Figure 2 Four different combinations of these modes are shown, including:
[0064] Safe thread mode (short for the combination of security domain and thread mode)
[0065] Less safe thread mode (a combination of less safe domain and thread mode)
[0066] The Security Handler pattern (a combination of the Security Domain and Handler patterns) and
[0067] Less secure handler mode (a combination of less secure domain and handler mode).
[0068] As described below, the actions performed in response to exception conditions and exception return conditions may depend on the specific transitions made between these respective combinations of security domains and modes.
[0069] Figure 3 Some of the registers 14 of the processing system are shown. It should be understood that this representation does not show all possible registers that may be provided; many other registers may be provided. Figure 3 As shown, the register 14 includes a general register 16, a floating point register 18 and a plurality of control registers 20 ( Figure 3Only some of the control registers are shown—other control registers may also be provided). In this example, 16 general purpose registers labeled R0 to R15 and 32 floating point registers labeled S0 to S31 are provided. In some embodiments, floating point registers 18 may also include a floating point status and control register (FPSCR), which may store floating point flag values, floating point rounding modes, etc. In some embodiments, general purpose registers 16 may also include a program status register (XPSR), which may store integer flag values, and other information related to the current context.
[0070] Of the general registers R0 to R15, registers R0 to R12 are used to store general operands, such as input operands for arithmetic or logic instructions or operands for deriving addresses for load / store instructions for accessing the memory system 6. General registers R13 to R15 may be used for such general operands, but they are also used for other control functions.
[0071] Register R15 is used as a program counter (PC) register which stores a program counter which provides an indication of the current point in the program reached by the processing circuitry 4. The program counter register may be used by the fetch stage 8 to determine which instructions to fetch from the memory system.
[0072] Register R14 is used as a link register (LR) for storing a function return address when a function is called so that when the processing associated with the function is completed, the address in the link register can be used to redirect program flow back to the next instruction after the function call instruction. In addition, the link register can be used when an exception occurs to store an exception return value, which provides information for controlling the popping of the architectural state when a corresponding exception return condition is encountered. This will be discussed in more detail below.
[0073] Register R13 is used as a stack pointer register that provides a stack pointer that indicates the address of a stack data structure in memory. The stack data structure can be used to save the architectural state when an exception condition occurs and to restore the architectural state when an exception return condition occurs. Figure 3 As shown, register R13 is banked to provide a number of different physical registers in hardware, each of which can be accessed using register designator R13. When R13 is specified, a particular banked register is selected, depending on the current security domain and mode of the processing circuitry.
[0074] For example, the library stack pointer registers may include a secure main stack pointer register (MSP_S), a secure process stack pointer register (PSP_S), a less secure main stack pointer register (MSP_NS), and a less secure process stack pointer register (PSP_NS). Typically, the secure stack pointer registers MSP_S and PSP_S are accessible by the processing circuit 4 when the processing circuit 4 is in the secure domain S, but cannot be accessed when the processing circuit 4 is in the less secure domain NS. The less secure stack pointer registers MSP_NS and PSP_NS can be accessed in both the less secure domain and the secure domain. Typically, it is desirable to use the process stack pointer PSP_S or PSP_NS in thread mode T, and it is desirable to use the main stack pointer MSP_S or MSP_NS in handler mode H. Providing separate main stacks and process stacks for handler mode and thread mode can make the development of exception handler code simpler, because it means that after the exception returns, the thread running in thread mode generally cannot access any data that the exception handler may leave on the main stack. This can simplify the development of exception handler code because the exception handler does not need to include instructions to clear all of its data from the main stack data structure. However, as will be discussed in more detail below, some processes in thread mode T may use a main stack pointer, wherein a stack pointer selection value (SPSEL) 30 stored in a control register (CONRTOL) 32 controls whether the main stack pointer or the process stack pointer should be used in thread mode T. Therefore, which stack pointer should be used can be determined not only based on a combination of the current mode (thread or handler) and the current domain (safe or less safe), but also based on the stack pointer selection value 30. Figure 3 As shown, the stack pointer selection value 30 can be grouped (banked) between security states, so that by using separate secure version SPSEL-S and less secure version SPSEL-LS of the stack pointer selection value 30, the secure domain and the less secure domain can independently control whether the secure thread mode and the less secure thread mode use the main stack pointer, respectively.
[0075] Typically, within the body of an exception handler operating in handler mode H or within a thread operating in thread mode T, the selection of a secure or non-secure stack pointer may depend on the current security domain in which the processing circuitry 4 is executing code. For exception entry and return, pushes and pops of state are performed from the stack identified by the stack pointer associated with the security domain of the background code running before the exception occurred.
[0076] The control register 32 may also include a privilege control value 31 that controls whether code executed in the thread mode is privileged or unprivileged. The privilege control value may be set differently for the secure domain and the less secure domain (e.g., the secure thread mode may be unprivileged and the less secure thread mode may be privileged, or vice versa). Alternatively, the secure thread mode and the less secure thread mode may operate at the same privilege level. It should be appreciated that the privilege control value 31 is only one example, and there may be other ways of using the architectural state stored in the control register to control the privilege level assigned to code in the secure thread mode / less secure thread mode. Figure 3 In the example of , the privilege control value 31 is grouped so that separate secure privilege control values PRIV-S and less secure privilege control values PRIV_LS are provided to control the privilege level used by the thread mode in the secure domain and the less secure domain, respectively. However, another approach may be to provide a single control bit that is switched at domain transition.
[0077] like Figure 3 As shown, control registers 20 may include configuration registers 34 that may store configuration data, including a reentry enable configuration indicator 36 that may specify whether processing circuitry should perform reentry checks in response to a security gateway instruction as described below.
[0078] The control register 20 may also include one or more security stack pointer limit registers 38 and 39, which are used to specify a limit address 40, which provides a limit on the extent to which the security stack data structure pointed to by the security stack pointers MSP_S and PSP_S can be extended. In this example, there are two limit registers, one limit register 39 for the security main stack pointer MSP_S, and another limit register 38 for the security process stack pointer PSP_S. The limit address in each limit register can be used to limit how far the stack data structure can be extended. Reference numeral 40 shows how to arrange the limit address of the PSPLIM_S register 38. If the processing circuit or the exception control circuit 28 detects that the main or process security stack data structure has been extended beyond the limit address in the corresponding limit register 38 and 39 (or detects an attempt to update the stack pointer to a value beyond the limit address), the exception control circuit 28 can trigger a signal notification of the fault, which itself can trigger an exception, and then the exception handler can respond to the fault by taking some recovery actions or other measures to ensure safety. This can be used to ensure that an attacker cannot subvert security measures by causing so many exceptions or by calling so many functions that the stack data structure expands into areas used for other data, potentially corrupting data in those other areas.
[0079] One aspect of handling exception entry and return is the pushing and popping of architectural state. When an exception condition occurs, some of the architectural state stored in registers 14 may need to be saved to memory so that even if an exception handler executed after the exception is entered overwrites those registers, the previous contents of the registers can subsequently be restored from memory when it is necessary to return to the process that was executing before the exception occurred. Figure 3 A stack data structure pointed to by one of the library stack pointer registers shown in can be used to save this state.
[0080] For performance reasons, it is useful to separate the registers that may need to be saved in response to such an exception entry event into two groups, referred to as "caller" registers and "callee" registers. The caller registers are the registers that the exception control circuitry 28 implemented in hardware is responsible for saving to the stack. Therefore, the software of the exception handler does not need to include instructions for saving the caller registers to the stack data structure.
[0081] like Figure 4 As shown, the caller registers may include a subset of general registers. In this example, the caller state includes general registers R0, R1, R2, R3 and R12, link register LR (R14), an indication of the return address to which processing will return after exception handling, and program state register XPSR, which may provide condition codes for controlling the results of conditional instructions. It should be understood that this is only a specific example of which register states may be included in the caller registers.
[0082] like Figure 4 As shown in the basic stack frame in the right part, for a process that does not use any floating point registers 18, the basic stack frame may only include some integer registers 16 or control registers 20 and the return address. However, if the process executed before the exception also uses floating point registers 18, then Figure 4 As shown in the expanded stack frame on the left, the caller registers may also include a subset S0-S15 of the floating point registers 18. The floating point context may also include additional control registers, such as a floating point status control register FPSCR for controlling the processing of floating point operations.
[0083] like Figure 4As shown in the middle portion of , the extended floating point stack frame may also include space reserved for additional floating point contexts, but the floating point context is not actually saved to this reserved space on the stack when handling exception entry. Instead, a lazy floating point context save may be used, where space is reserved on the stack in response to an exception so that a new stack pointer generated after exception entry is predictable, but actual saving of the floating point context to this reserved space is postponed until the first time a floating point state is needed after the exception. In this way, if a subsequent exception return occurs before the exception handler accesses any floating point context, the time and effort spent on saving the floating point context from the floating point registers 18 to memory may be avoided.
[0084] therefore, Figure 4 All of the example stack frames shown in are examples of a caller register stack frame (first stack frame) that includes state saved from the caller registers but does not include state associated with the callee registers.
[0085] After the exception control circuit 28 saves the caller stack frame to the stack in response to the exception event, execution of the exception handling code can begin, and the exception handler software can then save the state from the additional callee registers to the stack (if the exception handler software knows that it will overwrite this state during its execution). However, this state saving by the exception handler is performed by controlling the load / store unit of the processing circuit 4 to save the relevant data to the memory in response to the load / store instructions provided in the exception handler code, which may be slower (compared to the case if the exception control circuit 28 controls the push in the hardware). However, it is beneficial to allow partitioning between the caller and callee register states so that the software executed after entering the exception can affect which registers need to be saved. If the exception handler never accesses a particular callee register (e.g., general register R7 or floating point register S27), the exception handler does not need to save the corresponding architectural state, and the effort and time associated with completing this state saving in the exception control circuit 28 and hardware has also been avoided. Writers of exception handler code, or compilers of such code, may be encouraged to use caller registers before using additional callee registers to reduce the chances of needing to do additional state saving in software.
[0086] However, if exception entry causes a transition from the secure domain to the less secure domain and the original background process was executing in thread mode before the exception was placed in the secure domain, this may make the callee registers within register store 14 accessible to the less secure exception handler to be executed after the most recent exception if only the caller registers are saved to memory by exception control circuitry 28. This may be undesirable because the callee registers may include information derived from secure areas of memory address space (which the SAU 24 would otherwise prevent the less secure exception handler from accessing).
[0087] Thus, for certain transitions from the secure domain to the less secure domain (where background processing was previously executed in the secure domain), the exception control circuitry 28 may save the callee registers to the relevant stack data structure in addition to the caller registers, and may clear the contents of the saved registers (including both the caller registers and the callee registers). Thus, by performing the extra state save in hardware, this means that software that would normally save the callee registers cannot access potentially secure information stored in those registers before the exception occurred.
[0088] Therefore, for some exception entry transitions, instead of storing Figure 4 Instead of the caller stack frame shown in Figure 5 The second stack frame shown (under hardware control of the exception control circuit 28, i.e., without requiring explicit load / store instructions to be executed by the processing circuit 4). Again, as Figure 5 As shown in the left part of , for cases where no floating-point context is needed, the stack frame can omit saving any floating-point state. In this case, the second stack frame includes Figure 4 , and also includes additional callee state, which includes registers R4-R11. The additional state saved by the hardware may also include an integrity signature 50, which will be described in more detail below. Alternatively, for the case where the floating point context also needs to be saved, in addition to Figure 4 In addition to the caller state shown in the left example of FIG. , the extended second stack frame also includes additional callee floating point registers S16 to S31, as shown in FIG. Figure 5 As shown on the right side of Figure 5 , but some embodiments may reserve space for callee and caller floating point registers and use the same Figure 4 These registers are saved with delay in the same manner as described.
[0089] therefore, Figure 4 The base caller stack frame shown in the example of may be an example of a first exception stack frame, and Figure 5The example stack frame of , which also includes additional architectural state associated with the callee registers, may be an example of a second exception stack frame that includes a subset of the architectural state data from the registers that is omitted from the first exception stack frame. Upon exception entry transition, the exception control circuitry may select which of the first exception stack frame and the second exception stack frame the hardware should save, for example depending on the security domain associated with the processing performed before and after the exception or other state information associated with the control registers 20. Whether to save the floating point context and whether to use the delayed floating point context save option may depend on a control parameter specified in one of the control registers 20.
[0090] When the exception control hardware 28 saves the caller and callee states, the integrity signature 50 is included in the second exception stack frame, but Figure 4 The integrity signature 50 may be omitted from the first exception stack frame shown. The integrity signature 50 may have a special reserved value that does not correspond to an executable address (e.g., an address that would cause a fault to be signaled if an attempt was made to fetch instructions from it). This integrity signature may be used to detect certain forms of attacks that may be installed on the processing circuitry that attempt to circumvent the security protection provided by hardware that enforces the partitioning between secure and less secure domains. One possible attack vector may be that an attacker attempts to perform an exception entry transition to enter the handling of an exception, but then forges a return transition that is different from the transition expected to return from the exception entry, such as performing a function return transition. The signature 50 may be located at a location on the stack frame that is expected to store the function return address if a function return is performed, and since the integrity signature 50 may have a special value that does not correspond to an executable address, this means that no valid function return address can match the signature. Therefore, if a return address is detected for a function return that matches the integrity signature 50, a fault may be triggered because it means that the stack frame being used to perform the function return was actually saved to the stack in response to the exception entry event (which may be an indication that an attack is being performed). Additionally, for a return from an exception for which additional architectural state associated with the callee registers is present on the stack, part of the security check may check whether the value at the associated offset in the stack corresponding to the integrity signature 50 has the expected value, as the absence of a signature may indicate that an inappropriate sequence of exception entry and return events has been triggered.
[0091] Thus, providing an integrity signature on the stack is an example of a protection action that may be performed for certain exception entry transitions. In particular, for at least one form of secure thread mode to less secure handler mode exception entry transition, an integrity signature may be saved on the stack. However, integrity signature 50 is not included in such Figure 4In the basic caller stack frame shown, it may be expected that protection measures are not needed when executing an exception entry from the secure domain to an exception handler that is also in the secure domain. For the case when a secure exception occurs during secure context processing in thread mode and no other exceptions occur during processing of the secure exception, avoiding the callee state in hardware (which includes the integrity signature) can help reduce interrupt processing latency so that the next exception return simply goes back to the previous secure context processing.
[0092] However, if Figure 8 As shown, omitting protection actions for abnormal entry transitions of secure threads to less secure handler modes may sometimes provide an exploitable path for attackers. Figure 8 The following sequence of events is shown:
[0093] 1. An interrupt (IRQ 1) causes a transition to secure handler mode. The caller-save registers are automatically saved to the secure process stack (indicated by PSP_S) by the exception control hardware 28. To reduce interrupt processing latency, the callee-save registers are not saved, so Figure 4 The first exception stack frame of the type shown is saved (leaving out the integrity signature). This is acceptable because the target state is safe and therefore can be trusted not to corrupt these registers.
[0094] 2. Another interrupt (IRQ 2) causes a transition to non-secure handler mode. At this point, the hardware reserves both the caller and callee save registers, because the transition is to a non-secure state that cannot be trusted to process secure values. Therefore, Figure 5 The second exception stack frame of the type shown in is saved to the secure main stack (indicated by MSP_S). When this exception occurs during processing in handler mode, the main stack is used.
[0095] 3. An attacker who has control over the non-secure domain can then forge an exception return or function return to secure thread mode (instead of the expected exception return to secure handler mode to return from IRQ 2). Since the stack frame saved to the secure process stack in step 1 does not have an integrity signature on its stack, if a pop attempt for a return to secure thread mode causes the caller-only exception stack frame saved to the secure process stack in step 1 to be popped, there is the potential for a security vulnerability.
[0096] This problem can be solved by setting the stack pointer select value 30 in step 1 to indicate that thread mode should subsequently use the main stack pointer (MSP) (rather than the process stack pointer (PSP) normally used for thread mode) for pop operations. This means that if an attacker forges a fake exception return in step 3, the pop will be from the main stack rather than the unprotected process stack. Since the stack frame on the main stack is actually a return for IRQ 2 (return to handler mode) rather than a return to thread mode, other integrity checks may fail (for example, a mismatch may be detected between the mode actually returned to and the mode indicated in the pop status (which is the mode to return to when the stack frame is popped)). Therefore, the attack can be detected.
[0097] Figure 6 is a table showing many different forms of exception entry conversions that can be supported by the exception control circuit. As shown in the first four columns of the table, which exception entry conversion is selected depends on the security domain and mode associated with the background processing performed before the exception entry occurs, whether the background processing uses the main stack pointer or the process stack pointer (indicated by the stack pointer selection value 30) for thread mode, and the security domain associated with the exception condition itself. For example, the type of exception that has occurred may imply whether the exception type is a safe exception or a less safe exception, or the exception may be associated with additional control information (which specifies which security domain is associated with the exception). Please note that there is no conversion corresponding to the background processing performed in the handler mode using the process stack pointer, because the process stack pointer can only be used when the background mode is the thread mode. Therefore, for the case when the background mode is the handler mode, there is no equivalent content of the 9th to 12th rows of the table.
[0098] Figure 6 Column 5 of the table shows, for each different exception entry conversion, which stack frame format is used.
[0099] For the transitions indicated in lines 5 to 8, 11, and 12, only the caller-saved registers need to be saved because the background processing being executed is in the less secure domain, so there is no risk of losing sensitive information even if the callee registers are not saved.
[0100] For the transitions shown in lines 2, 4, and 10, the background processing is located in the secure domain, while the target security domain of the exception is the less secure domain, so additional state saving of the callee-saved registers is performed in hardware by the exception control circuit 28 to prevent data in these registers from being leaked to the less secure exception handler.
[0101] for Figure 6, while the architecture may only require saving the caller registers, it may allow for the optional saving of the callee registers if desired. This may be useful because if the system first performs one type of exception entry conversion (which requires saving both the caller and callee saved registers), but a higher priority exception occurs while saving the callee registers, so a different exception entry (which does not require saving the callee registers) is selected, the hardware can more simply continue saving the callee registers, rather than stopping the saving and having to cancel the changes associated with the previous saving of the callee registers that were made in response to the first exception. The exception return value written to the link register R14 may include a flag DCRS, which may be set to indicate whether the default stack rules have been followed and only the caller registers are on the stack, or whether the callee registers are also placed on the stack. This flag may be checked when performing an exception return to determine which pops need to be performed, and may also be used to determine which integrity checks should be performed based on the integrity signature. This exception return value placed in the link register may also specify other information referenced during the exception return, such as whether to use a safe stack or a less safe stack for push, a flag indicating the operating mode in which the push is performed (and the corresponding exception is expected to be returned to), or a flag indicating whether the stack frame is a standard integer stack frame only or an extended floating point stack frame. It should be understood that other information may also be indicated in the exception return value.
[0102] Figure 7 is a table showing many different forms of exception return conversions that the exception control circuitry 28 can use to return processing to previous processing that was performed before the exception was executed. As shown in the first five columns of the table, the specific conversion selected depends on the security domain associated with the exception, the security state when the exception return is requested, the stack pointer to return to, the mode to return to, and the security state to return to. The determination of which stack pointer, mode, and security state to return to can be based on information associated with the exception return instruction that triggered the exception return event. The security state when the exception return is requested may be different from the security domain associated with the original exception because, for example, a function call may have been made because the exception was executed, which may result in a transition between a less secure domain and a secure domain. Therefore, when an exception occurs, the security domain associated with the exception can also be determined from a flag placed in the exception return value in the link register. Similar to Figure 6 The exception in the transition is Figure 7For example, there is no "return to handler" equivalent of the transitions in lines 5, 6, 11, 12, 17, and 18, because it is not possible to use the process stack pointer in handler mode. In addition, when currently in the less secure state (i.e., there is no mirroring of lines 1 to 6, where the security state when the exception return is requested is less secure), there is no exception return transition to return from a secure exception, because these transitions are also prohibited. Although a less secure exception can subsequently call a secure function that triggers an exception return, for a secure exception, it is not allowed for the secure exception to subsequently call a less secure function that triggers an exception return.
[0103] Figure 7 Column 6 of _ illustrates, for each exception return transition, whether callee registers are expected to be present on the stack frame associated with this exception, and therefore whether any integrity signature check is required to determine whether the value at a particular offset on the stack frame matches the expected integrity signature value. For most exception return transitions, either callee registers are not expected and integrity signatures are not checked, or both are expected and integrity signature checks are performed. However, for the transitions shown in rows 1, 3, and 5 (which correspond to Figure 6 The exception entry transitions on lines 1, 3, and 9 may optionally save callee registers in addition to the caller registers), whether callee registers are expected and whether the integrity signature is to be checked may depend on the DCRS flag that is saved in the exception return value in the link register when the exception occurs.
[0104] The above article about Figure 6 A potential attack exploiting the lack of an integrity signature is described, which is addressed by setting a stack pointer select value of 30 in response to a secure to secure exception entry transition. However, to protect against another form of attack, it may be desirable to provide an architectural means for detecting a transition sequence that results in a switch back to secure thread mode in a context where the stack pointer select value 30 indicates that the primary stack pointer is to be used as the selected stack pointer by the thread mode.
[0105] The processing circuit 4 may support certain instructions, called gateway instructions (or "secure gateway" instructions, SG), which can be used to mark valid entry points into the secure domain when switching from a less secure domain to a secure domain. When the program flow changes from processing in the less secure domain to an instruction at an instruction address (the SAU 24 indicates that the instruction address is associated with the secure domain), the processing circuit 4 may check whether the first instruction executed at the target address after the program flow change is a secure gateway instruction, and if not, the processing circuit 4 may trigger a fault. The writer or compiler of the secure code can mark points in the code that allow less secure code to call secure code using secure gateway instructions. This, for example, prevents less secure code from being able to branch to arbitrary locations within the secure code (such branches may cause security vulnerabilities by allowing some security measures to be circumvented). For example, in the case where the secure code includes a password check, if protection against arbitrary branch points is not provided, this may allow less secure code to branch to a portion of the secure function that bypasses the password check, thereby effectively allowing the password check to be circumvented, even if the non-secure code does not have the correct password. This is a relatively simplistic example, but there may be other more complex examples where there may be significant security risks if less secure code is able to branch to certain points within secure functions. Therefore, providing a secure gateway instruction can protect valid entry points to secure code, and any other entry points can be treated as invalid entry points that trigger a fault, thereby improving security.
[0106] Although the secure gateway instruction will typically be present at a valid entry point to the secure domain, the secure gateway instruction may also be used to trigger a check on the secure main stack pointer to check whether it is safe to use the secure main stack pointer stored in register MSP_S. Even if an attacker provides code including a secure gateway instruction for a malicious secure function, the secure gateway instruction may still be trusted to trigger the processing circuit 4 to perform an additional security check on the stack pointer because even if the remainder of the secure thread mode code is malicious, the attacker cannot avoid providing the secure gateway instruction because any instruction other than the secure gateway instruction at the point of entry into the secure thread mode code will trigger a fault.
[0107] In one example, the stack pointer validation action triggered by the secure gateway instruction when transitioning from a less secure domain may simply check whether the stack pointer select value 30 is equal to 0, indicating whether the primary stack pointer should be used in thread mode. Therefore, if the stack pointer select value is equal to 0, this may trigger a fault. This may prevent attacks, but may exclude some valid use cases (where it may still be desirable to allow secure thread mode to use the primary stack pointer).
[0108] Thus, in the example discussed below, the stack pointer verification action may alternatively involve triggering a permission check to check whether the memory access check circuit 22 allows a load request that specifies a target address derived from the stack pointer indicated by the stack pointer selection value 30 to be used in the secure thread mode. Thus, in the case where the stack pointer selection value 30 has previously been set to indicate the main stack pointer, the permission check may be based on the address stored in the secure main stack pointer register MSP_S to check whether the thread mode is allowed to access the stack data structure indicated by the main stack pointer, and thereby check whether it is safe to use the stack pointer.
[0109] In some cases, the security gateway instruction may actually trigger a load request for the target address to invoke the permission check performed by the memory access check circuit 22 for the target address of the load. Such a load request may also serve as a defense against reentry scenarios that may sometimes result in incorrect processing results. This is particularly useful in Fig. 9 is shown in the example of . At point 1, a secure thread mode function is called from a less secure state. The first instruction after branching to the secure state should be an SG instruction (otherwise a fault occurs). Prior to this call, the unsafe state sets a timer interrupt to fire after a specific amount of time. The unsafe code can schedule this timer to fire during a critical security operation designed to support reentry. When the timer triggers, control is redirected to the less secure handler mode. The less secure handler mode then returns to the less secure thread mode (deprivileged operation). At point 2, the less secure thread mode calls again to the secure state. Because the secure state is entered again when a critical operation (which is not designed to be secure against reentry) has not yet been completed, this may lead to a reentry attack. For example, a critical operation may be an operation such as updating an event counter, which is used to count the number of times a given event occurs. In response to each occurrence of an event, the following function may be called (where #count represents the address where the counter value is stored in memory):
[0110] LDR r0,[#count] / / Load current count value from memory
[0111] ADD r0,r0,#1 / / Add one to the current count value
[0112] STR r0,[#count] / / Store the updated count value back to memory.
[0113] If a timer interrupt occurs between a load and store instruction, and this function is then called again on a subsequent occurrence of that event, this may result in missing one of the two occurrences in the count, since both instances of executing this function will read the same initial value for the load instruction, and therefore only one count increment will occur despite the function being called twice. It will be appreciated that this is a relatively simple example, and that numerous other examples of code that is not safe for reentrancy can be provided.
[0114] Although such reentrancy issues may affect both secure and less secure functions, it may not be considered reasonable to provide an architectural function for checking whether reentry has occurred for less secure code, because there may be software techniques by which a writer or compiler of software can design less secure functions to be safe for reentry or include checks for detecting whether reentry has occurred, and although this may increase code or reduce performance, it may not be desirable to introduce any security vulnerabilities when executing code in the less secure domain. However, for the secure domain, these software techniques for detecting reentry or preventing reentry may introduce security vulnerabilities, and therefore reducing the chance of such vulnerabilities may preferably provide an architectural check for whether reentry has occurred.
[0115] For reentrancy checking, it should be recognized that when there has been an abnormal entry transition from a secure domain to a less secure domain ( Fig. 9 solid line in the figure) or there is already an exception function call from the secure domain to the less secure domain after the exception entry transition from the secure domain to the less secure domain ( Fig. 9 In the case of a secure to less secure exception transition (solid line), an integrity signature value is expected and therefore the secure function is called a second time from the less secure domain in thread mode (in Fig. 9 2), when a secure gateway is present, a load may be triggered, thereby specifying as its target address the selected stack pointer selected for use in secure thread mode based on the step pointer selection value 30. The processing circuitry may check whether the integrity signature 50 is present at this address, and if so, trigger a fault, as this would indicate that the relevant stack frame saved to memory upon the exception entry transition from the secure domain to the less secure domain has not yet been popped upon the exception return in response, indicating that this is a re-entry situation to the same secure function code where a previous instance of processing the same secure function has not previously been completed.
[0116] On the other hand, if the function call ( Fig. 9), the integrity signature 50 will not be present in the stack at the location indicated by the selected stack pointer value, but in this case, reentrancy can be detected because at the point in time when the second call to secure thread mode is made, the stack pointer selection value (SPSEL) 30 will still be set to 0, indicating that the main stack pointer will be used because Fig. 9 The transition marked with a dashed line 3 in FIG. 1 has resulted in the stack pointer select value being set to 0, and in the case of reentrancy, the stack pointer select value has not yet been set back to 1 because there is no corresponding Fig. 9 Any corresponding exception return transition opposite to the interrupt labeled 3 in . Thus, an SPSEL with a value of 0 when a secure thread mode function is called is again a sign that reentrancy is about to occur.
[0117] Thus, any such reentrancy check can prevent a chain of transitions that results in calling the same function in safe thread mode after an earlier call to safe code (which was interrupted and not yet resumed) from causing incorrect processing results.
[0118] It is not always necessary to perform such reentrancy checks on secure gateway instructions that are executed after being called from a less secure domain. Figure 3 As shown, a reentry enable configuration bit 36 may be provided in the configuration register 34 to control whether a reentry check is required for a secure gateway instruction at an address associated with a secure domain when translating from a less secure domain to a secure gateway instruction at an address associated with a secure domain. For example, if a secure function is known to have code that is safe for reentry, reentry checks may be disabled to improve performance and save power. However, even if reentry checks are disabled, the secure gateway instruction may still trigger the processing circuit to issue a load request for a target address corresponding to a selected stack pointer, or to issue another type of request that triggers a permission check on the target address, as this still guards against some types of attacks involving manipulation of the stack pointer as discussed above.
[0119] Fig.10 The diagram shows the use of Figure 1The flowchart of the method for data processing performed by the processing device 2 shown, which includes a check performed in response to a secure gateway instruction. In step 100, the next instruction to be processed is obtained. In step 102, it is detected whether the current domain is a less secure domain, and in step 104, it is detected whether the next instruction is captured from an area of the memory marked as associated with the secure domain by the attribute data in the SAU 24. Generally, for the conversion from the less secure domain to the instruction captured from the secure area of the memory, some checks may be required to check whether the entry to the secure domain is valid. The situation where the current domain is a less secure domain and the next instruction is captured from the secure memory is called a given change of control flow. If the current domain is a secure domain or the instruction is captured from a less secure area of the memory, this is not a given change of control flow and no subsequent security / reentry check is required. If the current domain is a secure domain or the instruction is captured from a less secure memory, then in step 106, the instruction can be executed normally according to the function represented by the next instruction.
[0120] If a given change of control flow from a less secure domain to an instruction fetched from secure memory is identified, then processing circuitry 4 checks whether the next instruction is a secure gateway (SG) instruction at step 108. If the next instruction is anything other than a secure gateway instruction, then a security fault is raised at step 110. This ensures that the system can only transition to the secure domain at certain points in the code marked by secure gateway instructions.
[0121] If the instruction is identified as a secure gateway instruction, then at step 112, the processing circuit 4 determines whether the current operating mode is a thread mode. If the current mode is a handler mode, the subsequent check for reentry and stack pointer verification can be omitted, and at step 106, the instruction can be executed normally. For secure gateway instructions, this normal execution may include at least one security check for whether a transition to a secure domain is allowed. If all required security checks for the secure gateway instruction are passed, executing the secure gateway instruction causes the processing circuit 4 to update the register of the current security domain of the specified operation, so that the current domain is switched from the less secure domain to the secure domain.
[0122] It should be noted that a secure gateway instruction may also be encountered when the current domain is a secure domain. This may be because the same code may be called from a less secure function or from a secure function. In the case of executing a secure gateway instruction while already in a secure domain, then program flow will continue from step 102 to step 106 as discussed above.
[0123] If, at step 112, the current mode is determined to be the thread mode, then at step 114, in response to the secure gateway instruction, the processing circuit 4 triggers the memory access check circuit 22 to perform a permission check to determine whether a load request is allowed, the load request requesting to load data at a target address from the memory 6 for the secure thread mode, the target address being derived from the selected stack pointer indicated by the stack pointer select value 30. Specifically, the target address may be equal to the stack pointer stored in the selected register MSP_S or PSP_S, which is selected depending on the stack pointer select value 30. Triggering the permission check causes the MPU 26 to check access permission for the target address.
[0124] The MPU 26 may maintain separate sets of memory attribute entries for the secure domain and the less secure domain. For a secure gateway instruction, a load request may be checked against access permissions associated with the secure domain, even though the current domain may still be the less secure domain. In addition, whether a load triggered by a secure gateway instruction is considered a privileged access request or an unprivileged access request may depend on the security policy. Figure 3 A privilege control value 31 is shown which specifies whether accesses from secure thread mode should be considered privileged or unprivileged.
[0125] The permission check at step 114 may be triggered in a number of different ways. In one example, the processing circuitry 4 may actually issue a load request specifying a target address, similar to the case of an actual load operation being performed. Alternatively, a different type of request (e.g., a store request or an address check request) may be issued to the memory access check circuitry 22 that triggers a permission check without triggering an actual memory access to the memory system 6. In the case where reentrancy checking is performed, issuing a load request may be most efficient (because the value loaded by such a load request will be needed at step 122), but when reentrancy checking is not performed, another type of request may be used. Alternatively, even if reentrancy checking is disabled, a load request may still be issued to invoke a memory access permission check, thereby reducing complexity by issuing the same type of request regardless of whether reentrancy checking is enabled or disabled.
[0126] Thus, at step 116, based on the MPU 26 lookup of the memory access permissions, the memory access checking circuitry 22 determines whether a load to the target address is permitted, and if not, a memory protection fault is raised at step 118. Thus, if the secure thread mode is considered unprivileged and the address associated with the selected stack pointer leads to privileged memory (which is typically expected if the primary stack pointer is currently selected), the load may not be permitted, and the memory fault may prevent subsequent secure code from manipulating the primary stack pointer value in a manner that is inappropriate or results in a security vulnerability.
[0127] If the permission check passes (loading the target address will be allowed), then at step 120, the processing circuit detects whether the reentry enable configuration value 36 indicates that reentry checking is enabled. If reentry checking is disabled, the method continues to step 106 to execute the SG instruction normally as described above. It should be noted that even if reentry checking is disabled, the permission check is still triggered at step 116 to provide protection against stack manipulation attacks.
[0128] If reentrancy checking is enabled, the method proceeds to step 122. If, at step 114, a load request has not been issued, then a load request specifying the target address may be issued at step 122 (although in practice, it may be more efficient to issue a load request at step 114 to trigger a permission check if reentrancy checking is enabled). Regardless of whether a load request is issued at step 114 or step 122, at step 122, the processing circuit 4 detects whether the value loaded from the memory 6 in response to the load request for the target address matches the integrity signature 50, which is such that Figure 5 As shown, the state save of the additional callee state is saved on the stack. If the loaded value matches the integrity signature, a reentry situation exists and therefore, at step 124, a safety fault is raised to prevent incorrect processing results caused by executing a second instance of a safety function when the first instance of the safety function has not yet completed.
[0129] Additionally, if reentrancy checking is enabled, then at step 126, the processing circuitry checks whether the stack pointer select value 30 indicates that the currently selected state pointer is the primary stack pointer, i.e., whether the stack pointer select value is equal to 0 in this example. If the currently selected stack pointer is the primary stack pointer, then again at step 124, a security fault is raised. If the loaded value does not match the integrity signature and the currently selected stack pointer is the process stack pointer (stack pointer select value is equal to 1), then at step 106, the SG instruction is executed normally because the reentrancy check has been passed.
[0130] Therefore, in summary, by using the secure gateway instruction to trigger validation of the stack pointer value and reentrancy checks (where enabled), this can provide protection against attacks as well as improve performance by avoiding the need for software to detect or mitigate reentrancy scenarios.
[0131] Fig.11The simulator implementation that can be used is illustrated. Although the embodiments described above 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 can also be provided according to the embodiments described herein, and this instruction execution environment can be implemented by a computer program. Such computer programs are generally referred to as simulators, as long as these simulators provide a software-based hardware architecture implementation. Variations of simulator computer programs include emulators, virtual machines, models, and binary converters (including dynamic binary converters). Typically, the simulator implementation can be run on a host processor 230, which optionally runs a host operating system 220, which supports the simulator program 210. In some arrangements, there may be multiple simulation layers between the hardware and the provided instruction execution environment, and / or multiple different instruction execution environments may be provided on the same main processor. Historically, powerful processors have been required to provide simulator implementations that run at reasonable speeds, but this approach may be reasonable in some cases, such as when it is desired to run another processor local code for compatibility or reuse reasons. For example, a simulator implementation can provide an instruction execution environment with additional functions that are not supported by the host processor hardware, 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" by Robert Bedichek, published in the 1990 USENIX Winter Symposium, pages 53-63.
[0132] 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 caches may be implemented as software data structures in simulated embodiments. In addition, the physical address space used to access the memory 6 in the hardware device 2 may be simulated as a simulated address space 200, which is mapped by the simulator 210 onto the virtual address space used by the host operating system 220. In an arrangement in which one or more hardware components referenced in the previously described embodiments are present on host hardware (e.g., the host processor 230), some simulated embodiments may utilize the host hardware where appropriate.
[0133] The simulator program 210 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 (which may include an application, an operating system, and a hypervisor), which is the same as the application program interface of the hardware architecture modeled by the simulator program 210. Therefore, the simulator program 210 may be used to execute program instructions of the target code from within the instruction execution environment, so that the host computer 230, which does not actually have the hardware features of the above-mentioned device 2, can simulate these features. The simulator program may include a processing program logic 235, a memory access check program logic 240 (which includes an MPU program logic 242 and a SAU program logic 244), and an exception control program logic, which provide a simulation. Figure 1 The processing pipeline 4 of the hardware device 2, the memory access check circuit 22 (including the MPU 26 and the SAU 24), and the function of the behavior of the exception control circuit 28. The architectural registers 14 of the system 2 can also be emulated using the register emulation program logic 255 maintained by the emulator code 210. It is used to map the architectural registers of the target architecture to the memory space used by the host hardware 230. Therefore, when a security gateway instruction is identified in the target code 200 after a given change in program flow during the processing of the target code 200, the security check and reentry check triggered by the gateway instruction in the hardware in the example discussed above can be performed in the target code 200. Fig.11 In the example of , it is instead executed in software by the simulator program 210 .
[0134] In this application, the phrase "configured to..." is used to indicate that elements of a device have a configuration capable of performing a defined operation. In this context, "configuration" means the arrangement or manner of interconnection of hardware or software. For example, a device may have dedicated hardware to provide the defined operation, or a processor or other processing device may be programmed to perform the function. "Configured to" does not mean that providing the defined operation requires that the device elements be changed in any way.
[0135] Although illustrative embodiments of the present invention have been described in detail herein with reference to the accompanying drawings, it is to be understood that the invention is not limited to those precise embodiments and that various changes and modifications may be effected by one skilled in the art without departing from the scope and spirit of the invention as defined by the appended claims.
Claims
1. A data processing device, include: processing circuitry for performing data processing in a security domain of a plurality of security domains, the plurality of security domains comprising at least a secure domain and a less secure domain; a memory access checking circuit for checking whether a memory access is permitted based on security attribute data indicating which of the plurality of security domains is associated with a target address of the memory access; as well as at least one stack pointer register, for storing a stack pointer, the stack pointer indicating a stack data structure in the memory; wherein: In response to a given change of program flow from processing in the less secure domain to a target instruction having an instruction address associated with the secure domain: The processing circuitry is configured to trigger a fault when the target instruction is an instruction other than a gateway instruction indicating a valid entry point to the security domain; as well as When the target instruction is the gateway instruction, the processing circuit is configured to trigger a stack pointer verification action in response to the gateway instruction to verify whether it is safe to use the selected stack pointer stored in the selected stack pointer register.
2. The apparatus of claim 1, wherein the stack pointer verification action include: A permission check is triggered to check whether a load request is allowed, the load request requesting to load a value from an address derived from a selected stack pointer stored in the selected stack pointer register.
3. The apparatus of claim 2, wherein the processing circuit is configured to operate at a privilege level of a plurality of privilege levels; and The memory access checking circuitry is configured to trigger a fault if a selected set of access permissions applicable to the target address specifies that a selected privilege level is prohibited from accessing the target address.
4. The device according to claim 3, in: The processing circuit is configured to perform data processing in one of a plurality of operating modes; and The selected privilege level comprises a privilege level associated with a process in a combination of a current operating mode of the processing circuitry and the security domain at the given change in program flow. 5 . The apparatus of claim 3 , wherein the selected set of access permissions comprises a set of access permissions applicable to the target address when a current domain of the processing circuit is the security domain.
6. The apparatus of any one of claims 2 to 5, wherein an address derived from a selected stack pointer is equal to the selected stack pointer.
7. The apparatus according to any one of claims 2 to 5, wherein in response to the given change in program flow, when the target instruction is the gateway instruction, the processing circuit is configured to perform a reentrancy check in response to the gateway instruction; The reentrancy check include: A fault is triggered when a value loaded from an address derived from a selected stack pointer is one of at least one integrity signature value.
8. The apparatus of claim 7, wherein in response to the given change in program flow, when the target instruction is the gateway instruction: The processing circuit is configured to determine whether to perform the reentrancy check in response to the gateway instruction based on a reentrancy check enable value, the reentrancy check enable value specifying whether the reentrancy check is enabled or disabled.
9. The apparatus of claim 8, wherein in response to the given change in program flow, when the target instruction is the gateway instruction: The processing circuitry is configured to trigger the permission check for the address derived from the selected stack pointer even when the reentrancy check enable value specifies that reentrancy checking is disabled.
10. The apparatus of claim 7 , comprising exception control circuitry to perform, in response to an exception condition, one of a plurality of exception entry transitions, the exception entry transition selected based at least on a current security domain of the processing circuitry, wherein for at least a subset of the plurality of exception entry transitions, the exception control circuitry is configured to trigger saving of a stack frame including the one of the at least one integrity signature value to a stack data structure identified by a stack pointer stored in one of the at least one stack pointer registers.
11. The apparatus of claim 7, comprising an exception control circuit that, in response to an exception return condition, performs an exception return conversion of a plurality of exception return conversions, the exception return conversion being selected based at least on a security domain associated with the exception return condition, wherein for at least a subset of the plurality of exception return conversions, the exception control circuit is configured to perform an integrity signature check, the integrity signature check include: A stack frame selected for the exception return conversion is accessed from a given stack data structure, and a fault is triggered when a mismatch is detected between a value at a predetermined location in the accessed stack frame and at least one of the at least one integrity signature value.
12. The apparatus of claim 7, wherein the reentrancy check further include: A fault is triggered when a stack pointer select value used to determine which stack pointer register to use for a push or pop of an architectural state has a predetermined value.
13. The device according to claim 12, in: Within a given security domain, the processing circuitry is configured to perform data processing in one of a plurality of modes, the plurality of modes including a handler mode for exception handling and a thread mode for background processing; The apparatus includes an exception control circuit that triggers storage of architectural state data to a data structure in response to an exception condition: When the exception condition occurs in the thread mode and the stack pointer select value has a first value, storing to a process stack data structure identified by a stack pointer stored in a process stack pointer register; as well as When the exception condition occurs in the thread mode and the stack pointer select value has a second value, storing to a primary stack data structure identified by a stack pointer stored in a primary stack pointer register; and The predetermined value includes the second value.
14. The apparatus of claim 13, wherein in response to at least one secure thread mode to secure handler mode exception entry transition, the exception control circuit is configured to update the stack pointer selection value to the second value.
15. The apparatus of claim 7, wherein in response to a change in program flow from processing in the security domain to a gateway instruction having an instruction address associated with the security domain, the processing circuit is configured to omit the reentrancy check.
16. The apparatus of claim 1, wherein within a given security domain, the processing circuit is configured to perform data processing in one of a plurality of modes, the plurality of modes comprising a handler mode for exception handling and a thread mode for background processing; The apparatus includes an exception control circuit that triggers storage of architectural state data to a data structure in response to an exception condition: When the exception condition occurs in the thread mode and the stack pointer select value has a first value, storing in a process stack data structure identified by the stack pointer stored in the process stack pointer register ; as well as When the exception condition occurs in the thread mode and the stack pointer select value has a second value, storing to a primary stack data structure identified by a stack pointer stored in a primary stack pointer register; as well as The stack pointer verification action includes: triggering a fault when the stack pointer selection value has the second value.
17. An apparatus according to claim 10, wherein in response to a given change in the program flow, when the target instruction is the gateway instruction and at least one security check performed in response to the gateway instruction is passed, the processing circuit is configured to trigger a switch of the current security domain from the less secure domain to the secure domain.
18. The device according to claim 1, in: In response to the given change of control flow, when the target instruction is the gateway instruction, the processing circuit is configured to trigger the stack pointer validation action at least when the processing circuit is in a predetermined operating mode.
19. The apparatus of claim 18, wherein within a given security domain, the processing circuit is configured to perform data processing in one of a plurality of modes, the plurality of modes comprising a handler mode for exception handling and a thread mode for background processing; and The predetermined operation mode includes the thread mode.
20. The apparatus according to any one of claims 18 and 19, wherein in response to the given change of control flow, when the target instruction is the gateway instruction, the processing circuit is configured to omit the stack pointer verification action when the processing circuit is in an operating mode other than the predetermined operating mode.
21. A data processing method for a processing circuit, the processing circuit being capable of performing data processing in a security domain of a plurality of security domains, the plurality of security domains comprising at least a secure domain and a less secure domain, for the processing circuit, checking whether a memory access is permitted based on security attribute data, the security attribute data indicating which security domain of the plurality of security domains is associated with a target address of the memory access; The method comprises: In response to a given change of program flow from processing in the less secure domain to a target instruction having an instruction address associated with the secure domain: determining whether the target instruction is a gateway instruction indicating a valid entry point into the security domain; When the target instruction is an instruction other than the gateway instruction, a fault is triggered; as well as When the target instruction is the gateway instruction, a stack pointer verification action is triggered in response to the gateway instruction to verify whether it is safe to use the selected stack pointer stored in the selected stack pointer register.
22. A computer readable storage medium storing a computer program for controlling a host data processing device to provide an instruction execution environment for instruction execution ; The computer program comprises: Processor logic for supporting data processing in a security domain of a plurality of security domains, the plurality of security domains comprising at least a secure domain and a less secure domain; memory access checker logic for checking whether a memory access is permitted based on security attribute data indicating which of the plurality of security domains is associated with a target address of the memory access; and register emulation program logic for controlling access to a memory of the host data processing device to emulate access to emulated architecture registers of a target architecture emulated by the computer program, the emulated architecture registers comprising at least one stack pointer register for storing a stack pointer indicating a stack data structure in the memory; In response to a given change of program flow from processing in the less secure domain to a target instruction having an instruction address associated with the secure domain: The handler logic is configured to trigger a fault when the target instruction is an instruction other than a gateway instruction indicating a valid entry point into the security domain; and When the target instruction is the gateway instruction, the handler logic is configured to trigger a stack pointer validation action in response to the gateway instruction to validate whether it is safe to use a selected stack pointer associated with a selected stack pointer register of the emulated architectural registers.
