+

CN115422554B - Request processing method, compiling method and trusted computing system - Google Patents

Request processing method, compiling method and trusted computing system Download PDF

Info

Publication number
CN115422554B
CN115422554B CN202211311423.6A CN202211311423A CN115422554B CN 115422554 B CN115422554 B CN 115422554B CN 202211311423 A CN202211311423 A CN 202211311423A CN 115422554 B CN115422554 B CN 115422554B
Authority
CN
China
Prior art keywords
memory
segment
program
security level
user
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211311423.6A
Other languages
Chinese (zh)
Other versions
CN115422554A (en
Inventor
张殷乾
陈国兴
闫守孟
徐品深
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Southern University of Science and Technology
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Southern University of Science and Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd, Southern University of Science and Technology filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202211311423.6A priority Critical patent/CN115422554B/en
Publication of CN115422554A publication Critical patent/CN115422554A/en
Application granted granted Critical
Publication of CN115422554B publication Critical patent/CN115422554B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities
    • G06F21/572Secure firmware programming, e.g. of basic input output system [BIOS]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities
    • G06F21/575Secure boot

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Storage Device Security (AREA)

Abstract

本说明书提供一种基于可信安全区的请求处理方法、编译方法和可信计算系统,可信安全区包括第一安全等级的内存段与第二安全等级的内存段,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址;所述请求处理方法包括:响应于任务请求,执行重置程序段中的可信安全区重置函数,将备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间;执行用户程序段中由用户源程序编译得到的用户目标程序,用户源程序中的内存访问指令被编译为对应访存地址属于第一安全等级的合法访问范围的安全内存访问指令。

Figure 202211311423

This specification provides a request processing method, compilation method, and trusted computing system based on a trusted security zone. The trusted security zone includes memory segments with the first security level and memory segments with the second security level. The memory segments with the first security level The segment includes a user data segment and a user program segment, the memory segment of the second security level includes a backup data segment and a reset program segment, and the legal access scope of the first security level includes at least a part of memory addresses in the memory segment of the first security level; The request processing method includes: in response to the task request, executing the trusted security area reset function in the reset program segment, and overwriting the memory backup stored in the backup data segment to the memory space corresponding to the legal access range of the first security level ; Execute the user target program compiled by the user source program in the user program segment, and the memory access instruction in the user source program is compiled into a safe memory access instruction whose corresponding memory access address belongs to the legal access range of the first security level.

Figure 202211311423

Description

请求处理方法、编译方法和可信计算系统Request processing method, compiling method and trusted computing system

技术领域technical field

本说明书实施例属于计算机技术领域,尤其涉及一种基于可信安全区的请求处理方法、编译方法和可信计算系统。The embodiments of this specification belong to the field of computer technology, and in particular relate to a request processing method, a compiling method and a trusted computing system based on a trusted security zone.

背景技术Background technique

可信执行环境(TEE,Trusted Execution Environment)是CPU内的一个安全区域,它运行在一个独立的环境中且与操作系统并行运行。在硬件信任根和快速内存加密引擎的帮助下,TEE可以为数据处理提供一个隔离的内存区域,称为enclave(可信安全区),enclave能够确保其中的程序和数据不受包括操作系统等特权软件在内的任何其他软件的攻击,并通过内存加密、远程证明等机制确保运行在enclave内的程序的机密性和完整性。Trusted Execution Environment (TEE, Trusted Execution Environment) is a secure area within the CPU, which runs in an independent environment and runs in parallel with the operating system. With the help of hardware root of trust and fast memory encryption engine, TEE can provide an isolated memory area for data processing, called enclave (trusted security area), enclave can ensure that programs and data in it are not protected from privileges including operating system software, including any other software attacks, and ensure the confidentiality and integrity of programs running in the enclave through mechanisms such as memory encryption and remote certification.

在利用enclave作为可信计算的任务执行框架的场景下,enclave中运行有由用户编写并加载进enclave的用户程序作为可信计算任务的执行组件,每次enclave接收到相应的任务请求,都会对enclave进行重启后调用该用户程序执行任务请求对应的可信计算任务。在相关技术中,通常使用传统的热启动或冷启动来重启enclave。In the scenario where the enclave is used as the task execution framework for trusted computing, the enclave runs user programs written by users and loaded into the enclave as execution components for trusted computing tasks. Every time the enclave receives a corresponding task request, it will After the enclave restarts, it invokes the user program to execute the trusted computing task corresponding to the task request. In related technologies, traditional hot or cold restarts are usually used to restart the enclave.

虽然外部程序难以对enclave进行攻击,但由用户编写并加载进enclave内的用户程序却突破了enclave的防线,可以从内部进行攻击。因此,如果对enclave执行会持续复用一些重启前组件的热启动,虽然可以提高重启enclave的效率,但可能会复用一些已经遭受攻击的组件从而导致enclave依然处于被攻击的状态,具有极大的安全隐患,特别是当热启动组件本身被攻击时,将使得enclave无法脱离被攻击的状态从而被攻击者完全掌控;而如果对enclave执行重新初始化所有组件的冷启动,则虽然可以避免热启动带来的安全隐患,但却带来了较大的时延,而对于大部分任务请求需要快速响应的可信计算服务场景来说,较长的冷启动时间严重影响了可信计算任务的执行效率。Although it is difficult for external programs to attack the enclave, user programs written by users and loaded into the enclave have broken through the defense line of the enclave and can attack from the inside. Therefore, if the execution of the enclave will continue to reuse the hot start of some components before restarting, although it can improve the efficiency of restarting the enclave, it may reuse some components that have been attacked, so that the enclave is still under attack. The security risks, especially when the hot start component itself is attacked, will make the enclave unable to get out of the attacked state and be completely controlled by the attacker; and if the cold start of reinitializing all components is performed on the enclave, although the hot start can be avoided For trusted computing service scenarios where most task requests require quick response, the long cold start time seriously affects the execution of trusted computing tasks efficiency.

发明内容Contents of the invention

本发明的目的在于提供一种基于可信安全区的请求处理方法、编译方法和可信计算系统。The purpose of the present invention is to provide a request processing method, a compiling method and a trusted computing system based on a trusted security zone.

根据本说明书一个或多个实施例的第一方面,提出了一种基于可信安全区的请求处理方法,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址;所述方法包括:According to the first aspect of one or more embodiments of this specification, a request processing method based on a trusted security zone is proposed, and the trusted security zone includes a memory segment with a first security level and a memory segment with a second security level , wherein the memory segment of the first security level includes the user data segment and the user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, and the legal access range of the first security level includes the at least a portion of a memory address in a memory segment; the method comprising:

响应于任务请求,执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份;In response to the task request, execute the trusted security area reset function in the reset program segment, and overwrite the memory backup stored in the backup data segment to the memory space corresponding to the legal access range of the first security level, the The memory backup includes a user data segment backup for overwriting to the user data segment;

在所述可信安全区重置函数执行完成后,执行所述用户程序段中由用户源程序编译得到的用户目标程序;其中,所述用户源程序中的内存访问指令被编译为所述用户目标程序中相应的安全内存访问指令,所述安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围。After the execution of the trusted security zone reset function is completed, the user target program compiled from the user source program in the user program segment is executed; wherein, the memory access instructions in the user source program are compiled into the user For the corresponding secure memory access instruction in the target program, the memory access address corresponding to the secure memory access instruction belongs to the legal access range of the first security level.

根据本说明书一个或多个实施例的第二方面,提出了一种编译方法,包括:According to a second aspect of one or more embodiments of the present specification, a compiling method is provided, including:

获取用于在可信安全区中执行的用户源程序,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址,所述用户程序段中的安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围;Acquiring a user source program for execution in a trusted security zone, the trusted security zone includes a memory segment with a first security level and a memory segment with a second security level, wherein the memory segment with the first security level includes user data segment and user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, the legal access scope of the first security level includes at least a part of the memory address in the memory segment of the first security level, and the user program The memory access address corresponding to the secure memory access instruction in the segment belongs to the legal access range of the first security level;

将所述用户源程序编译为用户目标程序,以使得所述用户源程序中的内存访问指令转换为所述用户目标程序中相应的安全内存访问指令;compiling the user source program into a user target program, so that memory access instructions in the user source program are converted into corresponding safe memory access instructions in the user target program;

将所述用户目标程序加载至所述用户程序段,以由所述可信安全区响应于任务请求进行重置后执行所述用户程序段中的所述用户目标程序;其中,对所述可信安全区进行重置包括:执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份。loading the user target program into the user program segment, so that the trusted security zone executes the user target program in the user program segment after reset in response to a task request; wherein, the user target program in the user program segment is executed; Resetting the trusted security zone includes: executing the trusted security zone reset function in the reset program segment, and overwriting the memory backup stored in the backup data segment to the memory space corresponding to the legal access range of the first security level , the memory backup includes a user data segment backup for overwriting to the user data segment.

根据本说明书一个或多个实施例的第三方面,提出了一种基于可信安全区的请求处理装置,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址;所述装置包括:According to a third aspect of one or more embodiments of the present specification, a request processing device based on a trusted security zone is proposed, the trusted security zone includes a memory segment with a first security level and a memory segment with a second security level , wherein the memory segment of the first security level includes the user data segment and the user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, and the legal access range of the first security level includes the at least a portion of memory addresses in a memory segment; said means comprising:

重置单元,用于响应于任务请求,执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份;The reset unit is configured to execute the trusted security area reset function in the reset program segment in response to the task request, and cover the memory backup stored in the backup data segment to the legal access range corresponding to the first security level memory space, the memory backup includes a user data segment backup for covering to the user data segment;

用户目标程序执行单元,用于在所述可信安全区重置函数执行完成后,执行所述用户程序段中由用户源程序编译得到的用户目标程序;其中,所述用户源程序中的内存访问指令被编译为所述用户目标程序中相应的安全内存访问指令,所述安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围。The user target program execution unit is configured to execute the user target program compiled from the user source program in the user program segment after the execution of the trusted security zone reset function is completed; wherein, the memory in the user source program The access instruction is compiled into a corresponding secure memory access instruction in the user target program, and the memory access address corresponding to the secure memory access instruction belongs to the legal access range of the first security level.

根据本说明书一个或多个实施例的第四方面,提出了一种编译装置,包括:According to a fourth aspect of one or more embodiments of the present specification, a compiling device is provided, including:

用户源程序获取单元,获取用于在可信安全区中执行的用户源程序,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址,所述用户程序段中的安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围;The user source program acquisition unit is configured to acquire the user source program for execution in the trusted security zone, the trusted security zone includes a memory segment with a first security level and a memory segment with a second security level, wherein the first security level The memory segment of the first security level includes the user data segment and the user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, and the legal access scope of the first security level includes at least a part of the memory segment of the first security level address, the memory access address corresponding to the secure memory access instruction in the user program segment belongs to the legal access range of the first security level;

编译单元,用于将所述用户源程序编译为用户目标程序,以使得所述用户源程序中的内存访问指令转换为所述用户目标程序中相应的安全内存访问指令;a compiling unit, configured to compile the user source program into a user target program, so that memory access instructions in the user source program are converted into corresponding secure memory access instructions in the user target program;

用户目标程序加载单元,用于将所述用户目标程序加载至所述用户程序段,以由所述可信安全区响应于任务请求进行重置后执行所述用户程序段中的所述用户目标程序;其中,对所述可信安全区进行重置包括:执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份。a user target program loading unit, configured to load the user target program into the user program segment, so as to execute the user target in the user program segment after being reset by the trusted security zone in response to a task request program; wherein, resetting the trusted security zone includes: executing the trusted security zone reset function in the reset program segment, and overwriting the memory backup stored in the backup data segment to the first security level The memory space corresponding to the legal access range, the memory backup includes a user data segment backup used to overwrite the user data segment.

根据本说明书一个或多个实施例的第五方面,提出了一种可信计算系统,包括一个前端可信安全区与至少一个后端可信安全区,其中:According to a fifth aspect of one or more embodiments of this specification, a trusted computing system is proposed, including a front-end trusted security zone and at least one back-end trusted security zone, wherein:

所述前端可信安全区用于接收客户端发送的任务请求,并将该任务请求转发至对应的后端可信安全区,以及将该后端可信安全区返回的针对该任务请求的执行结果发送至所述客户端;The front-end trusted security zone is used to receive the task request sent by the client, forward the task request to the corresponding back-end trusted security zone, and execute the task request returned by the back-end trusted security zone The result is sent to the client;

任一后端可信安全区用于在接收到所述前端可信安全区发送的任务请求的情况下执行如第一方面中任一项所述的方法,并将执行用户目标程序所生成的执行结果返回至所述前端可信安全区。Any back-end trusted security zone is used to execute the method as described in any one of the first aspect when receiving the task request sent by the front-end trusted security zone, and execute the The execution result is returned to the front-end trusted security zone.

根据本说明书一个或多个实施例的第六方面,提出了一种电子设备,包括:According to a sixth aspect of one or more embodiments of the present specification, an electronic device is provided, including:

处理器;processor;

用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;

其中,所述处理器通过运行所述可执行指令以实现如第一方面与第二方面中任一项所述的方法。Wherein, the processor implements the method according to any one of the first aspect and the second aspect by running the executable instruction.

根据本说明书一个或多个实施例的第七方面,提出了一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如第一方面与第二方面中任一项所述方法的步骤。According to a seventh aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, any one of the first aspect and the second aspect can be implemented. steps of the method described in the item.

本说明书实施例提供了一种可信安全区的安全重置方法,通过将可信安全区分为不同安全等级的内存段,并将由用户编写的用户源程序编译得到的用户目标程序置于第一安全等级的内存段中,由于用户源程序中的内存访问指令被编译为用户目标程序中相应的安全内存访问指令之后,该安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围,这使得用户目标程序只能访问到第一安全等级的合法访问范围的内存空间,从而避免用户目标程序作恶,通过修改其他安全等级的内存段中的程序或数据从内部破坏可信安全区的安全性。例如,用户目标程序无法修改处于第二安全等级的内存段中的内存备份或可信安全区重置函数,因此可以确保每次利用可信安全区重置函数对用户数据段进行重置的过程不会被已经运行在可信安全区中的用户目标程序所影响,即包括可信安全区重置函数在内的、处于第一安全等级的合法访问范围之外的组件都可以在可信安全区重置后持续复用。而对于可信安全区中用户目标程序所能够访问和修改的第一安全等级的合法访问范围对应的内存空间,则在执行可信安全区重置函数过程中通过内存备份对这部分内存空间进行覆盖,即对第一安全等级的合法访问范围对应的内存空间进行完全重置。不难发现,本说明书实施例所实现的可信安全区的安全重置方法本质上也属于一种热启动方法,然而相较于传统的热启动,本说明书实施例实现了只有传统的冷启动才能实现的消除安全隐患的效果,从而兼顾了安全性与效率。具体而言,由于持续复用的第二安全等级及其以上安全等级的内存段不会受到用户目标程序的攻击,因此可以确保持续复用的重置前组件的安全性,特别是执行重置过程的可信安全区重置函数本身的安全性,这维持了系统的自洽性。同时,通过将存在安全风险的第一安全等级的合法访问范围对应的内存空间进行完全重置,可以确保重置后的可信安全区不会继承重置前的可信安全区中的风险,使得即使可信安全区受到用户目标程序的攻击也可以脱离被攻击的状态。The embodiment of this specification provides a security reset method for a trusted security zone, by dividing the trusted security zone into memory segments with different security levels, and placing the user target program compiled by the user source program written by the user in the first place. In the security level memory segment, after the memory access instruction in the user source program is compiled into the corresponding security memory access instruction in the user target program, the memory access address corresponding to the security memory access instruction belongs to the legal access range of the first security level , which makes the user target program only have access to the memory space of the legal access scope of the first security level, thereby preventing the user target program from doing evil, and destroying the trusted security zone from the inside by modifying the program or data in the memory segment of other security levels safety. For example, the user target program cannot modify the memory backup or trusted security zone reset function in the memory segment of the second security level, so it can ensure that the process of resetting the user data segment by using the trusted security zone reset function every time It will not be affected by the user target program already running in the trusted security zone, that is, components outside the legal access range of the first security level, including the reset function of the trusted security zone, can be in the trusted security zone Continuous reuse after zone reset. For the memory space corresponding to the legal access range of the first security level that can be accessed and modified by the user target program in the trusted security zone, this part of the memory space is backed up during the execution of the reset function of the trusted security zone. Overwriting means completely resetting the memory space corresponding to the legal access scope of the first security level. It is not difficult to find that the security reset method of the trusted security zone implemented in the embodiment of this specification is also a hot start method in essence. However, compared with the traditional hot start, the embodiment of this specification realizes only the traditional cold start. The effect of eliminating potential safety hazards can be achieved, thus taking into account both safety and efficiency. Specifically, since the memory segments of the second security level and above security level that are continuously reused cannot be attacked by user target programs, the security of the pre-reset components that are continuously multiplexed can be ensured, especially when performing reset The trusted enclave of the process resets the security of the function itself, which maintains the self-consistency of the system. At the same time, by completely resetting the memory space corresponding to the legal access range of the first security level with security risks, it can be ensured that the reset trusted security zone will not inherit the risks in the trusted security zone before reset, Even if the trusted security zone is attacked by the user's target program, it can escape from the attacked state.

附图说明Description of drawings

为了更清楚地说明本说明书实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书中记载的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following will briefly introduce the drawings that need to be used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments recorded in this specification. , for those skilled in the art, other drawings can also be obtained according to these drawings without paying creative labor.

图1是一示例性实施例提供的一种基于可信安全区的请求处理方法的流程图。Fig. 1 is a flowchart of a request processing method based on a trusted security zone provided by an exemplary embodiment.

图2是一示例性实施例提供的一种可信安全区的示意图。Fig. 2 is a schematic diagram of a trusted security zone provided by an exemplary embodiment.

图3是一示例性实施例提供的一种划分内存块后的可信安全区的示意图。Fig. 3 is a schematic diagram of a trusted security zone after memory blocks are divided according to an exemplary embodiment.

图4是一示例性实施例提供的一种编译方法的流程图。Fig. 4 is a flowchart of a compiling method provided by an exemplary embodiment.

图5是一示例性实施例提供的一种设备的结构示意图。Fig. 5 is a schematic structural diagram of a device provided by an exemplary embodiment.

图6是一示例性实施例提供的一种基于可信安全区的请求处理装置的框图。Fig. 6 is a block diagram of an apparatus for request processing based on a trusted security zone provided by an exemplary embodiment.

图7是一示例性实施例提供的一种编译装置的框图。Fig. 7 is a block diagram of a compiling device provided by an exemplary embodiment.

图8是一示例性实施例提供的一种可信计算系统的系统架构图。Fig. 8 is a system architecture diagram of a trusted computing system provided by an exemplary embodiment.

具体实施方式Detailed ways

为了使本技术领域的人员更好地理解本说明书中的技术方案,下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都应当属于本说明书保护的范围。In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described The embodiments are only some of the embodiments in this specification, not all of them. Based on the embodiments in this specification, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the protection scope of this specification.

请参见图1,图1是一示例性实施例提供的一种基于可信安全区的请求处理方法的流程图。图2是一示例性实施例提供的一种可信安全区的示意图,如图2所示,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址;如图1所示,该方法包括:Please refer to FIG. 1 . FIG. 1 is a flowchart of a request processing method based on a trusted security zone provided by an exemplary embodiment. Fig. 2 is a schematic diagram of a trusted security zone provided by an exemplary embodiment. As shown in Fig. 2, the trusted security zone includes memory segments of the first security level and memory segments of the second security level, wherein, The memory segment of the first security level includes the user data segment and the user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, and the legal access scope of the first security level includes the memory segment of the first security level at least a part of the memory address; as shown in Figure 1, the method includes:

S102:响应于任务请求,执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份。S102: In response to the task request, execute the trusted security area reset function in the reset program segment, overwrite the memory backup stored in the backup data segment to the memory space corresponding to the legal access range of the first security level, The memory backup includes a user data segment backup for overwriting to the user data segment.

在本说明书实施例中,可信安全区中的程序包括用户目标程序与系统目标程序,其中,用户目标程序由用户源程序编译得到,而系统目标程序由系统源程序编译得到。由于用户源程序是由用户进行编写的自定义程序,因此其被编译成用户目标程序并加载进可信安全区后会给可信安全区带来一定的安全风险;相比之下,系统源程序则由可信安全区的开发者编写,其编译得到的系统目标程序理论上不存在安全风险。于是,为了规避用户目标程序可能对可信安全区带来的安全风险,本说明书实施例采用了将可信安全区按照安全等级分段的安全策略,该安全策略规定处于低安全等级的内存段中的程序无法访问相对更高的安全等级的内存段中的内存空间,而处于高安全等级的内存段中的程序则可以访问到相对较低的安全等级的内存段中的内存空间。在这种安全策略的指导之下,通过将用于加载用户目标程序的用户程序段设置于最低安全等级(第一安全等级)的内存段中,同时将其他系统目标程序与敏感数据段设置于相对较高的安全等级的内存段中,从而使得存在安全风险的用户目标程序只能访问处于第一安全等级的内存段中的部分内存空间(称为第一安全等级的合法访问范围)。例如图2中所示的第一安全等级的内存段中的栈内存段、堆内存段和用户数据段均可以被用户目标程序所正常使用,然而用户目标程序则无法正常访问到除第一安全等级的合法访问范围此之外的所有内存空间,从而保护了系统目标程序与敏感数据段免受用户目标程序的攻击。In the embodiment of this specification, the programs in the trusted security zone include user target programs and system target programs, wherein the user target programs are compiled from user source programs, and the system target programs are compiled from system source programs. Since the user source program is a custom program written by the user, it will bring certain security risks to the trusted security zone after it is compiled into the user target program and loaded into the trusted security zone; in contrast, the system source program The program is written by the developer of the trusted security zone, and the system target program compiled by it theoretically has no security risk. Therefore, in order to avoid the security risk that the user target program may bring to the trusted security area, the embodiment of this specification adopts a security policy that divides the trusted security area into segments according to the security level. Programs in the program cannot access the memory space in the relatively higher security level memory segment, while programs in the high security level memory segment can access the memory space in the relatively lower security level memory segment. Under the guidance of this security policy, the user program segment used to load the user target program is set in the memory segment with the lowest security level (the first security level), and other system target programs and sensitive data segments are set in the memory segment. Relatively high security level memory segment, so that the user target program with security risks can only access part of the memory space in the first security level memory segment (called the legal access scope of the first security level). For example, the stack memory segment, the heap memory segment, and the user data segment in the memory segment of the first security level shown in Figure 2 can all be used normally by the user target program, but the user target program cannot normally access the All memory spaces outside the legal access range of the level, thus protecting the system target program and sensitive data segments from the attack of the user target program.

本说明实施例所涉及的系统目标程序包括用于执行可信安全区重置逻辑的可信安全区重置函数,该可信安全区重置函数具体被设置于第二安全等级的内存段中的重置程序段,这意味着可信安全区重置函数可以正常对第一安全等级的内存段中的内存空间进行访问和修改,因此不会影响可信安全区重置函数针对于第一安全等级的内存段中存在安全风险的内存空间(即第一安全等级的合法访问范围对应的内存空间)的重置过程的正常实施。具体而言,在可信安全区的接口函数(接口函数属于系统目标程序)接收到来源于可信安全区外部的用于请求执行可信计算任务的任务请求时,需要首先触发重置可信安全区的过程以为执行后续的可信计算任务提供一个清洁的任务执行环境,此时接口函数会调用并执行重置程序段中的可信安全区重置函数。可信安全区重置函数在执行过程中,会将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,使得第一安全等级的合法访问范围的内存空间被完全重置为用户源程序编译完成时的初始内存状态,完成重置可信安全区的过程。本说明书实施例所涉及的第一安全等级的合法访问范围至少包括第一安全等级的内存段中的用户数据段。The system target program involved in the embodiment of this description includes a trusted security zone reset function for executing trusted security zone reset logic, and the trusted security zone reset function is specifically set in the memory segment of the second security level The reset program segment, which means that the trusted security zone reset function can normally access and modify the memory space in the memory segment of the first security level, so it will not affect the trusted security zone reset function for the first security level The normal implementation of the reset process of the memory space with security risks in the memory segment of the security level (that is, the memory space corresponding to the legal access scope of the first security level). Specifically, when the interface function of the trusted security zone (the interface function belongs to the system target program) receives a task request for executing a trusted computing task from outside the trusted security zone, it needs to first trigger the reset of the trusted The process of the security zone provides a clean task execution environment for subsequent trusted computing tasks. At this time, the interface function will call and execute the trusted security zone reset function in the reset program segment. During the execution of the trusted security area reset function, the memory backup stored in the backup data segment will be overwritten to the memory space corresponding to the legal access range of the first security level, so that the memory of the legal access range of the first security level The space is completely reset to the initial memory state when the user source program is compiled, completing the process of resetting the trusted security zone. The legal access scope of the first security level involved in the embodiment of this specification includes at least the user data segment in the memory segment of the first security level.

需要注意的是,用户源程序在被编译为用户目标程序时,不仅在指令层面将高级/汇编语言编译为了机器语言(编译得到的机器码集合构成了用户目标程序),并将用户目标程序加载至用户程序段,同时也需要申请内存空间以存放程序涉及的数据变量,即这些在用户源程序编译后初始化或未初始化的数据变量被存放至了第一安全等级的内存段中的用户数据段,而本说明书实施例所涉及的内存备份中包括的用于覆盖至所述用户数据段的用户数据段备份,就包含有在用户源程序编译完成时用户数据段的内存状态。It should be noted that when the user source program is compiled into the user target program, it not only compiles the high-level/assembly language into machine language at the instruction level (the compiled machine code set constitutes the user target program), but also loads the user target program into To the user program segment, it is also necessary to apply for memory space to store the data variables involved in the program, that is, these data variables initialized or uninitialized after the user source program is compiled are stored in the user data segment in the memory segment of the first security level , and the user data segment backup used to overwrite the user data segment included in the memory backup involved in the embodiment of this specification includes the memory status of the user data segment when the user source program is compiled.

在第一安全等级的合法访问范围还包括第一安全等级的内存段中的用户程序段的情况下,内存备份还可以包括用于覆盖至所述用户程序段的用户程序段备份,该用户程序段备份是指在用户源程序编译完成时用户代码段的内存状态,也即刚编译完毕时得到的初始状态下的用户目标程序。在本说明书实施例中,由于用户目标程序可以访问和修改用户程序段,可能会对包含在其中的自身代码进行修改从而带来较大的安全风险,因此在对可信安全区进行重置的过程中,还可以将用户程序段备份覆盖至用户程序段对应的内存空间,从而使得用户目标程序恢复到刚编译完毕时的初始状态,以清空重置前用户程序段可能存在的安全风险。In the case that the legal access scope of the first security level also includes the user program segment in the memory segment of the first security level, the memory backup may also include a user program segment backup for overwriting to the user program segment, the user program The segment backup refers to the memory state of the user code segment when the user source program is compiled, that is, the user target program in the initial state obtained just after the compilation is completed. In the embodiment of this specification, because the user target program can access and modify the user program segment, it may modify its own code contained in it, which will bring a greater security risk. Therefore, when resetting the trusted security zone During the process, the backup of the user program segment can also be overwritten to the corresponding memory space of the user program segment, so that the user target program can be restored to the initial state just after compiling, so as to clear the possible security risks of the user program segment before resetting.

除此之外,本说明书实施例所涉及的内存备份还包括在用户源程序编译完成时栈内存段与堆内存段的内存状态,以用于在重置过程中覆盖至当前的债内存段与堆内存段。由于通常情况下栈内存段与堆内存段的内存状态在用户源程序编译完成时为空,因此在执行可信安全区重置函数并完成重置可信安全区的过程之后,栈内存段与堆内存段中的数据会被清空。本说明书实施例所涉及的用户数据段可以包括data段与bss段,其中,对应于用户源程序编译后得到的已初始化的全局变量保存在data 段中,而未初始化的全局变量则保存在bss段中。In addition, the memory backup involved in the embodiment of this specification also includes the memory status of the stack memory segment and the heap memory segment when the user source program is compiled, which is used to overwrite the current debt memory segment and heap memory segment during the reset process. heap memory segment. Usually, the memory state of the stack memory segment and the heap memory segment is empty when the user source program is compiled, so after executing the trusted security zone reset function and completing the process of resetting the trusted security zone, the stack memory segment and the heap memory segment are empty. The data in the heap memory segment will be cleared. The user data segment involved in the embodiment of this specification may include the data segment and the bss segment, wherein the initialized global variables corresponding to the compiled user source program are stored in the data segment, while the uninitialized global variables are stored in the bss segment paragraph.

在本说明书实施例中,还包括:响应于备份请求或者在所述可信安全区完成冷启动的情况下,执行所述重置程序段中的可信安全区备份函数,将第一安全等级的合法访问范围中的数据作为所述内存备份存储至所述备份数据段。如前所述,备份数据段中存储的内存备份具体为第一安全等级的合法访问范围的内存空间在用户源程序编译完成时的初始内存状态,而该内存备份其实是通过执行重置程序段中的可信安全区备份函数而被存储至备份数据段中。具体而言,在接口程序接收到来源于可信安全区外部的用于调用可信安全区备份函数的备份请求时,或者系统启动程序(属于系统目标程序)响应于可信安全区冷启动完成时(冷启动包括将用户源程序和系统源程序编译为用户目标程序与系统目标程序并被加载至可信安全区中的过程),都会触发调用并执行可信安全区备份函数。可信安全区备份函数在执行过程中,会将第一安全等级的合法访问范围中的数据作为所述内存备份复制并存储至所述备份数据段中,使得当前的第一安全等级的合法访问范围的内存空间的内存状态被完全保存起来以供可信安全区重置函数后续调用。In the embodiment of this specification, it also includes: in response to the backup request or in the case that the trusted security zone completes the cold start, executing the backup function of the trusted security zone in the reset program segment, setting the first security level to The data in the legal access range is stored in the backup data segment as the memory backup. As mentioned above, the memory backup stored in the backup data segment is specifically the initial memory state of the legally accessible memory space of the first security level when the user source program is compiled, and the memory backup is actually reset by executing the program segment The backup function in the trusted security zone is stored in the backup data segment. Specifically, when the interface program receives a backup request for calling the backup function of the trusted security zone from outside the trusted security zone, or the system startup program (belonging to the system target program) responds to the completion of the cold start of the trusted security zone When (cold start includes the process of compiling the user source program and the system source program into the user target program and the system target program and loading them into the trusted security zone), it will trigger the call and execute the trusted security zone backup function. During the execution of the trusted security zone backup function, the data in the legal access range of the first security level will be copied as the memory backup and stored in the backup data segment, so that the legal access of the current first security level The memory state of the scoped memory space is fully preserved for subsequent calls of the trusted enclave reset function.

在本说明书实施例中,所述将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,包括:启用用户权限硬件指令,并通过所述用户权限硬件指令为第一安全等级的合法访问范围对应的内存空间重新分配内存访问权限;将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,并在完成后禁用所述用户权限硬件指令。本说明书实施例所涉及的可信安全区enclave基于Intel SGX(Intel Software Guard Extensions,英特尔软件保护扩展)技术栈所实现,本说明书实施例所涉及的用户权限硬件指令(ENCLU)具体是指Intel SGX中定义的用于指导修改可信安全区内存权限的原生指令,由于该指令会对可信安全区的机密性产生影响,因此除非必要的情况我们不希望该指令能够被随意调用,特别是需要禁止该指令被用户目标程序所调用。在将内存备份覆盖至第一安全等级的合法访问范围对应的内存空间时,由于需要重新分配内存权限因此需要调用用户权限硬件指令(例如用于扩展Enclave现有内存范围的EMODPE指令),因此在这种情况下我们在需要在系统层面提前启用用户权限硬件指令,从而使得可信安全区的重置过程能够正常实现。而在可信安全区完成重置之后,为了避免用户目标程序使用用户权限硬件指令对可信安全区进行攻击,可以在每次完成可信安全区重置之后禁用所述用户权限硬件指令。具体而言,可以通过在可信安全区重置函数中定义一个针对是否启用用户权限硬件指令的全局保险值,在可信安全区重置函数的覆盖重置逻辑之前加入一个将该全局保险值设置为启用状态的逻辑,同时在可信安全区重置函数的覆盖重置逻辑之后加入一个将该全局保险值设置为禁用状态的逻辑。另外,还需要对每个用户权限硬件指令对应的调用条件进行修改,以使在其在全局保险值为启用状态而被调用的情况下正常执行,而在全局保险值为禁用状态而被调用的情况下不执行并返回错误。In the embodiment of this specification, the overwriting of the memory backup stored in the backup data segment to the memory space corresponding to the legal access scope of the first security level includes: enabling the user authority hardware instruction, and passing the user authority hardware instruction The instruction redistributes the memory access authority for the memory space corresponding to the legal access range of the first security level; the memory backup stored in the backup data segment is overwritten to the memory space corresponding to the legal access range of the first security level, and after completion Disable the user privilege hardware instruction. The trusted security zone enclave involved in the embodiment of this specification is implemented based on the Intel SGX (Intel Software Guard Extensions, Intel Software Guard Extensions) technology stack. The user authority hardware instruction (ENCLU) involved in the embodiment of this specification specifically refers to the Intel SGX The native instruction defined in is used to modify the memory permissions of the trusted security zone. Since this command will affect the confidentiality of the trusted security zone, we do not want this command to be called arbitrarily unless necessary, especially if the This command is prohibited from being called by the user target program. When overwriting the memory backup to the memory space corresponding to the legal access scope of the first security level, it is necessary to call the user permission hardware instruction (such as the EMODPE instruction used to expand the existing memory range of the Enclave) due to the need to reassign the memory permission. Therefore, in In this case, we need to enable user permission hardware instructions in advance at the system level, so that the reset process of the trusted security zone can be implemented normally. After the reset of the trusted security zone is completed, in order to prevent the user target program from using the user authority hardware instruction to attack the trusted security zone, the user authority hardware instruction may be disabled after each reset of the trusted security zone. Specifically, by defining a global insurance value for whether to enable user permission hardware instructions in the trusted security zone reset function, add a global security value before the override reset logic of the trusted security zone reset function The logic that is set to the enabled state, and a logic that sets the global security value to the disabled state is added after the override reset logic of the trusted security zone reset function. In addition, it is also necessary to modify the calling conditions corresponding to each user authority hardware instruction, so that it can be executed normally when the global insurance value is enabled, and when the global insurance value is disabled, it is called case does not execute and returns an error.

在本说明书实施例中,接口函数在接收到任务请求后,还会检查可信安全区中是否存在尚未执行完毕的可信计算任务。如果不存在则可以继续调用并执行可信安全区重置函数,如存在则可以进行等待,直到当前正在执行的可信计算任务执行完毕后,再调用并执行可信安全区重置函数,从而可以避免正在执行的可信计算任务可以完整执行而不会被任务请求所打断。另外,除了响应于任务请求而触发调用并执行可信安全区重置函数之外,接口程序也可以在接收到当前正在执行的可信计算任务执行完毕后返回的执行结果时触发调用并执行可信安全区重置函数,这样一来就可以在后续接收到新的任务请求后无需再次进行重置可信安全区的过程,而可以直接调用用户目标程序执行任务请求对应的可信计算任务。In the embodiment of this specification, after the interface function receives the task request, it also checks whether there is a trusted computing task that has not been completed in the trusted security zone. If it does not exist, you can continue to call and execute the trusted security zone reset function. If it exists, you can wait until the currently executing trusted computing task is completed, and then call and execute the trusted security zone reset function, so that It can prevent that the trusted computing task being executed can be completely executed without being interrupted by the task request. In addition, in addition to triggering the call and executing the trusted security zone reset function in response to the task request, the interface program can also trigger the call and execute the Trusted security zone reset function, so that after receiving a new task request, it is not necessary to reset the trusted security zone again, but can directly call the user target program to execute the trusted computing task corresponding to the task request.

S104:在所述可信安全区重置函数执行完成后,执行所述用户程序段中由用户源程序编译得到的用户目标程序;其中,所述用户源程序中的内存访问指令被编译为所述用户目标程序中相应的安全内存访问指令,所述安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围。S104: After the execution of the trusted security zone reset function is completed, execute the user target program compiled from the user source program in the user program segment; wherein, the memory access instruction in the user source program is compiled into the The corresponding secure memory access instruction in the user target program, the memory access address corresponding to the secure memory access instruction belongs to the legal access range of the first security level.

在本说明书实施例中,接口函数接收到任务请求后,首先调用并执行重置程序段中的可信安全区重置函数,然后在进一步接收到可信安全区重置函数的返回值后,可以确定所述可信安全区重置函数执行完成,于是接下来便可以开始执行所述任务请求对应的可信计算任务。由于执行可信计算任务的模块为用户目标程序,因此接口函数可以进一步调用并执行用户程序段中用户目标程序,调用时可以将所述任务请求中的一些必要的输入参数作为调用参数引入用户目标程序的执行过程。In the embodiment of this specification, after the interface function receives the task request, it first calls and executes the trusted security zone reset function in the reset program segment, and then after further receiving the return value of the trusted security zone reset function, It can be determined that the execution of the trusted security zone reset function is completed, and then the trusted computing task corresponding to the task request can be started to be executed. Since the module that executes the trusted computing task is the user target program, the interface function can further call and execute the user target program in the user program segment. When calling, some necessary input parameters in the task request can be introduced into the user target as calling parameters The execution process of the program.

在本说明书实施例中,“处于低安全等级的内存段中的程序无法访问相对更高的安全等级的内存段中的内存空间,而处于高安全等级的内存段中的程序则可以访问到相对较低的安全等级的内存段中的内存空间”的安全策略实际上是通过编译器技术实现的。例如,为了使第一安全等级的内存段中的用户目标程序只能访问到第一安全等级的合法访问范围,需要在将用户源程序编译为用户目标程序的过程中,通过编译器技术来改变传统编译过程中的指令转换规则,使得改变后的指令转换规则用于指导将所述用户源程序中的内存访问指令编译为所述用户目标程序中相应的安全内存访问指令,并确保用户目标程序中的安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围。由此一来,用户目标程序中所有的访存操作(包括读取操作与写入操作)都会被限制在第一安全等级的合法访问范围之内,而无法访问到第二安全等级及其以上安全等级的内存段对应的内存空间。又例如,为了确保第二安全等级的内存段中的可信安全区重置函数在执行时能够完成重置过程,则必然要求其能够正常访问第一安全等级的内存段。因此,在将系统源程序编译为系统目标程序的过程中,同样可以通过编译器技术来改变传统的指令转换规则,使得改变后的指令转换规则用于指导将系统源程序中的内存访问指令编译为系统目标程序中相应的安全内存访问指令,并确保可信安全区重置函数中的安全内存访问指令对应的访存地址属于第二安全等级的合法访问范围,由于第二安全等级的合法访问范围包括第一安全等级的内存段以及备份数据段,因此可信安全区重置函数能够正常完成可信安全区的重置过程。In the embodiment of this manual, "programs in memory segments with low security levels cannot access memory space in memory segments with relatively higher security levels, while programs in memory segments with high security levels can access relatively The security policy of "memory space in memory segment with lower security level" is actually implemented through compiler technology. For example, in order to make the user target program in the memory segment of the first security level only have access to the legal access range of the first security level, it is necessary to change the Instruction conversion rules in the traditional compilation process, so that the changed instruction conversion rules are used to guide the compilation of memory access instructions in the user source program into corresponding safe memory access instructions in the user target program, and ensure that the user target program The memory access address corresponding to the secure memory access instruction in belongs to the legal access scope of the first security level. As a result, all memory access operations (including read operations and write operations) in the user target program will be restricted within the legal access scope of the first security level, and cannot access the second security level and above The memory space corresponding to the memory segment of the security level. For another example, in order to ensure that the trusted security zone reset function in the memory segment of the second security level can complete the reset process during execution, it must be able to normally access the memory segment of the first security level. Therefore, in the process of compiling the system source program into the system target program, the traditional instruction conversion rules can also be changed through compiler technology, so that the changed instruction conversion rules are used to guide the compilation of memory access instructions in the system source program. It is the corresponding secure memory access instruction in the system target program, and ensure that the memory access address corresponding to the secure memory access instruction in the trusted security area reset function belongs to the legal access range of the second security level. Due to the legal access of the second security level The scope includes the memory segment of the first security level and the backup data segment, so the trusted security zone reset function can normally complete the process of resetting the trusted security zone.

用户源程序中的一个内存访问指令本质上为一个高级/汇编语言的编程语句,所述用户目标程序中的一个安全内存访问指令本质上是由一个或多个机器码构成的机器码集合。以用户源程序是汇编语言为例,如果按照传统编译过程中的指令转换规则,用户源程序中的一个内存访问指令将被编译为一个机器码;而如果按照本说明书实施例所涉及的改变后的指令转换规则,则用户源程序中的一个内存访问指令将被编译包含一个或多个机器码的安全内存访问指令,并且安全内存访问指令内蕴含的操作逻辑与通过传统编译得到的一个机器码所蕴含的操作逻辑不同,具体体现为:在内存访问指令对应的原始访问地址不属于第一安全等级的合法访问范围的情况下,当其被编译为安全内存访问指令后,其蕴含操作逻辑将发生变化,即安全内存访问指令将不再访问原始访问地址,而是访问一个属于第一安全等级的合法访问范围内的地址。不难发现,通过本说明书实施例所涉及的改变后的指令转换规则,使得每个编译得到的安全内存访问指令相较于编译前的内存访问指令其蕴含的操作逻辑发生了实质性变化,而这种变化正是使得安全内存访问指令的访存地址可以被限制在某一个合法访问范围的原因。由于汇编指令与机器码是一一对应的,这意味着如果安全内存访问指令包含多个机器码,则将安全内存访问指令反编译为汇编语言时可能得到多个汇编指令,也即通过编译实现改变内存访问指令其蕴含的操作逻辑的方法具体可能是通过内存访问指令内蕴含的操作逻辑所实现的。通过本说明书实施例所涉及的编译方法,能够消除由用户编写的用户源程序在源码层面的越界访存风险(越界访存风险是指访问了除规定的合法访问范围之外的内存空间),将具有越界访存风险的用户源程序净化为了不具有越界访存风险的用户目标程序。A memory access instruction in the user source program is essentially a high-level/assembly language programming statement, and a safe memory access instruction in the user target program is essentially a machine code set composed of one or more machine codes. Taking the user source program as an assembly language as an example, if the instruction conversion rules in the traditional compilation process are followed, a memory access instruction in the user source program will be compiled into a machine code; According to the instruction transformation rules, a memory access instruction in the user source program will be compiled into a safe memory access instruction containing one or more machine codes, and the operation logic contained in the safe memory access instruction is the same as a machine code obtained through traditional compilation The implied operation logic is different, which is specifically reflected in the following: when the original access address corresponding to the memory access instruction does not belong to the legal access scope of the first security level, when it is compiled into a safe memory access instruction, its implied operation logic will be Changes occur, that is, the secure memory access instruction will no longer access the original access address, but access an address that belongs to the legal access range of the first security level. It is not difficult to find that through the changed instruction conversion rules involved in the embodiments of this specification, the operation logic contained in each compiled safe memory access instruction has undergone substantial changes compared with the pre-compiled memory access instruction. This change is the reason why the memory access address of the safe memory access instruction can be limited to a certain legal access range. Since there is a one-to-one correspondence between assembly instructions and machine codes, this means that if a secure memory access instruction contains multiple machine codes, multiple assembly instructions may be obtained when the secure memory access instruction is decompiled into assembly language, that is, implemented by compiling The method of changing the operation logic contained in the memory access instruction may specifically be realized through the operation logic contained in the memory access instruction. Through the compiling method involved in the embodiment of this manual, the risk of out-of-boundary access at the source code level of the user source program written by the user can be eliminated (out-of-boundary access risk refers to accessing memory space other than the specified legal access range), Purify the user source program with the risk of out-of-bounds access to the user target program without the risk of out-of-bounds access.

在本说明书实施例中,还包括:响应于所述任务请求,将执行所述用户目标程序所生成的所述任务请求对应的执行结果返回至所述任务请求的发起方。在用户目标程序执行完毕后,接口程序将接收到调用用户目标程序所返回的执行结果,该执行结果即为所述任务请求对应的可信计算任务的执行结果,此时接口程序可以将该执行结果返回给处于可信安全区外部的、所述任务请求对应的发起方,至此可信安全区就完成了一次完整执行可信计算任务的全过程。In the embodiment of the present specification, it further includes: in response to the task request, returning an execution result corresponding to the task request generated by executing the user target program to the initiator of the task request. After the user target program is executed, the interface program will receive the execution result returned by calling the user target program. The execution result is the execution result of the trusted computing task corresponding to the task request. At this time, the interface program can execute the The result is returned to the initiator corresponding to the task request outside the trusted security zone, and the trusted security zone has completed a whole process of completely executing the trusted computing task.

本说明书实施例提供了一种可信安全区的安全重置方法,通过将可信安全区分为不同安全等级的内存段,并将由用户编写的用户源程序编译得到的用户目标程序置于第一安全等级的内存段中,由于用户源程序中的内存访问指令被编译为用户目标程序中相应的安全内存访问指令之后,该安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围,这使得用户目标程序只能访问到第一安全等级的合法访问范围的内存空间,从而避免用户目标程序作恶,通过修改其他安全等级的内存段中的程序或数据从内部破坏可信安全区的安全性。例如,用户目标程序无法修改处于第二安全等级的内存段中的内存备份或可信安全区重置函数,因此可以确保每次利用可信安全区重置函数对用户数据段进行重置的过程不会被已经运行在可信安全区中的用户目标程序所影响,即包括可信安全区重置函数在内的、处于第一安全等级的合法访问范围之外的组件都可以在可信安全区重置后持续复用。而对于可信安全区中用户目标程序所能够访问和修改的第一安全等级的合法访问范围对应的内存空间,则在执行可信安全区重置函数过程中通过内存备份对这部分内存空间进行覆盖,即对第一安全等级的合法访问范围对应的内存空间进行完全重置。不难发现,本说明书实施例所实现的可信安全区的安全重置方法本质上也属于一种热启动方法,然而相较于传统的热启动,本说明书实施例实现了只有传统的冷启动才能实现的消除安全隐患的效果,从而兼顾了安全性与效率。具体而言,由于持续复用的第二安全等级及其以上安全等级的内存段不会受到用户目标程序的攻击,因此可以确保持续复用的重置前组件的安全性,特别是执行重置过程的可信安全区重置函数本身的安全性,这维持了系统的自洽性。同时,通过将存在安全风险的第一安全等级的合法访问范围对应的内存空间进行完全重置,可以确保重置后的可信安全区不会继承重置前的可信安全区中的风险,使得即使可信安全区受到用户目标程序的攻击也可以脱离被攻击的状态。The embodiment of this specification provides a security reset method for a trusted security zone, by dividing the trusted security zone into memory segments with different security levels, and placing the user target program compiled by the user source program written by the user in the first place. In the security level memory segment, after the memory access instruction in the user source program is compiled into the corresponding security memory access instruction in the user target program, the memory access address corresponding to the security memory access instruction belongs to the legal access range of the first security level , which makes the user target program only have access to the memory space of the legal access scope of the first security level, thereby preventing the user target program from doing evil, and destroying the trusted security zone from the inside by modifying the program or data in the memory segment of other security levels safety. For example, the user target program cannot modify the memory backup or trusted security zone reset function in the memory segment of the second security level, so it can ensure that the process of resetting the user data segment by using the trusted security zone reset function every time It will not be affected by the user target program already running in the trusted security zone, that is, components outside the legal access range of the first security level, including the reset function of the trusted security zone, can be in the trusted security zone Continuous reuse after zone reset. For the memory space corresponding to the legal access range of the first security level that can be accessed and modified by the user target program in the trusted security zone, this part of the memory space is backed up during the execution of the reset function of the trusted security zone. Overwriting means completely resetting the memory space corresponding to the legal access scope of the first security level. It is not difficult to find that the security reset method of the trusted security zone implemented in the embodiment of this specification is also a hot start method in essence. However, compared with the traditional hot start, the embodiment of this specification realizes only the traditional cold start. The effect of eliminating potential safety hazards can be achieved, thus taking into account both safety and efficiency. Specifically, since the memory segments of the second security level and above security level that are continuously reused cannot be attacked by user target programs, the security of the pre-reset components that are continuously multiplexed can be ensured, especially when performing reset The trusted enclave of the process resets the security of the function itself, which maintains the self-consistency of the system. At the same time, by completely resetting the memory space corresponding to the legal access range of the first security level with security risks, it can be ensured that the reset trusted security zone will not inherit the risks in the trusted security zone before reset, Even if the trusted security zone is attacked by the user's target program, it can escape from the attacked state.

可选的,所述可信安全区还包括第三安全等级的内存段,第三安全等级的内存段包括密钥数据段与证明程序段,所述方法还包括:Optionally, the trusted security zone further includes a memory segment of a third security level, and the memory segment of the third security level includes a key data segment and a certification program segment, and the method further includes:

响应于程序证明请求,执行所述证明程序段中的嵌套证明函数,基于所述密钥数据段中存储的嵌套证明私钥对待证明数据进行签名以生成可信程序证明,所述待证明数据包括所述用户程序段和/或重置程序段中的数据;In response to the program certification request, execute the nested certification function in the certification program segment, sign the data to be certified based on the nested certification private key stored in the key data segment to generate a trusted program certification, and the certification data to be certified The data includes data in the user program segment and/or the reset program segment;

将所述可信程序证明提供至所述程序证明请求的发起方,并接收在所述发起方确认所述可信程序证明验证通过的情况下发送的所述任务请求。providing the trusted program certification to the initiator of the program certification request, and receiving the task request sent when the initiator confirms that the trusted program certification is verified.

在本说明书实施例中,可信安全区中还包括有第三安全等级的内存段,该内存段中加载有属于系统目标程序的嵌套证明函数,且为了确保嵌套证明函数能够正常实现相应的嵌套证明过程,第三安全等级低合法访问范围包括密钥数据段以及第一安全等级、第二安全等级的内存段。对于任意可信安全区外部的验证方,其都可以通过向可信安全区发起程序证明请求以验证可信安全区内部的程序的完整性,例如,任务请求的发起方也可以同时作为验证方,在验证可信安全区的程序完整性后再向可信安全区发起任务请求,从而可以确保可信安全区可以按照预期规范地执行可信计算任务。具体而言,任务请求的发起方可以在发起任务请求之前,首先向可信安全区发起程序证明请求。由可信安全区中的接口程序接受该程序证明请求后,调用并执行证明程序段中的嵌套证明函数,并在嵌套证明函数返回相应的可信程序证明后,将可信程序证明提供至程序证明请求的发起方也即后续任务请求的发起方。程序证明请求的发起方在对可信程序证明验证通过的情况下,向可信安全区发起任务请求。嵌套证明函数在执行时用于:基于所述密钥数据段中存储的嵌套证明私钥对待证明数据进行签名以生成可信程序证明,向调用点返回该可信程序证明。所述待证明数据包括所述用户程序段和/或重置程序段中的数据,也即用户目标程序和/或可信安全区重置函数,在具体实施时,待证明数据也可以是用户目标程序和/或可信安全区重置函数对应的哈希值。In the embodiment of this specification, the trusted security zone also includes a memory segment with a third security level. The memory segment is loaded with a nested attestation function belonging to the system target program, and in order to ensure that the nested attestation function can normally implement the corresponding The nested certification process, the third security level low legal access range includes the key data segment and the memory segment of the first security level and the second security level. For any verifier outside the trusted security zone, it can verify the integrity of the program inside the trusted security zone by initiating a program certification request to the trusted security zone. For example, the initiator of the task request can also be the verifier at the same time After verifying the program integrity of the trusted security zone, a task request is initiated to the trusted security zone, so as to ensure that the trusted security zone can perform trusted computing tasks according to expectations. Specifically, before initiating the task request, the initiator of the task request may at first certify the request to the initiator of the trusted security zone. After the interface program in the trusted security zone accepts the program certification request, it calls and executes the nested certification function in the certification program segment, and after the nested certification function returns the corresponding trusted program certification, it provides the trusted program certification The initiator of the verification request to the program is also the initiator of the follow-up task request. The initiator of the program certification request initiates a task request to the trusted security zone under the condition that the trusted program certification is verified. When executed, the nested certification function is used to: sign the data to be certified based on the nested certification private key stored in the key data segment to generate a trusted program certificate, and return the trusted program certificate to the calling point. The data to be certified includes the data in the user program segment and/or the reset program segment, that is, the user target program and/or the reset function of the trusted security zone. The hash value corresponding to the target program and/or the trusted enclave reset function.

而程序证明请求的发起方则可以通过事先公开的嵌套证明公钥对所述可信程序证明进行验签,在验签成功后就可以确定该可信程序证明来源可信,由此进一步通过程序完整性检验,在事先公开的用户目标程序和/或可信安全区重置函数对应的哈希值与所述待证明数据中包含的哈希值比对一致的情况下,确认所述用户程序段和/或重置程序段中运行的程序未经篡改。此时程序证明请求的发起方再向可信安全区发起任务请求,就可以确保可信安全任务对应的可信安全区重置过程与用户目标程序执行过程均可在预期下规范地进行。The initiator of the program certification request can verify the signature of the trusted program certification through the pre-published nested certification public key. After the signature verification is successful, it can be determined that the source of the trusted program certification is credible. Program integrity check, in the case that the hash value corresponding to the pre-disclosed user target program and/or trusted security zone reset function is consistent with the hash value contained in the data to be certified, confirm that the user The program running in the program segment and/or the reset segment has not been tampered with. At this time, the initiator of the program certification request initiates a task request to the trusted security zone, which can ensure that the process of resetting the trusted security zone corresponding to the trusted security task and the execution process of the user target program can be carried out in a standardized and expected manner.

在传统的远程认证机制中,是由一个专门用于签名的可信安全区(称为QuotingEnclave)使用CPU私钥对待检验的可信安全区中的全部程序进行签名以生成可信程序证明(称为Quote),由于验证方没有掌握对应的CPU公钥无法验证该可信程序证明,因此需要将该可信程序证明转交给远程认证服务器来验证,最终验证方在确定远程认证服务器对该可信程序证明验证成功的情况下,就可以确定该可信程序证明来源可信,并进一步通过程序完整性检验来确认该可信程序证明来源的可信安全区中的程序未经篡改。而在本说明书实施例中,不同于传统的远程认证机制,是由可信安全区中处于第三安全等级的内存段中的嵌套证明函数来对可信安全区自身中处于第一或第二安全等级的内存段中的程序进行签名,由于嵌套证明公钥可以进行公开,因此作为验证方可以对独立地对可信程序证明进行验证,而无需借助远程认证服务器的支持,大大提高了验证方验证程序完整性的效率与成本。In the traditional remote authentication mechanism, a trusted security zone (called QuotingEnclave) dedicated to signatures uses the CPU private key to sign all programs in the trusted security zone to be verified to generate trusted program certificates (called QuotingEnclave). Quote), since the verifier does not have the corresponding CPU public key and cannot verify the credible program certificate, it needs to transfer the credible program certificate to the remote authentication server for verification. If the verification of the program certification is successful, it can be determined that the source of the trusted program certification is credible, and the program integrity check is further performed to confirm that the program in the trusted security zone of the trusted program certification source has not been tampered with. However, in the embodiment of this specification, different from the traditional remote authentication mechanism, the nested certification function in the memory segment of the third security level in the trusted security zone is used to verify the first or second security zone in the trusted security zone itself. The program in the memory segment of the second security level is signed. Since the public key of the nested certificate can be disclosed, as the verifier, it can independently verify the credible program certificate without the support of a remote authentication server, which greatly improves The efficiency and cost of verifying the integrity of the program by the verifier.

