Hardware verification of dynamically generated code
Through dynamic code validator and instruction package mechanism, the dynamic generated code is verified and restricted, and the security problem of dynamic code execution in computer systems is solved, ensuring the integrity and security of the system.
Patent Information
- Application Number
- CN202410908148.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2021-06-15
- Filing Date
- 2021-10-29
- Publication Date
- 2024-11-01
AI Technical Summary
In computer systems, since the dynamically generated code cannot be authenticated, it is difficult to successfully execute without damaging the security of the system, and the prior art is difficult to effectively verify its security.
With the support of the dynamic code generator, dynamically generated code is analyzed to ensure that it meets a set of standards, including limiting branch target addresses, prohibiting unlicensed instructions, and ensuring that the code does not exit the dynamic code execution area. Mechanisms such as instruction packages and isolation zones to verify and execute dynamic code.
It realizes that without compromising system security, validates and executes dynamically generated code, prevents malicious activities and incorrect operations, and ensures the integrity and security of the system.
Smart Images

Figure CN118886007A_ABST
Abstract
Description
[0001] This application is a divisional application of the invention patent application with application number 202180073713.9, application date October 29, 2021, and name “Hardware Verification of Dynamically Generated Code”. Background Art Technical Field
[0002] Embodiments described herein relate to managing dynamically generated code in a computer system.
[0003] Related technical description
[0004] The software code executed in a computer system may include static code and dynamically generated code. Static code may be cryptographically signed by a trusted source and therefore may be authenticated and trusted for execution in the system (e.g., the code is trusted because it will not attempt any malicious intent or "attack" the system in an attempt to control the system or destroy data in the system). Dynamically generated code cannot be authenticated in this manner and is therefore untrustworthy. Successfully executing dynamically generated code without compromising the security of the system is a challenge. BRIEF DESCRIPTION OF THE DRAWINGS
[0005] The following detailed description refers to the accompanying drawings, which are now briefly described.
[0006] Figure 1 is a block diagram illustrating one embodiment of dynamic code generation and verification.
[0007] Figure 2 is a flow chart illustrating one embodiment of dynamic code verification.
[0008] Figure 3 is shown in more detail Figure 2 A flow chart of one embodiment of a portion of the flow chart shown.
[0009] Figure 4 is shown in more detail Figure 3 A flow chart of one embodiment of a portion of the flow chart shown.
[0010] Figure 5 is a block diagram of one embodiment of a computing device.
[0011] Figure 6 is shown in more detail Figure 5 A block diagram of one embodiment of a processing unit is shown.
[0012] Figure 7 It shows Figure 6 A flow chart of the operation of an embodiment of the processing unit is shown.
[0013] Figure 8 is shown in more detail Figure 7 A flow chart of one embodiment of a portion of the flow chart shown.
[0014] Fig. 9 is a block diagram of one embodiment of a computing device.
[0015] Fig.10 is a block diagram of one embodiment of a computer-accessible storage medium.
[0016] Although the embodiments described in the present disclosure may be subject to various modifications and alternatives, specific embodiments thereof are shown by way of example in the drawings and will be described in detail herein. However, it should be understood that the drawings and specific embodiments thereof are not intended to limit the embodiments to the particular forms disclosed, but on the contrary, the present invention is intended to cover all modifications, equivalents and alternatives falling within the spirit and scope of the appended claims. The headings used herein are for organizational purposes only and are not intended to limit the scope of the specification. DETAILED DESCRIPTION
[0017] Various embodiments for verifying that dynamically generated code meets a set of criteria to be executed in a system before permitting the code to execute are described below. Figures 1 to 5 Describes a software-based implementation and then focuses on Figures 6 to 8 A hardware-based implementation is described.
[0018] Software Implementation
[0019] Figure 1 is a block diagram of one embodiment of the dynamic code generator 10 and the dynamic code verifier 12. Figure 1 Also shown in the figure are a dynamic code buffer 14, a dynamic code execution area 16 surrounded by isolation areas 18A-18B, and one or more static code areas 20. Boxes 14, 16, 18A-18B, and 20 can all be areas in a system memory in a computer system. For example, a memory address space addressable by read and write operations issued by one or more processors in a computer system can be mapped to a system memory. Similarly, the dynamic code generator 10 and the dynamic code verifier 12 can be code sequences stored in the system memory and executed by one or more processors. The static code execution area 20 and the dynamic code execution area 16 can also store code sequences to be executed by one or more processors.
[0020] The dynamic code generator 10 may be configured to generate dynamic code for execution in a system. "Dynamically generated code" or "dynamic code" may refer to any code generated during the execution of a program (e.g., "at runtime") to be executed as part of a program. For example, some programming language implementations allow just-in-time (JIT) compilation. Certain programming languages may experience higher execution performance when using JIT compilation (e.g., JavaScript). When JavaScript code is being executed, the JIT JavaScript implementation may compile the JavaScript code into binary instructions defined by the instruction set architecture implemented by the processor in the computer system. Another example of dynamically generated code may be self-modifying code. As the name implies, the code in the running program generates new code for execution, or modifies previously generated code, and then executes the newly generated or modified code. Another example of dynamically generated code may occur when binary translation is adopted. In binary translation, code expressed in one instruction set is translated into corresponding code in another instruction set, and the translated code is executed to implement the operation represented by the original code. The binary translation mechanism can be static (e.g., translating the entire program before execution), dynamic (e.g., translating the program while it is executing), or a combination of static and dynamic mechanisms. In general, "code" or "code sequence" refers to a plurality of instructions defined in an instruction set architecture of a processor in a computer system, such that the processor can retrieve the code and execute it directly (e.g., as opposed to an interpreted program or source program written in a given programming language that is compiled into executable code).
[0021] In contrast, "static code" or "statically generated code" may refer to any program that is fully available in system memory when the program begins to be executed (e.g., loaded into system memory by an operating system or other control code based on the command to execute the program). Therefore, the operating system kernel and / or system hardware may "know" the entire program before the program begins to execute. In some cases, the program is dynamically linked to other code (e.g., services or functions provided by the operating system, other code available at runtime, etc.). However, dynamically linked code is also fully available at runtime and is therefore statically generated. Static code may be loaded into the static code execution area 20 for execution. The static code execution area 20 may be controlled by the operating system to have only execution permission (or possibly read permission and execution permission), but not write permission. Therefore, during the execution of static code, static code may be unchangeable (e.g., unmodifiable). The operating system itself (e.g., the kernel and various operating system services) may also be in the static code execution area 20.
[0022] In some cases, statically generated code may be cryptographically signed by the entity that generated the code or the entity that authorized execution of the program on the computer system (e.g., the manufacturer of the computer system), and thus the entity attests to the authenticity of the program and has verified that the program is not a malicious attacker and / or does not attempt to perform operations that could compromise the integrity of the system. For dynamically generated code, such attestation may not occur.
[0023] In order to protect the computer system and other programs / data on the computer system from malicious attacks or even erroneous operations of dynamically generated code sequences, a dynamic code verifier 12 is provided. The dynamic code generator 10 can be configured to write the dynamically generated code to the dynamic code buffer 14. Once the code is completed, the dynamic code generator 10 can attempt to initiate the execution of the dynamic code, which can cause the dynamic code verifier 12 to verify the dynamically executed code in the dynamic code buffer 14. The dynamic code verifier 12 can be transparent to the dynamic code generator 10 (for example, the dynamic code generator 10 may not "know" that the dynamic code verifier 12 is instantiated and will verify the dynamically generated code). Alternatively, the dynamic code generator 10 can know the dynamic code verifier 12 and can cooperate with the dynamic code verifier 12 (for example, initiating execution can include communicating to the dynamic code verifier 12 that the dynamic code is available in the dynamic code buffer 14). In another embodiment, when generating dynamic code, the dynamic code verifier 12 can operate in parallel with the dynamic code generator 10.
[0024] like Figure 1 As shown, the dynamic code verifier 12 executes in kernel execution mode 22. Kernel mode 22 may be different from user execution mode 24. User mode 24 may be effective for the dynamic code generator 10, the dynamic code execution area 16, and the static code execution area 20. In one embodiment, some code in the static code execution area 20 may also be executed in kernel mode 22. For example, user mode 24 may have a lower privilege level than kernel mode 22. A more privileged code may access restricted processor resources (and may modify those restricted resources) that a less privileged code may not access (or at least may not modify). A more privileged code may also control the allocation of some resources (e.g., memory pages) to a less privileged code.
[0025] The dynamic code verifier 12 can be configured to analyze the dynamic code to ensure that the code meets certain characteristics, so as to provide dynamic code to be sufficiently contained to prevent successful malicious activities from or using dynamic code and to prevent the erroneous operation of dynamic code from affecting other programs or the operating system itself. At least some guarantees. In one embodiment, the dynamic code verifier 12 can verify the code to be moved to the dynamic code execution area 16. The dynamic code verifier 12 can analyze the dynamic code to ensure that any branch in the dynamic code can only have a branch target in the dynamic code execution area 16, or if the target is outside the dynamic code execution area 16, the target is a valid target address in multiple valid target addresses. For example, the target address in a static code execution area in the static code execution area 20 can be predefined (for example, by the operating system) as a valid target address for the dynamic code. For example, some entry points of the kernel or operating system service can be permitted for dynamic code, and therefore can be valid target addresses. Any valid target address set can be defined in various embodiments. In one embodiment, the valid target address can be provided to the dynamic code verifier 12 as a valid target list, which is locked in a read-only memory before generating the dynamic code. In another embodiment, valid targets may be specified as gates (e.g., vectors of valid targets), and the dynamic code verifier 12 may be configured to ensure that any branches outside the dynamic code execution region 16 use a sequence of identified gates that load the branch (e.g., jump) to.
[0026] In one embodiment, the dynamic code verifier 12 can verify other characteristics of the dynamic code. For example, some instructions defined in the instruction set architecture may not be permitted in the dynamic code (e.g., access to special registers such as model-specific registers or mode configuration registers in the processor, privileged instructions, etc.). Additional details are provided below for one embodiment.
[0027] The instruction set architecture may support "indirect branches" that form target addresses from one or more register values (and displacements that may also be encoded into branch instructions). Since register values are generally unpredictable (e.g., register contents may be read from memory or calculated from other register contents via arithmetic / logic (ALU) instructions), in one embodiment, additional instructions may be used to limit the generated pointer to acceptable target addresses. More specifically, in one embodiment, an indirect branch may be preceded by one or more other instructions that operate on the contents of one or more registers used by the indirect branch to form a target address. These other instructions may modify the contents of the register to ensure that it cannot generate an address outside the dynamic code execution area 16 (e.g., "caged" target addresses, or "constrained" target addresses, or "restricted" target addresses), except for one of the valid target addresses in the valid target list. One or more previous instructions and indirect branch instructions may be referred to as "instruction packages" or simply "packages", and the dynamic code verifier 12 may verify that any indirect branch instructions instantiated in the dynamic code are included in the package. In one embodiment, the dynamic code verifier 12 may further verify that the package is aligned with a boundary defined based on the size of the package. For example, in one embodiment, for a packet size of 16 bytes, the size of the instruction may be 4 bytes and there may be 4 instructions (including indirect branch instructions) in the packet. Such packets may be aligned to 16-byte boundaries. That is, the initial instruction in the packet is stored at an address with a number of least significant bits (LSBs) set to zero based on the size of the packet (e.g., 4 bits for a 16-byte packet). Other numbers of instructions, instruction sizes, and packet sizes may be supported in other embodiments, including smaller or larger numbers of instructions, instruction sizes, and packet sizes.
[0028] The caged / constrained / restricted instructions in the instruction packet may have any form. For example, the instruction may mask the register contents of the indirect branch to ensure that enough LSBs are zero to align the target address to the packet boundary, and the most significant bits (MSBs) above the size of the dynamic code execution region 16 may be masked to zero. The mask value may be added to the base address of the dynamic code execution region 16, and the result may be the target address register of the indirect branch instruction. If multiple registers are added together to generate the target address or displacements are added, these additions may be initially performed and the results may be masked as proposed above.
[0029] Other types of branch instructions may also be instantiated in the instruction packet. For example, explicit far call and jump instructions (which are defined as having a potential far-reaching target address that may be outside the dynamic code execution region 16) may need to be instantiated in the instruction packet.
[0030] It should be noted that the term "branch instruction" may refer to any type of instruction that causes (or may cause for a conditional branch instruction) the next instruction to be executed to be an instruction at the target address of the branch instruction. Other instructions (e.g., ALU instructions and load / store instructions) cause the next instruction to be executed to be an instruction at the next sequential address after the current instruction, unless an exception is signaled on the instruction due to some errors during the execution of the instruction. The exception causes the current code sequence to be refreshed, and the processor executes from the exception vector address defined for the exception. Examples of branch instructions are indirect branches, calls, returns, jumps (conditional or unconditional), conditional branches, relative branches with a target address generated based on displacement and an address for storing relative branches, etc.
[0031] In one embodiment, the dynamic code generator 10 may insert no-operation instructions ("nops") in the dynamic code to ensure alignment of instruction packets. No-operations may be instructions that, when executed, do not affect the state of a processor executing code, state data in memory, or any other state in a computer system.
[0032] More specifically, in one embodiment, the instruction packet may ensure the following properties:
[0033] For explicit far jumps and calls, the target address is found on a valid target list (or identified gate), or the target is within the dynamic code execution region 16 .
[0034] For register-based indirect branches (e.g., jumps, calls, and returns), the target address is restricted to the dynamic code execution region 16 and aligned to a boundary defined by the size of the instruction packet. Since the instruction packet is also aligned to the same boundary, this rule ensures that one dynamically generated indirect branch can not bypass the caged instruction for another indirect branch.
[0035] In the case of the above constraints on indirect branches, the exit outside the dynamic code execution area 16 can be limited to the target in the effective target list. Static code can jump (or "tail call", using the jump at the end of the function or other code sequence instead of the call instruction) to the dynamic code, but the return from the dynamic code to the calling static code can use the "trampoline" mechanism of the target address returned to the effective target list, and the static instruction is instantiated at the target address to complete the return to the calling static code. Therefore, the "trampoline" can be an intermediate code sequence between the call / return code (dynamic code or static code) and the called / returned code (static code or dynamic code) to allow the conversion between the call / return code through the controlled point, thereby preventing the call / return code from having any access to the called / returned code. That is, generally speaking, a trampoline can exist in the static code to control the call or return to the dynamic code, so as to implement any restrictions that may be expected on the static code (for example, to ensure that the static code enters the dynamic code at the appropriate point, including at the beginning of the instruction packet of the branch). Trampolines may exist in the dynamic code to control calls or returns to static code, thereby enforcing any restrictions on the dynamic code that may be desired (eg, ensuring a proper entry point to the static code).
[0036] In one embodiment, the dynamic code verifier 12 can verify the dynamic code on an instruction-by-instruction basis. The dynamic code verifier 12 can verify, for example, that the instruction is well-formed and has a valid encoding. The dynamic code verifier 12 can verify that the branch is part of one or more valid instruction packet types. For branches with an explicit target address, the target address is verified to be on a valid target list or within a dynamic code execution region 16. Other indirect branches are verified to restrict the contents of their target registers to the dynamic code execution registers 16.
[0037] In one embodiment, the dynamic code verifier 12 may not allow the following instructions (for this example, the instructions are from the ARM instruction set architecture, but any other instruction set architecture may be used in various embodiments): branch-related pointer authentication instructions, instructions related to system calls (SVCs), most move-in / move-out system registers, hint instructions other than nop, cache control instructions other than dc, and illegal instruction encodings. If an inappropriate instruction sequence is found (e.g., terminating a process including dynamic code, or causing the process to "crash"), the dynamic code verifier 12 may reject the instruction sequence. More generally, instructions that are not permitted may include any instructions that can be used to directly or indirectly jump from the dynamic code execution area 16 to an unsafe address or damage the program by making an operating system call.
[0038] Although the present embodiment uses instruction packets as discussed above, other embodiments may implement branch target constraints in other ways. For example, an embodiment may track the location of instruction packets within the dynamic code, and if the target is not in the instruction packet, relative branches to non-boundary aligned targets may be permitted, rather than ensuring that all relative branches have target addresses aligned with the instruction packet boundary. If the dynamic code verifier 12 has not yet encountered code at a non-boundary aligned target, the dynamic code verifier 12 may also track the non-boundary aligned target, and if the non-boundary aligned target is within the instruction packet (or is not found in the dynamic code at all, which may also be malicious activity or simply an error), the dynamic code is rejected.
[0039] Another embodiment may adopt a pointer authentication branch ("PAC branch") instead of an instruction packet, or in addition to an instruction packet. For example, if it is ensured that the PAC branch uses a specific distributor or key provided by the operating system that the operating system uses to sign the effective target address, the PAC branch may be permitted. In this embodiment, the dynamic code verifier 12 may further ensure that the dynamic code does not use a specific distributor / key to sign the pointer. Alternatively, more than one specific distributor / key may be used, and one distributor / key in the specific distributor / key may be used for branch target authentication and may not be used by the dynamic code to sign the pointer, but other distributors / keys in the specific distributor / key may be used by the dynamic code to sign other pointers and authenticate other pointers. Various mechanisms may exist to ensure the use of a specific distributor / key. For example, a register may be reserved (not permitted as the destination of an instruction in the dynamic code), and a specific distributor / key may be stored in a reserved register. The dynamic code verifier 12 may verify that the reserved register is not the destination of an instruction in the dynamic code and that the reserved register is used for pointer authentication.
[0040] In one embodiment, an isolation area 18A-18B may be provided. Isolation area 18A-18B may be inaccessible (e.g., for isolation area, read, write and execute permissions may be closed). Therefore, any attempt to access isolation area 18A-18B from dynamic code may cause an exception in dynamic code. For example, if such an exception occurs, the operating system may terminate the process including dynamic code. In one embodiment, isolation area 18A-18B may be sized based on the maximum displacement that a relative branch may have in an instruction set architecture. That is, isolation area 18A-18B may be at least large enough to include any branch target address that can be generated by a relative branch instruction at any point in dynamic code area 16. A given instruction set architecture supports the number of bits of displacement in a relative branch instruction, and therefore determines the maximum displacement according to the number of bits. Therefore, a relative branch instruction placed at the minimum digital address in the dynamic code execution area 16 and encoded with the maximum negative displacement will generate an address in isolation area 18A-18B (e.g., isolation area 18B). Similarly, a relative branch instruction placed at the maximum digital address within the dynamic code execution region 16 and encoded with the maximum positive displacement will generate an address within the isolation region 18A-18B (e.g., isolation region 18A). By using isolation regions 18A-18B, relative branch instructions can be permitted without the need for the dynamic code verifier 12 to verify the target address of the relative branch instruction. Correctly encoded relative branch instructions will have a target address within the dynamic code execution region 16, and incorrectly encoded relative branch instructions will cause an exception. Other embodiments may verify the target address of the relative branch instruction, and may not require isolation regions 18A-18B, or may be sized based on other considerations.
[0041] In one embodiment, the dynamic code verified by the dynamic code verifier 12 as acceptable for execution can be moved into the dynamic code execution area 16 (or each instruction can be moved when it is verified). In various embodiments, the dynamic code verifier 12 can perform the movement, or other code or hardware can perform the movement. In other embodiments, the dynamic code verifier 12 can verify the dynamic code in situ in the dynamic code buffer 14, and can execute the dynamic code from the dynamic code buffer 14. That is to say, the dynamic code buffer 14 can also be the dynamic code execution area 16. In this embodiment, the dynamic code buffer 14 can be surrounded by isolation areas 18A-18B. In addition, in such embodiments, the dynamic code verifier 12 or the operating system can ensure the read / write exclusivity of the dynamic code buffer 14. That is to say, the dynamic code buffer 14 can be writable but not executable, or executable but not writable, but cannot be both writable and executable at the same time.
[0042] As mentioned above, the dynamic code verifier 12 may be part of an operating system (e.g., part of a kernel) and may therefore run at a higher privilege level than user code, such as the dynamic code generator 10. In a kernel-based implementation, for example, the dynamic code generator 10 may execute a system call to request that the code in the dynamic code buffer 14 be installed in the dynamic code execution area 16 for execution. Since the kernel executes at a higher privilege level than the dynamic code verifier 12, the kernel may provide itself with a translation with write permission to the dynamic code execution area 16. Lower privilege translations accessible to the dynamic code generator 10 and other user code may have execute permission (and possibly read permission), but not write permission.
[0043] Although the illustrated embodiment shows one dynamic code buffer 14 and one dynamic code execution region 16 , in other embodiments there may be multiple dynamic code buffers 14 and / or dynamic code execution regions 16 .
[0044] Figure 2 is a high-level flow chart illustrating the operation of one embodiment of the dynamic code verifier 12. Although the blocks are shown in a particular order, other orders may be used. The dynamic code verifier 12 may include a plurality of instructions that, when executed on a processor in a computer system, cause the computer system to perform Figure 2 The operation shown.
[0045] The dynamic code verifier 12 can analyze the dynamically generated code in the dynamic code buffer 14, thereby applying various rules and constraints ("requirements" or "standards") described herein (box 30). If the dynamically generated code meets the standard (decision box 32, "yes" branch), the dynamic code verifier 12 can permit the execution of the dynamically generated code (e.g., copy the code to the dynamic code execution area 16-box 34). If the dynamically generated code violates one or more standards (decision box 32, "no" branch), the dynamic code verifier 12 can reject the dynamically generated code (box 36). Rejecting the dynamically generated code can be implemented in many ways. For example, the process including the dynamically generated code can be terminated. In other embodiments, the dynamic code generator 10 can be notified that the dynamically generated code has not been verified. In various embodiments, the reason for failure can be provided, or no reason can be given to protect security.
[0046] Figure 3 is shown in more detail Figure 21. More specifically, the determination of whether the dynamically generated code meets the execution criteria (decision box 32) is shown in more detail. Although the boxes are shown in a particular order, other orders may be used. The dynamic code verifier 12 may include a plurality of instructions that, when executed on a processor in a computer system, cause the computer system to execute Figure 3 The operation shown.
[0047] The dynamic code verifier 12 may analyze a given instruction and determine whether the instruction is a valid instruction (decision box 40). For example, the dynamic code verifier 12 may verify that the opcode of the instruction is a valid opcode in the instruction set, that the operands and other encodings of the instruction are consistent with the opcode, etc. If the instruction is not a valid instruction (decision box 40, "no" branch), the dynamic code verifier 12 may reject the dynamically generated code (box 36). On the other hand, if the instruction is valid (decision box 40, "yes" branch), the dynamic code verifier 12 may determine whether the instruction is permitted in the dynamically generated code (decision box 42). As mentioned above, some instructions may not be permitted due to the potential risk that executing the instruction may result in an exit from the dynamic code execution area 16. If the instruction is valid but not permitted (decision box 42, "no" branch), the dynamic code verifier 12 may reject the dynamically generated code (box 36).
[0048] If the instruction is valid and permitted (decision blocks 40 and 42, "yes" branch), and the instruction is a branch (decision block 44, "yes" branch), the dynamic code verifier 12 may verify that the branch cannot exit the dynamic code execution region 16 (decision block 46, "yes" branch), or if the branch can exit (decision block 46, "no" branch), the exit is a valid exit (e.g., the exit is to a permitted address outside the dynamic code execution region - decision block 48, "yes" branch). In either case, the branch instruction may be permitted in the dynamically generated code. The dynamic code verifier 12 may determine whether there are more instructions in the dynamically generated code sequence, and if so (decision branch 50, "yes" branch), the next instruction may be selected and the analysis repeated. In the absence of more instructions (decision block 50, "no" branch), the dynamically generated code may be permitted to execute (block 34). On the other hand, if the branch instruction can exit (decision block 46, "no" leg) and the exit cannot be verified as valid (decision block 48, "no" leg), the dynamic code verifier 12 may reject the dynamically generated code sequence (block 36).
[0049] The determination of whether a branch cannot be exited (other than a valid exit) may be based on both the type of branch instruction and (for some types of branch instructions) the target address of the branch instruction may be limited to the dynamic code execution region 16 or the presence of other instructions that are valid exits. Thus, in some cases, the branch target address may not be determined by the dynamic code verifier 12 and may therefore be rejected, even though it may actually remain within the dynamic code execution region 16 or use a valid exit during execution. That is, unless it can be proven that the branch remains in the dynamic code execution region 16 or can be a valid exit, the dynamically generated code that includes the branch may be rejected.
[0050] Figure 4 is shown in more detail Figure 3 More specifically, the combination of decision blocks 46 and 48 (determining that a branch cannot be exited or is a valid exit) is shown in more detail. Thus, once the dynamic code verifier 12 has determined that an instruction is a branch, it can execute Figure 4 Although the blocks are shown in a particular order, other orders may be used. The dynamic code verifier 12 may include a plurality of instructions that, when executed on a processor in a computer system, cause the computer system to perform Figure 4 The operation shown.
[0051] A branch instruction is typically an instruction that causes the next instruction to be executed to be the instruction at the target address or the next consecutive (sequential) instruction of the branch instruction. A branch instruction may be unconditional (where the target address is always the address of the next instruction to be executed) or conditional (where the address of the next instruction may be the target address, or a sequential address based on the result of a previous instruction communicated by a conditional code in the processor or communicated directly). A branch instruction may be an indirect branch, where at least one register operand is used to form the target address, or may be a direct branch, where the target address is formed by an immediate field (or displacement field) encoded directly into the instruction. A direct branch may be an absolute branch (where the target address is a displacement / immediate value) or a relative branch (where the target address is determined based on the displacement / immediate field and the address of the branch instruction itself).
[0052] If the branch instruction is an indirect branch (decision box 60, "yes" branch), the branch instruction is required to be included in an instruction packet that ensures that the target address is within the dynamic code execution region 16 or is a valid exit. If the indirect branch is in an instruction packet with the correct instruction set for limiting the target address to the dynamic code execution region or ensuring that the target address is a valid exit (decision box 62, "yes" branch), and the instruction packet is aligned to an address that is a multiple of the size of the instruction packet (decision box 64, "yes" branch), then the branch is valid and the dynamic code verifier 12 can process the next instruction (box 50). However, if the indirect branch is not in the instruction packet (decision box 62, "no" branch) or the instruction packet is not aligned (decision box 64, "no" branch), the dynamic code verifier 12 can reject the dynamically generated code (box 36).
[0053] If the branch instruction is not an indirect branch (decision box 60, "no" branch) but is a direct branch (decision box 66, "yes" branch), the target address can be determined based on the instruction itself (and possibly the address of the instruction itself). However, the target address may need to be aligned with the instruction packet boundary, so that a direct branch cannot be used to bypass the instruction branch in the instruction packet to the indirect branch, and thus may exit the dynamic code execution area to an invalid target. If the target address is aligned (decision box 68, "yes" branch), the branch instruction may be permitted and the dynamic code verifier 12 may check for additional instructions (box 50). If the target address is not aligned (decision box 68, "no" branch), the dynamic code verifier 12 may reject the dynamically generated code (box 36). In addition, if the branch instruction is neither indirect nor direct (decision boxes 60 and 66, "no" branches), the branch instruction is of a type that is not permitted because the target address may not be guaranteed. Branch instructions that are neither direct nor indirect may include return instructions, which, for example, read the target address from a memory location.
[0054] A more detailed example using the ARM 64 instruction set will now be presented, with the dynamic code being JIT JavaScript code and the static code being precompiled C++ code (more briefly referred to as JIT code and C++ code). However, other embodiments may use any instruction set, including other versions of the ARM instruction set, Intel x86 instruction set, Power instruction set, RISC5 instruction set, etc. When an exemplary instruction sequence is shown, instruction addresses (in hexadecimal notation, starting with "0x") and instructions are shown in Arial Narrow font to distinguish them from the rest of the text.
[0055] On ARM64, the maximum span of PC relative branches is 28 bits (±128M). In this way, the size of the allocation of isolation area 18A-18B can be at least 128M. In one embodiment, in order to simplify the target address restrictions and maximize the address space entropy, the base address of the dynamic code execution area 16 can keep the number of least significant bits that change for the dynamic code execution area 16 to a minimum. In one embodiment, the mask sequence for the register indirect address mask can be calculated and saved in the same read-only configuration memory used by the valid target list.
[0056] Text Far Jump Pack
[0057] Depending on the target address, a packet with a literal address (including a patchable branch) may be generated. If the target address is outside the dynamic code execution area 16, it may be required that the address be in a valid target list. For literal addresses within the dynamic code execution area 16, the target address may be required to point to a packet boundary (e.g., a 16-byte boundary). The literal address and subsequent indirect branch realizations may be issued together as a packet, where the first address of these instructions is aligned to the packet boundary. In one embodiment, the macro assembler may ensure that the realized target address is aligned to the packet boundary.
[0058] Example call to C++ code
[0059] 0xe567ba160:movz x16,#0x8c48
[0060] 0xe567ba164:movk x16,#0x152,lsl#16
[0061] 0xe567ba168:movk x16,#0x1,lsl#32
[0062] 0xe567ba16c:blr x16
[0063] Example call targeting dynamic code execution area 16
[0064] 0xe567b90e0:movz x16,#0x98c0
[0065] 0xe567b90e4:movk x16,#0x567b,lsl#16
[0066] 0xe567b90e8:movk x16,#e,lsl#32
[0067] 0xe567b90ec:blr x16
[0068] Register Pack
[0069] The packet with the target address in the register can also be 16-byte aligned. The target address is aligned to a 16-byte address and the target address is caged to point to the dynamic code execution region 16, modulo the isolation regions 18A-18B on either side of the actual dynamic code execution region memory. The same instruction sequence can be used for jumps, calls, and returns.
[0070] Example call package
[0071] 0xe567bb308:ldr x8,[x2],#16 ...
[0073] 0xe567bb320:and x8,x8,#0xffffff0
[0074] 0xe567bb324:movz x17,#0xe5,lsl#16
[0075] 0xe567bb328:add x8,x8,x17,lsl#12
[0076] 0xe567bb32c:blr x8
[0077] Note that the immediate values used for AND, MOVE, and ADD instructions may vary depending on the base address of the dynamic code execution region 16.
[0078] Example Return Package :
[0079] 0xe567b824c:ldp fp,lr,[sp],#16 ...
[0081] 0xe567b8250:and lr,lr,#0xffffff0
[0082] 0xe567b8254:movz x17,#0xe5,lsl#16
[0083] 0xe567b8258:add lr,lr,x17,lsl#12
[0084] 0xe567b825c:ret
[0085] When the target address is in the static code execution area 20, a trampoline may be automatically created to tail call the target function. These trampolines may be in the form of literal packets.
[0086] PAC Signature Text Package
[0087] In one embodiment, PAC branches may not be permitted in dynamic code. However, other embodiments may permit their use with an extended PAC branch package, and confirm that the target address is in the valid target list or is 16-byte aligned and in the dynamic code execution area 16. The following exemplary instruction sequence for a signed indirect jump or call using a literal address includes 6 instructions: 4 for implementing a 64-bit signature pointer, 1 for implementing a label or divider as an lr (a temporary register at this time), and then the authentication and branch instructions. Adding two branches to this sequence allows it to be aligned on a 16-byte boundary, and possible entries into the package are safe. The following is an example of an 8-instruction package with added PC relative branches:
[0088] 0xe567bea60:movz lr,#0xb38a
[0089] 0xe567bea64:movz x16,#0x985c
[0090] 0xe567bea68:movk x16,#0x5a1,lsl#16
[0091] 0xe567bea6c:b 0xe567bea74
[0092] 0xe567bea70:b 0xe567bea60
[0093] 0xe567bea74:movk x16,#0xf501,lsl#32
[0094] 0xe567bea78:movk x16,#0xd840,lsl#48
[0095] 0xe567bea7c:blrab x16,lr
[0096] Trampoline between C++ and JIT code
[0097] Because the JIT code is not allowed to return directly to the C++ code due to the return address being caged in the dynamic code execution area 16, another technique can be used for these calls from the C++ code. There are also cases where virtual calls to functions can be made in the dynamic code execution area 16 or the static code execution area 20. Various trampolines can be used for these cases. Some trampolines can have tightly coupled components in both the static code execution area 20 and the dynamic code execution area 16. The trampoline for calls from the C++ code can be called in the dynamic code execution area 16, where the jump address listed via the effective target returns to the static code execution area 20.
[0098] Directing C++ code to the JIT code trampoline
[0099] Consider the main entry from C++ code to JIT code. The entry point is called vmEntryToJavaScript and includes an inline trampoline and JIT components on the C++ side:
[0100]
[0101]
[0102] The way this trampoline works is that the return location vmEntryReturn is placed in the valid target list. JIT-side code is generated to expect the target JIT entry point in register x0. The JIT code restricts x0 to the dynamic code execution area 16 and then makes a call. On return from this call, the JIT side of the trampoline far jumps to the vmEntryReturn label listed for the valid targets. The starting address of the resulting JIT code is stored in a variable locked as read-only. The contents of this variable are used as the target in the C++ side. There are many other instances of these types of C++ calls to JIT trampolines, where C++ is called through a function pointer pointing to a trampoline in the dynamic code execution area 16. The trampoline calls the JIT code and then returns to the calling C++ code using a direct branch to the valid target. These trampolines are created when the JIT system is initialized, before the user code is JIT compiled and executed.
[0103] Callable C++ to JIT trampoline
[0104] In one embodiment, the trampoline described in the previous section may be sufficient. Additional trampolines may be implemented as needed.
[0105] JIT to C++ tail call trampoline
[0106] When a virtual call is made to a C++ function, we need to create a trampoline with a valid target listed entry point for that C++ function. We then use the trampoline similar to using any other JIT function pointer. The trampoline makes a tail call to the C++ function.
[0107] Host Function Trampoline Thunk :
[0108] 0xe99e3cb50:movz x16,#0x56ec
[0109] 0xe99e3cb54:movk x16,#0x1aa,lsl#16
[0110] 0xe99e3cb58:movk x16,#0x1,lsl#32
[0111] 0xe99e3cb5c:br x16
[0112] Linking and JIT Copying
[0113] When the JIT code is copied from the dynamic code buffer 14 to the dynamic code execution area 16 and linked, the code passes through the dynamic code verifier 12 that checks whether the instructions are safe. The dynamic code verifier 12 checks each instruction as it is copied to ensure that it is valid and is in the right place in the valid location of the package. If there are no confirmation failures when copying the instructions, the code is made available for use by the VM. If there are any confirmation failures, the dynamic code verifier can immediately terminate (crash) the process.
[0114] Dynamic code validator instruction validator
[0115] In this embodiment, the instruction validator in the dynamic code verifier 12 is built based on the reconstruction of the ARM64 disassembler. Each instruction group in the disassembler has added a new isValid() method. Most instruction groups perform simple confirmations to check undefined instruction patterns. Other instruction groups check various instructions that are not allowed within the group. Branch instructions have more involved checks. Below is an example of a detailed check performed by an embodiment of the instruction validator.
[0116] Invalid instruction encodings are not allowed.
[0117] Any of the svc, hvc, smc, hlt, or dpcs directives are not allowed.
[0118] Authenticated branch instructions (braa, brab, blraa, blrab, blraaz, blrabz, braaz, brabz, eretaa, eretab, retaa, retab) are not allowed.
[0119] mrs, msr are not allowed, except for instructions that read the user-mode status flags.
[0120] Check that the bl and blr instructions are located at addresses ending in 0xc.
[0121] For indirect branches, check that the three previous instructions are a sequence of move-wide instructions with the same target register. If so, we check to see if the address materialized by this move-wide sequence is on the valid target list, to a 16-byte aligned target in the JIT area, or to address 0. Branches to 0 are patched before they are actually used. If the three previous instructions are not a sequence of move-wide instructions to the same target register, we check that the three previous instructions constitute a valid JIT caged sequence.
[0122] In one embodiment, the system grants the ability to patch JIT code, replacing branch targets quite frequently, such as the branch to 0 instructions we issue to patch them. The dynamic code verifier 16 validates from the previous 16-byte alignment boundary to the next 16-byte alignment boundary each time it is called. In the case of a branch through a register after a move-wide sequence that materializes 0 into the register, when we validate the move-wide sequence, we will include the existing branch to verify that the combined branch package adheres to the package rules.
[0123] Valid target list construction
[0124] Source annotations can be used to extract valid targets in statically compiled C++ code. A source annotation can be a compiler directive to take the address of a function and store that address into a read-only space in the object file. The code that actually creates the list of valid targets reads the addresses from that read-only space and puts them into a statically sized hash table that can be locked by making it read-only for the rest of the process's life. The hash table only needs to answer the question "is this a valid target for the JIT code to call?"
[0125] The source code for function foo() might look like this:
[0126]
[0127] The VALID_JIT_TARGET annotation effectively creates the following additional source for the compiler:
[0128] void*_JITTarget_void
[0129] __attribute__((used,section("__DATA_CONST,__jit_targets")))=
[0130] reinterpret_cast<void*> (foo);
[0131] In one embodiment, the effective target list creation may include a compiler tool that will gather the annotated function pointers and then use perfect hashing to create a read-only hash table. This may be similar to the process used when creating statically generated C++ code.
[0132] Lockable configuration data
[0133] At several places in this example, various data is placed into a read-only area. We have had this capability for a little longer than the JIT effort verified by this software. We use this storage area for many parts of this feature, including the list of valid targets, trampoline addresses, JIT area details, and register cage sequences. This area is available during process initialization. It runs before the JavaScript virtual machine is available, and therefore before the JIT code is derived from user-provided JavaScript code. After the JIT engine is initialized, we make the entire configuration area read-only. The OS does not provide a mechanism to restore this area back to read-write for the remainder of the life of the process.
[0134] Computer Systems
[0135] Now turn to Figure 5 , a block diagram of a computing device (which may also be referred to as a computing system or computer system) is depicted according to some embodiments. Computing device 1510 may be used to implement various portions of the present disclosure. Computing device 1510 is an example of a device that may be used as a mobile device, a server computing system, a client computing system, or any other computing system that implements various portions of the present disclosure.
[0136] Computing device 1510 can be any suitable type of device, including but not limited to a personal computer system, a desktop computer, a laptop or notebook computer, a mobile phone, a mainframe computer system, a web server, a workstation, or a network computer. As shown, computing device 1510 includes a processing unit 1550, a storage subsystem 1512, and an input / output (I / O) interface 1530 coupled via an interconnect 1560 (e.g., a system bus). I / O interface 1530 can be coupled to one or more I / O devices 1540. Computing device 1510 also includes a network interface 1532, which can be coupled to a network 1520 for communicating with, for example, other computing devices.
[0137] Processing unit 1550 includes one or more processors. In some embodiments, processing unit 1550 includes one or more coprocessor units. In some embodiments, multiple instances of processing unit 1550 may be coupled to interconnect 1560. Processing unit 1550 (or each processor within processing unit 1550) may include a cache or other form of on-board memory. In some embodiments, processing unit 1550 may be implemented as a general-purpose processing unit, and in other embodiments, it may be implemented as a special-purpose processing unit (e.g., an ASIC). In general, computing device 1510 is not limited to any particular type of processing unit or processor subsystem.
[0138] Storage subsystem 1512 may be used by processing unit 1550 (e.g., to store instructions that can be executed by processing unit 1550 and data used by the processing unit). Storage subsystem 1512 may be implemented by any suitable type of physical memory medium, including hard disk storage, floppy disk storage, removable disk storage, flash memory, random access memory (RAM—SRAM, EDO RAM, SDRAM, DDR SDRAM, RDRAM, etc.), ROM (PROM, EEPROM, etc.), etc. In some embodiments, storage subsystem 1512 may consist only of volatile memory. Storage subsystem 1512 may store program instructions that can be executed by computing device 1510 using processing unit 1550, including program instructions that can be executed to cause computing device 1510 to implement various techniques disclosed herein. Storage subsystem 1512 may include, for example, the system memory described above. In at least some embodiments, storage subsystem 1512 may represent an example of a non-transitory computer-readable medium that can store executable instructions.
[0139] In the illustrated embodiment, the computing device 1510 also includes non-transitory media 1514 as an element that may be distinct from the storage subsystem 1512. For example, the non-transitory media 1514 may include a persistent, tangible storage device such as a disk, non-volatile memory, tape, optical media, holographic media, or other suitable type of storage device. Although shown as distinct from the storage subsystem 1512, in some embodiments, the non-transitory media 1514 may be integrated within the storage subsystem 1512. The non-transitory media 1514 may also be an example of a medium that may store instructions that, when executed, cause the computing device 1510 to perform operations as described herein.
[0140] According to various embodiments, I / O interface 1530 may represent one or more interfaces and may be any of various types of interfaces configured to be coupled to other devices and communicate with other devices. In some embodiments, I / O interface 1530 is a bridge chip from a front-end bus to one or more back-end buses. I / O interface 1530 may be coupled to one or more I / O devices 1540 via one or more corresponding buses or other interfaces. Examples of I / O devices include storage devices (hard disks, optical drives, removable flash drives, storage arrays, SANs or associated controllers), network interface devices, user interface devices, or other devices (e.g., graphics, sound, etc.).
[0141] According to the present disclosure, a method is disclosed. The method may include: in a kernel executed in a kernel execution mode different from a user execution mode, receiving a request to move a dynamically generated code sequence from a buffer in a memory to a dynamic code execution area in a memory; in a kernel executed in kernel mode, verifying that the dynamically generated code sequence stored in the memory meets one or more criteria to be executed in a computer system, wherein the one or more criteria include the absence of a subset of instructions that are not permitted in the dynamically generated code; and based on successful verification, moving the dynamically generated code sequence to the dynamic code execution area by the kernel executed in kernel mode. The one or more criteria may also ensure that the dynamically generated code sequence cannot exit the dynamic code execution area, except for one or more predefined addresses. In one embodiment, ensuring that the dynamically generated code sequence cannot exit may include: ensuring that a branch instruction in the dynamically generated code sequence has a target address within the dynamic code execution area, or ensuring that the target address is one of the predefined addresses. In one embodiment, the first branch instruction in the dynamically generated code sequence may be included in an instruction packet with one or more previous instructions, and the one or more previous instructions limit the first target address of the first branch instruction to the dynamic code execution area. In one embodiment, the instruction packet may be aligned with a boundary based on the size of the instruction packet. In one embodiment, the one or more criteria may also include the absence of a branch target address within the instruction packet. In one embodiment, the method may also include: in a kernel executing in kernel mode, receiving another request to move a second dynamically generated code sequence from a buffer in a memory to a dynamic code execution area in a memory; in a kernel executing in kernel mode, determining that the second dynamically generated code sequence stored in the memory does not meet at least one of the one or more criteria to be executed in a computer system; and based on determining that the second dynamically generated code does not meet at least one or more criteria, preventing the second dynamically generated code sequence from being moved to the dynamic code execution area. In one embodiment, the method also includes: in a kernel executing in kernel mode, receiving another request to move a second dynamically generated code sequence from a buffer in a memory to a dynamic code execution area in a memory; in a kernel executing in kernel mode, determining that the second dynamically generated code sequence stored in the memory does not meet at least one of the one or more criteria to be executed in a computer system; and based on determining that the second dynamically generated code does not meet at least one or more criteria, rejecting the second dynamically generated code sequence. In one embodiment, the method also includes: based on unsuccessful verification, terminating the process that transmitted the request to move the dynamically generated code sequence to the dynamic code execution area.
[0142] In one embodiment, a non-transitory computer-accessible storage medium may store a plurality of instructions that, when executed on a computer system, implement operations including: in a kernel executing in a kernel execution mode different from a user execution mode, receiving a request to move a dynamically generated code sequence from a buffer in a memory to a dynamic code execution region in a memory; in a kernel executing in kernel mode, verifying that the dynamically generated code sequence stored in the memory meets one or more criteria to be executed in the computer system, wherein the one or more criteria include the absence of a subset of instructions that are not permitted in the dynamically generated code; and based on successful verification, moving the dynamically generated code sequence to the dynamic code execution region by the kernel executing in kernel mode. In one embodiment, the one or more criteria may also ensure that the dynamically generated code sequence cannot exit the dynamic code execution region, except for one or more predefined addresses. In one embodiment, ensuring that the dynamically generated code sequence cannot exit may include: ensuring that a branch instruction in the dynamically generated code sequence has a target address within the dynamic code execution region, or ensuring that the target address is one of the predefined addresses. In one embodiment, a first branch instruction in the dynamically generated code sequence may be included in an instruction packet having one or more previous instructions, and the one or more previous instructions limit the first target address of the first branch instruction to the dynamic code execution region. In one embodiment, the instruction packet may be aligned to a boundary based on the size of the instruction packet. In one embodiment, the one or more criteria may also include the absence of a branch target address within the instruction packet. In one embodiment, the operation may also include: in a kernel executed in kernel mode, receiving another request to move a second dynamically generated code sequence from a buffer in a memory to a dynamic code execution area in a memory; in a kernel executed in kernel mode, determining that the second dynamically generated code sequence stored in the memory does not meet at least one of the one or more criteria to be executed in a computer system; and based on determining that the second dynamically generated code does not meet at least one or more criteria, preventing the second dynamically generated code sequence from being moved to the dynamic code execution area. In one embodiment, the operation may also include: in a kernel executed in kernel mode, receiving another request to move a second dynamically generated code sequence from a buffer in a memory to a dynamic code execution area in a memory; in a kernel executed in kernel mode, determining that the second dynamically generated code sequence stored in the memory does not meet at least one of the one or more criteria to be executed in a computer system; and based on determining that the second dynamically generated code does not meet at least one or more criteria, rejecting the second dynamically generated code sequence. In one embodiment, the operation may also include: based on unsuccessful verification, terminating the process that transmitted the request to move the dynamically generated code sequence to the dynamic code execution area.
[0143] In one embodiment, a computer system may include: one or more processors; and a non-transitory computer-accessible storage medium storing a plurality of instructions that, when executed on the computer system, implement operations including: receiving, in a kernel executing in a kernel execution mode different from a user execution mode, a request to move a dynamically generated code sequence from a buffer in a memory to a dynamic code execution region in a memory; in the kernel executing in kernel mode, verifying that the dynamically generated code sequence stored in the memory meets one or more criteria to be executed in the computer system, wherein the one or more criteria include the absence of a subset of instructions that are not permitted in the dynamically generated code; and based on successful verification, moving the dynamically generated code sequence to the dynamic code execution region by the kernel executing in kernel mode. In one embodiment, the one or more criteria may also ensure that the dynamically generated code sequence excludes branch instructions having a target address outside the dynamic code execution region (except for one or more predefined addresses).
[0144] Hardware Implementation
[0145] In other embodiments, enforcement of the execution standards for dynamically generated code may be implemented in hardware (e.g., on one or more processors that execute dynamically generated code). Figure 1 The description of still generally applies. The processor may be programmed to identify the dynamic code execution region 16, and thus may enforce execution standards on dynamically generated code by determining that execution is occurring within the dynamic code execution region 16. The execution standards may also be different in some cases, as described in more detail below.
[0146] Now turn to Figure 6 , which shows a block diagram of one embodiment of the processing unit 1550 in more detail. In the illustrated embodiment, the processing unit 1550 includes at least one processor 160. The processor 160 may include one or more configuration registers 162, monitoring circuits 164, and execution core circuits (or more briefly, "execution cores") 166. The configuration registers 162 may be programmable to define the dynamic code execution region 16 in the memory. As previously discussed, the dynamically generated code is executed in the dynamic code execution region 16 during use. The monitoring circuits 164 are further coupled to the execution core 166. In some embodiments, more than one processor 160 (e.g., Figure 6 A second processor 160 is shown in FIG.
[0147] The monitoring circuit 164 may be configured to monitor the dynamically generated code sequence being executed in the processor 160 to ensure that the dynamically generated code sequence meets one or more execution criteria. For example, the monitoring circuit 164 may receive various data about the instruction being executed by the execution core 166, such as the program counter address (PC) from which the instruction is stored in the memory and from which the instruction is obtained, the instruction itself (or various signals decoded from the instruction, such as whether the instruction is a branch, the branch type, whether the instruction is an instruction that is not permitted in the dynamically executed code, etc.), and the target address (TA) of the branch instruction. The monitoring circuit 164 may be configured to cause an exception in the processor based on the detection of a violation of one or more execution criteria (for example, the monitoring circuit 164 may assert an exception signal for the instruction to the execution core 166). The exception may cause the processor 160 to stop executing the dynamically generated code sequence, and thus prevent the execution of the code that violates the execution criteria. Therefore, instead of checking the dynamically executed code before permitting the execution of the dynamically executed code, the hardware implementation may permit the execution and terminate the execution if the execution criteria are not met. Instruction packets for restricting the target address of indirect branches may not be used in this embodiment because the monitoring circuitry can detect whether the target address exits the dynamic code execution region 16 and if so whether the exit is to a permitted target.
[0148] As mentioned above, the execution standard may include a subset of instructions that are not permitted in the dynamically generated code sequence. For this embodiment, a subset of non-permitted instructions identical to the subset of non-permitted instructions of the above-mentioned software embodiment may be defined. For example, the following instructions may not be allowed in the dynamically generated code sequence (for this example, the instructions are from the ARM instruction set architecture, but any other instruction set architecture may be used in various embodiments): unauthenticated indirect branch instructions, instructions related to system call (SVC), most of the shifts in / out of system registers, prompt instructions other than nop, cache control instructions other than dc, and illegal instruction encodings. More generally, non-permitted instructions may include any instructions that can be used to directly or indirectly jump to an unsafe address from the dynamic code execution area 16 or damage a program by making an operating system call.
[0149] In addition, the processor 160 may support additional encryption key sets ("keys") for use with dynamically generated code sequences. The original key set ("standard keys") is available for static code to sign pointers, including pointers that will be used by the dynamically generated code to branch out from the dynamic code execution area 16. Therefore, code outside the dynamically generated code sequence can sign pointers with standard keys and provide signed pointers to the dynamically generated code sequence for use, thereby controlling the exit point from the dynamic code execution area 16. Additional keys ("dynamic code keys") are available for dynamically generated code to sign pointers to target addresses within the dynamic code execution area 16, but if the dynamic code key is used to sign a pointer to an address outside the dynamic code execution area, when an attempt is made to use the pointer, the pointer will fail to pass authentication. Therefore, the dynamically generated code can only use pointers to locations outside the dynamic code execution area 16 if they are signed by external code and provided to the dynamically generated code. The separation of keys between the dynamically generated code and the external code can permit, for example, secure sharing of a common stack between the dynamically generated code and the external code. In one embodiment, the cryptographic signature / authentication instructions in the dynamically generated code may not be able to specify a standard key (e.g., such instructions may be considered nop by the processor 160 or may cause a fault). Therefore, the standard key may not be accessible to the dynamically generated code. In addition, in one embodiment, there may be multiple standard keys. In such an embodiment, one of the standard keys may be made available to both the dynamically generated code and the external code, while the other standard keys in the standard keys may be limited to the external code. In one embodiment, there may be separate programmable controls, one for signing and authenticating instructions, and one for authenticating branch / return instructions. If a signature instruction is executed and the corresponding control does not permit the signature operation, the processor 160 may "nop" the instruction (e.g., not perform the signature operation). Therefore, subsequent authentication instructions (or authentication branch instructions using pointers) may cause authentication to fail. In a specific implementation, the ability to sign / authenticate may be controlled separately for signing / authenticating pointers outside the dynamic execution area, and for signing / authenticating pointers within the dynamic execution area.
[0150] In one embodiment, processor 160 may also support “forced signing”, where pointer signature instructions executed by external code are forced to be signed with the dynamic code key so that they will authenticate correctly within the dynamic code execution area 16.
[0151] Configuration registers 162 may define dynamic code execution region 16 (e.g., base address and extent range, base address and end address, etc.). In addition, configuration registers 162 may be programmed to select various other programmable attributes for dynamic code execution in its processor. For example, in one embodiment, configuration registers 162 may be programmed with one or more address ranges outside of dynamic code execution region 16. Dynamically generated code may be permitted to sign pointers in address ranges with standard keys. This may be an exception to the general rule mentioned above, that is, dynamically generated code is not permitted to sign pointers with standard keys.
[0152] In one embodiment, monitoring circuitry may permit direct branches to targets within dynamic code execution region 16, but may force an exception if the direct branch has a target outside of dynamic code execution region 16. In another embodiment, isolation regions 18A-18B may be defined and may cover the maximum extent of direct branches outside of dynamic code execution region 16. Isolation regions 18A-18B may be marked as inaccessible (no read, write, or execute permissions), and direct branches to these targets may experience exceptions in execution core 166 due to permission failures. In yet another embodiment, monitoring circuitry 164 may detect targets in isolation regions 18A-18B and force exceptions.
[0153] Although for the sake of clarity, Figure 6 The monitoring circuit 164 is shown as being separate from the execution core 166, but the monitoring circuit 164 may actually be integrated into the execution core 166, where the circuit is distributed in each pipeline stage where the monitoring check is performed. In addition, various embodiments of the execution core 166 may use a superscalar design, etc. to execute multiple instructions in parallel. Therefore, the monitoring circuit 164 may be configured to monitor multiple instructions in different pipelines at the same time, and may also monitor instructions in different pipeline stages at the same time.
[0154] In various embodiments, the execution core 166 may have any construction and micro-architecture features. For example, the execution core 166 may include a superscalar or scalar implementation. The execution core 166 may include an in-order or out-of-order implementation, as well as a speculative or non-speculative implementation. The execution core 166 may include any combination of the above features. In some embodiments, the implementation may include microcode. The execution core 166 may include various execution units, each of which is configured to perform operations of various types (e.g., integer, floating point, vector, load / store, etc.). The execution core 166 may include different numbers of pipeline stages and various other performance enhancement features, such as branch prediction. The execution core 166 may include one or more of an instruction decoding unit, a scheduler or reservation station, a reorder buffer, a memory management unit, an I / O interface, etc.
[0155] As mentioned above, a processing unit 1500 including one or more processors such as processor 160 may be deployed in a computer system such as computing device 1510. The computer system may include a memory system (e.g., a portion of storage device 1512 and / or medium 1514). The dynamic code execution area 16 may be defined in an address range within the memory system, wherein the dynamically generated code is executed in the dynamic code execution area during use. At least one processor 160 may be coupled to the memory system, wherein the processor includes a monitoring circuit configured to monitor a dynamically generated code sequence being executed in the computer system to ensure that the dynamically generated code sequence meets one or more execution criteria, wherein the one or more execution criteria include the absence of a subset of instructions that are not permitted in the dynamically generated code sequence, wherein the dynamically generated code sequence is stored in the dynamic code execution area, and wherein the processor is configured to take an exception based on detecting a violation of one or more execution criteria. In one embodiment, the one or more execution criteria include a requirement to encrypt and sign a branch target outside the dynamic code execution area with one of a set of one or more encryption keys. In one embodiment, the set of one or more encryption keys cannot be accessed by the dynamically generated code sequence. In one embodiment, a second set of one or more encryption keys is provided for the dynamically generated code sequence to encrypt and sign one or more target addresses from an external source into the dynamically generated code sequence. In one embodiment, one or more execution criteria include a requirement that the branch target is within one of one or more predefined address ranges outside the dynamic code execution area. In one embodiment, the processor is configured to detect an attempt to access a pair of address ranges adjacent to the address range corresponding to the dynamic code execution area, and prevent the access by taking an exception, and wherein the size of a given address range in the pair of address ranges is based on the range of degrees that a given direct branch instruction in the dynamic code execution area can reach. In one embodiment, there may be separate programmable controls for signing / authenticating instructions and authenticated branch / return instructions. For example, separate control may provide the following capabilities: the ability to sign a pointer address when executing a dynamically generated code sequence is separated from the ability to authenticate and branch to an appropriate "pre-signed" address of the dynamically generated code sequence, which is provided to the dynamically generated code sequence by other code. In a specific implementation, the ability to sign / authenticate can be controlled separately for signing / authenticating pointers outside the dynamic execution area, and for signing / authenticating pointers within the dynamic execution area.
[0156] Figure 7 It shows Figure 61550 / processor 160. However, for ease of understanding, the blocks are shown in a particular order, and other orders may be used. The blocks may be executed in parallel in the combinatorial logic in the processor 160 and more specifically the monitoring circuit 164. The blocks, combinations of blocks, and / or the flowchart as a whole may be pipelined in one or more clock cycles. The processor 160 and more specifically the monitoring circuit 164 may be configured to implement Figure 7 The operation shown.
[0157] The monitoring circuit 164 may be configured to use instruction information such as PC to analyze the instructions being executed to determine when a dynamically generated code sequence is executed in the computer system, thereby ensuring that the dynamically generated code sequence meets one or more execution criteria. The monitoring circuit 60 may analyze the instruction information (box 70) and may detect whether the instruction is obtained from the dynamic code execution area 16 (decision box 72). If the instruction is not from the dynamic code execution area 16 (decision box 72, "no" branch), the instruction may be executed normally according to the instruction set architecture implemented by the processor 160 (box 74). Normal execution may include detecting and taking various exceptions that are not related to the implementation of execution standards for dynamically generated code (for example, exceptions defined in the instruction set architecture, such as failed translation, attempting to execute privileged instructions in a non-privileged mode such as user mode 24, etc.). If the instruction comes from the dynamic core execution area 16 (decision box 72, "yes" branch), the monitoring circuit 164 may determine whether the instruction meets one or more execution criteria (decision box 76). If the instruction satisfies the execution criteria (decision block 76, "yes" branch), the instruction may continue to execute normally (e.g., as defined in the instruction set architecture implemented by the processor 160, possibly modified for dynamic code execution as previously mentioned) (block 78). If the monitoring circuitry 164 detects a violation of one or more execution criteria (decision block 76, "no" branch), the monitoring circuitry 164 may be configured to force an exception (block 80). That is, the monitoring circuitry 164 may cause the processor 160 (e.g., the execution core 166) to take an exception for the instruction that violates the execution criteria. In some cases, the monitoring circuitry 164 may be configured to modify the execution of the instruction rather than force an exception (block 80). For example, if the dynamically generated code is not permitted to sign certain pointers (e.g., pointers outside the dynamic code execution region 16), the monitoring circuitry 164 may be configured to force a "nop" for signed instructions.
[0158] Note that one or more instructions that are processed in parallel by processor 160 may be executed in parallel. Figure 7 (and the following description Figure 8 ) operations (e.g., in a superscalar manner and / or in a pipelined manner).
[0159] Figure 8is shown in more detail Figure 7 160 and more specifically the monitoring circuit 164 may be configured to implement the process of executing the program in parallel. Figure 8 The operation shown.
[0160] The monitoring circuitry 70 may determine whether the instruction is a valid instruction (e.g., the instruction has a valid opcode, the operands are correct for the instruction, etc.) (decision block 90). If the instruction is invalid, the processor may take an exception (block 80). In one embodiment, detecting an invalid instruction may be performed by the execution core 166 itself (e.g., as part of decoding an instruction). In other embodiments, the monitoring circuitry 164 may detect an invalid instruction or may receive an indication of an invalid instruction from the execution core 166. If the instruction is valid, the monitoring circuitry 164 may determine whether the instruction is permitted (decision block 92). That is, one of the one or more execution criteria may include the absence of a subset of instructions that are not permitted in the dynamically generated code sequence, and if the instruction is in the subset, the instruction is permitted. If the instruction is permitted (decision block 92, "no"), the monitoring circuitry 164 may force an exception (block 80).
[0161] If the instruction is permitted and is a branch instruction (decision box 92, "yes" branch and decision box 94, "yes" branch), the monitoring circuit 164 may determine whether the branch instruction attempts to exit the dynamic code execution area 16 (decision box 96). That is, if the branch instruction has a branch target address outside the dynamic code execution area 16, the branch instruction may attempt to exit the dynamic code execution area 16, and the monitoring circuit may determine whether the branch target address is cryptographically signed with one of the standard keys (decision box 98). If it is not cryptographically signed (decision box 98, "no" branch), the branch violates the execution standard of the dynamically generated code, and the monitoring circuit may be configured to force an exception (box 80). If the branch target address is signed with one of the standard keys (decision box 98, "yes" branch), the instruction may be executed (box 78). As mentioned above, in one embodiment, the standard key may not be accessible to the dynamically generated code sequence. The dynamically generated code sequence may have one or more dynamic code keys for cryptographic signing purposes (e.g., cryptographically signing one or more target addresses into the dynamically generated code sequence from an external source). In another embodiment, the branch target address may be valid and not violate the execution criteria if the branch target address is required to be within one of one or more predefined address ranges outside the dynamic code execution region. For example, the address range may be programmed into the configuration register 162. If the instruction is a branch instruction that does not exit the dynamic code execution region 16 (decision block 94, "yes" branch and decision block 96, "no" branch), or the instruction is not a branch (decision block 94, "no" branch), the instruction may continue to execute normally.
[0162] In one embodiment, monitoring circuitry 164 (or execution core 166, through a permission check) may detect whether a direct branch has a branch target address within isolation region 18A or 18B. If the direct branch has such a target address in one of the pair of address ranges (i.e., isolation regions 18A-18B) adjacent to dynamic code execution region 16, then these regions may be inaccessible to prevent the relative branch instruction from exiting the dynamic code execution region. The size of a given address range in the pair of address ranges is based on the extent to which a given direct branch instruction within the dynamic code execution region can be reached.
[0163] Additional system implementation
[0164] Next turn Fig. 9, a block diagram of an embodiment of system 700 is shown. In the illustrated embodiment, system 700 includes at least one instance of computing device 1510. As shown, system 700 is shown as having applications in a wide range of fields. For example, system 700 can be used as a part of a chip, circuit, component, etc. of a desktop computer 710, a laptop computer 720, a tablet computer 730, a cellular or mobile phone 740, or a TV 750 (or a set-top box coupled to a TV). A smart watch and a health monitoring device 760 are also shown. In some embodiments, a smart watch may include various general computing related functions. For example, a smart watch may provide access to email, mobile phone services, user calendars, etc. In various embodiments, a health monitoring device may be a dedicated medical device or otherwise include dedicated health-related functions. For example, a health monitoring device may monitor a user's vital signs, track a user's proximity to other users for the purpose of epidemiological social distance, contact tracking, provide communications to emergency services in the event of a health crisis, etc. In various embodiments, the above-mentioned smart watch may or may not include some or any health monitoring related functions. Other wearable devices are also contemplated, such as devices worn around the neck, devices implantable in the human body, glasses designed to provide augmented and / or virtual reality experiences, and the like.
[0165] The system 700 may also be used as part of a cloud-based service 770. For example, the previously mentioned devices and / or other devices may access computing resources in the cloud (i.e., remotely located hardware and / or software resources). Still further, the system 700 may be used in one or more devices in a home other than those previously mentioned. For example, a home appliance may monitor and detect noteworthy situations. For example, various devices in a home (e.g., a refrigerator, a cooling system, etc.) may monitor the status of the device and provide an alert to the homeowner (or, for example, a maintenance agency) if a particular event is detected. Alternatively, a thermostat may monitor the temperature in a home and may automatically adjust the heating / cooling system based on a history of responses by the homeowner to various situations. Fig. 9 Also shown in the figure are applications of system 700 to various modes of transportation. For example, system 700 may be used for control and / or entertainment systems for airplanes, trains, buses, taxis, private cars, watercraft ranging from private boats to cruise ships, scooters (for rental or private use), etc. In various cases, system 700 may be used to provide automated guidance (e.g., self-driving vehicles), general system control, etc. Any of these and many other implementations are possible and contemplated. Note that Fig. 9 The devices and applications shown are exemplary only and are not intended to be limiting. Other devices are possible and contemplated.
[0166] Computer accessible storage media
[0167] Now turn to Fig.10 , a block diagram of an embodiment of a computer-accessible storage medium 800 is shown. Generally speaking, a computer-accessible storage medium may include any storage medium that can be accessed by a computer during use to provide instructions and / or data to a computer. For example, a computer-accessible storage medium may include a storage medium such as a magnetic or optical medium, for example, a disk (fixed or removable), a tape, a CD-ROM, a DVD-ROM, a CD-R, a CD-RW, a DVD-R, a DVD-RW or a blue-ray. The storage medium may also include a volatile or non-volatile memory medium, such as a RAM (for example, a synchronous dynamic RAM (SDRAM), a Rambus DRAM (RDRAM), a static RAM (SRAM) etc.), a ROM or a flash memory. The storage medium may be physically included in a computer to which the storage medium provides instructions / data. Alternatively, the storage medium may be connected to a computer. For example, the storage medium may be connected to a computer via a network or a wireless link such as a network attached storage device. The storage medium may be connected via a peripheral interface such as a universal serial bus (USB). Typically, the computer-accessible storage medium 800 can store data in a non-transitory manner, where non-transitory in this context can refer to not transmitting instructions / data via signals. For example, a non-transitory storage device can be volatile (and may lose the stored instructions / data in response to a power outage) or non-volatile.
[0168] Fig.10 The computer-accessible storage medium 800 in the embodiment may store one or more of the dynamic code generator 10, the dynamic code verifier 12, and / or the static code 802, which may include various static codes loaded into the static code execution area 20 for execution. The dynamic code generator 10 may include a plurality of instructions that, when executed on a processor in a computer system, cause the computer system to perform operations including the operations described above for the dynamic code generator 10. The dynamic code verifier 12 may include a plurality of instructions that, when executed on a processor in a computer system, cause the computer system to perform operations including the operations described above for the dynamic code verifier 12. The static code 802 may include a plurality of instructions that, when executed on a processor in a computer system, cause the computer system to perform operations including the operations described above for statically generated code.
[0169] The computer-accessible storage medium 800 may store a database 804 representing an integrated circuit. Generally speaking, the database 804 may be a database that can be read by a program and used directly or indirectly to manufacture hardware including the integrated circuit. For example, the database may be a behavioral level description of hardware functions in a high-level design language (HDL) such as Verilog or VHDL or a register transfer level (RTL) description. The description may be read by a synthesis tool, which may synthesize the description to generate a netlist including a list of gate circuits from a synthesis library. The netlist includes a set of gates that also represent the functions of the hardware including the integrated circuit. The netlist may then be placed and routed to generate a data set for describing the geometry to be applied to the mask. The mask may then be used in various semiconductor manufacturing steps to generate one or more semiconductor circuits corresponding to the integrated circuit. Alternatively, the database 804 on the computer-accessible storage medium 800 may be a netlist (with or without a synthesis library) or a data set as desired.
[0170] Although computer-accessible storage medium 800 stores a representation of an integrated circuit, other embodiments may carry a representation of any portion of an integrated circuit as desired, including Figure 6 Any subset of the components shown. Database 804 may represent any of the components described above.
[0171] This disclosure includes references to "an embodiment" or groups of "embodiments" (e.g., "some embodiments" or "various embodiments"). Embodiments are different specific implementations or examples of the disclosed concepts. References to "an embodiment," "one embodiment," "a particular embodiment," etc. do not necessarily refer to the same embodiment. A large number of possible embodiments are contemplated, including those specifically disclosed, as well as modifications or substitutions that fall within the spirit or scope of this disclosure.
[0172] The present disclosure may discuss potential advantages that may be generated by the disclosed embodiments. Not all of these implementations will necessarily exhibit any or all of the potential advantages. Whether a particular implementation achieves an advantage depends on many factors, some of which are outside the scope of the present disclosure. In fact, there are many reasons why a particular implementation that falls within the scope of the claims may not exhibit some or all of any of the disclosed advantages. For example, a particular implementation may include other circuit systems outside the scope of the present disclosure, which, in combination with one of the disclosed embodiments, negate or reduce one or more of the disclosed advantages. In addition, suboptimal design execution of a particular implementation (e.g., a specific implementation technique or tool) may also negate or reduce the disclosed advantages. Even if a specific implementation of the technology is assumed, the realization of the advantages may still depend on other factors, such as the environmental conditions in which the specific implementation is deployed. For example, the input provided to a particular implementation may prevent one or more problems solved in the present disclosure from occurring in a particular occasion, and as a result, the benefits of its solution may not be realized. In view of the existence of possible factors external to the present disclosure, any potential advantages described herein should not be understood as claim limitations that must be met in order to prove infringement. Instead, the identification of such potential advantages is intended to show one or more types of improvements available to designers who benefit from the present disclosure. Permanently describing such advantages (eg, stating that a particular advantage "may occur") is not intended to convey a doubt as to whether such advantage can actually be achieved, but rather to recognize that achievement of such advantage typically depends on technical realities of additional factors.
[0173] Unless otherwise indicated, the embodiments are non-limiting. That is, the disclosed embodiments are not intended to limit the scope of the claims drafted based on the present disclosure, even if only a single example is described for a particular feature. The embodiments disclosed in the present invention are intended to be illustrative and non-restrictive, without any contrary statement in the present invention. Therefore, the present application is intended to allow claims covering the disclosed embodiments, as well as such alternatives, modifications and equivalent forms, which will be apparent to those skilled in the art who are aware of the effective effects of the present disclosure.
[0174] For example, features in this application may be combined in any suitable manner. Accordingly, new claims may be made during the prosecution of this patent application (or a patent application claiming priority thereto) for any such combination of features. In particular, with reference to the appended claims, features of dependent claims may be combined, where appropriate, with features of other dependent claims, including claims that are dependent on other independent claims. Similarly, features from corresponding independent claims may be combined, where appropriate.
[0175] Thus, while the appended dependent claims may be drafted such that each dependent claim is dependent upon a single other claim, additional dependencies are also contemplated. Any combination of dependent features consistent with the present disclosure is contemplated and may be claimed in this or another patent application. In short, the combinations are not limited to those specifically recited in the appended claims.
[0176] It is also contemplated that claims drafted in one format or legal type (eg, apparatus) are intended to support corresponding claims in another format or legal type (eg, method), where appropriate.
[0177] Because this disclosure is a legal document, various terms and phrases may be subject to regulatory and judicial interpretation. Notice is hereby given that the definitions provided in the following paragraphs and throughout this disclosure will be used to determine how to interpret claims drafted based on this disclosure.
[0178] Unless the context clearly dictates otherwise, reference to an item in the singular (i.e., a noun or noun phrase preceded by "a," "an," or "the") is intended to mean "one or more." Thus, reference to "an item" in a claim does not exclude additional instances of that item without the accompanying context. A "plurality" item refers to a collection of two or more items.
[0179] The word "may" is used herein in a permissive sense (ie, having the potential to, being able to), rather than the mandatory sense (ie, must).
[0180] The terms "including" and "comprising" and forms thereof are open ended and mean "including, but not limited to."
[0181] When the term "or" is used in this disclosure with respect to a list of options, it will generally be understood to be used in an inclusive sense unless the context provides otherwise. Thus, the expression "x or y" is equivalent to "x or y, or both," thus covering 1) x but not y, 2) y but not x, and 3) both x and y. On the other hand, phrases such as "either x or y, but not both" make it clear that "or" is used in an exclusive sense.
[0182] The expressions "w, x, y, or z, or any combination thereof" or "... at least one of w, x, y, and z" are intended to cover all possibilities involving individual elements up to the total number of elements in the set. For example, given the set [w, x, y, z], these phrases cover any single element in the set (e.g., w but not x, y, or z), any two elements (e.g., w and x, but not y or z), any three elements (e.g., w, x, and y, but not z), and all four elements. The phrase "... at least one of w, x, y, and z" thus refers to at least one element in the set [w, x, y, z], thereby covering all possible combinations in the list of elements. The phrase should not be interpreted as requiring the presence of at least one instance of w, at least one instance of x, at least one instance of y, and at least one instance of z.
[0183] In this disclosure, various "labels" may precede a noun or noun phrase. Unless the context provides otherwise, different labels used for a feature (e.g., "first circuit," "second circuit," "particular circuit," "given circuit," etc.) refer to different instances of the feature. In addition, unless otherwise specified, the labels "first," "second," and "third" do not imply any type of ordering (e.g., spatial, temporal, logical, etc.) when applied to features.
[0184] The phrase "based on" or is used to describe one or more factors that influence a determination. This term does not exclude that there may be additional factors that may influence the determination. That is, a determination may be based only on the specified factors or on the specified factors and other unspecified factors. Consider the phrase "A is determined based on B." This phrase specifies that B is a factor used to determine A or that B influences the determination of A. This phrase does not exclude that the determination of A may also be based on some other factor such as C. This phrase is also intended to cover embodiments in which A is determined based only on B. As used herein, the phrase "based on" is synonymous with the phrase "based at least in part on."
[0185] The phrases "in response to" and "in response to" describe one or more factors that trigger an effect. The phrase does not exclude the possibility that additional factors may influence or otherwise trigger the effect, either in conjunction with the specified factors or independently of the specified factors. That is, the effect may be responsive to these factors alone, or may be responsive to the specified factors as well as other unspecified factors. Consider the phrase "in response to B, A is performed." The phrase specifies that B is a factor that triggers the execution of A or triggers a specific result of A. The phrase does not exclude that the execution of A may also be responsive to certain other factors, such as C. The phrase also does not exclude that the execution of A may be performed jointly in response to B and C. This phrase is also intended to cover embodiments in which A is performed only in response to B. As used herein, the phrase "in response to" is synonymous with the phrase "at least partially in response to." Similarly, the phrase "in response to" is synonymous with the phrase "at least partially in response to."
[0186] Within the present disclosure, different entities (which may be variously referred to as "units," "circuits," other components, etc.) may be described or claimed as being "configured to" perform one or more tasks or operations. This expression—[an entity] configured to [perform one or more tasks]—is used herein to refer to a structure (i.e., a physical thing). More specifically, this expression is used to indicate that this structure is arranged to perform one or more tasks during operation. A structure may be said to be "configured to" perform a task even if the structure is not currently being operated. Thus, an entity described or stated as "configured to" perform a task refers to a physical thing used to implement the task, such as a device, a circuit, a system with a processor unit, and a memory storing executable program instructions, etc. This phrase is not used herein to refer to an intangible thing.
[0187] In some cases, various units / circuits / components may be described herein as performing a set of tasks or operations. It should be understood that these entities are "configured to" perform those tasks / operations, even if not specifically stated.
[0188] The term "configured to" is not intended to mean "configurable to". For example, an unprogrammed FPGA would not be considered "configured to" perform a particular function. However, the unprogrammed FPGA may be "configurable to" perform that function. After being appropriately programmed, the FPGA may then be considered "configured to" perform the particular function.
[0189] Different "circuits" may be described in the present disclosure. These circuits or "circuitry" constitute hardware that includes various types of circuit elements, such as combinational logic, clock storage devices (e.g., flip-flops, registers, latches, etc.), finite state machines, memories (e.g., random access memory, embedded dynamic random access memory), programmable logic arrays, etc. The circuitry may be custom designed or taken from a standard library. In various specific implementations, the circuitry may include digital components, analog components, or a combination of both, as appropriate. Certain types of circuits may be generally referred to as "units" (e.g., decoding units, arithmetic logic units (ALUs), functional units, memory management units (MMUs), etc.). Such units are also referred to as circuits or circuitry.
[0190] Thus, the disclosed circuits / units / components and other elements shown in the drawings and described herein include hardware elements, such as those described in the preceding paragraphs. In many cases, the internal arrangement of hardware elements in a particular circuit can be specified by describing the functionality of that circuit. For example, a particular "decode unit" may be described as performing the function of "processing an opcode for an instruction and routing the instruction to one or more of a plurality of functional units," meaning that the decode unit is "configured to" perform that function. For a person skilled in the computer arts, this functional specification is sufficient to suggest a set of possible structures for the circuit.
[0191] In various embodiments, as discussed in the preceding paragraphs, the arrangement of circuits, units, and other elements defined by the functions or operations they are configured to implement, relative to each other and such circuits / units / components and the manner in which they interact form a microarchitecture definition of hardware, which is ultimately manufactured in an integrated circuit or programmed into an FPGA to form a physical implementation of the microarchitecture definition. Therefore, the microarchitecture definition is considered by those skilled in the art to be a structure from which many physical implementations can be derived, all of which fall into the broader structure described by the microarchitecture definition. That is, a technician with a microarchitecture definition provided in accordance with the present disclosure can implement the structure by coding a description of the circuit / unit / component in a hardware description language (HDL) such as Verilog or VHDL without undue experimentation and with the application of ordinary technicians. HDL descriptions are often expressed in a manner that can be displayed as functional. However, for those skilled in the art, the HDL description is a way to convert the structure of a circuit, unit, or component into the next level of specific implementation details. Such HDL descriptions may take the form of behavioral code (which is generally non-synthesizable), register transfer language (RTL) code (which is generally synthesizable compared to behavioral code), or structural code (e.g., a netlist specifying logic gates and their connectivity). The HDL description may be sequentially synthesized for a library of cells designed for a given integrated circuit manufacturing technology, and may be modified for timing, power, and other reasons to obtain a final design database that is transmitted to the factory to generate masks and ultimately produce integrated circuits. Some hardware circuits or portions thereof may also be custom designed in a schematic editor and captured into an integrated circuit design along with the synthesized circuitry. The integrated circuit may include transistors and other circuit elements (e.g., passive elements such as capacitors, resistors, inductors, etc.), as well as interconnects between transistors and circuit elements. Some embodiments may implement multiple integrated circuits coupled together to implement the hardware circuit, and / or discrete elements may be used in some embodiments. Alternatively, the HDL design may be synthesized into a programmable logic array such as a field programmable gate array (FPGA), and may be implemented in an FPGA. This decoupling between the design of a set of circuits and the subsequent low-level implementation of those circuits often leads to a situation where a circuit or logic designer never specifies a specific set of structures for the low-level implementation beyond a description of what the circuits are configured to do, because that process is performed at different stages of the circuit implementation process.
[0192] The fact that many different low-level combinations of circuit elements can be used to achieve the same specification of a circuit results in a large number of equivalent structures for that circuit. As noted, these low-level circuit implementations can vary depending on variations in manufacturing technology, the foundry selected to manufacture the integrated circuit, the cell libraries provided for a particular project, etc. In many cases, the selection made by different design tools or methodologies to produce these different implementations can be arbitrary.
[0193] Furthermore, for a given embodiment, a single implementation of a particular functional specification of a circuit typically includes a large number of devices (e.g., millions of transistors). Thus, the shear volume of this information makes it impractical to provide a complete description of the low-level structure used to implement a single embodiment, let alone the large number of equivalent possible implementations. For this reason, the present disclosure describes the structure of the circuit using functional shorthand commonly used in the industry.
[0194] Numerous variations and modifications will become apparent to those skilled in the art once the above disclosure is fully appreciated. It is intended that the following claims be interpreted to encompass all such variations and modifications.
Claims
1. A method comprising: monitoring, by monitoring circuitry of a computer system, a dynamically generated code sequence being executed in the computer system to ensure that the dynamically generated code sequence satisfies one or more execution criteria, wherein the one or more execution criteria specify: allowing a branch target outside an execution region of a memory storing the dynamically generated code sequence when the branch target is within one of one or more predefined address ranges outside the execution region; detecting, by the monitoring circuit, a violation of the one or more performance standards; and An exception is forced by the monitoring circuit based on detecting the violation.
2. The method of claim 1, wherein a set of cryptographic keys is provided to the dynamically generated code sequence for use in cryptographically signing one or more target addresses from an external source into the dynamically generated code sequence.
3. The method of claim 1, wherein a pair of address ranges adjacent to the address range corresponding to the execution region are inaccessible to instructions in the dynamically generated code sequence to prevent a direct branch instruction from exiting the execution region.
4. The method of claim 3, wherein a size of a given address range in the pair of address ranges is based on a range of extents that a given direct branch instruction within the execution region can reach.
5. The method of claim 1, wherein the one or more execution standards specify that dynamically generated code sequences are prohibited including unauthenticated indirect branch instructions.
6. The method of claim 1, wherein the one or more execution criteria include a requirement that branch targets outside of the execution region be signed with a key that is not accessible to the dynamically generated code sequence.
7. The method of claim 1, wherein the execution region is defined by one or more programmable registers of the computer system.
8. A processor, comprising: one or more registers programmable to define an execution region in memory, wherein the dynamically generated code is stored in the execution region during use; and a monitoring circuit coupled to the one or more registers and configured to: monitoring a dynamically generated code sequence being executed in the processor to ensure that the dynamically generated code sequence satisfies one or more execution criteria, wherein the one or more execution criteria specify: allowing a branch target outside the execution region when the branch target is within a predefined address range outside the execution region; as well as An exception is raised in the processor based on detecting a first specific violation of the one or more execution standards.
9. The processor of claim 8, wherein the monitoring circuit is configured to: Based on detecting a second specific violation of the one or more execution standards with respect to signing a specific pointer, execution of the signed instruction associated with the second specific violation is modified.
10. The processor of claim 8, wherein the monitoring circuit is configured to: detecting an attempt by the dynamically generated code sequence to access an address within a pair of address ranges adjacent to an address range corresponding to the execution region; and The access is prevented by causing an exception in the processor.
11. The processor of claim 10, wherein a size of a given one of the pair of address ranges is based on a range of extents that can be reached by a direct branch instruction within the execution region.
12. The processor of claim 8, wherein the one or more execution criteria specify that any one of a set of prohibited instructions is not present in the dynamically generated code sequence.
13. The processor of claim 8, wherein the one or more execution criteria include a requirement that branch targets outside of the execution region be signed with a key that is not accessible to the dynamically generated code sequence.
14. The processor of claim 8, wherein the monitoring circuit is configured to: A program counter of the processor is evaluated to determine when the dynamically generated code sequence is being executed in the processor to ensure that the dynamically generated code sequence satisfies one or more execution criteria.
15. A computer system comprising: a memory system, wherein a dynamic code execution region is defined in an address range within the memory system, and wherein dynamically generated code is stored in the dynamic code execution region during use; and at least one processor coupled to the memory system and configured to: monitoring a dynamically generated code sequence being executed in the computer system to ensure that the dynamically generated code sequence satisfies one or more execution criteria, wherein the one or more execution criteria specify: allowing a branch target outside the dynamic code execution region when the branch target is within a predefined address range outside the dynamic code execution region; as well as An exception is taken based on detecting a violation of the one or more performance criteria.
16. The computer system of claim 15, wherein the at least one processor is configured to provide a set of cryptographic keys to the dynamically generated code sequence to cryptographically sign one or more target addresses from an external source into the dynamically generated code sequence.
17. The computer system of claim 15, wherein the at least one processor is configured to enforce the one or more execution criteria on the code based on detecting that execution of code is occurring within the dynamic code execution region.
18. The computer system of claim 15, wherein the at least one processor is configured to detect an attempt to access within a pair of address ranges adjacent to an address range corresponding to the dynamic code execution region and prevent the access by taking an exception, and wherein a size of a given address range in the pair of address ranges is based on a range of extents that can be reached by direct branch instructions within the dynamic code execution region.
19. The computer system of claim 15, wherein the one or more execution standards specify that branch targets outside of the dynamic code execution region be cryptographically signed with one of a set of one or more cryptographic keys.
20. The computer system of claim 15, wherein the one or more execution standards specify that dynamically generated code sequences are prohibited from including illegal instruction encodings.
