Processor and return address processing method
By setting up a hardware conversion circuit in the processor to convert, store and convert the return address, the performance and security issues of program control flow being maliciously changed in the prior art are solved, and efficient control flow integrity protection is achieved.
Patent Information
- Application Number
- CN201910586325.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-07-01
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2039-07-01
AI Technical Summary
When existing technology prevents program control flow from being maliciously changed, it is necessary to identify call and return instructions and insert encryption and decryption instructions during the program compilation stage, resulting in reduced program running performance and the risk of software theft and security risks.
Set up a hardware conversion circuit in the processor to convert, store and convert the return address to prevent attackers from tampering with the return address, ensure the integrity of the program control flow, avoid identifying instructions and inserting additional instructions during the compilation stage, and improve performance and security.
The hardware conversion circuit realizes safe conversion of the return address to prevent malicious changes, improves the defense reliability and performance of the program control flow, avoids the risk of software theft, and ensures the normal operation of the program.
Smart Images

Figure CN112181491B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a processor and a method for processing a return address. Background Art
[0002] When the processor is running a program, an attacker may maliciously hijack the program control flow. Specifically, the attacker modifies the return address of the subroutine, changing the normal return address to a malicious return address, so that the processor jumps to the code segment pointed to by the malicious return address after executing the subroutine code, thereby changing the program control flow and destroying the control flow integrity (CFI) of the program.
[0003] At present, in order to prevent the program control flow from being maliciously changed, it is usually necessary to monitor the control flow when the program is running, and if the program control flow is changed, an alarm is issued. In a related technology, during the program compilation stage, the call instruction and return instruction corresponding to the subroutine are identified, an encryption instruction is inserted before the call instruction, and a decryption instruction is inserted before the return instruction. Furthermore, during the program running stage, before the processor calls the subroutine, the return address of the subroutine is first encrypted using the encryption instruction, and the encrypted address is pushed onto the stack. After the subroutine is executed, the encrypted address popped off the stack is decrypted using the decryption instruction to obtain the original return address, so that the processor can continue to execute from the return address.
[0004] After adopting the above defense technology, even if the attacker hijacks the encrypted address from the stack, the attacker cannot tamper with the encrypted address to an encrypted malicious address because the attacker does not know the key used by the encryption instruction. In other words, the attacker still cannot control the jump position of the program after hijacking the program control flow. Therefore, it can prevent the attacker from maliciously changing the program control flow and protect the integrity of the program control flow.
[0005] However, in the above technology, multiple additional instructions need to be inserted into the program, which reduces the running performance of the program. Summary of the invention
[0006] The embodiments of the present application provide a processor and a method for processing a return address, which protects the control flow integrity of a program without reducing the program running performance.
[0007] In a first aspect, an embodiment of the present application provides a processor, including: a processing core and a conversion circuit;
[0008] The processing core is used to output a return address;
[0009] The conversion circuit is used to convert the return address output by the processing core to obtain a converted return address, and output the converted return address to a stack in the memory;
[0010] The conversion circuit is further configured to convert the conversion return address in the stack to obtain the return address when the processing core needs to use the return address, and output the return address to the processing core.
[0011] In this embodiment, before the return address is stored in the memory, the conversion circuit converts the return address once, so the memory stores the converted return address. Since the attacker cannot know the conversion operation performed in the conversion circuit, the attacker cannot modify the converted return address in the memory to the converted return address corresponding to the malicious instruction, thereby preventing the attacker from maliciously changing the program control flow. After the converted return address is popped from the memory, the conversion circuit converts the converted return address again to obtain the original return address, so that the processing core can execute subsequent instructions according to the original return address, thereby ensuring the integrity of the program control flow. Since the above-mentioned conversion process is implemented by the hardware conversion circuit during the program running process, there is no need to identify the call instruction and the return instruction in the compilation stage, and there is no need to insert additional encryption instructions and decryption instructions, thereby avoiding the impact on the operating performance of the processor. At the same time, the risk of software theft is also avoided.
[0012] Optionally, the processor further includes a register;
[0013] The conversion circuit is specifically used to convert the return address output by the processing core to obtain a conversion return address, and output the conversion return address to the register, so that the conversion return address is output to the stack in the memory via the register;
[0014] The conversion circuit is also specifically used to convert the conversion return address in the stack to obtain the return address when the processing core needs to use the return address, and output the return address to the register, so that the return address is output to the processing core via the register.
[0015] In this embodiment, a hardware conversion circuit is set on the write path of the register, and the conversion circuit is used to convert the return address entering the register, that is, all inputs that need to enter the register will first be converted by the conversion circuit, and then the conversion result will be input into the register. In this way, the return address can be automatically identified without changing the control flow of the processor, which is easy to implement.
[0016] Optionally, the processor further includes a register;
[0017] When the processing core outputs the return address, the register is used to store the return address output by the processing core;
[0018] The conversion circuit is specifically used to convert the return address output by the register to obtain a converted return address, and output the converted return address to a stack in the memory;
[0019] When the processing core needs to use the return address, the register is also used to store the converted return address output by the stack;
[0020] The conversion circuit is also specifically used to perform the conversion on the conversion return address output by the register to obtain the return address, and output the return address to the processing core.
[0021] In this embodiment, a hardware conversion circuit is set on the read path of the register, and the conversion circuit is used to convert the return address output by the register, that is, all values output from the register will first be converted by the conversion circuit. In this way, the return address can be automatically identified without changing the control flow of the processor, which is easy to implement.
[0022] Optionally, the conversion satisfies the following conditions:
[0023] B=IP(A),A=IP(B)
[0024] Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
[0025] Optionally, the conversion circuit is specifically used for:
[0026] At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
[0027] Among them, the at least one bit includes bits corresponding to a changing segment and bits corresponding to an unchanged segment of the program's code address; the program's code address includes instruction addresses of multiple instructions, the unchanged segment is a bit position with the same bits in multiple instruction addresses, and the changing segment is a bit position with different bits in multiple instruction addresses.
[0028] By storing the conversion model and conversion parameters in the hardware circuit, attackers cannot obtain these sensitive information, thereby improving the defense reliability of the program control flow; when the conversion circuit converts at least one bit of the return address, the changing segment and the unchanged segment are converted at the same time, which can increase the difficulty of brute force cracking by attackers and ensure the security of the program control flow.
[0029] Optionally, the conversion circuit is specifically used for:
[0030] Grouping at least one bit of the return address to obtain a plurality of bit groups;
[0031] Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model;
[0032] The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
[0033] Optionally, the number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
[0034] Optionally, the types of conversion models include: modular multiplication conversion model and modular addition conversion model.
[0035] Optionally, the register is a register used to store a return address.
[0036] Optionally, the processor is a processor based on the ARM instruction set, and the register is an LR register.
[0037] Optionally, the processor is a processor based on the RISC V instruction set, and the register is an RA register.
[0038] In a second aspect, an embodiment of the present application provides a method for processing a return address, which is applied to a processor, wherein the processor includes: a processing core and a conversion circuit, and the method includes:
[0039] When the processing core outputs the return address, the return address is converted by the conversion circuit to obtain a converted return address, and the converted return address is output to a stack in a memory;
[0040] When the return address needs to be used, the conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core.
[0041] Optionally, the processor further includes a register, and converting the return address by the conversion circuit to obtain a converted return address, and outputting the converted return address to a stack in the memory includes:
[0042] Converting the return address by the conversion circuit to obtain a conversion return address, and outputting the conversion return address to the register, so that the conversion return address is output to a stack in the memory via the register;
[0043] The converting the conversion return address in the stack by the conversion circuit to obtain the return address, and outputting the return address to the processing core includes:
[0044] The conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the register, so that the return address is output to the processing core via the register.
[0045] Optionally, the processor further includes a register, the return address is output to the register by the processing core, and the converting the return address by the conversion circuit to obtain a converted return address, and outputting the converted return address to a stack in the memory includes:
[0046] Convert the return address output by the register by the conversion circuit to obtain a converted return address, and output the converted return address to a stack in the memory;
[0047] The converting the conversion return address in the stack by the conversion circuit to obtain the return address, and outputting the return address to the processing core includes:
[0048] The conversion return address output by the register is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core.
[0049] Optionally, the conversion satisfies the following conditions:
[0050] B=IP(A),A=IP(B)
[0051] Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
[0052] Optionally, converting the return address to obtain a converted return address includes:
[0053] At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
[0054] Optionally, the converting at least one bit of the return address using at least one conversion model to obtain the converted return address includes:
[0055] Grouping at least one bit of the return address to obtain a plurality of bit groups;
[0056] Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model;
[0057] The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
[0058] Optionally, the number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
[0059] Optionally, the types of conversion models include: modular multiplication conversion model and modular addition conversion model.
[0060] Optionally, the register is a register used to store a return address.
[0061] Optionally, the processor is a processor based on the ARM instruction set, and the register is an LR register.
[0062] Optionally, the processor is a processor based on the RISC V instruction set, and the register is an RA register.
[0063] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor as described in any one of the first aspects.
[0064] In a fourth aspect, an embodiment of the present application provides a chip, comprising: a processor as described in any one of the first aspect.
[0065] The processor and return address processing method provided in the embodiment of the present application are provided with a hardware conversion circuit in the processor. When the return address needs to be saved, the return address is converted by the conversion circuit, and the obtained converted return address is output to the memory; when the return address needs to be used, the converted return address in the memory is converted by the conversion circuit to obtain the return address. In the embodiment of the present application, since the attacker cannot know the conversion operation performed in the conversion circuit, the attacker cannot modify the converted return address in the memory to the converted return address corresponding to the malicious instruction, thereby preventing the attacker from maliciously changing the program control flow. In addition, since the above-mentioned conversion process is implemented by the hardware conversion circuit during the program running process, compared with the above-mentioned related technologies, there is no need to identify the call instruction and the return instruction in the compilation stage, and there is no need to insert additional encryption instructions and decryption instructions, thereby avoiding affecting the operating performance of the processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0067] Figure 2 A schematic diagram of the structure of a processor provided in an embodiment of the present application;
[0068] Figure 3 A schematic diagram of the return address processing process provided in an embodiment of the present application;
[0069] Figure 4A and Figure 4B A schematic diagram of the processing process of the existing return address;
[0070] Figure 5A and Figure 5B A schematic diagram of the return address processing process provided in an embodiment of the present application;
[0071] Figure 6 A schematic diagram of the program running process provided in the embodiment of the present application;
[0072] Fig. 7A and Figure 7B A schematic diagram of the return address processing process provided in an embodiment of the present application;
[0073] Figure 8 A flowchart of a method for processing a return address provided in an embodiment of the present application. DETAILED DESCRIPTION
[0074] In order to facilitate the understanding of this application, first combine Figure 1 , the structure of the electronic device to which the processor of the present application is applicable is described.
[0075] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 1 As shown, the electronic device 10 includes a processor 100 and a memory 200. The memory 200 is used to store computer programs and data. There are many types of memories, which can be divided into main memory and auxiliary memory according to their uses. The main memory is also called "internal memory", or "memory" for short. The memory is used to temporarily store computer programs and data during the operation of the processor. The auxiliary memory is also called "external memory", or "external memory" for short. The external memory is used to store computer programs and data that are temporarily not used during the operation of the processor. The processor 100 is used to execute the computer program stored in the memory 200.
[0076] The processor is the core device of the electronic device. The processor usually includes at least one processing core, a cache, and an input and output interface for communicating with other devices of the electronic device. The processing core refers to the processing unit in the processor used to perform data processing tasks. The processing core is the main device responsible for calculation in the processor.
[0077] The processor in this application may be a central processing unit (CPU), a graphics processing unit (GPU), etc.
[0078] The processor can be used to execute computer programs in electronic devices. The processor can recognize and execute instructions in the computer program, so that the electronic device can complete a certain function or obtain a certain result.
[0079] A computer program is an instruction sequence consisting of multiple instructions. A subroutine can also be called in a computer program. A subroutine can also be called a "sub-procedure" or a "sub-function". A subroutine consists of one or more instructions, is responsible for completing a specific task, and has relative independence. Usually, a program that contains a subroutine call is called a main program. The main program and the subroutine are relative, for example: Program A calls Program B, and Program B calls Program C. Then, relative to Program A, Program B is a subroutine, and relative to Program C, Program B is a main program.
[0080] The normal execution flow of a computer program is called program control flow. When executing a computer program, the processor executes each instruction according to the program control flow. However, when the processor is executing a computer program, an attacker may maliciously hijack the program control flow. The purpose of these malicious attack events is usually to change the control flow of the program, thereby destroying the control flow integrity (CFI) of the program. For example, a common malicious attack event that destroys the CFI of a program is a return oriented programming (ROP) attack.
[0081] The following describes the process of a processor executing a computer program under normal circumstances and the process of a processor executing a computer program under a ROP attack with a specific example.
[0082] Assume that a computer program includes: instruction A, instruction B and instruction C. Instruction B is a subroutine call instruction. The address of instruction A is 0x0000, the address of instruction B is 0x0004, and the address of instruction C is 0x0008. The normal program execution process is to execute instruction A, instruction B and instruction C in sequence. The normal process of the processor executing the program is as follows.
[0083] 1) The processor executes instruction A.
[0084] Since instruction B is a subroutine call instruction, when the processor executes instruction B, it will jump to the address of the subroutine corresponding to instruction B. In order to ensure that the processor can correctly return to the address of instruction C after executing the subroutine corresponding to instruction B, the processor will save the address of instruction C before executing instruction B. That is,
[0085] 2) The processor writes the address of instruction C into the memory. In the embodiment of the present application, the address of instruction C is referred to as the return address.
[0086] For example, the processor may write the return address to a stack in memory.
[0087] 3) The processor executes instruction B, jumps to the address of the subroutine corresponding to instruction B, and executes the subroutine.
[0088] 4) When the subroutine is finished, the return address (0x0008) is read from the memory and the program jumps to address 0x0008 to execute instruction C.
[0089] When there is a ROP attack, the attacker tampers with the return address stored in the memory. For example, the attacker modifies the address (0x0008) of instruction C stored in the memory to a malicious address through remote software. After the processor executes the subroutine corresponding to instruction B, it reads the malicious address from the memory and jumps to the malicious address for execution. Thus, the integrity of the program control flow is destroyed.
[0090] Currently, in order to prevent the program control flow from being maliciously changed, it is usually necessary to monitor the control flow when the program is running, and if the program control flow is changed, an alarm is issued.
[0091] In a related technology, software is used to defend against malicious changes to the program control flow. Specifically, during the program compilation phase, the call instruction and return instruction corresponding to the subroutine are first identified. Exemplarily, the call instruction is a call instruction, and the return instruction is a ret instruction. Then, an encryption instruction is inserted before the call instruction. Exemplarily, the encryption instruction is an instruction that uses a preset key to encrypt the return address. At the same time, a decryption instruction is inserted before the return instruction. Exemplarily, the decryption instruction is an instruction that uses the same key to decrypt the encrypted return address.
[0092] After such compilation, during the program running phase, before the processor calls the subroutine, it first executes the encryption instruction to encrypt the subroutine's return address and stores the encrypted address in the memory. After the subroutine is executed, the decryption instruction is used to decrypt the encrypted address read from the memory to obtain the original return address, so that the processor can continue to execute from the return address.
[0093] The specific encryption and decryption method can be to define a special register in the processor, which is specifically used to store the key and cannot be used for other purposes. When encrypting, the original return address is XORed with the key in the special register to obtain the encrypted return address, and then stored in the memory. When decrypting, the encrypted return address read from the memory is XORed with the key in the special register again to obtain the original return address. That is, both the encryption instruction and the decryption instruction need to be XORed once.
[0094] After adopting the above defense technology, even if the attacker hijacks the encrypted return address from the memory, the attacker cannot tamper with the encrypted return address to an encrypted malicious address because the attacker does not know the key used by the encryption instruction. In other words, the attacker still cannot control the jump position of the program after hijacking the program control flow. Therefore, it can prevent the attacker from maliciously changing the program control flow and protect the integrity of the program control flow.
[0095] However, there are at least the following problems in the above-mentioned related technologies: 1) It is necessary to identify the call instructions and return instructions during the program compilation stage, and insert multiple additional encryption instructions and decryption instructions into the program, which reduces the program's running performance. 2) Since the key is stored in the register and encryption and decryption are performed in software, there is a risk of software theft and poor protection security. 3) The use of XOR operations on each bit separately makes brute force cracking difficult, and each brute force cracking can cause the program to jump to the code area, which poses a security risk. 4) Since a special register is required to store the key, the special register cannot be used by other functions, which limits the application scenarios.
[0096] In order to solve at least one of the above problems, an embodiment of the present application provides a processor, in which a hardware conversion circuit is set in the processor. When the return address needs to be saved, the return address is converted by the conversion circuit, and the obtained conversion return address is output to the memory; when the return address needs to be used, the conversion circuit is used to convert the conversion return address in the memory to obtain the return address. In the embodiment of the present application, since the attacker cannot know the conversion operation performed in the conversion circuit, the attacker cannot modify the conversion return address in the memory to the conversion return address corresponding to the malicious instruction, thereby preventing the attacker from maliciously changing the program control flow. In addition, since the above conversion process is implemented by the hardware conversion circuit during the program running process, compared with the above related technologies, there is no need to identify the call instruction and the return instruction in the compilation stage, and there is no need to insert additional encryption instructions and decryption instructions, thereby avoiding affecting the running performance of the processor.
[0097] The technical solutions shown in the present application are described in detail below through specific embodiments. It should be noted that the following embodiments can exist independently or in combination with each other, and the same or similar contents will not be described repeatedly in different embodiments.
[0098] Figure 2 This is a schematic diagram of the structure of the processor provided in the embodiment of the present application. Figure 2 As shown, the processor 100 of this embodiment includes: a processing core 110 and a conversion circuit 120 .
[0099] The processing core 110 is used to output a return address.
[0100] The conversion circuit 120 is used to convert the return address output by the processing core 110 to obtain a converted return address, and output the converted return address to a stack in the memory.
[0101] The conversion circuit 120 is further configured to perform the conversion on the conversion return address in the stack to obtain the return address when the processing core 110 needs to use the return address, and output the return address to the processing core 110 .
[0102] The embodiment of the present application does not specifically limit the type of processor. The processor in the embodiment of the present application can be, but is not limited to, the following types: a processor based on the ARM instruction set, a processor based on the RISC-V instruction set.
[0103] The embodiment of the present application does not specifically limit the bit width of the processor. The processor can be a 32-bit processor, a 64-bit processor, or a processor with other bit widths.
[0104] The number of processing cores in the processor may be one or more. A processing core refers to a processing unit in the processor for performing data processing tasks. When the number of processing cores is one, the processor is a single-core processor. When the number of processing cores is multiple, the processor is a multi-core processor. The processing core is used to output a return address. The return address is the address of the next instruction to be executed by the processing core.
[0105] In the present application, a processing core is any circuit that needs to store a return address in memory and needs to obtain a return address from memory. Exemplarily, the processing core is a program counter (PC). PC can also be called an instruction counter. PC is used to store the address of the next instruction to be executed by the processor. Before the program starts executing, the processor sends the starting address of the program, that is, the address of the first instruction of the program, to PC. When executing instructions, the processor will automatically modify the value in PC, that is, each time an instruction is executed, the value in PC is increased by an amount so that the value in PC always points to the address of the next instruction to be executed.
[0106] In the present application, the conversion circuit is arranged on the data path between the processing core and the memory. Figure 3 Describe the processing of the return address by the translation circuit.
[0107] Figure 3 The following is a schematic diagram of the process of processing the return address provided in the embodiment of the present application. Figure 3 As shown, when the processing core needs to store the return address in the memory, the return address output by the processing core passes through the conversion circuit, the conversion circuit converts the return address to obtain the converted return address, and then outputs the converted return address to the stack in the memory. When the processing core needs to use the return address, the converted return address popped from the memory passes through the conversion circuit, the conversion circuit performs the same conversion on the converted address to obtain the original return address, and then outputs the original return address to the processing core.
[0108] The processing core needs to store the return address into the memory, which may mean that before the processing core executes the call instruction, the return address corresponding to the call instruction needs to be stored into the memory.
[0109] Correspondingly, the processing core needs to use the return address, which may mean that when the processing core returns from the subroutine corresponding to the calling instruction, it needs to obtain the return address corresponding to the calling instruction from the memory.
[0110] It is understandable that in the embodiment of the present application, the conversion circuit can use one or more conversion models to convert the return address. This embodiment does not specifically limit this, and several possible conversion methods can be referred to the detailed description of the subsequent embodiments.
[0111] In the present application, the conversion circuit converts the return address once before the return address is stored in the memory, so the memory stores the converted return address. Since the attacker cannot know the conversion operation performed in the conversion circuit, the attacker cannot modify the converted return address in the memory to the converted return address corresponding to the malicious instruction, thereby preventing the attacker from maliciously changing the program control flow.
[0112] After the converted return address is popped from the memory, the conversion circuit converts the converted return address again to obtain the original return address, so that the processing core can execute subsequent instructions according to the original return address, ensuring the integrity of the program control flow.
[0113] In this application, since the above conversion process is implemented by a hardware conversion circuit during program execution, compared with the above related technologies, there is no need to identify the call instruction and return instruction at the compilation stage, and no need to insert additional encryption instructions and decryption instructions, thereby avoiding the impact on the processor's operating performance. At the same time, compared with the above related technologies, there is no need for a special register to store the key, thereby avoiding the risk of software theft.
[0114] In one possible implementation, the processor further includes a control circuit, which can identify whether the address output by the processing core is a return address. When the control circuit identifies that the address output by the processing core is a return address, the return address is controlled to be input into the conversion circuit. The conversion circuit converts the return address to obtain a converted return address, and outputs the converted return address to a stack in the memory. When the control circuit identifies that the processing core needs to use the return address, under the control of the control circuit, the converted return address popped from the memory is input into the conversion circuit. The conversion circuit converts the converted return address to obtain an original return address, and outputs the original return address to the processing core.
[0115] In another possible implementation, the processor is not aware of the existence of the conversion circuit. The conversion circuit is set on the data path between the processing core and the memory, that is, when the return address is transmitted from the processing core to the memory, and when it is transmitted from the memory to the processing core, it will pass through the conversion circuit. This implementation only requires the conversion circuit to be set on the data path between the processing core and the memory, without changing the existing control flow of the processor, and is easy to implement.
[0116] Optionally, the processor also includes a register, which is a register specifically used to store a return address.
[0117] For this type of processor, the register is the only way for the return address to go from the processing core to the memory. Exemplarily, when the return address of the subroutine needs to be output to the memory, the processing core first outputs the return address to the register, and then the register outputs the return address to the memory. When the return address needs to be used, the return address popped from the memory is also first output to the register, and then the register outputs the return address to the processing core.
[0118] It is understandable that for processors with different instruction sets, the registers used to store the return address may be different.
[0119] Exemplarily, the processor is a processor based on the ARM instruction set, and the register is a link register (LR).
[0120] Exemplarily, the processor is a processor based on the RISC V instruction set, and the register is a return address (RA) register.
[0121] The following uses the ARM instruction set processor as an example to describe the processor structure and the return address processing process. Figure 4A and Figure 4B The figure is a schematic diagram of the existing return address processing process. Figure 4A The example is a schematic diagram of the process of pushing the return address into the stack. Figure 4B The example is a schematic diagram of the process of popping the return address from the stack.
[0122] Before the processing core executes the call instruction, it needs to store the return address corresponding to the call instruction into the memory. For example, Figure 4A As shown, under the control of the processing core, the return address output by the PC enters the LR register. Then, the return address output by the LR register is stored in the stack in the memory.
[0123] When the processing core returns from the subroutine corresponding to the call instruction, it needs to read the return address from the memory. For example, Figure 4B As shown in FIG. 1 , the return address popped from the memory stack enters the LR register. Then, the LR register outputs the return address to the processing core.
[0124] The conversion circuit in this embodiment can be arranged before the above-mentioned register or after the above-mentioned register.
[0125] It should be noted that, in this embodiment, the conversion circuit is arranged before the register, which means that the conversion circuit is arranged on the write path of the register, that is, arranged at the input end of the register. When the conversion circuit is arranged before the register, it means that all return addresses entering the register will first pass through the conversion circuit and then enter the register. In this embodiment, the conversion circuit is arranged after the register, which means that the conversion circuit is arranged on the read path of the register, that is, arranged at the output end of the register. When the conversion circuit is arranged after the register, it means that all return addresses output from the register will pass through the conversion circuit.
[0126] The above two implementation modes are described below respectively.
[0127] Figure 5A and Figure 5B A schematic diagram of the return address processing process provided in the embodiment of the present application. In this embodiment, the conversion circuit is set on the write path of the LR register. Among them, Figure 5A The example shows the process of pushing the return address onto the stack. Figure 5B The example shows the process of popping the return address from the stack.
[0128] The conversion circuit is specifically used to convert the return address output by the processing core to obtain a converted return address, and output the converted return address to the register, so that the converted return address is output to a stack in the memory via the register.
[0129] The conversion circuit is also specifically used to convert the conversion return address in the stack to obtain the return address when the processing core needs to use the return address, and output the return address to the register, so that the return address is output to the processing core via the register.
[0130] like Figure 5A As shown, since the conversion circuit is set on the write path of the register, the return address output by the processing core will first pass through the conversion circuit when it is output to the LR register. The conversion circuit converts the return address output by the processing core to obtain the conversion return address, so that the conversion return address is actually stored in the LR register. Then, the LR register outputs the conversion return address to the stack in the memory, that is, the conversion return address is actually pushed into the stack. Since the attacker cannot know the conversion operation performed in the conversion circuit, the attacker cannot modify the conversion return address in the memory to the conversion return address corresponding to the malicious instruction, thereby preventing the attacker from maliciously changing the program control flow.
[0131] like Figure 5B As shown in the figure, when the processing core needs to use the return address, since the conversion circuit is set on the write path of the LR register, the conversion return address popped from the memory will pass through the conversion circuit before entering the LR register. The conversion circuit converts the conversion return address to obtain the original return address, so that the original return address is actually stored in the LR register. Then, the LR register outputs the original return address to the processing core. This ensures the normal control flow of the program.
[0132] The following uses a processor based on the ARM instruction set as an example, combined with the running process of an actual program, to illustrate.
[0133] Figure 6 The following is a schematic diagram of the program running process provided in the embodiment of the present application. Figure 6 As shown, the program includes the following ARM instructions: SUB, STP, ADD, LDP, ADD, and RET.
[0134] When the control flow is ready to enter the subroutine, that is, when the processing core executes the STP instruction, the return address is output to the LR (0x30) register. Before the return address enters the LR register, the return address first passes through the conversion circuit, which converts the return address to obtain the converted return address, so that the converted return address actually enters the LR register. After that, the LR register outputs the converted return address to the stack in the memory.
[0135] When the control flow returns from the end of the subroutine, that is, when the processing core executes the LDP instruction, the converted return address is read from the memory stack. Before entering the LR (0x30) register, the converted return address will first pass through the conversion circuit, which converts the converted return address again to obtain the original return address. The original return address is stored in the LR register and used when the processing core executes the RET instruction.
[0136] In this embodiment, a hardware conversion circuit is set on the write path of the LR register, and the conversion circuit is used to convert the return address entering the LR register, that is, all inputs that need to enter the LR register will first be converted by the conversion circuit, and then the conversion result will be input into the LR register. In this way, the return address can be automatically identified without changing the control flow of the processor, which is easy to implement.
[0137] Fig. 7A and Figure 7B A schematic diagram of the return address processing process provided in the embodiment of the present application. In this embodiment, the conversion circuit is set on the read path of the LR register. Among them, Fig. 7A The example shows the process of pushing the return address onto the stack. Figure 7B The example shows the process of popping the return address from the stack.
[0138] When the processing core outputs the return address, the register is used to store the return address output by the processing core. The conversion circuit is specifically used to convert the return address output by the register to obtain a converted return address, and output the converted return address to a stack in a memory.
[0139] When the processing core needs to use the return address, the register is also used to store the converted return address output by the stack. The conversion circuit is also specifically used to convert the converted return address output by the register to obtain the return address, and output the return address to the processing core.
[0140] like Fig. 7AAs shown, the return address output by the processing core is output to the LR register. Since the conversion circuit is set on the read path of the LR register, the LR register will pass through the conversion circuit when it outputs the return address to the stack in the memory. The conversion circuit converts the return address output by the LR register to obtain the conversion return address, so that the conversion return address is actually pushed into the stack. Since the attacker cannot know the conversion operation performed in the conversion circuit, the attacker cannot modify the conversion return address in the memory to the conversion return address corresponding to the malicious instruction, thereby preventing the attacker from maliciously changing the program control flow.
[0141] like Figure 7B As shown in FIG. 1 , when the processing core needs to use the return address, the converted return address popped from the memory stack enters the LR register. Since the conversion circuit is set on the read path of the LR register, the conversion return address will pass through the conversion circuit when the LR register outputs the converted return address to the processing core. The conversion circuit converts the converted return address to obtain the original return address, so that the original return address is actually input to the processing core. This ensures the normal control flow of the program.
[0142] In this embodiment, a hardware conversion circuit is set on the read path of the LR register, and the conversion circuit is used to convert the return address output by the LR register, that is, all values output from the LR register will first be converted by the conversion circuit. In this way, the return address can be automatically identified without changing the control flow of the processor, which is easy to implement.
[0143] It should be noted that the above embodiments are described by taking a processor based on the ARM instruction set as an example. However, the processor adapted by the embodiments of the present application is not limited thereto. The embodiments of the present application are also applicable to processors of other instruction sets, as long as there is a register specifically used to store the return address in the processor.
[0144] It should be noted that in the above embodiments, for processors based on the ARM instruction set and processors based on the RISC-V instruction set, if the compiler supports the leaf subroutine optimization option (i.e., in the leaf subroutine, the return address is not saved from the LR / RA register to the stack in the memory, but is always saved in the LR / RA register), this optimization function needs to be turned off to ensure that the use of LR / RA in the leaf subroutine is no different from that in the general branch (subroutine). Otherwise, when the return address is read from the LR / RA register without decryption, it will affect the normal return of the subroutine.
[0145] The specific conversion process of the conversion circuit in the above embodiments is introduced below.
[0146] In the embodiment of the present application, the conversion circuit performs conversion on the return address, and satisfies the following conditions:
[0147] B=IP(A),A=IP(B)
[0148] Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
[0149] It can be understood that there may be multiple conversion models that meet the above conditions, including but not limited to: XOR conversion model, modular multiplication conversion model, and modular addition conversion model.
[0150] In one possible implementation, a plurality of conversion models are stored in the conversion circuit, and different conversion models correspond to one or more sets of optional conversion parameters. By storing the conversion model and conversion parameters in the hardware circuit, attackers cannot obtain such sensitive information, thereby improving the defense reliability of the program control flow.
[0151] When the conversion circuit converts the return address, at least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
[0152] Among them, the at least one bit includes bits corresponding to a changing segment and bits corresponding to an unchanged segment of the program's code address; the program's code address includes instruction addresses of multiple instructions, the unchanged segment is a bit position with the same bits in multiple instruction addresses, and the changing segment is a bit position with different bits in multiple instruction addresses.
[0153] For example, taking the code area of libc as an example, since the number of instructions in the program is limited, by comparing the starting address and the ending address of the code address of the program, it can be found that several high-order bits, or even a dozen or dozens of high-order bits of the code address will not change. In this application, these bits that will not change are referred to as the constant section of the code address. Correspondingly, the bits of the code address that will change are called the changing section of the code address.
[0154] In the embodiment of the present application, when the conversion circuit converts at least one bit of the return address, the changing segment and the unchanged segment are converted at the same time, which can increase the difficulty of brute force cracking by an attacker and ensure the security of the program control flow.
[0155] Exemplarily, before running the program, the conversion circuit randomly selects a conversion model and a set of conversion parameters to convert the return address during the program running process. If an error occurs during program running, that is, a ROP attack occurs, when the program is re-run, the conversion model and / or conversion parameters are replaced, so that the attacker cannot carry out multiple attacks on the same conversion model and conversion parameters, further improving the security of the program control flow.
[0156] The following describes the process of the processor processing the return address in conjunction with several specific implementations.
[0157] In a possible implementation, assuming that the processor is a 32-bit processor based on the ARM instruction set, the conversion circuit is set on the write path of the LR register, and the conversion circuit adopts a modular multiplication conversion model. The processor processes the return address as follows:
[0158] 1) Before the processing core executes the call instruction (for example, calling the func function), the return address will be stored in the LR register. Since the conversion circuit is set on the write path of the register, the return address will first be converted by the conversion circuit to obtain the converted return address, so that the actual address entering the LR register is the converted return address.
[0159] For the convenience of description, in this embodiment, the return address output by the processing core (i.e., the original return address) is recorded as a[31:0]. The converted return address converted by the conversion circuit (i.e., the return address actually entered into the LR register) is recorded as b[31:0]. The conversion circuit performs the modular multiplication operation as shown below:
[0160] a×q≡b mod p
[0161] Among them, p and q are the conversion parameters corresponding to the modular multiplication conversion model. From the above formula, it can be seen that the return address a and the parameter q in the conversion circuit are modularly multiplied, the modulus is p, and the output is the conversion return address b. Among them, q and p satisfy the following relationship:
[0162] q 2 ≡1mod p
[0163] It is understandable that there can be multiple combinations of p and q that satisfy the above relationship. For example, if p = 2^{32}, then q can be selected as any of the following:
[0164] 4294967295, 2147483649, 2147483647
[0165] In practical applications, p should be larger than the maximum code address but not too large to save the chip area of the conversion circuit. In addition, when q=p-1 or q=1, the above requirements are always met, but for security reasons, q is not selected as 1.
[0166] In this embodiment, since the modular multiplication conversion model performs a whole operation on the 32-bit return address a[31:0], that is, the changing segment and the unchanged segment of the code address are operated at the same time, the attacker cannot carry out a specific attack only on the changing segment, and the attacker cannot guarantee that each brute force cracking can jump to the code area, thereby improving the security of the program control flow.
[0167] 2) Read the conversion return address from the LR register and store it in the stack in the memory.
[0168] 3) Execute function func.
[0169] 4) Before returning from function func, the converted return address is read from the memory and the popped converted return address is stored in the LR register. Since a conversion circuit is set on the write path of the LR register, the popped converted return address will first pass through the conversion circuit. The conversion circuit converts the converted return address again to obtain the original return address, and then the original return address is stored in the LR register. The conversion circuit performs the same modular multiplication operation, as follows:
[0170] b×q≡a mod p
[0171] Wherein, p and q are conversion parameters corresponding to the modular multiplication conversion model, which are the same as the parameters used in the first conversion process mentioned above. The conversion return address b is the input of the conversion model, and the return address a is the output of the conversion model.
[0172] From the above two conversion processes, it can be seen that the return address returns to its original value after two similar conversions.
[0173] 5) Execute the return operation.
[0174] If the converted return address b is not maliciously tampered with in the memory stack, then after the conversion by the conversion circuit, the return address a is the correct return address, and the program executes normally. If the converted return address b is maliciously tampered with in the memory stack, since the attacker cannot know the sensitive information p and q, it is impossible to construct a legal malicious converted return address. Therefore, after the conversion by the conversion circuit, the return address a is garbled. When executing the return operation, the program will execute the code at the garbled address, which will most likely cause a memory error. As a result, the attacker cannot achieve the purpose of changing the program control flow.
[0175] In another possible implementation, assuming that the processor is a 32-bit processor based on the ARM instruction set, the conversion circuit is set on the read path of the LR register, and the conversion circuit adopts a modular addition conversion model. The processor processes the return address as follows:
[0176] 1) Before the processing core executes the call instruction (for example, calling the func function), the return address is stored in the LR register.
[0177] 2) Read the return address from the LR register and store it in the stack in memory.
[0178] Since the conversion circuit is arranged on the read path of the LR register, the return address output by the LR register will first be converted by the conversion circuit to obtain the converted return address, so that the converted return address is actually pushed into the stack.
[0179] For the convenience of expression, in this embodiment, the return address output by the LR register (i.e., the original return address) is recorded as a[31:0]. The converted return address converted by the conversion circuit (i.e., the return address actually pushed into the stack) is recorded as b[31:0]. The conversion circuit performs the modular addition operation shown in the following formula:
[0180] a+q≡b mod p
[0181] Among them, p and q are the conversion parameters corresponding to the modular addition conversion model. From the above formula, it can be seen that the return address a and the parameter q in the conversion circuit are modularly added, the modulus is p, and the output is the conversion return address b. Among them, q and p satisfy the following relationship:
[0182] q≡p / 2
[0183] It is understandable that there may be multiple combinations of p and q that satisfy the above relationship. For example, if p=2^{32}+2, then q=2^{31}+1.
[0184] In practical applications, p should be larger than the maximum code address but not too large to save the chip area of the conversion circuit.
[0185] In this embodiment, since the modular addition conversion model operates the 32-bit return address a[31:0] as a whole, that is, the changing segment and the unchanged segment of the code address are operated at the same time, the attacker cannot carry out a specific attack only on the changing segment, and the attacker cannot guarantee that each brute force cracking can jump to the code area, thereby improving the security of the program control flow.
[0186] 3) Execute function func.
[0187] 4) Before returning from function func, read the conversion return address from the memory and store the popped conversion return address in the LR register.
[0188] 5) The conversion return address is read from the LR register and output to the processing core to perform the return operation.
[0189] Since a conversion circuit is set on the read path of the LR register, the converted return address of the stack will first pass through the conversion circuit. The conversion circuit converts the converted return address again to obtain the original return address, and then the original return address is output to the processing core. The conversion circuit performs the same modular addition operation as follows:
[0190] b+q≡a mod p
[0191] Wherein, p and q are conversion parameters corresponding to the modular addition conversion model, which are the same as the parameters used in the first conversion process mentioned above. The conversion return address b is the input of the conversion model, and the return address a is the output of the conversion model.
[0192] From the above two conversion processes, it can be seen that the return address returns to its original value after two similar conversions.
[0193] If the converted return address b is not maliciously tampered with in the memory stack, then after the conversion by the conversion circuit, the return address a is the correct return address, and the program executes normally. If the converted return address b is maliciously tampered with in the memory stack, since the attacker cannot know the sensitive information p and q, it is impossible to construct a legal malicious converted return address. Therefore, after the conversion by the conversion circuit, the return address a is garbled. When executing the return operation, the program will execute the code at the garbled address, which will most likely cause a memory error. As a result, the attacker cannot achieve the purpose of changing the program control flow.
[0194] In another possible implementation, the conversion circuit groups at least one bit of the return address to obtain multiple bit groups; uses the conversion model to convert the bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model; then, the converted return address is obtained based on the conversion results corresponding to each of the bit groups.
[0195] It is understandable that there are many ways to group at least one bit of the return address, which is not specifically limited in this embodiment. Taking a 32-bit processor system as an example, the 32 bits of the return address can be divided into two bit groups, three bit groups, or more bit groups.
[0196] Exemplarily, when divided into two bit groups, the first 16 bits can be taken as one group and the last 16 bits as one group; the first 8 bits can be taken as one group and the last 24 bits can be taken as one group; the odd bits can be taken as one group and the even bits can be taken as one group. It is understandable that there are other grouping methods, which are not listed here. When divided into two bit groups, the conversion models adopted by the two bit groups can be the same or different. For example: both bit groups adopt the modular multiplication conversion model, or both bit groups adopt the modular addition conversion model, or one bit group adopts the modular multiplication conversion model and the other bit group adopts the modular addition conversion model.
[0197] Exemplarily, when divided into three bit groups, the first 8 bits can be taken as a group, the middle 16 bits can be taken as a group, and the last 8 bits can be taken as a group; the first 10 bits can be taken as a group, the middle 8 bits can be taken as a group, and the last 14 bits can be taken as a group; the 1st, 4th, 7th, 10th, 13th, 16th, 19th, 22nd, 25th, 28th, and 31st bits can be taken as a group, the 2nd, 5th, 8th, 11th, 14th, 17th, 20th, 23rd, 26th, and 29th bits can be taken as a group, and the 0th, 3rd, 6th, 9th, 12th, 15th, 18th, 21st, 24th, 27th, and 30th bits can be taken as a group. It can be understood that there are other grouping methods, which are not listed here. When divided into three bit groups, the conversion models adopted by the three bit groups can be the same or different.
[0198] The following is an explanation with examples.
[0199] Assume that the processor is a 32-bit processor based on the ARM instruction set, and the conversion circuit is set on the write path of the LR register. The conversion circuit divides the 32 bits of the return address into two bit groups, one bit group includes the bits corresponding to the odd bits of the return address, and the other bit group includes the bits corresponding to the even bits of the return address. One of the bit groups adopts the modular multiplication conversion model, and the other bit group adopts the modular addition conversion model. Then the processor processes the return address as follows:
[0200] 1) Before the processing core executes the call instruction (for example, calling the func function), the return address will be stored in the LR register. Since the conversion circuit is set on the write path of the register, the return address will first be converted by the conversion circuit to obtain the converted return address, so that the actual address entering the LR register is the converted return address.
[0201] For the convenience of description, in this embodiment, the return address output by the processing core (i.e., the original return address) is recorded as a[31:0]. a[31:0] is divided into two bit groups, namely a1[15:0] and a2[15:0], where:
[0202] a1[15:0]≡{a
[31] ,a
[29] ,a
[27] ,…,a[1]}
[0203] a2[15:0]≡{a
[30] ,a
[28] ,a
[26] ,…,a[0]}
[0204] Correspondingly, the conversion return address obtained by the conversion circuit (i.e., the return address actually entering the LR register) is recorded as b[31:0]. b[31:0] is divided into two bit groups, namely b1[15:0] and b2[15:0], where
[0205] b1[15:0]≡{b
[31] ,b
[29] ,b
[27] ,…,b[1]}
[0206] b2[15:0]≡{b
[30] ,b
[28] ,b
[26] ,…,b[0]}
[0207] When the conversion circuit converts the return address, it uses the modular multiplication conversion model for a1[15:0] and the modular addition conversion model for a2[15:0], as shown below:
[0208] a1×q1≡b1modp1
[0209] a2+q2≡b2modp2
[0210] Among them, p1 and q1 are the conversion parameters corresponding to the modular multiplication conversion model, and p2 and q2 are the conversion parameters corresponding to the modular addition conversion model. From the above formula, it can be seen that a1 and the parameter q1 in the conversion circuit perform modular multiplication, the modulus is p1, and the output is b1. a2 and the parameter q2 in the conversion circuit perform modular addition, the modulus is p2, and the output is b2.
[0211] Among them, p1 and q1 satisfy the following relationship:
[0212] q1 2 ≡1mod p1
[0213] It is understandable that there can be multiple combinations of p1 and q1 that satisfy the above relationship. For example, if p1 = 2^{16}+8, then q1 can be selected as any of the following:
[0214] 65543, 60083, 54619, 49159, ..., 5461
[0215] p2 and q2 satisfy the following relationship:
[0216] q2≡p2 / 2
[0217] It is understandable that there may be multiple combinations of p2 and q2 that satisfy the above relationship. For example, if p2=2^{32}+6, then q2=2^{31}+3.
[0218] In practical applications, p1 and p2 should be larger than the maximum code address but not too large to save the chip area of the conversion circuit.
[0219] In this embodiment, for the 32-bit return address a, the 32 bits are divided into two groups according to odd bits and even bits, one of which adopts the modular multiplication conversion model, and the other adopts the modular addition conversion model. It can be seen that the change segment and the unchanged segment of the code address are operated at the same time, so that the attacker cannot carry out a specific attack only on the change segment, and the attacker cannot guarantee that each brute force cracking can jump to the code area, thereby improving the security of the program control flow.
[0220] 2) Read the conversion return address from the LR register and store it in the stack in the memory.
[0221] 3) Execute function func.
[0222] 4) Before returning from function func, the converted return address is read from the memory and the popped converted return address is stored in the LR register. Since a conversion circuit is set on the write path of the LR register, the popped converted return address will first pass through the conversion circuit. The conversion circuit converts the converted return address again to obtain the original return address, and then the original return address is stored in the LR register.
[0223] When the conversion circuit converts the conversion return address, it uses the modular multiplication conversion model for b1[15:0] and the modular addition conversion model for b2[15:0], as shown below:
[0224] b1×q1≡a1modp1
[0225] b2+q2≡a2modp2
[0226] Among them, p1 and q1 are conversion parameters corresponding to the modular multiplication conversion model, which are the same as the parameters used in the first conversion process mentioned above. p2 and q2 are conversion parameters corresponding to the modular addition conversion model, which are the same as the parameters used in the first conversion process mentioned above.
[0227] From the above two conversion processes, it can be seen that the return address returns to its original value after two similar conversions.
[0228] 5) Execute the return operation.
[0229] If the converted return address b is not maliciously tampered with in the memory stack, then after the conversion by the conversion circuit, the return address a is the correct return address, and the program executes normally. If the converted return address b is maliciously tampered with in the memory stack, since the attacker cannot know the sensitive information p1, q1, p2 and q2, it is impossible to construct a legal malicious converted return address. Therefore, after the conversion by the conversion circuit, the return address a is garbled. When executing the return operation, the program will execute the code at the garbled address, which will most likely cause a memory error. As a result, the attacker cannot achieve the purpose of changing the program control flow.
[0230] Figure 8 The flowchart of the method for processing the return address provided in the embodiment of the present application is shown in FIG. The method of the present embodiment is executed by a processor, wherein the processor includes: a processing core and a conversion circuit. Figure 8 As shown, the method of this embodiment includes:
[0231] S801: When the processing core outputs the return address, the return address is converted by the conversion circuit to obtain a converted return address, and the converted return address is output to a stack in a memory.
[0232] S802: When the return address needs to be used, the conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core.
[0233] In a possible implementation, the processor further includes a register, and converting the return address by the conversion circuit to obtain a converted return address, and outputting the converted return address to a stack in the memory includes:
[0234] Converting the return address by the conversion circuit to obtain a conversion return address, and outputting the conversion return address to the register, so that the conversion return address is output to a stack in the memory via the register;
[0235] The converting the conversion return address in the stack by the conversion circuit to obtain the return address, and outputting the return address to the processing core includes:
[0236] The conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the register, so that the return address is output to the processing core via the register.
[0237] In a possible implementation, the processor further includes a register, the return address is output to the register by the processing core, and the converting the return address by the conversion circuit to obtain a converted return address, and outputting the converted return address to a stack in the memory includes:
[0238] Convert the return address output by the register by the conversion circuit to obtain a converted return address, and output the converted return address to a stack in the memory;
[0239] The converting the conversion return address in the stack by the conversion circuit to obtain the return address, and outputting the return address to the processing core includes:
[0240] The conversion return address output by the register is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core.
[0241] In a possible implementation manner, the conversion satisfies the following conditions:
[0242] B=IP(A),A=IP(B)
[0243] Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
[0244] In a possible implementation manner, converting the return address to obtain a converted return address includes:
[0245] At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
[0246] In a possible implementation manner, converting at least one bit of the return address using at least one conversion model to obtain the converted return address includes:
[0247] Grouping at least one bit of the return address to obtain a plurality of bit groups;
[0248] Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model;
[0249] The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
[0250] In a possible implementation manner, the number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
[0251] In a possible implementation, the types of conversion models include: a modular multiplication conversion model and a modular addition conversion model.
[0252] In a possible implementation manner, the register is a register for storing a return address.
[0253] In a possible implementation manner, the processor is a processor based on an ARM instruction set, and the register is an LR register.
[0254] In one possible implementation, the processor is a processor based on the RISC V instruction set, and the register is an RA register.
[0255] The return address processing method provided in this embodiment can be applied to the processor described in any of the above embodiments. Its implementation principle and technical effects are similar and will not be described in detail here.
[0256] An embodiment of the present application further provides an electronic device, including: a processor, wherein the processor can adopt the structure of the processor in any of the above embodiments, and its implementation principle and technical effect are similar, which will not be repeated in this embodiment.
[0257] An embodiment of the present application also provides a chip, including: a processor, and the processor can adopt the structure of the processor in any of the above embodiments, and its implementation principle and technical effect are similar, which will not be repeated here.
[0258] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0259] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0260] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0261] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application.
[0262] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0263] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0264] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0265] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0266] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic device or a main control device.
Claims
1. A processor, It is characterized in that include: processing cores, conversion circuits, and registers; The processing core is used to output a return address; The conversion circuit is used to convert the return address output by the processing core to obtain a converted return address, and output the converted return address to a stack in the memory; The conversion circuit is further configured to convert the conversion return address in the stack to obtain the return address when the processing core needs to use the return address, and output the return address to the processing core; The conversion circuit is specifically used to convert the return address output by the processing core to obtain a conversion return address, and output the conversion return address to the register, so that the conversion return address is output to the stack in the memory via the register; The conversion circuit is also specifically used to convert the conversion return address in the stack to obtain the return address when the processing core needs to use the return address, and output the return address to the register, so that the return address is output to the processing core via the register.
2. The processor according to claim 1, It is characterized in that The conversion satisfies the following conditions: B=IP(A),A=IP(B) Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
3. The processor according to claim 2, It is characterized in that The conversion circuit is specifically used for: At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
4. The processor according to claim 3, It is characterized in that The conversion circuit is specifically used for: Grouping at least one bit of the return address to obtain a plurality of bit groups; Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model; The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
5. The processor according to claim 4, It is characterized in that The number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
6. The processor according to any one of claims 2 to 5, It is characterized in that The types of conversion models include: modular multiplication conversion model and modular addition conversion model.
7. A processor according to any one of claims 2 to 5, It is characterized in that The register is a register used to store a return address.
8. The processor according to claim 7, It is characterized in that The processor is a processor based on the ARM instruction set, and the register is an LR register.
9. The processor according to claim 7, It is characterized in that The processor is a processor based on the RISC V instruction set, and the register is an RA register.
10. A processor, It is characterized in that include: processing cores, conversion circuits, and registers; The processing core is used to output a return address; The conversion circuit is used to convert the return address output by the processing core to obtain a converted return address, and output the converted return address to a stack in the memory; The conversion circuit is further configured to convert the conversion return address in the stack to obtain the return address when the processing core needs to use the return address, and output the return address to the processing core; When the processing core outputs the return address, the register is used to store the return address output by the processing core; The conversion circuit is specifically used to convert the return address output by the register to obtain a converted return address, and output the converted return address to a stack in the memory; When the processing core needs to use the return address, the register is also used to store the converted return address output by the stack; The conversion circuit is also specifically used to perform the conversion on the conversion return address output by the register to obtain the return address, and output the return address to the processing core.
11. The processor according to claim 10, It is characterized in that The conversion satisfies the following conditions: B=IP(A),A=IP(B) Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
12. The processor according to claim 11, It is characterized in that The conversion circuit is specifically used for: At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
13. The processor according to claim 12, It is characterized in that The conversion circuit is specifically used for: Grouping at least one bit of the return address to obtain a plurality of bit groups; Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model; The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
14. The processor according to claim 13, It is characterized in that The number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
15. A processor according to any one of claims 11 to 13, It is characterized in that The types of conversion models include: modular multiplication conversion model and modular addition conversion model.
16. A processor according to any one of claims 11 to 13, It is characterized in that The register is a register used to store a return address.
17. The processor according to claim 16, It is characterized in that The processor is a processor based on the ARM instruction set, and the register is an LR register.
18. The processor according to claim 16, It is characterized in that The processor is a processor based on the RISC V instruction set, and the register is an RA register.
19. A method for processing a return address, It is characterized in that Applied to a processor, the processor comprising: a processing core and a conversion circuit, the method comprising: When the processing core outputs the return address, the return address is converted by the conversion circuit to obtain a converted return address, and the converted return address is output to a stack in a memory; When the return address needs to be used, the conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core; The processor also includes a register, and the converting circuit converts the return address to obtain a converted return address, and outputs the converted return address to a stack in the memory, including: Converting the return address by the conversion circuit to obtain a conversion return address, and outputting the conversion return address to the register, so that the conversion return address is output to a stack in the memory via the register; The converting the conversion return address in the stack by the conversion circuit to obtain the return address, and outputting the return address to the processing core includes: The conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the register, so that the return address is output to the processing core via the register.
20. The method according to claim 19, It is characterized in that The conversion satisfies the following conditions: B=IP(A),A=IP(B) Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
21. The method according to claim 20, It is characterized in that The converting the return address to obtain a converted return address includes: At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
22. The method according to claim 21, It is characterized in that The converting at least one bit of the return address using at least one conversion model to obtain the converted return address includes: Grouping at least one bit of the return address to obtain a plurality of bit groups; Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model; The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
23. The method according to claim 22, It is characterized in that The number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
24. The method according to any one of claims 20 to 23, It is characterized in that The types of conversion models include: modular multiplication conversion model and modular addition conversion model.
25. The method according to any one of claims 20 to 23, It is characterized in that The register is a register used to store a return address.
26. The method according to claim 25, It is characterized in that The processor is a processor based on the ARM instruction set, and the register is an LR register.
27. The method according to claim 25, It is characterized in that The processor is a processor based on the RISC V instruction set, and the register is an RA register.
28. A method for processing a return address, It is characterized in that Applied to a processor, the processor comprising: a processing core and a conversion circuit, the method comprising: When the processing core outputs the return address, the return address is converted by the conversion circuit to obtain a converted return address, and the converted return address is output to a stack in a memory; When the return address needs to be used, the conversion return address in the stack is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core; The processor further includes a register, the return address is output to the register by the processing core, the converting the return address by the conversion circuit to obtain a converted return address, and outputting the converted return address to a stack in the memory, including: Convert the return address output by the register by the conversion circuit to obtain a converted return address, and output the converted return address to a stack in the memory; The converting the conversion return address in the stack by the conversion circuit to obtain the return address, and outputting the return address to the processing core includes: The conversion return address output by the register is converted by the conversion circuit to obtain the return address, and the return address is output to the processing core.
29. The method according to claim 28, It is characterized in that The conversion satisfies the following conditions: B=IP(A),A=IP(B) Wherein, A is the return address, B is the conversion return address, and IP() is the conversion model adopted by the conversion.
30. The method according to claim 29, It is characterized in that The converting the return address to obtain a converted return address includes: At least one conversion model is used to convert at least one bit of the return address to obtain the converted return address.
31. The method according to claim 30, It is characterized in that The converting at least one bit of the return address using at least one conversion model to obtain the converted return address includes: Grouping at least one bit of the return address to obtain a plurality of bit groups; Using the conversion model to convert bits in each of the bit groups to obtain a conversion result corresponding to each of the bit groups, wherein at least two of the multiple bit groups use different conversion models, or the multiple bit groups use the same conversion model; The conversion return address is obtained according to the conversion results corresponding to each of the bit groups.
32. The method according to claim 31, It is characterized in that The number of the bit groups is two, one of which includes bits corresponding to odd-numbered bits of the return address, and the other bit group includes bits corresponding to even-numbered bits of the return address.
33. A method according to any one of claims 29 to 32, It is characterized in that The types of conversion models include: modular multiplication conversion model and modular addition conversion model.
34. A method according to any one of claims 29 to 32, It is characterized in that The register is a register used to store a return address.
35. The method according to claim 34, It is characterized in that The processor is a processor based on the ARM instruction set, and the register is an LR register.
36. The method according to claim 34, It is characterized in that The processor is a processor based on the RISC V instruction set, and the register is an RA register.
37. An electronic device, It is characterized in that Comprising a processor as claimed in any one of claims 1 to 9 or 10 to 18.