在本说明书实施例中,所述嵌套证明私钥由密钥管理服务器在确认所述可信安全区通过远程认证服务器的远程认证的情况下分配至所述可信安全区中的所述密钥数据段。如前所述,密钥数据段中存储有嵌套证明私钥,该私钥可以是由作为验证方的密钥管理服务器通过传统的远程认证机制,在验证包括证明内存段中的嵌套证明函数在内的可信安全区整体的程序完整性之后,可以向可信安全区分配该嵌套证明私钥,同时向外界公开该嵌套证明私钥对应的嵌套证明公钥,以用于完成后续基于嵌套证明函数的程序完整性验证过程。In the embodiment of this specification, the nested certification private key is assigned to the key in the trusted security zone by the key management server after confirming that the trusted security zone has passed the remote authentication of the remote authentication server. key data segment. As mentioned above, the private key of the nested certificate is stored in the key data segment, and the private key can be verified by the key management server as the verification party through the traditional remote authentication mechanism, and the verification includes the nested certificate in the certificate memory segment. After the overall program integrity of the trusted security zone including the function is completed, the nested proof private key can be distributed to the trusted security zone, and the nested proof public key corresponding to the nested proof private key can be disclosed to the outside world for use in Complete the follow-up program integrity verification process based on the nested proof function.

在本说明书实施例中,所述可信安全区包括不同安全等级的内存段,所述不同安全等级至少包括第一安全等级与第二安全等级,其中,任一安全等级的合法访问范围包括所述任一安全等级的内存段中的至少一部分内存地址以及低于所述任一安全等级的内存段;In the embodiment of this specification, the trusted security zone includes memory segments with different security levels, and the different security levels include at least the first security level and the second security level, wherein the legal access scope of any security level includes all At least a part of the memory address in the memory segment of any security level mentioned above and the memory segment lower than the above-mentioned any security level;

所述可信安全区中的程序包括所述用户目标程序与由系统源程序编译得到的系统目标程序,所述系统目标程序处于第二安全等级及其以上安全等级的内存段中,所述系统目标程序包括所述可信安全区重置函数;所述系统源程序中的内存访问指令被编译为所述系统目标程序中相应的安全内存访问指令,其中,所述任一安全等级的内存段中的安全内存访问指令对应的访存地址属于所述任一安全等级的合法访问范围。The programs in the trusted security zone include the user target program and the system target program compiled from the system source program, the system target program is in the memory segment of the second security level and above, and the system The target program includes the trusted security zone reset function; the memory access instructions in the system source program are compiled into corresponding secure memory access instructions in the system target program, wherein the memory segment of any security level The memory access address corresponding to the secure memory access instruction in is within the legal access range of any security level.

与用户源程序被编译为用户目标程序的过程类似,在将系统源程序编译为系统目标程序的过程中,也可以采用本说明书实施例所涉及的编译方法。具体而言,是将所述系统源程序中的内存访问指令编译为所述系统目标程序中相应的安全内存访问指令,并确保处于任一安全等级的内存段中的某一系统目标程序中的安全内存访问指令对应的访存地址属于所述任一安全等级的合法访问范围。通过本说明书实施例所涉及的编译方法,能够消除系统源程序在源码层面的越界访存风险,将具有越界访存风险的系统源程序净化为了不具有越界访存风险的系统目标程序。以图2所示的可信安全区为例,图2中处于第二安全等级的内存段的可信安全区重置函数中包含的安全内存访问指令仅能够访问备份数据段以及第一安全等级的内存段,而处于第三安全等级的内存段的嵌套证明函数中包含的安全内存访问指令则能够访问密钥数据段、第一安全等级的内存段以及第二安全等级的内存段。Similar to the process of compiling the user source program into the user target program, the compiling method involved in the embodiment of this specification can also be used in the process of compiling the system source program into the system target program. Specifically, it compiles the memory access instructions in the system source program into corresponding safe memory access instructions in the system target program, and ensures that the memory access instructions in a certain system target program in any security level memory segment The memory access address corresponding to the secure memory access instruction belongs to the legal access range of any security level. Through the compiling method involved in the embodiment of this specification, the risk of out-of-bounds memory access of the system source program at the source code level can be eliminated, and the system source program with out-of-bounds memory access risk can be purified into a system target program without out-of-bounds memory access risk. Taking the trusted security zone shown in Figure 2 as an example, the secure memory access instructions contained in the trusted security zone reset function of the memory segment at the second security level in Figure 2 can only access the backup data segment and the first security level , and the secure memory access instructions included in the nested attestation function of the memory segment at the third security level can access the key data segment, the memory segment at the first security level, and the memory segment at the second security level.

在本说明书实施例中,所述可信安全区定义有全局合法访问范围,所述全局合法访问范围在通过合法调用逻辑跳转至所述任一安全等级的内存段时被设置为所述任一安全等级的合法访问范围,否则被设置为第一安全等级的合法访问范围;所述任一安全等级的内存段中的安全内存访问指令对应的访存地址属于所述全局合法访问范围。在本说明书实施例中,为可信安全区定义了一个全局合法访问范围用于限制同一时刻下可信安全区中所有安全内存访问指令对应的访存地址,该全局合法访问范围并非固定值,而是可以根据可信安全区中的程序运行情况进行相应的改变,其可以改变的取值包括每个安全等级的合法访问范围。如前所述,本说明书实施例通过编译过程修改了源程序中的内存访问指令蕴含的操作逻辑,使编译得到的目标程序中相应的安全内存访问指令对应的访存地址被引导至全局合法访问范围之内。然而目标程序被加载进可信安全区后,却可以导致来自不同安全等级的内存段中安全内存访问指令所对应的访问地址属于不同的合法访问范围的现象,这并非是通过在编译过程中为拟加载至不同安全等级的内存段中安全内访问指令设置不同的操作逻辑实现的,事实上在编译过程中,无论是用户源程序还是系统源程序中的内存访问指令,最终都被按照统一的指令转换规则转换为了蕴含相同操作逻辑的安全内存访问指令,也即所有被加载至可信安全区中的安全内存访问指令对应的访存地址均属于所述全局合法访问范围。之所以可以产生任一安全等级的内存段中的安全内存访问指令对应的访存地址属于所述任一安全等级的合法访问范围的现象,是因为在通过合法调用逻辑由第x安全等级的内存段的程序跳转至第y安全等级的内存段时,全局合法访问范围被设置为第y安全等级的合法访问范围。因此,可信安全区中运行的程序只要是在合法调用逻辑下,就可以实现:虽然所有安全内存访问指令蕴含的操作逻辑相同,都是将实际访存地址限制在全局合法访问范围之内,但处于不同安全等级的内存段中的安全内存访问指令却具有实际上并不相同的合法访问范围。In the embodiment of this specification, the trusted security zone defines a global legal access range, and the global legal access range is set to any The legal access range of a security level, otherwise it is set as the legal access range of the first security level; the memory access address corresponding to the secure memory access instruction in the memory segment of any security level belongs to the global legal access range. In the embodiment of this specification, a global legal access range is defined for the trusted security zone to limit the memory access addresses corresponding to all secure memory access instructions in the trusted security zone at the same time. The global legal access range is not a fixed value. Instead, corresponding changes can be made according to the running conditions of the programs in the trusted security zone, and the values that can be changed include the legal access scope of each security level. As mentioned above, the embodiment of this specification modifies the operation logic contained in the memory access instruction in the source program through the compilation process, so that the memory access address corresponding to the corresponding safe memory access instruction in the compiled target program is guided to the global legal access within range. However, after the target program is loaded into the trusted security zone, the access addresses corresponding to the security memory access instructions in the memory segments with different security levels may belong to different legal access ranges. It is intended to be loaded into memory segments with different security levels and implemented by setting different operation logics for security internal access instructions. In fact, during the compilation process, no matter whether it is the memory access instructions in the user source program or the system source program, they are finally processed according to the unified The instruction conversion rule converts the instructions into secure memory access instructions with the same operation logic, that is, the memory access addresses corresponding to all the secure memory access instructions loaded into the trusted security zone belong to the global legal access range. The reason why the access address corresponding to the secure memory access instruction in the memory segment of any security level belongs to the legal access range of any security level is that the xth security level memory When the program in the segment jumps to the memory segment of the yth security level, the global legal access range is set to the legal access range of the yth security level. Therefore, as long as the program running in the trusted security zone is under the legal call logic, it can be realized: although the operation logic implied by all secure memory access instructions is the same, the actual memory access address is limited to the global legal access range, However, the secure memory access instructions in memory segments of different security levels have actually different legal access ranges.

通过本说明书实施例,可以限制不同安全等级的内存段中的程序之间通过非法调用逻辑进行跳转时,由于全局合法访问范围并未改变,因此从低安全等级的内存段随意跳转到高安全等级的内存段后将因为访存地址的限制从而无法正常执行高安全等级的内存段中的安全内存访问指令。例如,第一安全等级的内存段中的用户目标程序通过自定义的跳转指令等非法调用逻辑跳转至第二安全等级中的内存段的某个指令后,如果没有遇到安全内存访问指令将会正常继续执行(由于没有访问内存因此不会泄露信息或修改数据,安全风险较小),但如果一旦遇到安全内存访问指令,则由于此时的全局合法访问范围依旧是第一安全等级的合法访问范围,因此此时执行的安全内存访问指令虽然其位置处于第二安全等级的内存段中,但其实际的访存地址却会被限制在全局合法访问范围即第一安全等级的合法访问范围之中,从而使得从第一安全等级的内存段中非法跳转到第二安全等级的内存段后,其后续执行的安全内存访问指令依旧无法影响第一安全等级的合法访问范围之外的内存空间,从而减少了因非法调用逻辑而产生的系统安全风险。Through the embodiment of this specification, it is possible to restrict programs in memory segments of different security levels from jumping from memory segments with low security levels to high After the memory segment of the security level, the safe memory access instructions in the memory segment of the high security level cannot be normally executed due to the limitation of the memory access address. For example, after the user target program in the memory segment of the first security level jumps to an instruction in the memory segment of the second security level through illegal call logic such as a custom jump instruction, if no safe memory access instruction is encountered It will continue to execute normally (because there is no access to memory, it will not leak information or modify data, and the security risk is small), but if a secure memory access instruction is encountered, the global legal access scope at this time is still the first security level Therefore, although the secure memory access instruction executed at this time is located in the memory segment of the second security level, its actual memory access address will be limited to the global legal access range, that is, the legal access of the first security level. In the access range, so that after illegally jumping from the memory segment of the first security level to the memory segment of the second security level, the subsequent execution of the security memory access instruction still cannot affect the legal access range of the first security level memory space, thereby reducing the system security risk caused by illegal call logic.

在本说明书实施例中,合法调用逻辑主要是指通过所述系统目标程序中的边界修改函数实现的调用逻辑,当可信安全区中的某一程序在运行过程中需要调用处于不同安全等级(特别是更高安全等级)的内存段中的被调用函数时,都需要首先通过Ecall指令来调用边界修改函数实现合法的调用过程。该边界修改函数在执行时用于:更改全局合法访问范围到实际需要调用执行的被调用函数所处内存段的安全等级的合法访问范围,再调用至该被调用函数执行。同时,在被调用函数执行完毕后,还会将全局合法访问范围恢复为修改前的数值,并跳转至边界修改函数的调用点处继续执行后续指令。In the embodiment of this specification, the legal call logic mainly refers to the call logic realized by the boundary modification function in the system target program. When a program in the trusted security zone needs to call the Especially when the called function in the memory segment with a higher security level), it is necessary to first call the boundary modification function through the Ecall instruction to realize the legal calling process. The boundary modification function is used to: change the global legal access range to the legal access range of the security level of the memory segment where the called function actually needs to be called and executed, and then call to the called function for execution. At the same time, after the called function is executed, the global legal access range will be restored to the value before modification, and it will jump to the call point of the boundary modification function to continue executing subsequent instructions.

可选的,低安全等级的内存段的内存地址高于高安全等级的内存段,任一安全等级的合法访问范围为高于所述任一安全等级的边界地址的地址范围,所述任一安全等级的边界地址属于所述任一安全等级的内存段,所述全局合法访问范围为高于边界寄存器中存储的边界地址,所述合法调用逻辑包括通过所述系统目标程序中的边界修改函数实现的调用逻辑;Optionally, the memory address of the memory segment with a low security level is higher than that of the memory segment with a high security level, and the legal access range of any security level is an address range higher than the boundary address of any security level. The boundary address of the security level belongs to the memory segment of any security level, the global legal access range is higher than the boundary address stored in the boundary register, and the legal calling logic includes modifying the function through the boundary in the system target program Implemented calling logic;

执行属于所述系统目标程序且处于所述任一安全等级的内存段中的任一系统函数,包括:Execute any system function belonging to the system target program and in the memory segment of any security level, including:

调用所述边界修改函数,将所述边界寄存器中存储的原边界地址修改为所述任一安全等级的边界地址;calling the boundary modifying function to modify the original boundary address stored in the boundary register to the boundary address of any security level;

在所述边界修改函数中调用执行所述任一系统函数,并在执行完成所述任一系统函数后,将边界寄存器中存储的边界地址修改为所述原边界地址。Call and execute any of the system functions in the boundary modifying function, and modify the boundary address stored in the boundary register to the original boundary address after the execution of any of the system functions is completed.

图2中所示的可信安全区中各内存段的内存地址自下而上越来越高,从而确保低安全等级的内存段的内存地址高于高安全等级的内存段,即第一安全等级的内存段的内存地址高于第二安全等级的内存段的内存地址,而第二安全等级的内存段的内存地址高于第三安全等级的内存段的内存地址。在本说明书实施例中,通过设置不同安全等级的边界地址来定义不同安全等级的合法访问范围,具体而言,任一安全等级的合法访问范围为高于所述任一安全等级的边界地址的地址范围,从而使任一安全等级的合法访问范围包括低于所述任一安全等级的内存段。同时,为使任一安全等级的合法访问范围包括所述任一安全等级的内存段中的至少一部分内存地址,则需要确保任一安全等级的边界地址属于所述任一安全等级的内存段且高于该边界地址的内存空间至少包含一个数据段。另外,所述全局合法访问范围由边界寄存器中的边界地址所定义,具体为高于边界寄存器中存储的边界地址。The memory address of each memory segment in the trusted security zone shown in Figure 2 is getting higher and higher from bottom to top, so as to ensure that the memory address of the memory segment with a low security level is higher than that of the memory segment with a high security level, that is, the first security level The memory address of the memory segment of the second security level is higher than the memory address of the memory segment of the second security level, and the memory address of the memory segment of the second security level is higher than the memory address of the memory segment of the third security level. In the embodiment of this specification, the legal access range of different security levels is defined by setting boundary addresses of different security levels. Specifically, the legal access range of any security level is higher than the boundary address of any security level address range, so that the legal access range of any security level includes memory segments lower than any security level. At the same time, in order to make the legal access range of any security level include at least a part of memory addresses in the memory segment of any security level, it is necessary to ensure that the boundary address of any security level belongs to the memory segment of any security level and The memory space above this boundary address contains at least one data segment. In addition, the global legal access range is defined by the boundary address in the boundary register, specifically higher than the boundary address stored in the boundary register.

如前所述,在需要调用属于所述系统目标程序且处于所述任一安全等级的内存段中的任一系统函数之前,需要通过合法调用逻辑进行调用。也即首先调用并执行所述边界修改函数,边界修改函数在执行时用于:将所述边界寄存器中存储的原边界地址修改为所述任一安全等级的边界地址,同时调用并执行所述任一系统函数,并在执行完成所述任一系统函数后,将边界寄存器中存储的边界地址修改为所述原边界地址,以完成针对所述任一系统函数的合法调用逻辑。通过本说明实施例,可以使得通过合法调用逻辑所调用的系统函数可以被正常执行,而通过除合法调用逻辑之外的非法调用逻辑所调用的系统函数无法正常执行,从而减少了因非法调用逻辑而产生的系统安全风险。As mentioned above, before any system function that belongs to the system target program and is in the memory segment of any security level needs to be called, it needs to be called through legal call logic. That is to say, the boundary modification function is first called and executed, and the boundary modification function is used to: modify the original boundary address stored in the boundary register to the boundary address of any security level, and simultaneously call and execute the boundary modification function. Any system function, and after the execution of any system function, modify the boundary address stored in the boundary register to the original boundary address, so as to complete the legal call logic for any system function. Through the embodiment of this description, the system function called by legal call logic can be executed normally, but the system function called by illegal call logic other than legal call logic cannot be executed normally, thereby reducing the number of calls caused by illegal call logic. resulting in system security risks.

可选的,所述任一安全等级的内存段包括相应的数据段与内存地址低于该数据段的程序段,所述任一安全等级的边界地址用于分隔所述任一安全等级的内存段中的数据段与程序段。由此一来,配合上前述的安全内存访问指令所蕴含的操作逻辑,可以使得处于任一安全等级的内存段中程序段内的程序无法访问和修改自身程序段中的程序,从而减少了因篡改程序而产生的系统安全风险,实现了在某一个安全等级的内存段内部的保护机制。以图2为例,第一安全等级的边界地址用于分隔第一安全等级的内存段中的用户数据段与用户程序段,从而限制用户目标程序对自身进行篡改;第二安全等级的边界地址用于分隔第二安全等级的内存段中的备份数据段与重置程序段,从而限制可信安全区重置函数对自身进行篡改;第三安全等级的边界地址用于分隔第三安全等级的内存段中的密钥数据段与证明程序段,从而限制嵌套证明函数对自身进行篡改。Optionally, the memory segment of any security level includes a corresponding data segment and a program segment whose memory address is lower than the data segment, and the boundary address of any security level is used to separate the memory segment of any security level The data segment and program segment in the segment. As a result, combined with the operation logic contained in the aforementioned secure memory access instructions, programs in program segments in memory segments of any security level cannot access and modify programs in their own program segments, thereby reducing the The system security risk caused by tampering with the program realizes the protection mechanism inside the memory segment of a certain security level. Taking Figure 2 as an example, the boundary address of the first security level is used to separate the user data segment and the user program segment in the memory segment of the first security level, thereby restricting the user target program from tampering itself; the boundary address of the second security level It is used to separate the backup data segment and the reset program segment in the memory segment of the second security level, thereby restricting the reset function of the trusted security zone from tampering with itself; the boundary address of the third security level is used to separate the memory segment of the third security level The key data segment and the proof program segment in the memory segment, thereby restricting the nested proof function from tampering with itself.

可选的,低安全等级的内存段的内存地址高于高安全等级的内存段,任一安全等级的合法访问范围为高于所述任一安全等级的边界地址的地址范围,所述任一安全等级的边界地址属于所述任一安全等级的内存段,所述任一安全等级的内存段中的任一安全内存访问指令在执行时用于:Optionally, the memory address of the memory segment with a low security level is higher than that of the memory segment with a high security level, and the legal access range of any security level is an address range higher than the boundary address of any security level. The boundary address of the security level belongs to the memory segment of any security level, and any secure memory access instruction in the memory segment of any security level is used for:

将用于编译为所述任一安全内存访问指令的内存访问指令对应的原始访问地址与边界寄存器中存储的边界地址相减,并将得到的差值存储至偏移寄存器,所述边界寄存器中存储的边界地址为所述任一安全等级的边界地址;Subtracting the original access address corresponding to the memory access instruction compiled into any one of the safe memory access instructions from the boundary address stored in the boundary register, and storing the difference obtained in the offset register, in the boundary register The stored boundary address is the boundary address of any security level;

将所述偏移寄存器中存储的所述差值取绝对值后与所述边界寄存器中存储的所述边界地址相加得到的加数作为所述任一安全内存访问指令对应的访存地址,并基于该访问地址访问内存。taking the absolute value of the difference stored in the offset register and the addend obtained by adding the boundary address stored in the boundary register as the memory access address corresponding to any secure memory access instruction, And access the memory based on the access address.

本说明书实施例介绍了安全内存访问指令所具体蕴含的操作逻辑,由此我们可以分析得到本说明书实施例所涉及的编译方法的指令转换规则。以用户源程序是AT&T汇编语言为例,假设用户源程序中存在一个内存访问指令“movq%rax,0x(%rdx,%rcx,3)”,该内存访问指令所蕴含的操作逻辑为“将寄存器rax中存储的值写入地址为0x(%rdx,%rcx,3)的内存空间”,由于其对应的访问地址0x(%rdx,%rcx,3)在实际执行时是不确定的,如果直接执行该指令将带来越界访存风险。因此,为了将其限制在第一安全等级的合法访问范围内,我们可以在将其编译为作为机器码的安全内存访问指令时改变其蕴含的操作逻辑,使操作逻辑不再为直接访问地址0x(%rdx,%rcx,3),而是访问一个高于第一安全等级的边界地址的重定向地址。具体而言,如果我们对该例子中编译得到的安全内存访问指令进行反编译,可以得到如下的汇编指令集合:“The embodiment of this specification introduces the specific operation logic contained in the secure memory access instruction, so we can analyze and obtain the instruction conversion rules of the compiling method involved in the embodiment of this specification. Taking the user source program as AT&T assembly language as an example, assuming that there is a memory access instruction "movq%rax, 0x (%rdx, %rcx, 3)" in the user source program, the operation logic contained in the memory access instruction is "will The value stored in the register rax is written to the memory space whose address is 0x (%rdx, %rcx, 3), because its corresponding access address 0x (%rdx, %rcx, 3) is uncertain during actual execution, If this instruction is executed directly, there will be a risk of out-of-bounds memory access. Therefore, in order to limit it to the legal access scope of the first security level, we can change the operation logic contained in it when compiling it into a safe memory access instruction as machine code, so that the operation logic is no longer directly accessing address 0x (%rdx, %rcx, 3), instead accessing a redirection address that is higher than the boundary address of the first security level. Specifically, if we decompile the safe memory access instructions compiled in this example, we can get the following assembly instruction set: "

leaq 0x(%rdx,%rcx,3),%r14leaq 0x(%rdx, %rcx, 3), %r14

subq%r15,%r14subq %r15, %r14

shlq $1,%r14shlq $1, %r14

shrq $1,%r14shrq $1, %r14

movq%rax,(%r15,%r14,1)。”movq %rax, (%r15, %r14, 1). "

其中,寄存器r15即存放有边界地址的边界寄存器,而寄存器r14即偏移寄存器。Among them, the register r15 is the boundary register storing the boundary address, and the register r14 is the offset register.

因此,上述汇编指令集合所蕴含的操作逻辑也即编译得到的安全内存访问指令的操作逻辑,具体为“将地址0x(%rdx,%rcx,3)写入寄存器r14,将寄存器r14中存储的值与r15中存储的值相减得到的差值写入寄存器r14,将r14中存储的值的最高位设为0(由于最高位代表正负号,因此该操作视为取绝对值),将寄存器rax中存储的值写入地址(%r15,%r14,1),该地址为r14中存储的值与r15中存储的值之和”。不难发现,如果原始访问地址0x(%rdx,%rcx,3)高于边界地址,则最终安全内存访问指令对应的访存地址与原始访问地址一致;如果原始访问地址低于边界寄存器中的边界地址,则最终安全内存访问指令对应的访存地址被修改为一个高于边界地址的随机地址。因此,无论内存访问指令对应的原始访问地址为何,编译得到的安全内存访问指令对应的访存地址总是高于边界寄存器中的边界地址,即安全内存访问指令对应的访存地址总是属于当前的全局合法访问范围。Therefore, the operation logic contained in the above assembly instruction set is also the operation logic of the compiled secure memory access instruction, specifically "write address 0x (%rdx, %rcx, 3) into register r14, and write the address stored in register r14 The difference obtained by subtracting the value stored in r15 from the value stored in r14 is written into register r14, and the highest bit of the value stored in r14 is set to 0 (since the highest bit represents the sign, this operation is regarded as an absolute value), and the The value stored in register rax is written to address (%r15, %r14, 1), which is the sum of the value stored in r14 and the value stored in r15". It is not difficult to find that if the original access address 0x (%rdx, %rcx, 3) is higher than the boundary address, the memory access address corresponding to the final safe memory access instruction is consistent with the original access address; if the original access address is lower than the boundary register boundary address, the memory access address corresponding to the final safe memory access instruction is modified to a random address higher than the boundary address. Therefore, regardless of the original access address corresponding to the memory access instruction, the memory access address corresponding to the compiled secure memory access instruction is always higher than the boundary address in the boundary register, that is, the memory access address corresponding to the secure memory access instruction always belongs to the current The global legal access scope.

可选的,所述用户目标程序被设置为禁止调用所述边界寄存器与所述偏移寄存器,所述边界寄存器中存储的边界地址仅能通过执行所述系统目标程序中的边界修改函数进行修改。为了确保安全内存访问指令的有效性,我们需要确保用户目标程序无法调用所述边界寄存器与所述偏移寄存器,同时为修改边界寄存器中的边界地址提供唯一的合法渠道,从而避免通过边界修改函数以外的方式修改边界寄存器中的边界地址,确保边界寄存器中用于定义全局合法访问范围的边界地址不会被随意修改,使得安全内存访问指令能够按照预期地减少越界访存风险。Optionally, the user target program is set to prohibit calling the boundary register and the offset register, and the boundary address stored in the boundary register can only be modified by executing the boundary modification function in the system target program . In order to ensure the effectiveness of safe memory access instructions, we need to ensure that the user target program cannot call the boundary register and the offset register, and at the same time provide the only legal channel for modifying the boundary address in the boundary register, thereby avoiding modifying the function through the boundary Modify the boundary address in the boundary register in other ways to ensure that the boundary address in the boundary register used to define the global legal access range will not be modified arbitrarily, so that the safe memory access instruction can reduce the risk of out-of-bounds memory access as expected.

可选的,所述任一安全等级的边界地址被设置为不可访问。在处理任一安全等级的内存段中的push指令这种特殊情况时,由于执行push指令会不断降低栈指针指向的访存地址,从而可能访问到低于所述任一安全等级的边界地址的内存空间,即存在穿越所述任一安全等级的合法访问范围的风险,因此,可以强制将所述任一安全等级中边界地址设置为不可访问,从而避免因push指令所带来的越界访存风险。Optionally, the boundary address of any security level is set as inaccessible. When dealing with the special case of the push instruction in the memory segment of any security level, since the execution of the push instruction will continuously reduce the memory access address pointed by the stack pointer, it is possible to access the boundary address lower than the boundary address of any security level Memory space, that is, there is a risk of crossing the legal access range of any security level. Therefore, the boundary address in any security level can be forcibly set to be inaccessible, thereby avoiding the out-of-bounds memory access caused by the push instruction risk.

可选的,所述可信安全区被划分为若干个首尾连接的内存块,同一安全内存访问指令包含于同一内存块中,所述可信安全区中的安全跳转点与任一内存块的起始地址对齐,所述可信安全区中的安全跳转点包括循环起始地址、条件分支起始地址与非敏感函数的函数起始地址;Optionally, the trusted security zone is divided into a number of end-to-end connected memory blocks, the same secure memory access instruction is included in the same memory block, and the security jump point in the trusted security zone is the same as any memory block The starting address of the trusted security zone is aligned, and the safe jump point in the trusted security zone includes the starting address of the loop, the starting address of the conditional branch and the function starting address of the non-sensitive function;

所述可信安全区中的程序包括所述用户目标程序与由系统源程序编译得到的系统目标程序,所述系统目标程序处于第二安全等级及其以上安全等级的内存段中,所述系统目标程序包括所述可信安全区重置函数;所述用户源程序中的地址跳转指令被编译为所述用户目标程序中相应的安全地址跳转指令,和/或所述系统源程序中的地址跳转指令被编译为所述系统目标程序中相应的安全地址跳转指令,其中,任一安全地址跳转指令对应的跳转地址为用于编译为所述任一安全地址跳转指令的地址跳转指令对应的原始跳转地址所处内存块的起始地址。The programs in the trusted security zone include the user target program and the system target program compiled from the system source program, the system target program is in the memory segment of the second security level and above, and the system The target program includes the trusted security zone reset function; the address jump instruction in the user source program is compiled into a corresponding safe address jump instruction in the user target program, and/or in the system source program The address jump instruction is compiled into a corresponding safe address jump instruction in the system target program, wherein the jump address corresponding to any safe address jump instruction is used for compiling into any safe address jump instruction The starting address of the memory block where the original jump address corresponding to the address jump instruction is located.

如前所述,安全内存访问指令实际上是包含有一个或多个机器码的机器码集合,并且只有完整执行时才能起到规避访存越界风险的作用。然而,攻击者可以在用户目标程序或系统目标程序中利用地址跳转指令来跳过安全内存访问指令,或者通过同时修改其他寄存器的值并跳转到安全内存访问指令中间的某个机器码处,从而扰乱一次完整的安全内存访问指令的执行,甚至能够突破安全内存访问指令限制访存地址的效果,使攻击者能够越界访问到预期的合法访问范围之外的内存空间。为了避免攻击者通过地址跳转指令来部分或完全规避安全内存访问指令的有效性,本说明书实施例提出了另一种安全策略,该安全策略将可信安全区再次划分为若干个首位连接的称为内存块的地址空间,这些内存块的大小可以相同或不同,任一安全内存访问指令都被完整地包含于某一个内存块中,同时规定可信安全区中所有的安全地址跳转指令只能跳转到某一个内存块的起始地址,而不能直接跳转到任何一个内存块的内部。As mentioned above, a safe memory access instruction is actually a set of machine codes containing one or more machine codes, and only when it is completely executed can it avoid the risk of memory access out of bounds. However, an attacker can use the address jump instruction in the user target program or the system target program to skip the secure memory access instruction, or by simultaneously modifying the value of other registers and jumping to a machine code in the middle of the secure memory access instruction , so as to disrupt the execution of a complete secure memory access instruction, and even break through the effect of the secure memory access instruction to limit the memory access address, so that the attacker can access the memory space beyond the expected legal access range. In order to prevent attackers from partially or completely circumventing the effectiveness of secure memory access instructions through address jump instructions, the embodiment of this specification proposes another security strategy, which divides the trusted security zone into several first-connected The address space is called a memory block. The sizes of these memory blocks can be the same or different. Any secure memory access instruction is completely contained in a certain memory block. At the same time, all secure address jump instructions in the trusted security zone are specified. It can only jump to the start address of a certain memory block, but not directly to the inside of any memory block.

通过上述安全策略,可以使得任何安全地址跳转指令总是无法跳转到某一个安全内存访问指令中间的某个机器码,这意味着攻击者无法通过自定义的地址跳转指令来扰乱任一安全内存访问指令的完整执行,从而使得任一安全内存访问指令只要被执行就必然能够达到其预期的规避访存越界风险的作用,因为源程序中的地址跳转指令总是会被编译为相应的安全地址跳转指令。当然,该安全策略无法阻止攻击者完全跳过一个安全内存访问指令,但这种情况下实际上也不会产生任何访存越界风险。Through the above security strategy, any safe address jump instruction can always be unable to jump to a certain machine code in the middle of a certain safe memory access instruction, which means that an attacker cannot disturb any The complete execution of the safe memory access instruction, so that any safe memory access instruction must be able to achieve its expected effect of avoiding the risk of memory access out-of-bounds as long as it is executed, because the address jump instruction in the source program will always be compiled into the corresponding safe address jump instructions. Of course, this security policy cannot prevent an attacker from completely skipping a safe memory access instruction, but in this case there is actually no risk of memory out-of-bounds access.

与前述的编译方法类似,本说明书实施例同样也是通过编译器技术来实现上述安全策略,在对用户源程序和/或系统源程序进行编译时,通过编译器技术来改变传统编译过程中的指令转换规则。在将用户/系统源程序编译为用户/系统目标程序的过程中,使得改变后的指令转换规则用于指导将所述用户/系统源程序中的地址跳转指令编译为所述用户/系统目标程序中相应的安全地址跳转指令,并确保用户/系统目标程序中的任一安全地址跳转指令对应的跳转地址为用于编译为所述任一安全地址跳转指令的地址跳转指令对应的原始跳转地址所处内存块的起始地址。通过本说明书实施例所涉及的编译方法,能够消除用户/系统源程序在源码层面的跳转干扰风险(跳转干扰风险是指通过跳转至安全内存访问指令内部而使安全内存访问指令失效),将具有跳转干扰风险的用户/系统源程序净化为了不具有跳转干扰风险的用户/系统目标程序。Similar to the aforementioned compiling method, the embodiment of this specification also uses compiler technology to implement the above security policy. When compiling user source programs and/or system source programs, the compiler technology is used to change the instructions in the traditional compilation process. Conversion rules. In the process of compiling the user/system source program into the user/system target program, the changed instruction conversion rules are used to guide the compilation of address jump instructions in the user/system source program into the user/system target program The corresponding safe address jump instruction in the program, and ensure that the jump address corresponding to any safe address jump instruction in the user/system target program is an address jump instruction for compiling into any safe address jump instruction The starting address of the memory block where the corresponding original jump address is located. Through the compiling method involved in the embodiment of this specification, the jump interference risk of the user/system source program at the source code level can be eliminated (jump interference risk means that the safety memory access instruction is invalidated by jumping to the inside of the safety memory access instruction) , purify the user/system source program with the jump interference risk into the user/system target program without the jump interference risk.

虽然上述安全策略能够确保用户/系统目标程序不存在跳转干扰风险,然而由于客观上安全地址跳转指令相较于编译前的地址跳转指令,其所蕴含的操作逻辑已经发生了变化,使其无法正常跳转到地址跳转指令对应的原始跳转地址,而是会被引导跳转至原始跳转地址所处内存块的起始地址,这将有可能导致用户/系统目标程序无法完成其正常执行流程。为避免上述安全策略影响用户/系统目标程序的正常执行流程,我们还将所述可信安全区中的安全跳转点与任一内存块的起始地址对齐,所述可信安全区中的安全跳转点包括循环起始地址、条件分支起始地址与非敏感函数的函数起始地址,具体而言,是在将编译得到的用户/系统目标程序加载至可信安全区中时,将用户/系统目标程序中包含的安全跳转点与事先划分好的内存块的起始地址自动对齐。可信安全区中的安全跳转点是指为了使得用户/系统目标程序能够正常执行而必需的一些跳转点,例如对于一个循环逻辑而言,其必然会存在一个被反复跳转的循环起始地址,又例如对于一个条件分支逻辑而言,在不同的条件下会跳转至不同的条件分支起始地址,再例如如果需要通过跳转方式调用一个非敏感函数,则必然需要跳转至该非敏感函数的函数起始地址。由于可信安全区中的所有安全跳转点均与可信安全区中相应内存块的起始地址对齐,因此如果要维持用户/系统目标程序的正常执行流程,只需要利用仅能跳转至某一个内存块的起始地址的安全地址跳转指令就可以实现,即在这种安全跳转点与内存块起始地址的对齐设计下,可以在消除用户/系统源程序在源码层面的跳转干扰风险的同时,不影响用户/系统目标程序的正常执行。Although the above security strategy can ensure that the user/system target program does not have the risk of jump interference, objectively, compared with the address jump instruction before compiling, the operation logic contained in the safe address jump instruction has changed, so that It cannot normally jump to the original jump address corresponding to the address jump instruction, but will be guided to jump to the start address of the memory block where the original jump address is located, which may cause the user/system target program to fail to complete Its normal execution flow. In order to prevent the above-mentioned security policy from affecting the normal execution flow of the user/system target program, we also align the security jump point in the trusted security zone with the starting address of any memory block, and the security jump point in the trusted security zone The safe jump point includes the starting address of the loop, the starting address of the conditional branch, and the function starting address of the non-sensitive function. Specifically, when the compiled user/system target program is loaded into the trusted security zone, the The safe jump point contained in the user/system target program is automatically aligned with the start address of the pre-divided memory block. The safe jump points in the trusted security zone refer to some jump points necessary to enable the user/system target program to execute normally. For example, for a loop logic, there must be a loop that is repeatedly jumped. For example, for a conditional branch logic, it will jump to different conditional branch start addresses under different conditions. For example, if you need to call a non-sensitive function by jumping, you must jump to The function start address of this insensitive function. Since all security jump points in the trusted security zone are aligned with the start addresses of the corresponding memory blocks in the trusted security zone, if you want to maintain the normal execution flow of the user/system target program, you only need to use the The safe address jump instruction of the starting address of a certain memory block can be realized, that is, under the alignment design of the safe jump point and the starting address of the memory block, the jump of the user/system source program at the source code level can be eliminated. While reducing the risk of interference, it does not affect the normal execution of user/system target programs.

另外,为了避免安全地址跳转指令直接跳转到敏感函数或敏感指令处执行,还可以设置任一内存块的起始地址不与敏感指令或敏感函数的起始地址对齐。本说明书实施例所涉及的敏感指令是指可能会对可信安全区的安全性造成破坏的指令,例如前述的用户权限硬件指令,本说明书实施例涉及的敏感函数是指可能会对可信安全区的安全性造成破坏的函数,例如前述的边界修改函数。In addition, in order to prevent the safe address jump instruction from directly jumping to the sensitive function or sensitive instruction for execution, it is also possible to set the starting address of any memory block not to be aligned with the starting address of the sensitive instruction or sensitive function. The sensitive instructions involved in the embodiments of this specification refer to instructions that may damage the security of the trusted security zone, such as the aforementioned user authorization hardware instructions. The sensitive functions involved in the embodiments of this specification refer to instructions that may damage the trusted security zone. A function that destroys the security of the zone, such as the aforementioned boundary modification function.

图3是一示例性实施例提供的一种划分内存块后的可信安全区的示意图。如图3所示,如果用户/系统源程序中的地址跳转指令所蕴含的操作逻辑是跳转至内存块a中间的某个地址的话,那么将该地址跳转指令通过本说明书涉及的编译方法进行编译得到的安全地址跳转指令则在执行时用于:跳转至内存块a的起始地址(图中内存块a的安全跳转点)。Fig. 3 is a schematic diagram of a trusted security zone after memory blocks are divided according to an exemplary embodiment. As shown in Figure 3, if the operation logic contained in the address jump instruction in the user/system source program is to jump to a certain address in the middle of memory block a, then the address jump instruction is passed through the compilation involved in this specification. The safe address jump instruction obtained by compiling the method is used during execution to: jump to the starting address of memory block a (the safe jump point of memory block a in the figure).

可选的,所述任一安全地址跳转指令在执行时用于:Optionally, any safe address jump instruction is used for:

将用于编译为所述任一安全地址跳转指令的地址跳转指令对应的原始跳转地址与对齐常量进行与运算,并将与运算得到的结果作为跳转地址进行跳转。performing an AND operation on the original jump address corresponding to the address jump instruction compiled into any safe address jump instruction and the alignment constant, and using the result of the AND operation as the jump address for jumping.

本说明书实施例介绍了安全地址跳转指令所具体蕴含的操作逻辑,由此我们可以分析得到本说明书实施例所涉及的编译方法的指令转换规则。以用户源程序是AT&T汇编语言为例,假设用户源程序中存在一个地址跳转指令“jmpq*%rax”,该地址跳转指令所蕴含的操作逻辑为“将寄存器rax存储的值作为跳转地址进行跳转”,由于其对应的跳转地址*%rax在实际执行时是不确定的,如果直接执行该指令将带来跳转干扰风险。因此,为了确保不会跳转至安全地址跳转指令中间的机器码,我们可以在将其编译为作为机器码的安全地址跳转指令时改变其蕴含的操作逻辑,使操作逻辑不再为直接跳转至地址*%rax,而是跳转至与地址*%rax邻近的一个内存块的起始地址。具体而言,如果我们对该例子中编译得到的安全地址跳转指令进行反编译,可以得到如下的汇编指令集合:“The embodiment of this specification introduces the specific operation logic contained in the safe address jump instruction, so we can analyze and obtain the instruction conversion rules of the compiling method involved in the embodiment of this specification. Taking the user source program in AT&T assembly language as an example, assuming that there is an address jump instruction "jmpq*%rax" in the user source program, the operation logic contained in the address jump instruction is "use the value stored in the register rax as a jump Address to jump", because its corresponding jump address *%rax is uncertain during actual execution, if this instruction is executed directly, there will be a risk of jump interference. Therefore, in order to ensure that we will not jump to the machine code in the middle of the safe address jump instruction, we can change the operation logic contained in it when compiling it into a safe address jump instruction as machine code, so that the operation logic is no longer direct Jump to address *%rax, but jump to the start address of a memory block adjacent to address *%rax. Specifically, if we decompile the safe address jump instruction compiled in this example, we can get the following assembly instruction set: "

andq%rax,0Xffffffffffffffe0andq%rax,0Xfffffffffffffe0

jmpq *%rax。”jmpq *%rax. "

其中,0Xffffffffffffffe0为对齐常量,每个内存块的起始地址的后五位均为0,因此每个内存块的地址空间均为固定的32bit(每个内存块最多容纳32条指令)。Among them, 0Xfffffffffffffffe0 is an alignment constant, and the last five bits of the start address of each memory block are all 0, so the address space of each memory block is fixed at 32 bits (each memory block can hold up to 32 instructions).

因此,上述汇编指令集合所蕴含的操作逻辑也即编译得到的安全地址跳转指令的操作逻辑,具体为“将寄存器rax存储的值与对齐常量0Xffffffffffffffe0进行与运算得到的某一个内存块的起始地址存放至寄存器rax,将寄存器rax存储的值作为跳转地址进行跳转”。不难发现,如果原始跳转地址为某一个的内存块的起始地址(由于采用了安全跳转点与内存块起始地址的对齐设计,因此其在正常执行流程下必然为某一个的内存块的起始地址),则最终安全地址跳转指令对应的跳转地址与原始跳转地址一致;如果原始跳转地址不为某一个的内存块的起始地址(通常意味着程序作恶),则最终安全地址跳转指令对应的跳转地址被修改为原始跳转地址所处内存块的起始地址。因此,无论地址跳转指令对应的原始跳转地址为何,编译得到的安全地址跳转指令对应的跳转地址总是被吸附至某一个内存块的起始地址。Therefore, the operation logic contained in the above assembly instruction set is also the operation logic of the compiled safe address jump instruction, which is specifically "the start of a certain memory block obtained by ANDing the value stored in the register rax and the alignment constant 0Xfffffffffffffffe0 The address is stored in the register rax, and the value stored in the register rax is used as the jump address to jump." It is not difficult to find that if the original jump address is the start address of a certain memory block (due to the alignment design between the safe jump point and the start address of the memory block, it must be a certain memory block under the normal execution flow. Block start address), then the jump address corresponding to the final safe address jump instruction is consistent with the original jump address; if the original jump address is not the start address of a certain memory block (usually means that the program is evil), Then the jump address corresponding to the final safe address jump instruction is modified to the start address of the memory block where the original jump address is located. Therefore, no matter what the original jump address corresponding to the address jump instruction is, the jump address corresponding to the compiled safe address jump instruction is always absorbed to the start address of a certain memory block.

另外,作为用户/系统源程序中的地址跳转指令的ret指令也需要进行类似的编译过程,将地址跳转指令编译为用户/系统目标程序中的安全地址跳转指令以消除对应的跳转干扰风险。ret指令通常是用于在被调用函数执行完毕后跳转至调用点处,通常情况下调用点的地址会存放至栈顶,然而如果攻击者在被调用函数的执行过程中修改栈顶存放的值,则可能使得ret指令返回至任意内存地址,带来跳转干扰风险。In addition, the ret instruction as the address jump instruction in the user/system source program also needs to undergo a similar compilation process, and the address jump instruction is compiled into a safe address jump instruction in the user/system target program to eliminate the corresponding jump Interference risk. The ret instruction is usually used to jump to the call point after the called function is executed. Usually, the address of the call point will be stored on the top of the stack. However, if the attacker modifies the address stored on the top of the stack during the execution of the called function value, it may cause the ret instruction to return to any memory address, bringing the risk of jump interference.

假设用户源程序中存在一个地址跳转指令“retq”,该地址跳转指令所蕴含的操作逻辑为“将栈顶存放的值作为跳转地址进行跳转”,由于其对应的跳转地址在实际执行时是不确定的,如果直接执行该指令将带来跳转干扰风险。因此,为了确保不会跳转至安全地址跳转指令中间的机器码,我们可以在将其编译为作为机器码的安全地址跳转指令时改变其蕴含的操作逻辑,使操作逻辑不再为直接跳转至作为原始跳转地址的栈顶存放的值,而是跳转至与原始跳转地址邻近的一个内存块的起始地址。具体而言,如果我们对该例子中编译得到的安全地址跳转指令进行反编译,可以得到如下的汇编指令集合:“Assuming that there is an address jump instruction "retq" in the user source program, the operation logic contained in the address jump instruction is "jump the value stored on the top of the stack as the jump address", because its corresponding jump address is in The actual execution is uncertain, and if the instruction is executed directly, there will be a risk of jump interference. Therefore, in order to ensure that we will not jump to the machine code in the middle of the safe address jump instruction, we can change the operation logic contained in it when compiling it into a safe address jump instruction as machine code, so that the operation logic is no longer direct Jump to the value stored on the top of the stack as the original jump address, but instead jump to the start address of a memory block adjacent to the original jump address. Specifically, if we decompile the safe address jump instruction compiled in this example, we can get the following assembly instruction set: "

popq%r14popq%r14

andq%r14,0Xffffffffffffffe0andq%r14,0Xfffffffffffffe0

jmpq *%r14。”jmpq *%r14. "

其中,寄存器r14作为偏移寄存器除了存放前述的差值,还在这里用于存放跳转地址(由于指令必然是由CPU串行执行的,因此作为CPU寄存器的r14可以在不同的指令中复用),0Xffffffffffffffe0为对齐常量,每个内存块的起始地址的后五位均为0,因此每个内存块的地址空间均为固定的32bit。Among them, the register r14 is used as an offset register to store the above-mentioned difference, and it is also used to store the jump address here (since the instructions must be serially executed by the CPU, r14 as a CPU register can be reused in different instructions ), 0Xfffffffffffffffe0 is an alignment constant, and the last five bits of the start address of each memory block are all 0, so the address space of each memory block is a fixed 32bit.

因此,上述汇编指令集合所蕴含的操作逻辑也即编译得到的安全地址跳转指令的操作逻辑,具体为“将栈顶存放的值出栈并存放至寄存器rax,将寄存器rax存储的值与对齐常量0Xffffffffffffffe0进行与运算得到的某一个内存块的起始地址存放至寄存器rax,将寄存器rax存储的值作为跳转地址进行跳转”。与前述的记载类似,无论地址跳转指令对应的原始跳转地址为何,编译得到的安全地址跳转指令对应的跳转地址总是被吸附至某一个内存块的起始地址。Therefore, the operation logic contained in the above assembly instruction set is also the operation logic of the compiled safe address jump instruction. The constant 0Xfffffffffffffe0 and the start address of a certain memory block are stored in the register rax, and the value stored in the register rax is used as the jump address to jump." Similar to the foregoing description, no matter what the original jump address corresponding to the address jump instruction is, the jump address corresponding to the compiled safe address jump instruction is always absorbed to the start address of a certain memory block.

可选的,所述系统目标程序中的任一敏感函数在其占用的内存块中的函数起始地址与该内存块的起始地址之间插入有停机指令,所述停机指令在执行时用于触发系统停机。在本说明书实施例中,为了避免通过前述的安全地址跳转指令跳转至敏感函数从而破坏系统的安全性,可以设置任一敏感函数与其所处的内存块不对齐。具体而言,可以在任一敏感函数占用的内存块中的函数起始地址与该内存块的起始地址之间插入有停机指令,使存放有敏感函数的内存块的起始地址与停机指令对齐,这样一来,即使安全地址跳转指令跳转到了存放有敏感函数的内存块,也会被首先引导至停机指令从而触发系统停机,确保敏感函数无法通过安全跳转指令进行跳转执行,维护了系统的安全性。如图3所示,由于内存块b和内存块c均需要存放敏感函数a,因此内存块b和内存块c的起始地址均与停机指令对齐,而不会与敏感函数a对齐,这确保了通过安全地址跳转指令在跳转至内存块b和内存块c时,只能跳转到其上的停机指令,从而保护了敏感函数a不会被随意跳转调用。需要注意的是,停机指令可以看作一种非敏感函数,因此其也视为一类安全跳转点。Optionally, any sensitive function in the system target program has a shutdown instruction inserted between the function start address in the memory block it occupies and the start address of the memory block, and the shutdown instruction is executed with to trigger a system shutdown. In the embodiment of the present specification, in order to avoid breaking the security of the system by jumping to the sensitive function through the aforementioned safe address jump instruction, any sensitive function can be set to be misaligned with the memory block where it is located. Specifically, a shutdown instruction can be inserted between the function start address in the memory block occupied by any sensitive function and the start address of the memory block, so that the start address of the memory block storing the sensitive function is aligned with the shutdown instruction In this way, even if the safe address jump instruction jumps to the memory block storing the sensitive function, it will be directed to the shutdown instruction first to trigger the system shutdown, ensuring that the sensitive function cannot be executed through the safe jump instruction. Maintenance system security. As shown in Figure 3, since memory block b and memory block c both need to store sensitive function a, the starting addresses of memory block b and memory block c are both aligned with the shutdown instruction, but not with sensitive function a, which ensures When jumping to the memory block b and the memory block c through the safe address jump instruction, it can only jump to the stop instruction thereon, thereby protecting the sensitive function a from being called by random jumping. It should be noted that the halt instruction can be regarded as a non-sensitive function, so it is also regarded as a type of safe jump point.

可选的,在所述任一敏感函数占用有至少两个内存块的情况下,所述至少两个内存块中的所述任一敏感函数通过标签跳转指令进行连接。Optionally, in the case that any sensitive function occupies at least two memory blocks, any sensitive function in the at least two memory blocks is connected through a label jump instruction.

在本说明书实施例中,跳转指令按照类型可以分为地址跳转指令与标签跳转指令,其中,地址跳转指令就是按照指令中给出的跳转地址进行跳转的指令,例如“jmpq *%rax”就是指跳转至寄存器rax中存储的地址所在的内存空间;而标签跳转指令则是按照指令中给出的标签进行直接跳转的指令,例如“jmp L1”就是指跳转至全局唯一的标签L1处所标记的内存空间。在本说明书实施例中,地址跳转指令会按照前述改变后的指令转换规则编译为安全跳转指令,而标签跳转指令则会按照传统编译过程中的指令转换规则进行编译,因此其蕴含的操作逻辑不会产生变化。In the embodiment of this specification, jump instructions can be divided into address jump instructions and label jump instructions according to types, wherein the address jump instruction is an instruction to jump according to the jump address given in the instruction, such as "jmpq *%rax" refers to jumping to the memory space where the address stored in the register rax is located; and the label jump instruction is an instruction to directly jump according to the label given in the instruction, for example, "jmp L1" refers to jump To the memory space marked at the globally unique label L1. In the embodiment of this specification, the address jump instruction will be compiled into a safe jump instruction according to the above-mentioned changed instruction conversion rules, while the label jump instruction will be compiled according to the instruction conversion rules in the traditional compilation process, so its implied The operating logic will not change.

在本说明书实施例中,同一敏感函数其可能包含大量的指令,因此可能无法被完整存放进同一个内存块中,而在同一敏感函数占用至少两个内存块的情况下,由于指令运行时是顺序执行的,两个内存块的交界处必然会被停机指令所隔断,这导致敏感函数无法正常进行执行。基于此,我们将存储于不同内存块中的同一敏感函数通过标签跳转指令连接起来,从而可以使得敏感函数的大小多大,都可以正常执行而不会被停机指令所中断。如图3所示,敏感函数a需要同时占用内存块b和内存块c,然而内存块c开头的停机指令会阻断敏感函数a的正常执行,于是我们通过在内存块b中存储的敏感函数a的第一部分的末尾添加一个标签跳转指令,同时将该标签跳转指令所跳转的标签标记为内存块c中存储的敏感函数a的第二部分的起始地址处,从而使得敏感函数a在执行完第一部分后通过标签跳转指令跳转至第二部分继续执行,而不会影响敏感函数a的正常执行流程。In the embodiment of this specification, the same sensitive function may contain a large number of instructions, so it may not be completely stored in the same memory block, and in the case of the same sensitive function occupying at least two memory blocks, because the instruction is running For sequential execution, the junction of two memory blocks will inevitably be separated by a shutdown instruction, which will cause sensitive functions to fail to execute normally. Based on this, we connect the same sensitive function stored in different memory blocks through label jump instructions, so that no matter how large the size of the sensitive function is, it can be executed normally without being interrupted by the stop instruction. As shown in Figure 3, sensitive function a needs to occupy memory block b and memory block c at the same time, but the stop instruction at the beginning of memory block c will block the normal execution of sensitive function a, so we pass the sensitive function stored in memory block b Add a label jump instruction at the end of the first part of a, and mark the label jumped by the label jump instruction as the starting address of the second part of the sensitive function a stored in the memory block c, so that the sensitive function After executing the first part, a jumps to the second part through the label jump instruction to continue execution, without affecting the normal execution flow of the sensitive function a.

可选的,任一内存块的起始地址与相应的安全检测函数的函数起始地址对齐,任一内存块中的安全检测函数在执行时用于:Optionally, the start address of any memory block is aligned with the function start address of the corresponding security detection function, and the security detection function in any memory block is used to:

确定跳转至所述任一内存块中的安全检测函数的安全地址跳转指令所处的跳转点内存段的安全等级;Determine the safety level of the jump point memory segment where the safety address jump instruction jumping to the safety detection function in any memory block is located;

在确定用于编译为该安全地址跳转指令的地址跳转指令对应的原始跳转地址或所述任一内存块的起始地址不属于所述跳转点内存段的安全等级的合法访问范围的情况下,触发系统停机;When it is determined that the original jump address corresponding to the address jump instruction used to compile the safe address jump instruction or the start address of any memory block does not belong to the legal access range of the security level of the jump point memory segment In the case of , trigger system shutdown;

在确定该原始跳转地址或所述任一内存块的起始地址属于所述跳转点内存段的安全等级的合法访问范围的情况下,顺序执行下一个指令或跳转至该原始跳转地址。In the case of determining that the original jump address or the starting address of any memory block belongs to the legal access range of the security level of the jump point memory segment, execute the next instruction in sequence or jump to the original jump address.

本说明书实施例所涉及的安全检测函数属于系统目标函数中的非敏感函数,由于其会被插入至每个内存块的开头而用户程序段中可能包括一个或多个内存块,因此用户程序段中也会被插入一个或多个安全检测函数,而该插入的过程发生在将用户目标程序加载至用户程序段的过程中,使得用户程序段中同时混杂有用户目标程序与系统目标程序。安全检测函数可以通过边界寄存器中的值来确定跳转至所述任一内存块中的安全检测函数的安全地址跳转指令所处的跳转点内存段的安全等级,具体而言,可以将边界寄存器中的值与不同安全等级的边界地址进行比对,从而将比对一致的边界地址的安全等级确定为跳转点内存段的安全等级。为了使安全检测函数能够获取用于编译为跳转至此处的安全地址跳转指令的地址跳转指令对应的原始跳转地址,可以在将地址跳转指令编译为安全地址跳转指令时添加一个操作逻辑,使得安全地址跳转指令中还包括如下操作逻辑:在进行与运算之前将原始跳转地址入栈从而将原始跳转地址到保留在堆栈中。而在安全检测函数执行的过程中,就可以通过出栈指令来获取该原始跳转指令。我们还可以设置任一安全等级的合法访问范围的边界与内存块的边界对齐,这意味着任何一个内存块都不会跨越不同安全等级的合法访问范围,因此只要跳转到任一内存块的起始地址没有越界就能够说明跳转到该任一内存块中的任意地址都不会越界。于是,如果在确定原始跳转地址或所述任一内存块的起始地址(所述任一内存块的起始地址维护于所述任一内存块中的安全检测函数之内而不需要从其他地方获取)属于所述跳转点内存段(即跳转至所述任一内存块中的安全检测函数的安全地址跳转指令所处的内存段)的安全等级的合法访问范围的情况下,则说明该跳转合法,便可以进行顺序执行下一个指令或跳转至原始跳转地址继续执行;否则证明该跳转不合法,将执行一个停机指令并触发系统停机。本说明书实施例可以彻底清除系统中因地址跳转指令而带来的越界跳转风险,使得任何程序不仅无法访问其合法访问范围之外的内存地址,也无法正常跳转至其合法访问范围之外的内存地址。The security detection function involved in the embodiment of this specification belongs to the non-sensitive function in the system target function, because it will be inserted into the beginning of each memory block and the user program segment may include one or more memory blocks, so the user program segment One or more safety detection functions will also be inserted into the user program segment, and the insertion process occurs during the process of loading the user target program into the user program segment, so that the user program segment is mixed with the user target program and the system target program. The security detection function can determine the security level of the jump point memory segment where the security address jump instruction of the security detection function in any memory block jumps to the security detection function through the value in the boundary register. Specifically, the The value in the boundary register is compared with the boundary addresses of different security levels, so that the security level of the compared boundary address is determined as the security level of the jump point memory segment. In order to enable the safety detection function to obtain the original jump address corresponding to the address jump instruction compiled as a safe address jump instruction to jump here, you can add a when compiling the address jump instruction into a safe address jump instruction Operation logic, so that the safe address jump instruction also includes the following operation logic: before performing the AND operation, the original jump address is pushed into the stack, so that the original jump address is reserved in the stack. During the execution of the security detection function, the original jump instruction can be obtained by popping the stack instruction. We can also set the boundary of the legal access range of any security level to be aligned with the boundary of the memory block, which means that any memory block will not cross the legal access range of different security levels, so as long as jump to any memory block If the start address does not cross the boundary, it means that jumping to any address in any memory block will not cross the boundary. Therefore, if the original jump address or the start address of any memory block is determined (the start address of any memory block is maintained within the safety detection function in any memory block without requiring Obtained elsewhere) belongs to the legal access range of the security level of the jump point memory segment (that is, the memory segment where the safety address jump instruction jumping to the safety detection function in any of the memory blocks is located) , it means that the jump is legal, and the next instruction can be executed sequentially or jump to the original jump address to continue execution; otherwise, it proves that the jump is illegal, and a stop instruction will be executed and the system will be stopped. The embodiment of this manual can completely eliminate the risk of out-of-bounds jumps caused by address jump instructions in the system, so that any program can not only access memory addresses outside its legal access range, but also cannot normally jump to its legal access range. external memory address.

另外,为了确保各用户/系统目标程序的正常执行而不会被内存块中插入的安全检测函数所打断,可以在连续的内存块之间通过标签跳转指令进行连接从而在用户/系统目标程序正常的顺序执行时跳过执行安全监测函数,例如在每个内存块的末尾插入一个标签跳转指令,该标签跳转指令所跳转的标签标记为下一个内存块中安全检测函数的函数终止地址后的地址。In addition, in order to ensure that the normal execution of each user/system target program will not be interrupted by the safety detection function inserted in the memory block, it is possible to connect consecutive memory blocks through label jump instructions so that the user/system target program During the normal sequence execution of the program, the safety monitoring function is skipped, for example, a label jump instruction is inserted at the end of each memory block, and the label jumped by the label jump instruction is marked as the function of the safety detection function in the next memory block The address after the termination address.

在本说明书实施例中,所述用户目标程序由所述可信安全区中的解释器将所述用户源程序编译得到;或者,所述用户目标程序由可信编译平台将所述用户源程序通过运行前编译得到,所述方法还包括:In the embodiment of this specification, the user target program is obtained by compiling the user source program by an interpreter in the trusted security zone; or, the user target program is compiled by a trusted compilation platform from the user source program Obtained by compiling before running, the method also includes:

获取所述用户目标程序,在确定所述可信编译平台提供的所述用户目标程序对应的签名验签成功的情况下,将所述用户目标程序加载至所述用户程序段。Acquire the user target program, and load the user target program into the user program segment when it is determined that the signature verification corresponding to the user target program provided by the trusted compilation platform is successful.

可信安全区中内嵌有解释器以实现将用户/系统源程序编译为用户/系统目标程序的功能,这种情况下可信安全区可以确定编译得到的用户目标程序由于使用了本说明书实施例所涉及的编译方法,于是不需要进一步确定用户目标程序是否可信。然而,如果是在AOT(Ahead-of-time,运行前编译)的场景下,可信安全区所直接接收到的就是用户目标程序,由于无法确定该用户目标程序是否使用了本说明书实施例所涉及的编译方法,因此还需要对其可信度进行验证后才会能将其加载至用户程序段,从而确保加载至用户程序段中的用户目标程序的访存越界风险、跳转干扰风险等风险已经消除。An interpreter is embedded in the trusted security zone to realize the function of compiling the user/system source program into a user/system target program. In this case, the trusted security zone can determine the compiled user target program. The compilation method involved in the example, so there is no need to further determine whether the user target program is credible. However, if it is in the AOT (Ahead-of-time, compiling before running) scenario, what the trusted security zone directly receives is the user target program, because it is impossible to determine whether the user target program uses the The compilation method involved, so its credibility needs to be verified before it can be loaded into the user program segment, so as to ensure the risk of out-of-bounds memory access and jump interference risks of the user target program loaded into the user program segment The risk has been eliminated.

可信安全区可以自己对所述可信编译平台提供的所述用户目标程序对应的签名进行验签,也可以由其他可信安全区所信任的可信机构对所述可信编译平台提供的所述用户目标程序对应的签名进行验签,然后基于对该可信机构的信任,可信安全区可以在确认该可信机构对签名验证成功的情况下将所述用户目标程序加载至所述用户程序段。图8是一示例性实施例提供的一种可信计算系统的系统架构图,以图8为例,假设后端可信安全区需要加载一个由外部可信编译平台所编译得到的用户目标程序,那么该用户目标程序对应的签名可以由后端可信安全区自身进行验签,也可以交由前端可信安全区进行验签,然后在前端可信安全区验签成功的情况下通知后端可信安全区,后端可信安全区基于与前端可信安全区之间的信任关系从而可以将所述用户目标程序加载至所述用户程序段。The trusted security zone may verify the signature corresponding to the user target program provided by the trusted compilation platform by itself, or a trusted organization trusted by other trusted security zones may verify the signature provided by the trusted compilation platform. The signature corresponding to the user target program is verified, and then based on the trust of the trusted organization, the trusted security zone can load the user target program to the user program segment. Fig. 8 is a system architecture diagram of a trusted computing system provided by an exemplary embodiment. Taking Fig. 8 as an example, it is assumed that the back-end trusted security zone needs to load a user target program compiled by an external trusted compilation platform , then the signature corresponding to the user target program can be verified by the back-end trusted security zone itself, or it can be handed over to the front-end trusted security zone for signature verification, and then the front-end trusted security zone will be notified when the signature verification is successful. The end trusted security zone, the back-end trusted security zone can load the user target program into the user program segment based on the trust relationship with the front-end trusted security zone.

请参见图4,图4是一示例性实施例提供的一种编译方法的流程图。如图1所示,该方法包括:Please refer to FIG. 4 , which is a flow chart of a compiling method provided by an exemplary embodiment. As shown in Figure 1, the method includes:

S402:获取用于在可信安全区中执行的用户源程序,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址,所述用户程序段中的安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围。S402: Obtain a user source program for execution in a trusted security zone, the trusted security zone includes a memory segment with a first security level and a memory segment with a second security level, wherein the memory segment with the first security level includes The user data segment and the user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, the legal access range of the first security level includes at least a part of memory addresses in the memory segment of the first security level, the The memory access address corresponding to the secure memory access instruction in the user program segment belongs to the legal access range of the first security level.

S404:将所述用户源程序编译为用户目标程序,以使得所述用户源程序中的内存访问指令转换为所述用户目标程序中相应的安全内存访问指令。S404: Compile the user source program into a user object program, so that memory access instructions in the user source program are converted into corresponding secure memory access instructions in the user object program.

S406:将所述用户目标程序加载至所述用户程序段,以由所述可信安全区响应于任务请求进行重置后执行所述用户程序段中的所述用户目标程序;其中,对所述可信安全区进行重置包括:执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份。S406: Load the user target program into the user program segment, so that the trusted security zone executes the user target program in the user program segment after being reset in response to a task request; wherein, the user target program in the user program segment is executed; Resetting the trusted security zone includes: executing the trusted security zone reset function in the reset program segment, and overwriting the memory backup stored in the backup data segment to the legal access range corresponding to the first security level memory space, the memory backup includes a user data segment backup for overwriting to the user data segment.

本说明书实施例所涉及的编译方法在前文实施例中已经有详细的记载,这里不再赘述。需要注意的是,本说明书实施例所涉及的编译方法同样适用于将系统源程序编译为系统目标程序。The compiling method involved in the embodiment of this specification has been described in detail in the foregoing embodiments, and will not be repeated here. It should be noted that the compiling methods involved in the embodiments of this specification are also applicable to compiling a system source program into a system target program.

通过本说明书实施例涉及的编译方法,配合划分有不同安全等级的内存段的可信安全区的内存架构,能够使得用户源程序中的内存访问指令转换为用户目标程序中相应的安全内存访问指令,且安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围,由此一来就将具有跳转干扰风险的用户源程序净化为了不具有跳转干扰风险的用户目标程序。同时,在基于上述编译方法编译得到用户目标程序并加载至可信安全区中后,辅以不同安全等级的内存段的设计,能够实现一种可信安全区的安全重置方法,相较于传统的热启动,本说明书实施例所涉及的安全重置方法实现了只有传统的冷启动才能实现的消除安全隐患的效果,从而兼顾了安全性与效率。Through the compiling method involved in the embodiment of this specification, in conjunction with the memory architecture of the trusted security zone divided into memory segments with different security levels, the memory access instructions in the user source program can be converted into corresponding secure memory access instructions in the user target program , and the memory access address corresponding to the secure memory access instruction belongs to the legal access range of the first security level, thereby purifying the user source program with the risk of jump interference into the user target program without the risk of jump interference. At the same time, after compiling the user target program based on the above compilation method and loading it into the trusted security zone, supplemented by the design of memory segments with different security levels, a secure reset method for the trusted security zone can be realized. Traditional hot start, the safety reset method involved in the embodiment of this specification achieves the effect of eliminating potential safety hazards that can only be achieved by traditional cold start, thus taking into account both safety and efficiency.

图5是一示例性实施例提供的一种设备的示意结构图。请参考图5,在硬件层面,该设备包括处理器502、内部总线504、网络接口506、内存508以及非易失性存储器510,当然还可能包括其他业务所需要的硬件。本说明书一个或多个实施例可以基于软件方式来实现,比如由处理器502从非易失性存储器510中读取对应的计算机程序到内存508中然后运行。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。Fig. 5 is a schematic structural diagram of a device provided by an exemplary embodiment. Please refer to FIG. 5 , at the hardware level, the device includes a processor 502 , an internal bus 504 , a network interface 506 , a memory 508 and a non-volatile memory 510 , and of course it may also include hardware required by other services. One or more embodiments of this specification may be implemented based on software, for example, the processor 502 reads a corresponding computer program from the non-volatile memory 510 into the memory 508 and executes it. Of course, in addition to software implementations, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each A logic unit, which can also be a hardware or logic device.

如图6所示,图6是本说明书根据一示例性实施例提供的一种基于可信安全区的请求处理装置的框图,该装置可以应用于如图5所示的设备中,以实现本说明书的技术方案。所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址;所述装置包括:As shown in FIG. 6, FIG. 6 is a block diagram of an apparatus for processing a request based on a trusted security zone according to an exemplary embodiment of this specification. This apparatus can be applied to the device shown in FIG. 5 to implement this Specifications for technical solutions. The trusted security zone includes memory segments of the first security level and memory segments of the second security level, wherein the memory segments of the first security level include user data segments and user program segments, and the memory segments of the second security level include backup For the data segment and the reset program segment, the legal access scope of the first security level includes at least a part of memory addresses in the memory segment of the first security level; the device includes:

重置单元601,用于响应于任务请求,执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份;The reset unit 601 is configured to, in response to the task request, execute the trusted security area reset function in the reset program segment, and cover the memory backup stored in the backup data segment to the legal access range of the first security level Corresponding memory space, the memory backup includes user data segment backup for covering to the user data segment;

用户目标程序执行单元602,用于在所述可信安全区重置函数执行完成后,执行所述用户程序段中由用户源程序编译得到的用户目标程序;其中,所述用户源程序中的内存访问指令被编译为所述用户目标程序中相应的安全内存访问指令,所述安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围。The user target program execution unit 602 is configured to execute the user target program compiled from the user source program in the user program segment after the execution of the trusted security zone reset function is completed; wherein, in the user source program The memory access instruction is compiled into a corresponding secure memory access instruction in the user target program, and the memory access address corresponding to the secure memory access instruction belongs to the legal access range of the first security level.

可选的,所述重置单元601具体用于:Optionally, the reset unit 601 is specifically used for:

启用用户权限硬件指令,并通过所述用户权限硬件指令为第一安全等级的合法访问范围对应的内存空间重新分配内存访问权限;Enable the user authority hardware instruction, and redistribute the memory access authority for the memory space corresponding to the legal access range of the first security level through the user authority hardware instruction;

将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,并在完成后禁用所述用户权限硬件指令。Overwrite the memory backup stored in the backup data segment to the memory space corresponding to the legal access scope of the first security level, and disable the user permission hardware instruction after completion.

可选的,所述内存备份还包括用于覆盖至所述用户程序段的用户程序段备份。Optionally, the memory backup further includes user program segment backup for overwriting to the user program segment.

可选的,还包括:Optionally, also include:

执行结果返回单元603,用于响应于所述任务请求,将执行所述用户目标程序所生成的所述任务请求对应的执行结果返回至所述任务请求的发起方。The execution result returning unit 603 is configured to, in response to the task request, return an execution result corresponding to the task request generated by executing the user target program to the initiator of the task request.

可选的,还包括:Optionally, also include:

备份单元604,用于响应于备份请求或者在所述可信安全区完成冷启动的情况下,执行所述重置程序段中的可信安全区备份函数,将第一安全等级的合法访问范围中的数据作为所述内存备份存储至所述备份数据段。The backup unit 604 is configured to execute the backup function of the trusted security zone in the reset program segment in response to a backup request or when the trusted security zone has completed a cold start, and convert the legal access scope of the first security level to The data in is stored in the backup data segment as the memory backup.

可选的,所述可信安全区被划分为若干个首尾连接的内存块,同一安全内存访问指令包含于同一内存块中,所述可信安全区中的安全跳转点与任一内存块的起始地址对齐,所述可信安全区中的安全跳转点包括循环起始地址、条件分支起始地址与非敏感函数的函数起始地址;Optionally, the trusted security zone is divided into a number of end-to-end connected memory blocks, the same secure memory access instruction is included in the same memory block, and the security jump point in the trusted security zone is the same as any memory block The starting address of the trusted security zone is aligned, and the safe jump point in the trusted security zone includes the starting address of the loop, the starting address of the conditional branch and the function starting address of the non-sensitive function;

所述可信安全区中的程序包括所述用户目标程序与由系统源程序编译得到的系统目标程序,所述系统目标程序处于第二安全等级及其以上安全等级的内存段中,所述系统目标程序包括所述可信安全区重置函数;所述用户源程序中的地址跳转指令被编译为所述用户目标程序中相应的安全地址跳转指令,和/或所述系统源程序中的地址跳转指令被编译为所述系统目标程序中相应的安全地址跳转指令,其中,任一安全地址跳转指令对应的跳转地址为用于编译为所述任一安全地址跳转指令的地址跳转指令对应的原始跳转地址所处内存块的起始地址。The programs in the trusted security zone include the user target program and the system target program compiled from the system source program, the system target program is in the memory segment of the second security level and above, and the system The target program includes the trusted security zone reset function; the address jump instruction in the user source program is compiled into a corresponding safe address jump instruction in the user target program, and/or in the system source program The address jump instruction is compiled into a corresponding safe address jump instruction in the system target program, wherein the jump address corresponding to any safe address jump instruction is used for compiling into any safe address jump instruction The starting address of the memory block where the original jump address corresponding to the address jump instruction is located.

可选的,所述系统目标程序中的任一敏感函数在其占用的内存块中的函数起始地址与该内存块的起始地址之间插入有停机指令,所述停机指令在执行时用于触发系统停机。Optionally, any sensitive function in the system target program has a shutdown instruction inserted between the function start address in the memory block it occupies and the start address of the memory block, and the shutdown instruction is executed with to trigger a system shutdown.

可选的,在所述任一敏感函数占用有至少两个内存块的情况下,所述至少两个内存块中的所述任一敏感函数通过标签跳转指令进行连接。Optionally, in the case that any sensitive function occupies at least two memory blocks, any sensitive function in the at least two memory blocks is connected through a label jump instruction.

可选的,任一内存块的起始地址与相应的安全检测函数的函数起始地址对齐,任一内存块中的安全检测函数在执行时用于:Optionally, the start address of any memory block is aligned with the function start address of the corresponding security detection function, and the security detection function in any memory block is used to:

确定跳转至所述任一内存块中的安全检测函数的安全地址跳转指令所处的跳转点内存段的安全等级;Determine the safety level of the jump point memory segment where the safety address jump instruction jumping to the safety detection function in any memory block is located;

在确定用于编译为该安全地址跳转指令的地址跳转指令对应的原始跳转地址或所述任一内存块的起始地址不属于所述跳转点内存段的安全等级的合法访问范围的情况下,触发系统停机;When it is determined that the original jump address corresponding to the address jump instruction used to compile the safe address jump instruction or the start address of any memory block does not belong to the legal access range of the security level of the jump point memory segment In the case of , trigger system shutdown;

在确定该原始跳转地址或所述任一内存块的起始地址属于所述跳转点内存段的安全等级的合法访问范围的情况下,顺序执行下一个指令或跳转至该原始跳转地址。In the case of determining that the original jump address or the starting address of any memory block belongs to the legal access range of the security level of the jump point memory segment, execute the next instruction in sequence or jump to the original jump address.

可选的,所述可信安全区还包括第三安全等级的内存段,第三安全等级的内存段包括密钥数据段与证明程序段,所述装置还包括:Optionally, the trusted security zone further includes a memory segment of a third security level, the memory segment of the third security level includes a key data segment and a certification program segment, and the device further includes:

嵌套证明单元605,用于响应于程序证明请求,执行所述证明程序段中的嵌套证明函数,基于所述密钥数据段中存储的嵌套证明私钥对待证明数据进行签名以生成可信程序证明,所述待证明数据包括所述用户程序段和/或重置程序段中的数据;The nested certification unit 605 is configured to respond to the program certification request, execute the nested certification function in the certification program segment, and sign the data to be certified based on the nested certification private key stored in the key data segment to generate a valid letter program certification, the data to be certified includes the data in the user program segment and/or reset program segment;

将所述可信程序证明提供至所述程序证明请求的发起方,并接收在所述发起方确认所述可信程序证明验证通过的情况下发送的所述任务请求。providing the trusted program certification to the initiator of the program certification request, and receiving the task request sent when the initiator confirms that the trusted program certification is verified.

可选的,所述嵌套证明私钥由密钥管理服务器在确认所述可信安全区通过远程认证服务器的远程认证的情况下分配至所述可信安全区中的所述密钥数据段。Optionally, the nested certification private key is allocated to the key data segment in the trusted security zone by the key management server after confirming that the trusted security zone has passed the remote authentication of the remote authentication server .

可选的,所述可信安全区包括不同安全等级的内存段,所述不同安全等级至少包括第一安全等级与第二安全等级,其中,任一安全等级的合法访问范围包括所述任一安全等级的内存段中的至少一部分内存地址以及低于所述任一安全等级的内存段;Optionally, the trusted security zone includes memory segments with different security levels, and the different security levels include at least a first security level and a second security level, wherein the legal access scope of any security level includes any of the At least a part of the memory address in the memory segment of the security level and the memory segment lower than any of the security levels;

所述可信安全区中的程序包括所述用户目标程序与由系统源程序编译得到的系统目标程序,所述系统目标程序处于第二安全等级及其以上安全等级的内存段中,所述系统目标程序包括所述可信安全区重置函数;所述系统源程序中的内存访问指令被编译为所述系统目标程序中相应的安全内存访问指令,其中,所述任一安全等级的内存段中的安全内存访问指令对应的访存地址属于所述任一安全等级的合法访问范围。The programs in the trusted security zone include the user target program and the system target program compiled from the system source program, the system target program is in the memory segment of the second security level and above, and the system The target program includes the trusted security zone reset function; the memory access instructions in the system source program are compiled into corresponding secure memory access instructions in the system target program, wherein the memory segment of any security level The memory access address corresponding to the secure memory access instruction in is within the legal access range of any security level.

可选的,低安全等级的内存段的内存地址高于高安全等级的内存段,任一安全等级的合法访问范围为高于所述任一安全等级的边界地址的地址范围,所述任一安全等级的边界地址属于所述任一安全等级的内存段,所述任一安全等级的内存段中的任一安全内存访问指令在执行时用于:Optionally, the memory address of the memory segment with a low security level is higher than that of the memory segment with a high security level, and the legal access range of any security level is an address range higher than the boundary address of any security level. The boundary address of the security level belongs to the memory segment of any security level, and any secure memory access instruction in the memory segment of any security level is used for:

将用于编译为所述任一安全内存访问指令的内存访问指令对应的原始访问地址与边界寄存器中存储的边界地址相减,并将得到的差值存储至偏移寄存器,所述边界寄存器中存储的边界地址为所述任一安全等级的边界地址;Subtracting the original access address corresponding to the memory access instruction compiled into any one of the safe memory access instructions from the boundary address stored in the boundary register, and storing the difference obtained in the offset register, in the boundary register The stored boundary address is the boundary address of any security level;

将所述偏移寄存器中存储的所述差值取绝对值后与所述边界寄存器中存储的所述边界地址相加得到的加数作为所述任一安全内存访问指令对应的访存地址,并基于该访问地址访问内存。taking the absolute value of the difference stored in the offset register and the addend obtained by adding the boundary address stored in the boundary register as the memory access address corresponding to any secure memory access instruction, And access the memory based on the access address.

可选的,所述用户目标程序被设置为禁止调用所述边界寄存器与所述偏移寄存器,所述边界寄存器中存储的边界地址仅能通过执行所述系统目标程序中的边界修改函数进行修改。Optionally, the user target program is set to prohibit calling the boundary register and the offset register, and the boundary address stored in the boundary register can only be modified by executing the boundary modification function in the system target program .

可选的,所述可信安全区定义有全局合法访问范围,所述全局合法访问范围在通过合法调用逻辑跳转至所述任一安全等级的内存段时被设置为所述任一安全等级的合法访问范围,否则被设置为第一安全等级的合法访问范围;所述任一安全等级的内存段中的安全内存访问指令对应的访存地址属于所述全局合法访问范围。Optionally, the trusted security zone defines a global legal access range, and the global legal access range is set to any security level when jumping to the memory segment of any security level through legal call logic Otherwise, it is set as the legal access range of the first security level; the memory access address corresponding to the secure memory access instruction in the memory segment of any security level belongs to the global legal access range.

可选的,低安全等级的内存段的内存地址高于高安全等级的内存段,任一安全等级的合法访问范围为高于所述任一安全等级的边界地址的地址范围,所述任一安全等级的边界地址属于所述任一安全等级的内存段,所述全局合法访问范围为高于边界寄存器中存储的边界地址,所述合法调用逻辑包括通过所述系统目标程序中的边界修改函数实现的调用逻辑;Optionally, the memory address of the memory segment with a low security level is higher than that of the memory segment with a high security level, and the legal access range of any security level is an address range higher than the boundary address of any security level. The boundary address of the security level belongs to the memory segment of any security level, the global legal access range is higher than the boundary address stored in the boundary register, and the legal calling logic includes modifying the function through the boundary in the system target program Implemented calling logic;

执行属于所述系统目标程序且处于所述任一安全等级的内存段中的任一系统函数,包括:Execute any system function belonging to the system target program and in the memory segment of any security level, including:

调用所述边界修改函数,将所述边界寄存器中存储的原边界地址修改为所述任一安全等级的边界地址;calling the boundary modifying function to modify the original boundary address stored in the boundary register to the boundary address of any security level;

在所述边界修改函数中调用执行所述任一系统函数,并在执行完成所述任一系统函数后,将边界寄存器中存储的边界地址修改为所述原边界地址。Call and execute any of the system functions in the boundary modifying function, and modify the boundary address stored in the boundary register to the original boundary address after the execution of any of the system functions is completed.

可选的,所述任一安全等级的内存段包括相应的数据段与内存地址低于该数据段的程序段,所述任一安全等级的边界地址用于分隔所述任一安全等级的内存段中的数据段与程序段。Optionally, the memory segment of any security level includes a corresponding data segment and a program segment whose memory address is lower than the data segment, and the boundary address of any security level is used to separate the memory segment of any security level The data segment and program segment in the segment.

可选的,所述任一安全等级的边界地址被设置为不可访问。Optionally, the boundary address of any security level is set as inaccessible.

可选的,所述用户目标程序由所述可信安全区中的解释器将所述用户源程序编译得到;或者,Optionally, the user target program is obtained by compiling the user source program with an interpreter in the trusted security zone; or,

所述用户目标程序由可信编译平台将所述用户源程序通过运行前编译得到,所述装置还包括:The user target program is obtained by compiling the user source program before running on a trusted compilation platform, and the device also includes:

验签单元606,用于获取所述用户目标程序,在确定所述可信编译平台提供的所述用户目标程序对应的签名验签成功的情况下,将所述用户目标程序加载至所述用户程序段。The signature verification unit 606 is configured to acquire the user target program, and load the user target program to the user target program when it is determined that the signature verification corresponding to the user target program provided by the trusted compilation platform is successful. program segment.

如图7所示,图7是本说明书根据一示例性实施例提供的一种编译装置的框图,该装置可以应用于如图5所示的设备中,以实现本说明书的技术方案。所述装置包括:As shown in FIG. 7 , FIG. 7 is a block diagram of a compiling device provided in this specification according to an exemplary embodiment. The device can be applied to the device shown in FIG. 5 to implement the technical solution of this specification. The devices include:

用户源程序获取单元701,获取用于在可信安全区中执行的用户源程序,所述可信安全区包括第一安全等级的内存段与第二安全等级的内存段,其中,第一安全等级的内存段包括用户数据段与用户程序段,第二安全等级的内存段包括备份数据段与重置程序段,第一安全等级的合法访问范围包括第一安全等级的内存段中的至少一部分内存地址,所述用户程序段中的安全内存访问指令对应的访存地址属于第一安全等级的合法访问范围;The user source program acquisition unit 701 is configured to acquire a user source program for execution in a trusted security zone, the trusted security zone includes a memory segment with a first security level and a memory segment with a second security level, wherein the first security level The memory segment of the first level includes the user data segment and the user program segment, the memory segment of the second security level includes the backup data segment and the reset program segment, and the legal access range of the first security level includes at least a part of the memory segment of the first security level memory address, the memory access address corresponding to the secure memory access instruction in the user program segment belongs to the legal access range of the first security level;

编译单元702,用于将所述用户源程序编译为用户目标程序,以使得所述用户源程序中的内存访问指令转换为所述用户目标程序中相应的安全内存访问指令;A compiling unit 702, configured to compile the user source program into a user target program, so that memory access instructions in the user source program are converted into corresponding secure memory access instructions in the user target program;

用户目标程序加载单元703,用于将所述用户目标程序加载至所述用户程序段,以由所述可信安全区响应于任务请求进行重置后执行所述用户程序段中的所述用户目标程序;其中,对所述可信安全区进行重置包括:执行所述重置程序段中的可信安全区重置函数,将所述备份数据段中存储的内存备份覆盖至第一安全等级的合法访问范围对应的内存空间,所述内存备份包括用于覆盖至所述用户数据段的用户数据段备份。A user target program loading unit 703, configured to load the user target program into the user program segment, so as to execute the user program segment in the user program segment after being reset by the trusted security zone in response to a task request. The target program; wherein, resetting the trusted security zone includes: executing the trusted security zone reset function in the reset program segment, and overwriting the memory backup stored in the backup data segment to the first security zone The memory space corresponding to the legal access scope of the level, the memory backup includes the user data segment backup used to overwrite the user data segment.

上述装置实施例与前述方法实施例相对应,不存在本质上的差异,前文针对图1与图4所示实施例的描述,均适用于图6与图7所示的实施例,这里不再赘述。The above-mentioned device embodiment corresponds to the foregoing method embodiment, and there is no essential difference. The foregoing descriptions for the embodiments shown in FIG. 1 and FIG. 4 are applicable to the embodiments shown in FIG. 6 and FIG. repeat.

如图8所示,图8是本说明书根据一示例性实施例提供的一种可信计算系统的系统架构图。所述可信计算系统包括一个前端可信安全区与至少一个后端可信安全区,其中:As shown in FIG. 8 , FIG. 8 is a system architecture diagram of a trusted computing system provided in this specification according to an exemplary embodiment. The trusted computing system includes a front-end trusted security zone and at least one back-end trusted security zone, wherein:

所述前端可信安全区用于接收客户端发送的任务请求,并将该任务请求转发至对应的后端可信安全区,以及将该后端可信安全区返回的针对该任务请求的执行结果发送至所述客户端;The front-end trusted security zone is used to receive the task request sent by the client, forward the task request to the corresponding back-end trusted security zone, and execute the task request returned by the back-end trusted security zone The result is sent to the client;

任一后端可信安全区用于在接收到所述前端可信安全区发送的任务请求的情况下执行如前述任一基于可信安全区的请求处理方法,并将执行用户目标程序所生成的执行结果返回至所述前端可信安全区。Any back-end trusted security zone is used to execute the request processing method based on any of the aforementioned trusted security zones when receiving the task request sent by the front-end trusted security zone, and will execute the user target program generated The execution result of is returned to the front-end trusted security zone.

如图8所示,可选计算系统中的前端可信安全区不需要承担执行可信计算任务的职能,而只作为客户端与后端可信安全区之间的中转站,真正执行可信计算任务的职能则由多个后端可信安全区承担。作为可信计算系统外部的客户端只与前端可信安全区建立信任关系并进行对接,而无需直接与多个用于执行不同可信计算任务的后端可信安全区建立信任关系,因此提高了客户端的便利性;同时,多个后端可信安全区只需要与前端可信安全区建立信任关系并对接,而无需直接面向不同的客户端与不同的客户端分别建立信任关系,因此在系统层面大大减小了网络连接和信任关系的维护成本。As shown in Figure 8, the front-end trusted security zone in the optional computing system does not need to undertake the function of performing trusted computing tasks, but only serves as a transfer station between the client and the back-end trusted security zone to truly perform trusted computing tasks. The functions of computing tasks are undertaken by multiple back-end trusted security zones. As a client outside the trusted computing system, it only establishes a trust relationship with the front-end trusted security zone and docks, without directly establishing a trust relationship with multiple back-end trusted security zones for performing different trusted computing tasks, thus improving At the same time, multiple back-end trusted security zones only need to establish a trust relationship with the front-end trusted security zone and do not need to directly establish trust relationships with different clients. Therefore, in The system level greatly reduces the maintenance cost of network connection and trust relationship.

本说明书实施例所涉及的可信计算系统中的后端可信安全区在处理任务请求时,通过前述的基于可信安全区的请求处理方法完成了快速且安全地重启过程,进而能够快速响应并执行任务请求对应的可信计算任务,同时,后端可信安全区采用的按照安全等级分段的安全策略也能够确保用于执行可信计算任务的用户目标程序难以从内部破坏可信安全区的安全性。When the back-end trusted security zone in the trusted computing system involved in the embodiment of this specification processes task requests, it completes the fast and safe restart process through the aforementioned request processing method based on the trusted security zone, and can respond quickly And execute the trusted computing task corresponding to the task request. At the same time, the security policy adopted by the back-end trusted security zone according to the security level can also ensure that the user target program used to execute the trusted computing task is difficult to destroy the trusted security from the inside. area security.

本说明书实施例中涉及后端可信安全区处理任务请求的过程可以参见前文实施例的描述,这里不再赘述。For the process of processing the task request in the back-end trusted security zone in the embodiment of this specification, please refer to the description of the previous embodiment, and details will not be repeated here.

在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device, PLD)(例如现场可编程门阵列(Field Programmable GateArray,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware DescriptionLanguage)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(RubyHardware Description Language)等,目前最普遍使用的是VHDL(Very-High-SpeedIntegrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。In the 1990s, the improvement of a technology can be clearly distinguished as an improvement in hardware (for example, improvements in circuit structures such as diodes, transistors, switches, etc.) or improvements in software (improvement in method flow). However, with the development of technology, the improvement of many current method flows can be regarded as the direct improvement of the hardware circuit structure. Designers almost always get the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that the improvement of a method flow cannot be realized by hardware physical modules. For example, a programmable logic device (Programmable Logic Device, PLD) (such as a field programmable gate array (Field Programmable GateArray, FPGA)) is such an integrated circuit, the logic function of which is determined by the user programming of the device. It is programmed by the designer to "integrate" a digital system on a PLD, instead of asking a chip manufacturer to design and make a dedicated integrated circuit chip. Moreover, nowadays, instead of making integrated circuit chips by hand, this kind of programming is mostly realized by "logic compiler (logic compiler)" software, which is similar to the software compiler used when writing programs. The original code of the computer must also be written in a specific programming language, which is called a hardware description language (Hardware Description Language, HDL), and there is not only one kind of HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language) , AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., currently the most commonly used is VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. It should also be clear to those skilled in the art that only a little logical programming of the method flow in the above-mentioned hardware description languages and programming into an integrated circuit can easily obtain a hardware circuit for realizing the logic method flow.

控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20 以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。The controller may be implemented in any suitable way, for example, the controller may take the form of a microprocessor or a processor and a computer readable medium storing computer readable program code (such as software or firmware) executable by the (micro)processor , logic gates, switches, Application Specific Integrated Circuits (ASICs), programmable logic controllers, and embedded microcontrollers, examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that, in addition to realizing the controller in a purely computer-readable program code mode, it is entirely possible to make the controller use logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded The same function can be realized in the form of a microcontroller or the like. Therefore, such a controller can be regarded as a hardware component, and the devices included in it for realizing various functions can also be regarded as structures within the hardware component. Or even, means for realizing various functions can be regarded as a structure within both a software module realizing a method and a hardware component.

上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为服务器系统。当然,本发明不排除随着未来计算机技术的发展,实现上述实施例功能的计算机例如可以为个人计算机、膝上型计算机、车载人机交互设备、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present invention does not exclude that with the development of computer technology in the future, the computer that realizes the functions of the above embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant , media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.

虽然本说明书一个或多个实施例提供了如实施例或流程图所述的方法操作步骤,但基于常规或者无创造性的手段可以包括更多或者更少的操作步骤。实施例中列举的步骤顺序仅仅为众多步骤执行顺序中的一种方式,不代表唯一的执行顺序。在实际中的装置或终端产品执行时,可以按照实施例或者附图所示的方法顺序执行或者并行执行(例如并行处理器或者多线程处理的环境,甚至为分布式数据处理环境)。术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、产品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、产品或者设备所固有的要素。在没有更多限制的情况下,并不排除在包括所述要素的过程、方法、产品或者设备中还存在另外的相同或等同要素。例如若使用到第一,第二等词语用来表示名称,而并不表示任何特定的顺序。Although one or more embodiments of the present specification provide the operation steps of the method described in the embodiment or the flowchart, more or fewer operation steps may be included based on conventional or non-inventive means. The sequence of steps enumerated in the embodiments is only one of the execution sequences of many steps, and does not represent the only execution sequence. When executed by an actual device or terminal product, the methods shown in the embodiments or drawings can be executed sequentially or in parallel (such as a parallel processor or multi-thread processing environment, or even a distributed data processing environment). The term "comprising", "comprising" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, product, or apparatus comprising a set of elements includes not only those elements, but also other elements not expressly listed elements, or also elements inherent in such a process, method, product, or apparatus. Without further limitations, it is not excluded that there are additional identical or equivalent elements in a process, method, product or device comprising said elements. For example, if the words first, second, etc. are used, they are used to indicate names and do not indicate any specific order.

为了描述的方便,描述以上装置时以功能分为各种模块分别描述。当然,在实施本说明书一个或多个时可以把各模块的功能在同一个或多个软件和/或硬件中实现,也可以将实现同一功能的模块由多个子模块或子单元的组合实现等。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。For the convenience of description, when describing the above devices, functions are divided into various modules and described separately. Of course, when implementing one or more of this specification, the functions of each module can be realized in the same or more software and/or hardware, and the modules that realize the same function can also be realized by a combination of multiple submodules or subunits, etc. . The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.

本发明是参照根据本发明实施例的方法、装置(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each procedure and/or block in the flowchart and/or block diagram, and combinations of procedures and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a Means for realizing the functions specified in one or more steps of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart flow or flows and/or block diagram block or blocks.

在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.

内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read only memory (ROM) or flash RAM. Memory is an example of computer readable media.

计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储、石墨烯存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information. Information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission medium that can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.

本领域技术人员应明白,本说明书一个或多个实施例可提供为方法、系统或计算机程序产品。因此,本说明书一个或多个实施例可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书一个或多个实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that one or more embodiments of this specification may be provided as a method, system or computer program product. Accordingly, one or more embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of the present description may employ a computer program embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein. The form of the product.

本说明书一个或多个实施例可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本本说明书一个或多个实施例,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。One or more embodiments of this specification may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. One or more embodiments of the present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including storage devices.

本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本说明书的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。Each embodiment in this specification is described in a progressive manner, the same and similar parts of each embodiment can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for relevant parts, refer to part of the description of the method embodiment. In the description of this specification, descriptions referring to the terms "one embodiment", "some embodiments", "example", "specific examples", or "some examples" mean that specific features described in connection with the embodiment or example , structures, materials or features are included in at least one embodiment or example of this specification. In this specification, the schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the described specific features, structures, materials or characteristics may be combined in any suitable manner in any one or more embodiments or examples. In addition, those skilled in the art can combine and combine different embodiments or examples and features of different embodiments or examples described in this specification without conflicting with each other.

以上所述仅为本说明书一个或多个实施例的实施例而已,并不用于限制本本说明书一个或多个实施例。对于本领域技术人员来说,本说明书一个或多个实施例可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在权利要求范围之内。The above description is only an example of one or more embodiments of this specification, and is not intended to limit one or more embodiments of this specification. For those skilled in the art, various modifications and changes may occur in one or more embodiments of this description. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this specification shall be included in the scope of the claims.

Claims (25)

1. A request processing method based on a trusted security zone comprises a memory segment with a first security level and a memory segment with a second security level, wherein the memory segment with the first security level comprises a user data segment and a user program segment, the memory segment with the second security level comprises a backup data segment and a reset program segment, and a legal access range of the first security level comprises at least one part of memory addresses in the memory segment with the first security level; the method comprises the following steps:
responding to a task request, executing a trusted security zone reset function in the reset program segment, and covering a memory backup stored in the backup data segment to a memory space corresponding to a legal access range of a first security level, wherein the memory backup comprises a user data segment backup covered to the user data segment;
after the execution of the reset function of the trusted safe area is finished, executing a user target program compiled by a user source program in the user program section; and compiling a memory access instruction in the user source program into a corresponding safe memory access instruction in the user target program, wherein a memory access address corresponding to the safe memory access instruction belongs to a legal access range of a first safety level.
2. The method of claim 1, wherein the overwriting the memory backup stored in the backup data segment to a memory space corresponding to a legal access range of a first security level comprises:
starting a user authority hardware instruction, and reallocating memory access authority to the memory space corresponding to the legal access range of the first security level through the user authority hardware instruction;
and covering the memory backup stored in the backup data segment to a memory space corresponding to a legal access range of a first security level, and forbidding the user authority hardware instruction after the memory backup is completed.
3. The method of claim 1, the memory backup further comprising a user program segment backup for overwriting the user program segment.
4. The method of claim 1, further comprising:
and responding to the task request, and returning an execution result corresponding to the task request generated by executing the user target program to an initiator of the task request.
5. The method of claim 1, further comprising:
and responding to a backup request or under the condition that the trusted security zone finishes cold start, executing a trusted security zone backup function in the reset program segment, and storing data in a legal access range of a first security level as the memory backup to the backup data segment.
6. The method according to claim 1, wherein the trusted security zone is divided into a plurality of memory blocks connected end to end, the same secure memory access instruction is contained in the same memory block, a security jump point in the trusted security zone is aligned with a start address of any memory block, the security jump point in the trusted security zone includes a loop start address, a conditional branch start address, and a function start address of a non-sensitive function, the trusted security zone includes memory segments of different security levels, the different security levels include at least a first security level and a second security level, wherein an mth security level is higher than an nth security level, and is a positive integer and m > n;
the programs in the trusted security zone comprise the user object program and a system object program compiled from a system source program, the system object program is positioned in a memory segment with a second security level and above, and the system object program comprises a trusted security zone reset function; and compiling the address jump instruction in the user source program into a corresponding safe address jump instruction in the user target program, and/or compiling the address jump instruction in the system source program into a corresponding safe address jump instruction in the system target program, wherein the jump address corresponding to any safe address jump instruction is a starting address of a memory block where an original jump address corresponding to the address jump instruction compiled into any safe address jump instruction is located.
7. The method according to claim 6, wherein any sensitive function in the system object program inserts a halt instruction between a function start address in a memory block occupied by the sensitive function and a start address of the memory block, and the halt instruction is used for triggering system halt when executed.
8. The method according to claim 7, wherein, when at least two memory blocks are occupied by any sensitive function, any sensitive function in the at least two memory blocks is connected by a tag jump instruction.
9. The method according to claim 6, wherein a start address of any memory block is aligned with a function start address of a corresponding security detection function, and the security detection function in any memory block is configured to, when executed:
determining the security level of a jump point memory segment where a security address jump instruction jumping to a security detection function in any memory block is located;
under the condition that the original jump address corresponding to the address jump instruction used for compiling the safe address jump instruction or the starting address of any memory block does not belong to the legal access range of the safety level of the jump point memory segment, triggering the system to stop;
and under the condition that the original jump address or the starting address of any memory block is determined to belong to a legal access range of the security level of the memory segment of the jump point, sequentially executing a next instruction or jumping to the original jump address.
10. The method of claim 1, the trusted secure zone further comprising a memory segment of a third security level, the memory segment of the third security level comprising a key data segment and an attestation program segment, the method further comprising:
executing a nested certification function in the certification program segment in response to a program certification request, and signing to-be-certified data based on a nested certification private key stored in the key data segment to generate a trusted program certification, wherein the to-be-certified data comprises data in the user program segment and/or the reset program segment;
providing the trusted program attestation to an initiator of the program attestation request, and receiving the task request sent if the initiator confirms that the trusted program attestation verifies.
11. The method of claim 10, the nested proof private key being assigned to the key data segment in the trusted secure zone by a key management server upon confirmation that the trusted secure zone is remotely authenticated by a remote authentication server.
12. The method according to claim 1 or 10, wherein the trusted secure zone comprises memory segments of different security levels, the different security levels comprising at least a first security level and a second security level, wherein a legal access range of any security level comprises at least a part of memory addresses in the memory segment of any security level and memory segments lower than any security level, and the m security level is higher than the n security level, is a positive integer and m > n;
the program in the trusted security zone comprises the user target program and a system target program obtained by compiling a system source program, the system target program is in a memory segment with a second security level and above, and the system target program comprises a trusted security zone reset function; and compiling the memory access instruction in the system source program into a corresponding safe memory access instruction in the system target program, wherein the memory access address corresponding to the safe memory access instruction in the memory segment of any safety level belongs to the legal access range of any safety level.
13. The method of claim 12, wherein the memory address of the memory segment with the low security level is higher than the memory segment with the high security level, the legal access range of any security level is an address range higher than the boundary address of any security level, the boundary address of any security level belongs to the memory segment with any security level, and any secure memory access instruction in the memory segment with any security level is used for:
subtracting an original access address corresponding to a memory access instruction used for being compiled into any one of the secure memory access instructions from a boundary address stored in a boundary register, and storing an obtained difference value into an offset register, wherein the boundary address stored in the boundary register is the boundary address of any one of the secure levels;
and taking the addend obtained by adding the absolute difference value stored in the offset register and the boundary address stored in the boundary register as the access address corresponding to any one of the secure memory access instructions, and accessing the memory based on the access address.
14. The method of claim 13, the user object program being arranged to disable invocation of the bound register and the offset register, the bound address stored in the bound register being modifiable only by execution of a bound-modifying function in the system object program.
15. The method according to claim 12, wherein the trusted security zone defines a global legal access scope, and the global legal access scope is set as a legal access scope of any security level when jumping to the memory segment of any security level through legal call logic, otherwise, is set as a legal access scope of a first security level; and the memory access address corresponding to the secure memory access instruction in the memory segment with any security level belongs to the global legal access range.
16. The method of claim 15, wherein the memory address of the memory segment with low security level is higher than that of the memory segment with high security level, the legal access range of any security level is the address range of the boundary address higher than any security level, the boundary address of any security level belongs to the memory segment with any security level, the global legal access range is the boundary address stored in the boundary register, and the legal call logic comprises the call logic realized by the boundary modification function in the system target program;
executing any system function belonging to the system target program and in the memory segment of any security level, including:
calling the boundary modification function to modify the original boundary address stored in the boundary register into the boundary address of any security level;
and calling and executing any system function in the boundary modification function, and modifying the boundary address stored in the boundary register into the primary boundary address after the execution of any system function is completed.
17. The method of claim 16, wherein the memory segment of any security level comprises a corresponding data segment and a program segment having a lower memory address than the data segment, and the boundary address of any security level is used to separate the data segment from the program segment in the memory segment of any security level.
18. The method of claim 16, wherein the boundary address of any security level is set to be inaccessible.
19. The method of claim 1, the user target program being compiled from the user source program by an interpreter in the trusted secure zone; or,
the user target program is obtained by compiling the user source program before running through a trusted compiling platform, and the method further comprises the following steps:
and acquiring the user target program, and loading the user target program to the user program section under the condition that the signature verification corresponding to the user target program provided by the trusted compiling platform is determined to be successful.
20. A compilation method comprising:
the method comprises the steps that a user source program executed in a trusted security zone is obtained, wherein the trusted security zone comprises a memory segment with a first security level and a memory segment with a second security level, the memory segment with the first security level comprises a user data segment and a user program segment, the memory segment with the second security level comprises a backup data segment and a reset program segment, the legal access range of the first security level comprises at least one part of memory addresses in the memory segment with the first security level, and the access address corresponding to a security memory access instruction in the user program segment belongs to the legal access range of the first security level;
compiling the user source program into a user target program so as to convert a memory access instruction in the user source program into a corresponding safe memory access instruction in the user target program;
loading the user target program to the user program segment to execute the user target program in the user program segment after the trusted secure zone is reset in response to a task request; wherein resetting the trusted secure zone comprises: and executing a trusted security zone reset function in the reset program segment, and covering the memory backup stored in the backup data segment to a memory space corresponding to a legal access range of a first security level, wherein the memory backup comprises a user data segment backup used for covering the user data segment.
21. A request processing device based on a trusted security zone, wherein the trusted security zone comprises a memory segment with a first security level and a memory segment with a second security level, the memory segment with the first security level comprises a user data segment and a user program segment, the memory segment with the second security level comprises a backup data segment and a reset program segment, and a legal access range of the first security level comprises at least one part of memory addresses in the memory segment with the first security level; the device comprises:
a resetting unit, configured to execute a trusted security region resetting function in the resetting program segment in response to a task request, and cover a memory backup stored in the backup data segment to a memory space corresponding to a legal access range of a first security level, where the memory backup includes a user data segment backup for covering the user data segment;
the user target program execution unit is used for executing a user target program obtained by compiling a user source program in the user program segment after the execution of the reset function of the trusted security zone is finished; and compiling a memory access instruction in the user source program into a corresponding safe memory access instruction in the user target program, wherein a memory access address corresponding to the safe memory access instruction belongs to a legal access range of a first safety level.
22. A compiling apparatus comprising:
the system comprises a user source program obtaining unit, a trusted security zone and a processing unit, wherein the trusted security zone comprises a memory segment with a first security level and a memory segment with a second security level, the memory segment with the first security level comprises a user data segment and a user program segment, the memory segment with the second security level comprises a backup data segment and a reset program segment, the legal access range of the first security level comprises at least one part of memory addresses in the memory segment with the first security level, and the memory access address corresponding to a security memory access instruction in the user program segment belongs to the legal access range of the first security level;
the compiling unit is used for compiling the user source program into a user target program so as to convert the memory access instruction in the user source program into a corresponding safe memory access instruction in the user target program;
a user target program loading unit, configured to load the user target program into the user program segment, so as to execute the user target program in the user program segment after being reset by the trusted secure area in response to a task request; wherein resetting the trusted secure zone comprises: and executing a trusted security zone reset function in the reset program segment, and covering the memory backup stored in the backup data segment to a memory space corresponding to a legal access range of a first security level, wherein the memory backup comprises a user data segment backup used for covering the user data segment.
23. A trusted computing system comprising a front-end trusted security zone and at least one back-end trusted security zone, wherein:
the front-end trusted security zone is used for receiving a task request sent by a client, forwarding the task request to a corresponding rear-end trusted security zone, and sending an execution result aiming at the task request returned by the rear-end trusted security zone to the client;
any back-end trusted secure zone is used for executing the method according to any one of claims 1-19 when receiving a task request sent by the front-end trusted secure zone, and returning an execution result generated by executing a user target program to the front-end trusted secure zone.
24. An electronic device, comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor implements the method of any one of claims 1-20 by executing the executable instructions.
25. A computer readable storage medium having stored thereon computer instructions which, when executed by a processor, carry out the steps of the method according to any one of claims 1 to 20.
CN202211311423.6A 2022-10-25 2022-10-25 Request processing method, compiling method and trusted computing system Active CN115422554B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211311423.6A CN115422554B (en) 2022-10-25 2022-10-25 Request processing method, compiling method and trusted computing system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211311423.6A CN115422554B (en) 2022-10-25 2022-10-25 Request processing method, compiling method and trusted computing system

Publications (2)

Publication Number Publication Date
CN115422554A CN115422554A (en) 2022-12-02
CN115422554B true CN115422554B (en) 2023-03-24

Family

ID=84207214

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211311423.6A Active CN115422554B (en) 2022-10-25 2022-10-25 Request processing method, compiling method and trusted computing system

Country Status (1)

Country Link
CN (1) CN115422554B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116451235B (en) * 2023-03-27 2024-04-09 亿咖通(湖北)技术有限公司 Memory protection method, device, storage medium and program product

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114625646A (en) * 2022-03-14 2022-06-14 烽火通信科技股份有限公司 Method and device for detecting system memory out-of-bounds

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8099605B1 (en) * 2006-06-05 2012-01-17 InventSec AB Intelligent storage device for backup system
US8001390B2 (en) * 2007-05-09 2011-08-16 Sony Computer Entertainment Inc. Methods and apparatus for secure programming and storage of data using a multiprocessor in a trusted mode
CN104111896B (en) * 2014-07-30 2017-07-14 云南大学 Virtual memory management method and its device in big data processing
WO2016026113A1 (en) * 2014-08-21 2016-02-25 华为技术有限公司 Secure interaction method and device
US10972768B2 (en) * 2019-06-27 2021-04-06 Intel Corporation Dynamic rebalancing of edge resources for multi-camera video streaming
CN114116524A (en) * 2020-08-25 2022-03-01 华为技术有限公司 Method and device for creating secure page table and accessing memory
CN113672237B (en) * 2021-09-03 2022-03-11 支付宝(杭州)信息技术有限公司 Program compiling method and device for preventing memory boundary crossing

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114625646A (en) * 2022-03-14 2022-06-14 烽火通信科技股份有限公司 Method and device for detecting system memory out-of-bounds

Also Published As

Publication number Publication date
CN115422554A (en) 2022-12-02

Similar Documents

Publication Publication Date Title
KR101503785B1 (en) Method And Apparatus For Protecting Dynamic Library
US10114958B2 (en) Protected regions
EP3123311B1 (en) Malicious code protection for computer systems based on process modification
JP6248153B2 (en) Activate trust level
TWI570589B (en) Apparatus for providing trusted computing
CN105022954B (en) Soar tri-state operation system security kernel service dynamic operation method on CPU
RU2439665C2 (en) Compilation of executable code in less trustworthy address space
CN103329139B (en) Systems and methods for supporting JIT in a secure system with randomly assigned memory ranges
JP5114617B2 (en) Secure terminal, program, and method for protecting private key
US8478973B2 (en) System and method for providing a secure application fragmentation environment
US9594915B2 (en) Information processing apparatus
CN105760773A (en) System and method of controlling opening of file by vulnerable application
CN112818327B (en) TrustZone-based user-level code and data security and credibility protection method and device
US11336444B2 (en) Hardware security module for verifying executable code, device having hardware security module, and method of operating device
JP5346608B2 (en) Information processing apparatus and file verification system
WO2009107330A1 (en) Information processor and method for controlling the same
US8812873B2 (en) Secure execution of a computer program using binary translators
US10628611B2 (en) Exclusive execution environment within a system-on-a-chip computing system
CN107092824B (en) Application program running method and device
CN112182560B (en) Efficient isolation methods, systems and media for Intel SGX internals
CN107735790B (en) Apparatus and method for transitioning between secure and less secure areas
KR102579861B1 (en) In-vehicle software update system and method for controlling the same
CN115422554B (en) Request processing method, compiling method and trusted computing system
KR101203722B1 (en) Apparatus and method for data protection
EP3440586B1 (en) Method for write-protecting boot code if boot sequence integrity check fails

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载