WO2019237865A1 - 一种数据保护方法及计算装置 - Google Patents

一种数据保护方法及计算装置 Download PDF

Info

Publication number
WO2019237865A1
WO2019237865A1 PCT/CN2019/086497 CN2019086497W WO2019237865A1 WO 2019237865 A1 WO2019237865 A1 WO 2019237865A1 CN 2019086497 W CN2019086497 W CN 2019086497W WO 2019237865 A1 WO2019237865 A1 WO 2019237865A1
Authority
WO
WIPO (PCT)
Prior art keywords
stack
data
field information
instruction
register
Prior art date
Application number
PCT/CN2019/086497
Other languages
English (en)
French (fr)
Inventor
杨力祥
Original Assignee
杨力祥
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 杨力祥 filed Critical 杨力祥
Publication of WO2019237865A1 publication Critical patent/WO2019237865A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/55Detecting local intrusion or implementing counter-measures
    • G06F21/56Computer malware detection or handling, e.g. anti-virus arrangements
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/55Detecting local intrusion or implementing counter-measures
    • G06F21/56Computer malware detection or handling, e.g. anti-virus arrangements
    • G06F21/562Static detection
    • G06F21/563Static detection by source code analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/55Detecting local intrusion or implementing counter-measures
    • G06F21/56Computer malware detection or handling, e.g. anti-virus arrangements
    • G06F21/566Dynamic detection, i.e. detection performed at run-time, e.g. emulation, suspicious activities
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/604Tools and structures for managing or administering access control systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms
    • G06F9/4486Formation of subprogram jump address
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2221/00Indexing scheme relating to security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F2221/03Indexing scheme relating to G06F21/50, monitoring users, programs or devices to maintain the integrity of platforms
    • G06F2221/034Test or assess a computer or a system

Definitions

  • the present application relates to the field of information technology, and in particular, to a data protection technology, and in particular to a technology in which specific data accessed by a CPU or a CPU automatically saves data in a memory to prevent data from being tampered with, particularly a protection technology related to a return address .
  • the function call instruction pushes the address that needs to be returned after the call is completed, so that the function call can return to the original execution order.
  • One attack method is to overwrite the address of the function pushed onto the stack and write to another address through stack overflow and other methods, so that when the code returns, it will jump to the address written by the attack program, and the attack program will reach The purpose of changing the program execution order.
  • the purpose of the present invention is to save the information that needs to be saved back to the scene no longer in the stack, but to save it in a separate storage area, avoid mixing with other data, and make other programs and instructions unable to modify the saved information, thereby Guarantee the accuracy of this information. In this way, the attacker cannot change the execution order by changing the return address.
  • the present invention discloses a method for preventing a new execution order from occurring Non-design intent execution techniques.
  • the return address of the branch instruction is protected to prevent a new execution sequence from being generated.
  • the invention discloses a data protection method, which is characterized by including:
  • the independent storage area in the step A is only used to store data related to the on-site protection of the transfer instruction or interrupt; in terms of functions or space, this storage area is independent of the pages that have been allocated for storing code, global data, and stack data. .
  • the CPU When the CPU needs to save the current state information, it includes a function call or when an interrupt occurs; when the CPU needs to fetch the saved data, it includes a function call or an interrupt return.
  • the independent storage area may be set in a memory or other CPU-addressable areas with storage functions.
  • the independent storage area is set in a memory in a stack manner.
  • the storage area to which the data belongs is used to store data generated by operations that require on-site protection, such as calling and interrupting, hereinafter referred to as on-site information stack.
  • on-site information stack data generated by operations that require on-site protection, such as calling and interrupting, hereinafter referred to as on-site information stack.
  • the original stack is called a data stack, which is used to store data such as local variables and parameters.
  • the field information stack and the data stack exist simultaneously.
  • the data stack can also store the return address or leave this location blank, but it is not used for any purpose.
  • the return address stored by the field information stack is the effective CPU's actual jump target.
  • the field information stack is characterized in that an ass register and an aesp register are added, which are respectively used to save a segment selector of the field information stack and a top pointer of the field information stack.
  • the data stack can be implemented with an existing stack in the system.
  • the step B further includes: when the data to be saved is pushed onto the field information stack, the value of the aesp register is automatically decremented, and the decrement value is the total length of the written data; the step C further includes: from the field information stack; When popping data, the value of the aesp register is automatically accumulated, and the accumulated value is the sum of the length of the popped data;
  • the independent storage area refers to a field information stack.
  • the pushadr instruction is used to push a data into the field information stack, and the aesp automatically points to the top of the new stack; the popadr instruction is used to pop a data from the field information stack, and the aesp automatically points to the new The top of the stack.
  • the calling instruction is modified, and the modified calling instruction pushes the return address into the field information stack, and modifies the value of aesp, and saves the parameters and local variables in the data stack.
  • the modified call instruction pushes the return address into the field information stack, and modifies the value of aesp.
  • Parameters, local variables, and return addresses are stored in the data stack.
  • the return instruction is modified.
  • the modified normal return instruction pops the return address from the field information stack and modifies the value of aesp.
  • Modify the interrupt return instruction The modified interrupt return instruction pops up from the scene information stack to save the scene data and modify the value of aesp.
  • the steps of writing the data to be saved to the field information stack include:
  • Step B1.1 further includes:
  • the processor obtains the management information of the data stack and the field information stack from the task status management structure of the current task, and accordingly presses the status information of the interrupt routine into the field information stack, and pushes the remaining information into the data stack.
  • steps a, b, and c are implemented by steps a, b, and c:
  • the processor obtains the segment selector and stack pointer of the data stack and field information stack from the tss of the current task. Push the stack segment selector and stack pointer of the interrupt routine's data stack and field information stack into the new field information stack, namely ss0, esp0 and ass0, aesp0;
  • the processor then saves the current values of the EFLAGS register, CS register, and EIP register into the new field information stack;
  • Step B1.2 further includes:
  • the processor pushes the status information of the interrupt routine into the current field information stack and the rest of the information into the current data stack.
  • the processor saves the current EFLAGS register, CS register and EIP register values in the current field information stack;
  • the step of fetching data from the field information stack includes:
  • step C1 is performed in step C, which specifically includes:
  • step C2 is performed in step C, which specifically includes:
  • step B2 When a call gate occurs and key data needs to be accessed in the stack, step B2 is performed.
  • the specific steps include:
  • a There are two stacks for each privilege level. One is a data stack, which is used to save local data and pass parameters. The other is a new field information stack of this design, which is used to save the data that the CPU needs to push in to perform an operation , Such as the return address.
  • a data stack which is used to save local data and pass parameters.
  • the other is a new field information stack of this design, which is used to save the data that the CPU needs to push in to perform an operation , Such as the return address.
  • Use the DPL of the target code segment that is, the new CPL, 0
  • TSS that is, ss0, esp0 and ass0, aesp0.
  • segment selector and stack pointer of the data stack to be switched from the current TSS, that is, ss0 and esp0; and the segment selector of the field information stack and the field information stack pointer, ass0 and aesp0.
  • the present invention also design a new page attribute, as a selective read-only page, when the CPU saves and retrieves data in the above manner, it is not limited to read-only, and can be written to the storage area normally.
  • Data including: push stack, pop stack, and other ordinary instructions when accessing this storage area are as if accessing a read-only page.
  • the page corresponding to the independent storage area established in the step A may be conditionally read-only protected.
  • the conditional read-only protection refers to a group of instructions dedicated to writing and reading the page. This group of instructions Access to the page is not restricted to read-only; other instructions can only access the page according to the read-only attribute.
  • the specific instructions or actions that are not restricted to read-only include call instructions, pushadr instructions, popadr instructions, ordinary return instructions, interrupt return instructions, call gate execution, and information to be saved when the interrupt gate is executed.
  • the conditional read-only protection includes an existing data transfer instruction, an operation instruction and other instructions that can directly change the value of the memory.
  • the memory area is read-only protected;
  • a selective read-only implementation is:
  • a safety CPU is characterized in that special registers are added to control the field information stack. For example, in the IA-32 architecture, ass and aesp registers are newly added to save the segment selector and the field of the field information stack. The top pointer of the information stack; the field information stack is used to store the return address.
  • the pushadr instruction is used to push a data into the field information stack, and the aesp automatically points to the top of the new stack;
  • the popadr instruction is used to pop an address from the field information stack, and the aesp automatically points to the new The top of the stack.
  • the calling instruction is modified.
  • the modified calling instruction pushes the return address into the field information stack, the parameters and local variables are stored in the data stack, and the value of aesp is modified.
  • the ordinary return instruction is modified, and the modified ordinary return instruction pops the return address from the field information stack and modifies the value of aesp.
  • a read-only selection bit is set in a special register or a flag register, indicating whether the current CPU is legally writing data to the field information stack; at the same time, several independent items such as "read-write, read-only, instruction" in the TLB are independent. On the basis of the column, a "selective read-only" flag is added. When the TLB accesses such a page, it determines whether the backup bit in the flag register is 1, if it is 1, it can be rewritten, and if it is not 1, it is reported. abnormal.
  • the data to be saved is pushed into the field information stack, and the value of the aesp register is automatically decremented, and the decrement value is the total length of the written data;
  • the value of the aesp register is automatically accumulated, and the accumulated value is the total length of the popped data.
  • the invention can prevent the return value of the function call or the address value returned by the interruption from being overwritten, and a new execution order is generated in the program, thereby causing an attack.
  • the present invention can prevent the state information when the interrupt is generated from being overwritten and cause the program execution to be chaotic after the interrupt returns.
  • read-only pages can ensure that the data in them is not overwritten.
  • the page cache needs to be refreshed, which will greatly reduce the efficiency of program execution.
  • the present invention can be achieved by establishing selective read-only pages, that is, to ensure that protected data is not overwritten, and the cache is not required to be refreshed frequently. Reduced efficiency.
  • Figure 1 Field information stack and data stack
  • the present invention proposes a method for protecting specific data accessed by the CPU, in particular to prevent calling instructions from returning address data and / or interrupts
  • the method of returning information and / or process switching scene information is modified.
  • a data protection method includes:
  • the independent storage area in the step A is only used to store data directly related to non-sequential execution; in terms of function or space, this storage area is independent of pages that have been allocated for storing code, global data, and stack data .
  • the non-sequential execution includes: function call, interrupt, and process switching.
  • the CPU When the CPU needs to save the current state information, it includes a function call and / or when an interrupt occurs and / or a process switch; when the CPU needs to fetch the saved data, it includes a function return and / or an interrupt return and / or a process switch.
  • the independent storage area may be set in a memory, or may be set in an area that is addressable by other CPUs and has a storage function.
  • the independent storage area may be set in a stack manner in the memory.
  • Figure 1 shows a specific embodiment. Privilege levels are common in modern CPU architectures, where operating systems usually run at 0 privilege level. Naturally, the code corresponding to system calls and interrupt response programs are also usually run at 0 privilege level as part of the operating system, and applications usually run At 3 privilege levels. In this embodiment, the operating system code runs at 0 privilege level, and the application program code runs at 3 privilege level.
  • each task has a separate stack for each privilege level, which is usually used to save parameters and local data, and the return address of the function is also stored in it.
  • the present invention also includes a stack with similar functions, which is called a data stack, as shown in the left side of FIG. 1. Among them, 0 privilege level and 3 privilege level each have a corresponding data stack, and local variables are stored thereon. , Function call parameters, and function return addresses.
  • the present invention further sets up a stack in memory for each privilege level of each task, for storing the return address.
  • the stack dedicated to holding the return address can be called a field information stack, as shown in the right side of FIG. 1.
  • the field information stack is allocated by the operating system when the task or process is created. When the function returns, the CPU will take the function return address from the field information stack, not the data stack, and pass it to the EIP register as a valid one.
  • the return address stored in the data stack will not be used for any purpose, and the return address of the field information stack is the effective target of the actual CPU jump.
  • two registers may be added for saving the field selector of the field information stack and the top pointer of the field information stack:
  • aesp Stores the top address value of the field information stack.
  • the step B further includes:
  • the step C further includes:
  • the value of the aesp register is automatically accumulated, and the accumulated value is the total length of the popped data.
  • the instructions of the CPU can also be improved as follows.
  • the pushADR instruction is used to push a data into the field information stack, and aesp automatically points to the new stack top.
  • the popADR instruction is used to pop an address from the field information stack, and aesp automatically points to the top of the new stack.
  • the above two instructions are the basic instructions for operating the field information stack, which are very similar to the functions of the push instruction and the pop instruction.
  • the push and pop operations operate on the data stack, and the top pointer of the stack accompanying the change is esp, where the value of the esp register automatically executes the push instruction Decrement, correspondingly, when the pop instruction is executed, the value of the esp register is automatically accumulated.
  • the pushadr and popadr instructions operate the field information stack, and the top pointer of the stack accompanying the change is aesp. Among them, the value of the aesp register is automatically decremented when the pushadr instruction is executed, and the value of the aesp register is automatically accumulated when the popadr instruction is executed.
  • the call instruction of the existing system has the following functions:
  • the call instruction pushes local variables, parameters, and return addresses into the stack, and the esp register decreases accordingly according to the size of the pushed data.
  • the modified calling instruction of the present invention has the following functions:
  • the modified call instruction in the present invention pushes the return address into the field information stack, and the parameters and local variables are stored in the data stack.
  • the modified call instruction pushes the return address into the field information stack, and the parameters, local variables, and return address are stored in The data stack.
  • the ordinary return instruction also needs to be modified.
  • the existing ret instruction has the following functions:
  • the ret exp command has the following functions:
  • the ret instruction automatically pops the return address from the stack according to the esp, and modifies the value of the esp.
  • the ordinary return instruction has the following functions:
  • the ret exp command has the following functions:
  • the modified ordinary return instruction pops the return address from the field information stack and modifies the value of aesp.
  • interrupt and its corresponding return will also cause the CPU to access data in the stack, and these data also have the risk of being attacked.
  • the information to be saved is also stored in the field information stack.
  • the information to be saved is also stored in the field information stack.
  • it can be achieved by:
  • step B1 when an interruption occurs, step B1 is performed, which specifically includes:
  • step B1. Compare the privilege level of the processing routine to be executed with the current privilege level. If the privilege level of the processing routine to be executed is less than the current privilege level, execute step B1.1;
  • Step B1.1 further includes:
  • the processor obtains the segment selector and stack pointer of the data stack and field information stack from the tss of the current task. Push the stack segment selector and stack pointer of the interrupt routine's data stack and field information stack into the new field information stack, namely ss0, esp0 and ass0, aesp0;
  • the processor then saves the current values of the EFLAGS register, CS register, and EIP register into the new field information stack;
  • Step B1.2 further includes:
  • the processor saves the current EFLAGS register, CS register and EIP register values in the current field information stack;
  • Step C further includes:
  • step B1 If in step B1, step B1.1 is selected for execution, step C1 is performed in step C, further including:
  • step B2 If in step B1, step B1.2 is selected for execution, then step C2 is performed in step C, further including:
  • the present invention can also propose corresponding improvements to the above mechanisms, which specifically include:
  • the present invention also includes a new page access mode, which is characterized by setting a page attribute as conditional read-only.
  • the page corresponding to the independent storage area established in the step A may be conditionally read-only protected.
  • conditional read-only refers to a group of instructions dedicated to writing and reading the page, and the group of instructions can access the page without being restricted by read-only; other instructions can only be accessed according to the read-only attribute The page.
  • conditional read-only protection includes an existing data transfer instruction, an operation instruction and other instructions that can directly change the value of the memory.
  • the memory area is accessed, the memory area is read-only protected;
  • the read-only restriction is not restricted.
  • the specific instructions or actions that are not restricted to read-only include: a call instruction, a pushadr instruction, a popadr instruction, executing a call gate, and writing information to be saved when an interrupt gate is executed.
  • conditional read-only protection further includes:
  • the CPU executes the above instruction or CPU behavior, it can write data to the above storage area without being restricted by read-only.
  • TLB is often used to improve the efficiency of memory reads and writes to avoid frequently reading the attributes in the page table into main memory. Therefore, selective read-only needs to be reflected in the TLB.
  • a bit in a special register or a flag register indicates whether the current CPU is legally writing data to the field information stack.
  • the legal ways to write data to the field information stack include: call instructions; pushadr instructions; save information when using a call gate; save information when using an interrupt gate.
  • the TLB contains several independent columns such as "read-write, read-only, and instruction", and a "selective read-only” is added, that is, pages whose page type is marked as “selectively read-only” are recorded in this column.
  • TLB visits such a page, it determines whether the backup bit in the above flag register is 1, if it is 1, it can be rewritten, if it is not 1, it reports an exception.
  • a safety CPU is characterized in that ass and aesp registers are newly added to store segment selectors of the field information stack and top pointers of the field information stack, respectively; the field information stack is used to store a return address.
  • pushadr and popadr instructions where the pushadr instruction is used to push a data into the field information stack, aesp automatically points to the new top of the stack; the popadr instruction is used to pop an address from the field information stack, and the aesp automatically points to the new top of the stack .
  • the modified call instruction pushes the return address into the field information stack, and the parameters and local variables are stored in the data stack.
  • Modify the ordinary return instruction pops the return address from the field information stack and modifies the value of aesp.
  • the modified ordinary return instruction pops the return address from the field information stack and modifies the value of aesp.
  • a secure CPU which is characterized by:
  • the value of the aesp register is automatically decremented, and the decrement value is the total length of the written data
  • the value of the aesp register is automatically accumulated, and the accumulated value is the sum of the length of the popped data;
  • the independent storage area refers to a field information stack.
  • a secure CPU characterized in that when the CPU needs to save the current state information due to an interrupt, compare the privilege level of the processing routine to be executed with the current privilege level, if the privilege level of the processing routine to be executed is less than the current privilege Level, go to step B1.1, if the same, go to step B1.2;
  • Step B1.1 further includes:
  • the processor obtains the segment selector and stack pointer of the data stack and field information stack from the tss of the current task. Push the stack segment selector and stack pointer of the interrupt routine's data stack and field information stack into the new field information stack, namely ss0, esp0 and ass0, aesp0;
  • the processor then saves the current values of the EFLAGS register, CS register, and EIP register into the new field information stack;
  • Step B1.2 further includes:
  • the processor saves the current EFLAGS register, CS register and EIP register values in the current field information stack;

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • Virology (AREA)
  • Automation & Control Theory (AREA)
  • Databases & Information Systems (AREA)
  • Executing Machine-Instructions (AREA)
  • Storage Device Security (AREA)

Abstract

本发明公开了一种CPU访问的特定数据的保护方法,涉及信息技术,特别是信息安全领域,特别涉及一种转移指令返回地址的保护方法,所述方法采用现场信息栈保存调用、中断等需要现场保护的操作产生的数据;增设ass寄存器和aesp寄存器,分别用于保存现场信息栈的段选择子和现场信息栈的栈顶指针;增设pushadr和popadr指令,其中pushadr指令用于向现场信息栈内压入一个地址,aesp自动指向新的栈顶;popadr指令用于从现场信息栈内弹出一个地址,aesp自动指向新的栈顶。应用本发明提供的方案,可以防止由于函数调用的返回值或中断返回的地址值被覆盖,而在程序中产生新的执行序,进而产生攻击。

Description

一种数据保护方法及计算装置 技术领域
本申请涉及信息技术领域,特别涉及一种数据保护技术,尤其涉及一种CPU访问的特定数据或CPU自动在内存中保存数据,防止数据被篡改的技术,特别是一种涉及返回地址的保护技术。
背景技术
现有技术中,函数调用指令会将调用完成后需要返回的地址压入栈中,使得函数调用完成后还能回到原来的执行序中。一种攻击手段就是通过栈溢出等方式,将压入栈中的函数地址覆盖,写入别的地址,这样代码在返回的时候就会跳转到攻击程序写入的地址,攻击程序就达到了更改程序执行序的目的。
除函数调用外,在中断、进程切换等操作中,也会将包括返回地址在内的信息写入栈中,如果被攻击程序改写返回地址,一样会导致执行序发生改变。
本发明的目的是使需要保存的返回现场的信息不再保存在栈中,转而保存在独立的存储区中,避免与其它数据混存,并使其它程序、指令无法修改保存的信息,从而保证这些信息的正确性。这样攻击程序就无法通过更改返回地址的方式更改执行序。
发明内容
针对现有技术中攻击者可以通过修改保存在栈中的返回地址,引发有利于 攻击的执行序,进而获得超越授权的问题,本发明公开了一种防止产生新的执行序的方法,防止产生非设计意图之外执行序的技术。
优选的,通过对转移指令的返回地址进行保护,防止产生新的执行序。
本发明公开了一种数据保护方法,其特征在于,包括:
A.设立独立存储区;
B.当CPU需要保存当前状态信息时,将需要保存的数据写入所述独立存储区;
C.当CPU需要取出所述保存的数据时,从所述独立存储区中取出数据。
所述A步骤中独立存储区仅用于存储与转移指令或中断的现场保护相关的数据;在功能或空间上,此存储区与已经被分配用于存储代码、全局数据、栈数据的页面独立。
所述CPU需要保存当前状态信息时包括函数调用或发生中断时;所述CPU需要取出所述保存的数据时包括函数调用或中断返回时。
所述独立存储区可以选择在内存或其他CPU可寻址的具备存储功能的区域中设置。
优选的,所述独立存储区在内存中以栈的方式设置。
优选的,所属存储区用于保存调用、中断等需要现场保护的操作产生的数据,以下简称为现场信息栈。为了区别原有的栈,将原有栈称为数据栈,用于保存局部变量、参数等数据。现场信息栈与数据栈同时存在。
为了兼容性,所述数据栈上也可同样存储返回地址或将该位置置空保留, 但不做任何用途,现场信息栈存储的返回地址才是有效的CPU实际进行跳转的目标。
所述现场信息栈,其特征在于:增设ass寄存器和aesp寄存器,分别用于保存现场信息栈的段选择子和现场信息栈的栈顶指针。
优选的,数据栈可用系统中现有的栈实现。
所述步骤B进一步包括:将需要保存的数据压入现场信息栈时,aesp寄存器的值自动递减,递减值为写入数据的长度总和;所述步骤C进一步包括:从所述现场信息栈中弹出数据时,aesp寄存器的值自动累加,累加值为弹出数据的长度总和;
所述独立存储区是指现场信息栈。
进一步的,增设pushadr和popadr指令,其中pushadr指令用于向现场信息栈内压入一个数据,aesp自动指向新的栈顶;popadr指令用于从现场信息栈内弹出一个数据,aesp自动指向新的栈顶。
进一步的,对调用指令进行修改,修改后的调用指令将返回地址压入现场信息栈,并修改aesp的值,参数和局部变量保存在数据栈。
优选的,为了更好的兼容现有的程序,修改后的调用指令将返回地址压入现场信息栈,并修改aesp的值,参数、局部变量和返回地址保存在数据栈,进一步的,对普通返回指令进行修改,修改后的普通返回指令从现场信息栈弹出返回地址,并修改aesp的值。对中断返回指令进行修改,修改后的中断返回指令从现场信息栈弹出中断现场保存数据,并修改aesp的值。
当由于发生中断而导致CPU需要保存当前状态信息时,将需要保存的数据写入现场信息栈的步骤包括:
比较将要执行的处理例程特权级与当前特权级,若将要执行的处理例程的特权级小于当前特权级,执行步骤B1.1,若相同,执行步骤B1.2;
步骤B1.1进一步包括:
处理器从当前任务的任务状态管理结构中获得数据栈和现场信息栈的管控信息,并据此把中断例程的状态信息压入现场信息栈,把其余信息压入数据栈。
例如,在IA-32体系结构中,通过步骤a、b、c予以实现:
a.处理器从当前任务的tss中获得数据栈和现场信息栈的段选择子和栈指针。依次把中断例程的数据栈和现场信息栈的栈段选择子和栈指针压入新的现场信息栈,即ss0,esp0和ass0,aesp0;
b.处理器随后把EFLAGS寄存器、CS寄存器、EIP寄存器的当前值保存进新现场信息栈中;
c.如果异常同时产生了一个错误码,则把它压入数据栈中。
步骤B1.2进一步包括:
处理器把中断例程的状态信息压入当前现场信息栈,把其余信息压入当前数据栈。
例如,在IA-32体系结构中,通过步骤d、e予以实现:
d.处理器在当前现场信息栈中保存当前EFLAGS寄存器、CS寄存器和EIP寄存器的值;
e.如果异常的错误码需要保存,则把它保存在当前的数据栈中。
当由于中断返回而导致CPU需要取出所述保存的数据时,需要把状态信息从现场信息栈中取出,并用它恢复中断现场。
例如,在IA-32体系结构中,通过如下方式实现:
当由于中断返回而导致CPU需要取出所述保存的数据时,从所述现场信息栈取出数据的步骤包括:
对中断返回指令进行修改:
如果在写入现场信息栈时选择执行步骤B1.1,则在步骤C中执行步骤C1,具体包括:
把新现场信息栈中保存的EFLAGS寄存器、CS寄存器、EIP寄存器的值,回传给EFLAGS寄存器、CS寄存器、EIP寄存器,把新现场信息栈中保存的ss0,esp0的值,回传给ss寄存器和esp寄存器,保存的ass0,aesp0的值,回传给ass寄存器和aesp寄存器;
如果在写入现场信息栈时选择执行步骤B1.2,则在步骤C中执行步骤C2,具体包括:
把新现场信息栈中保存的EFLAGS寄存器、CS寄存器、EIP寄存器的值,回传给EFLAGS寄存器、CS寄存器、EIP寄存器。
当发生调用门而导致需要在栈中存取关键数据时,执行步骤B2,具体步骤 包括:
a.每个特权级对应有两个栈,一个是数据栈,用于保存局部数据、传参;一个是本设计新增的现场信息栈,用于保存CPU执行某个操作需要压入的数据,如返回地址等。使用目标代码段的DPL(也就是新的CPL,0)从TSS中分别找到对应的数据栈和现场信息栈的指针,即ss0,esp0和ass0,aesp0。
b.从当前TSS中读取将要切换到的数据栈的段选择子和栈指针,即ss0和esp0;以及现场信息栈的段选择子和现场信息栈指针,即ass0和aesp0。
c.暂时保存当前SS寄存器和ESP寄存器的值。将数据栈的段选择子和栈指针载入SS寄存器和ESP寄存器。将暂时保存的SS寄存器和ESP寄存器的值(调用例程的)压入新现场信息栈。暂时保存当前ASS寄存器和EASP寄存器的值。将现场信息栈的段选择子和栈指针载入ASS寄存器和EASP寄存器。将暂时保存的ASS寄存器和EASP寄存器的值(调用例程的)压入新现场信息栈。
d.将调用门的参数计数域所指定个数的参数从调用例程的数据栈拷贝到新数据栈。如果参数个数域为0,则一个参数也不拷贝。
e.将返回指令指针(当前CS寄存器和EIP寄存器)压入新现场信息栈。
f.从调用门中将新代码段的段选择子和新指令指针分别载入CS寄存器和EIP寄存器,然后开始执行被调例程。
进一步的,为提升效率,本发明还设计一种新的页面属性,作为选择性只读页面,当CPU通过上述方式保存和获取数据时,不受只读限制,可以向该存储区正常写入数据,包括:压栈、出栈,而其他普通指令访问该存储区时效果 如同访问到只读页面。
所述步骤A中设立的独立存储区对应的页面可以受到条件性只读保护,所述条件性只读保护是指对于一组专用于对该页面进行写入和读取的指令,这组指令对该页面的访问可以不受只读限制;而其他指令只能按照只读属性访问该页面。
不受只读限制的具体指令或动作包括调用指令、pushadr指令、popadr指令、普通返回指令、中断返回指令、执行调用门、中断门时写入要保存的信息。
所述的条件性只读保护包括使现有的数据传输指令、运算指令等能够直接改变内存数值的指令在访问该存储区时,该存储区受到只读保护;
优选的,选择性只读的一种实现方式是:
在一个专用寄存器或标志寄存器中设置选择只读位,表示当前CPU是否正在合法向现场信息栈写入数据;同时在TLB原有的“读写、只读、指令”等几项独立的列的基础上,再加入一种“选择性只读”标记,TLB访问此类页面时,判断上述标志寄存器中的备份位是否为1,如为1可改写,如不为1则报出异常。
一种安全CPU,其特征在于:增设专用寄存器,用于管控现场信息栈,例如在在IA-32体系结构中,新增ass,aesp寄存器,分别用于保存现场信息栈的段选择子和现场信息栈的栈顶指针;所述现场信息栈用于存储返回地址。
进一步的,增设pushadr和popadr指令,其中pushadr指令用于向现场信息栈内压入一个数据,aesp自动指向新的栈顶;popadr指令用于从现场信息栈内弹出一个地址,aesp自动指向新的栈顶。
进一步的,对调用指令进行修改,修改后的调用指令将返回地址压入现场信息栈,参数和局部变量保存在数据栈,并修改aesp的值。
进一步的,对普通返回指令进行修改,修改后的普通返回指令从现场信息栈弹出返回地址,并修改aesp的值。
进一步的,中断发生时,将返回现场的信息压入现场信息栈,并修改aesp的值。
进一步的,中断返回时,从现场信息栈中弹出中断发生时压入的数据,并修改aesp的值。
进一步的,在一个专用寄存器或标志寄存器中设置选择只读位,表示当前CPU是否正在合法向现场信息栈写入数据;同时在TLB原有的“读写、只读、指令”等几项独立的列的基础上,再加入一种“选择性只读”标记,TLB访问此类页面时,判断上述标志寄存器中的备份位是否为1,如为1可改写,如不为1则报出异常。
进一步的,将需要保存的数据压入现场信息栈,aesp寄存器的值自动递减,递减值为写入数据的长度总和;
从所述现场信息栈中弹出数据时,aesp寄存器的值自动累加,累加值为弹出数据的长度总和。
本发明的技术方案可以实现以下技术效果:
本发明可以防止由于函数调用的返回值或中断返回的地址值被覆盖,而在 程序中产生新的执行序,进而产生攻击。
进一步的,本发明可以防止中断产生时的状态信息被覆盖而导致中断返回后程序执行混乱。
在现有体系下,只读页面可以保证其中的数据不被覆盖,但往只读页中写入数据,需要先将页属性设置为可读可写,写入之后再设置为只读,在此过程中,需要刷新页缓存,会带来程序执行效率大幅降低,本发明通过建立选择性只读页,可以实现,即保证被保护数据不被覆盖,由不需要频繁刷新也缓存而导致执行效率降低。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1:现场信息栈与数据栈
图2:指令执行效果示意图
图3:call指令执行示意图
图4:ret指令执行示意图
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是 全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
以下结合具体实施例做进一步的详细说明。
为了解决现有技术中的缺陷,提高包括操作系统在内的软件的安全性,本发明提出了一种CPU访问的特定数据的保护方法,特别是一种防止调用指令返回地址数据和/或中断返回信息和/或进程切换现场信息被修改的方法。
一种数据保护方法,包括:
A.设立独立存储区;
B.当CPU需要保存当前状态信息时,将需要保存的数据写入所述独立存储区;
C.当CPU需要取出所述保存的数据时,从所述独立存储区中取出数据。
进一步的,所述A步骤中独立存储区仅用于存储与非顺序执行直接相关的数据;在功能或空间上,此存储区与已经被分配用于存储代码、全局数据、栈数据的页面独立。
所述非顺序执行包括:函数调用、中断、进程切换。
所述CPU需要保存当前状态信息时包括函数调用和/或发生中断和/或进程切换时;所述CPU需要取出所述保存的数据时包括函数返回和/或中断返回和/或进程切换时。
所述独立存储区可以选择在内存中设置,也可以选择在其他CPU可寻址的 具备存储功能的区域中设置。
优选的,可以选择在内存中以栈的方式设置该独立存储区。
图1展示了一种具体的实施方式。现代CPU体系架构中普遍存在特权级,其中,操作系统通常运行在0特权级,自然的,系统调用对应的代码和中断响应程序作为操作系统的一部分也通常运行在0特权级,应用程序通常运行在3特权级。本实施例中,操作系统代码运行在0特权级,应用程序代码运行在3特权级。
现有系统中,每个任务的每个特权级有一个独立的栈,通常用于保存参数和局部数据,函数的返回地址也存于其中。本发明中也同样包含具备类似功能的栈,称之为数据栈,如图1中左侧所示,其中,0特权级和3特权级各有一个对应的数据栈,在其上存储局部变量、函数调用参数和函数返回地址等内容。特别的,为了独立存储函数的返回地址,本发明还为每个任务的每个特权级在内存中再设立一个栈,用于存储返回地址。可以将该专门用于保存返回地址的栈称为现场信息栈,如图1右侧所示。所述现场信息栈在由操作系统在任务或进程创建时进行分配。当函数返回时,CPU会从现场信息栈,而不是数据栈中取出函数返回地址,作为有效的传递给EIP寄存器。
优选的,考虑对现有系统的兼容,开发便利等因素,可以选择仍然将返回地址同时在数据栈中存储一份,使数据栈与现有的栈操作没有任何区别。但存储于数据栈的返回地址将不做任何用途,现场信息栈的返回地址才是有效的CPU实际进行跳转的目标。
优选的,为了使该现场信息栈能够区别于现有技术中的数据栈,可以选择 增设两个寄存器用于保存现场信息栈的段选择子和现场信息栈的栈顶指针:
ass:保存现场信息栈的段选择子;
aesp:保存现场信息栈的栈顶地址值。
所述步骤B进一步包括:
设置一个寄存器aesp,将需要保存的数据写入所述独立存储区时,aesp寄存器的值自动递减,递减值为写入数据的长度总和;
所述步骤C进一步包括:
从所述独立存储区中取出数据时,aesp寄存器的值自动累加,累加值为弹出数据的长度总和。
进一步的,还可以对CPU的指令进行如下改进。
1)增设指令
指令:pushADR src
指令:popADR dst
pushADR指令用于向现场信息栈内压入一个数据,aesp自动指向新的栈顶。
popADR指令用于从现场信息栈内弹出一个地址,aesp自动指向新的栈顶。
上述两条指令是操作现场信息栈的基础指令,其与push指令和pop指令的功能非常类似。
作为一种具体的实施方式,如图2所示,本实施例中,push与pop操作的是数据栈,伴随发生改变的栈顶指针是esp,其中,push指令执行时,esp寄存器的值自动递减,对应的,pop指令执行时,esp寄存器的值自动累加。pushadr与popadr指令操作的是现场信息栈,伴随发生改变的栈顶指针是aesp,其中,pushadr指令执行时,aesp寄存器的值自动递减,对应的,popadr指令执行时,aesp寄存器的值自动累加。
2)修改指令
修改了调用指令,现有系统的call指令,功能如下:
指令:call dst
段内直接:push(eip)(eip)<-(eip)+D32//eip+D32即为dst
段内间接:push(eip)(eip)<-(ea)
段间直接:push(cs)push(eip)(eip)<-dst指定的偏移地址(CS)<-dst指定的段地址。
如图3上部所示,现有技术中,call指令会向栈中压入局部变量、参数和返回地址,esp寄存器相应根据压入数据的大小递减。
本发明修改后的调用指令,功能如下:
指令:call dst
段内直接:pushadr(eip)(eip)<-(eip)+D32
段内间接:pushadr(eip)(eip)<-(ea)
段间直接:pushadr(cs)pushadr(eip)(eip)<-dst指定的偏移地址(CS)<-dst指定的段地址。
如图3下部所示,区别于现有系统中原有的call指令,本发明中经过修改的调用指令将返回地址压入现场信息栈,参数和局部变量保存在数据栈。
优选的,出于兼容性等考虑,可以选择仍然将返回地址在数据栈中存储一份,相应的,经过修改的调用指令将返回地址压入现场信息栈,参数、局部变量和返回地址保存在数据栈。
与调用指令的修改相对应,还需要修改普通返回指令。
现有ret指令,功能如下:
段内:(IP)<-pop()
段间:(IP)<-pop()(cs)<-pop()
ret exp指令,功能如下:
指令:ret exp
段内:(IP)<-pop()(esp)<-(esp)+D16
段间:(IP)<-pop()
(cs)<-pop()
(esp)<-(esp)+D16
如图4上部所示,ret指令根据esp从栈中自动弹出返回地址,并修改esp的值。
改造之后的普通返回指令,功能如下:
段内:(IP)<-popADR()
段间:(IP)<-popADR()(cs)<-popADR()
ret exp指令,功能如下:
指令:ret exp
段内:(IP)<-popADR()(esp)<-(esp)+D16
段间:(IP)<-popADR()
(cs)<-popadr()
(esp)<-(esp)+D16
如图4下部所示,改造后的普通返回指令从现场信息栈中弹出返回地址,并修改aesp的值。
进一步的,中断和其对应的返回也会导致CPU在栈中存取数据,这些数据同样存在被攻击的风险。
在一个具体的实施例中,发生中断时,需要保存的信息也保存在现场信息 栈。优选的,可通过如下方式实现:
步骤B中,发生中断时,执行步骤B1,具体包括:
B1.比较将要执行的处理例程特权级与当前特权级,若将要执行的处理例程的特权级小于当前特权级,执行步骤B1.1,若相同,执行步骤B1.2;
步骤B1.1进一步包括:
a.处理器从当前任务的tss中获得数据栈和现场信息栈的段选择子和栈指针。依次把中断例程的数据栈和现场信息栈的栈段选择子和栈指针压入新的现场信息栈,即ss0,esp0和ass0,aesp0;
b.处理器随后把EFLAGS寄存器、CS寄存器、EIP寄存器的当前值保存进新现场信息栈中;
c.如果异常同时产生了一个错误码,则把它压入数据栈中。
步骤B1.2进一步包括:
d.处理器在当前现场信息栈中保存当前EFLAGS寄存器、CS寄存器和EIP寄存器的值;
e.如果异常的错误码需要保存,则把它保存在当前的数据栈中。
相应的,中断返回也需要进行对应的修改,步骤C进一步包括:
如果在步骤B1中,选择执行步骤B1.1,则在步骤C中执行步骤C1,进一步包括:
把新现场信息栈中保存的EFLAGS寄存器、CS寄存器、EIP寄存器的值, 回传给EFLAGS寄存器、CS寄存器、EIP寄存器,把新现场信息栈中保存的ss0,esp0的值,回传给ss寄存器和esp寄存器,保存的ass0,aesp0的值,回传给ass寄存器和aesp寄存器。
如果在步骤B1中,选择执行步骤B1.2,则在步骤C中执行步骤C2,进一步包括:
把新现场信息栈中保存的EFLAGS寄存器、CS寄存器、EIP寄存器的值,回传给EFLAGS寄存器、CS寄存器、EIP寄存器。
一个关于调用门的实施例:
特别的,对于Intel体系而言,还有一些其他机制也会导致需要在栈中存取关键数据,例如,调用门。本发明也可以对上述机制提出相应的改进,具体包括:
1.每个特权级对应有两个栈,一个是数据栈,用于保存局部数据、传参;一个是本设计新增的现场信息栈,用于保存CPU执行某个操作需要压入的数据,如返回地址等。使用目标代码段的DPL(也就是新的CPL,0)从TSS中分别找到对应的数据栈和现场信息栈的指针,即ss0,esp0和ass0,aesp0。
2.从当前TSS中读取将要切换到的数据栈的段选择子和栈指针,即ss0和esp0;以及现场信息栈的段选择子和现场信息栈指针,即ass0和aesp0.
3.暂时保存当前SS寄存器和ESP寄存器的值。将数据栈的段选择子和栈指针载入SS寄存器和ESP寄存器。将暂时保存的SS寄存器和ESP寄存器的值(调用例程的)压入新现场信息栈。
暂时保存当前ASS寄存器和EASP寄存器的值。将现场信息栈的段选择子和栈指针载入ASS寄存器和EASP寄存器。将暂时保存的ASS寄存器和EASP寄存器的值(调用例程的)压入新现场信息栈。
4.将调用门的参数计数域所指定个数的参数从调用例程的数据栈拷贝到新数据栈。如果参数个数域为0,则一个参数也不拷贝。
5.将返回指令指针(当前CS寄存器和EIP寄存器)压入新现场信息栈。
6.从调用门中将新代码段的段选择子和新指令指针分别载入CS寄存器和EIP寄存器,然后开始执行被调例程。(此步骤与现有相同)
为了进一步提升访问效率,本发明还包括一种新的页面访问模式,其特征在于:设定一种页面属性为条件性只读。
优选的,所述步骤A中设立的独立存储区对应的页面可以受到条件性只读保护。
所述条件性只读是指对于一组专用于对该页面进行写入和读取的指令,这组指令对该页面的访问可以不受只读限制;而其他指令只能按照只读属性访问该页面。
其中,所述的条件性只读保护包括使现有的数据传输指令、运算指令等能够直接改变内存数值的指令在访问该存储区时,该存储区受到只读保护;
使CPU在特定时刻向上述存储区自动保存数据时或者CPU执行专门的向上述存储区保存数据的指令时不受只读限制。
优选的,不受只读限制的具体的指令或动作包括:调用指令、pushadr指令、 popadr指令、执行调用门、中断门时写入要保存的信息。
在一个具体的实施例中,所述条件性只读保护进一步包括:
在页属性表中建立一种新的只读分类,并且此位被置位时,原有的只读位无效;
修改TLB存储页面地址的格式,使这种只读分类能够被单独存储;
在TLB寻址时建立一种识别标志因素,能够区分此时CPU是否正在执行上述不受只读限制的指令或CPU行为;
CPU执行上述指令或CPU行为时,可以向上述存储区写入数据,不受只读限制。
现有系统中,往往通过TLB来提升内存读写效率,避免频繁到主存中读取页表中的属性。因此选择性只读还需体现在TLB中。
以下通过一具体实施例来说明如何实现选择性只读:
通过一个专用寄存器或标志寄存器的一位(称为“选择只读位”)表示当前CPU是否正在合法向现场信息栈写入数据。合法向现场信息栈写入数据的方式包括:调用指令;pushadr指令;使用调用门时保存信息;使用中断门时保存信息。
TLB中包含“读写、只读、指令”等几项独立的列,再加入一种“选择性只读”,即页面类型被标记为“选择性只读”的页面记入此列。TLB访问此类页面时,判断上述标志寄存器中的备份位是否为1,如为1可改写,如不为1则报出异常。
一种安全CPU,其特征在于:新增ass,aesp寄存器,分别用于保存现场信息栈的段选择子和现场信息栈的栈顶指针;所述现场信息栈用于存储返回地址。
还增设pushadr和popadr指令,其中pushadr指令用于向现场信息栈内压入一个数据,aesp自动指向新的栈顶;popadr指令用于从现场信息栈内弹出一个地址,aesp自动指向新的栈顶。
对调用指令进行修改,修改后的调用指令将返回地址压入现场信息栈,参数和局部变量保存在数据栈。
对普通返回指令进行修改,修改后的普通返回指令从现场信息栈弹出返回地址,并修改aesp的值。
对中断返回指令进行修改,修改后的普通返回指令从现场信息栈弹出返回地址,并修改aesp的值。
在一个专用寄存器或标志寄存器中设置选择只读位,表示当前CPU是否正在合法向现场信息栈写入数据;同时在TLB原有的“读写、只读、指令”等几项独立的列的基础上,再加入一种“选择性只读”标记,TLB访问此类页面时,判断上述标志寄存器中的备份位是否为1,如为1可改写,如不为1则报出异常。
一种安全CPU,其特征在于:
将需要保存的数据写入所述独立存储区时,aesp寄存器的值自动递减,递减值为写入数据的长度总和;
从所述独立存储区中取出数据时,aesp寄存器的值自动累加,累加值为弹出数据的长度总和;
所述独立存储区是指现场信息栈。
一种安全CPU,其特征在于:当由于发生中断而导致CPU需要保存当前状态信息时,比较将要执行的处理例程特权级与当前特权级,若将要执行的处理例程的特权级小于当前特权级,执行步骤B1.1,若相同,执行步骤B1.2;
步骤B1.1进一步包括:
a.处理器从当前任务的tss中获得数据栈和现场信息栈的段选择子和栈指针。依次把中断例程的数据栈和现场信息栈的栈段选择子和栈指针压入新的现场信息栈,即ss0,esp0和ass0,aesp0;
b.处理器随后把EFLAGS寄存器、CS寄存器、EIP寄存器的当前值保存进新现场信息栈中;
c.如果异常同时产生了一个错误码,则把它压入数据栈中。
步骤B1.2进一步包括:
d.处理器在当前现场信息栈中保存当前EFLAGS寄存器、CS寄存器和EIP寄存器的值;
e.如果异常的错误码需要保存,则把它保存在当前的数据栈中。

Claims (27)

  1. 一种数据保护方法,其特征在于,包括:
    A、设立独立存储区;
    B、当CPU需要保存当前状态信息时,将需要保存的数据写入所述独立存储区;
    C、当CPU需要取出所述保存的数据时,从所述独立存储区中取出数据。
  2. 根据权利要求1所述的方法,其特征在于:所述A步骤中独立存储区仅用于存储与转移指令或中断现场保护相关的数据;在功能或空间上,此存储区与已经被分配用于存储代码、全局数据、栈数据的页面独立。
  3. 根据权利要求1所述的方法,其特征在于:所述CPU需要保存当前状态信息时包括函数调用或发生中断时;所述CPU需要取出所述保存的数据时包括函数调用或中断返回时。
  4. 根据权利要求1所述的方法,其特征在于:所述独立存储区可以选择在内存或其他CPU可寻址的具备存储功能的区域中设置。
  5. 根据权利要求4所述的方法,其特征在于:所述独立存储区在内存中以栈的方式设置,标识所述栈的状态信息和栈顶、栈底值。
  6. 根据权利要求5所述的方法,其特征在于:所述独立存储区用于保存调用、中断等需要现场保护的操作产生的数据,称为现场信息栈;将用于保存局部变量、参数等数据的栈称作数据栈,现场信息栈与数据栈同时存在。
  7. 根据权利要求6所述的方法,其特征在于:所述数据栈上同样为返回地址占位,但不做任何用途,现场信息栈存储的返回地址才是有效的CPU实际进行跳转的目标。
  8. 根据权利要求6所述的方法,其特征在于:增设ass寄存器和aesp寄存器,分别用于保存现场信息栈的段选择子和现场信息栈的栈顶指针。
  9. 根据权利要求8所述的方法,其特征在于:
    所述步骤B进一步包括:将需要保存的数据压入所述现场信息栈时,aesp寄存器的值自动递减,递减值为写入数据的长度总和;
    所述步骤C进一步包括:从所述现场信息栈中弹出数据时,aesp寄存器的值自动累加,累加值为弹出数据的长度总和;
  10. 根据权利要求5所述的方法,其特征在于:增设pushadr和popadr指令,其中pushadr指令用于向现场信息栈内压入一个数据,aesp自动指向新的栈顶;popadr指令用于从现场信息栈内弹出一个数据,aesp自动指向新的栈顶。
  11. 根据权利要求5所述的方法,其特征在于:对调用指令进行修改,修改后的调用指令将返回地址压入现场信息栈,参数和局部变量保存在数据栈。
  12. 根据权利要求11所述的方法,其特征在于:修改后的调用指令将返回地址压入现场信息栈,参数、局部变量和返回地址保存在数据栈。
  13. 根据权利要求8所述的方法,其特征在于:对普通返回指令进行修改,修改后的普通返回指令从现场信息栈弹出返回地址,并修改aesp的值;对中断返回指令进行修改,修改后的中断返回指令从现场信息栈弹出中断现场保存数据,并修改aesp的值。
  14. 根据权利要求1或6所述的方法,其特征在于:当由于发生中断而导致CPU需要保存当前状态信息时,将需要保存的数据写入现场信息栈的步骤包括:
    比较将要执行的处理例程特权级与当前特权级,若将要执行的处理例程的特权级小于当前特权级,执行步骤B1.1,若相同,执行步骤B1.2;
    步骤B1.1进一步包括:
    处理器从当前任务的任务状态管理结构中获得数据栈和现场信息栈的管控 信息,并据此把中断例程的状态信息压入现场信息栈,把其余信息压入数据栈。
    步骤B1.2进一步包括:
    处理器把中断例程的状态信息压入当前现场信息栈,把其余信息压入当前数据栈。
  15. 根据权利要求14所述的方法,其特征在于:当由于中断返回而导致CPU需要取出所述保存的数据时,需要把状态信息从现场信息栈中取出,并用它恢复中断现场。
  16. 根据权利要求5所述的方法,其特征在于:当由于中断返回而导致CPU需要取出所述保存的数据时,需要把状态信息从现场信息栈中取出,并用它恢复中断现场。
  17. 根据权利要求5所述的方法,其特征在于:当发生调用门而导致需要在栈中存取关键数据时,执行步骤B2,具体步骤包括:
    B2-a.每个特权级对应有两个栈,一个是数据栈,用于保存局部数据、传参;一个是本设计新增的现场信息栈,用于保存CPU执行某个操作需要压入的数据,如返回地址等。使用目标代码段的DPL从任务状态管理结构中分别找到对应的数据栈和现场信息栈的管控信息;
    B2-b.从任务状态管理结构中读取将要切换到的数据栈和现场信息栈的位置信息;
    B2-c.保存当前数据栈和现场信息栈的管控信息到新现场信息栈,并切换数据栈和现场信息栈;
    B2-d.将调用门的参数计数域所指定个数的参数从调用例程的数据栈拷贝 到新数据栈。如果参数个数域为0,则一个参数也不拷贝。
    B2-e.将返回指令指针压入新现场信息栈。
    B2-f.保存新代码段管控信息,然后开始执行被调例程。
  18. 根据权利要求1所述的方法,其特征在于:所述步骤A中设立的独立存储区对应的页面可以受到条件性只读保护,所述条件性只读保护是指对于一组专用于对该页面进行写入和读取的指令,这组指令对该页面的访问可以不受只读限制;而其他指令只能按照只读属性访问该页面。
  19. 根据权利要求18所述的方法,其特征在于:
    所述的条件性只读保护包括使现有的数据传输指令、运算指令等能够直接改变内存数值的指令在访问该存储区时,该存储区受到只读保护;
    使CPU在特定时刻向上述存储区自动保存数据时或者CPU执行专门的向上述存储区保存数据的指令时不受只读限制。
  20. 根据权利要求18或19所述的方法,其特征在于:不受只读限制的具体指令或动作包括调用指令、pushadr指令、popadr指令、返回指令、中断返回指令、执行调用门、中断门时写入要保存的信息。
  21. 根据权利要求18或19所述的方法,其特征在于:
    在一个专用寄存器或标志寄存器中设置选择只读位,表示当前CPU是否正在合法向现场信息栈写入数据;同时在TLB原有的“读写、只读、指令”等几项独立的列的基础上,再加入一种“选择性只读”标记,TLB访问此类页面时,判断上述标志寄存器中的备份位是否为1,如为1可改写,如不为1则报出异常。
  22. 根据权利要求21所述的方法,其特征在于:合法向现场信息栈写入数据的方式包括:调用指令、pushadr指令、popadr指令、返回指令、中断返回指令、执行调用门、中断门时写入要保存的信息。
  23. 一种安全CPU,其特征在于:新增ass,aesp寄存器,分别用于保存现场信息栈的段选择子和现场信息栈的栈顶指针;所述现场信息栈用于存储返回地址。
  24. 根据权利要求23所述的安全CPU,其特征在于:
    将需要保存的数据压入现场信息栈时,aesp寄存器的值自动递减,递减值为写入数据的长度总和;
    从现场信息栈中取出数据时,aesp寄存器的值自动累加,累加值为弹出数据的长度总和。
  25. 根据权利要求23所述的安全CPU,其特征在于:增设pushadr和popadr指令,其中pushadr指令用于向现场信息栈内压入一个数据,aesp自动指向新的栈顶;popadr指令用于从现场信息栈内弹出一个数据,aesp自动指向新的栈顶。
  26. 根据权利要求23所述的安全CPU,其特征在于:
    对调用指令进行修改,修改后的调用指令将返回地址压入现场信息栈,并修改aesp的值,参数和局部变量保存在数据栈;
    对普通返回指令进行修改,修改后的普通返回指令从现场信息栈弹出返回地址,并修改aesp的值;
    和/或
    当由于发生中断而导致CPU需要保存当前状态信息时,执行权利要求14所述的方法;
    中断返回时,从现场信息栈中弹出中断发生时压入的数据,并修改aesp的值。
  27. 根据权利要求23所述的安全CPU,其特征在于:在一个专用寄存器或标志寄存器中设置选择只读位,表示当前CPU是否正在合法向现场信息栈写入 数据;同时在TLB原有的“读写、只读、指令”等几项独立的列的基础上,再加入一种“选择性只读”标记,TLB访问此类页面时,判断上述标志寄存器中的备份位是否为1,如为1可改写,如不为1则报出异常。
PCT/CN2019/086497 2018-06-12 2019-05-11 一种数据保护方法及计算装置 WO2019237865A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810599754.1A CN110598406B (zh) 2018-06-12 2018-06-12 一种数据保护方法及计算装置
CN201810599754.1 2018-06-12

Publications (1)

Publication Number Publication Date
WO2019237865A1 true WO2019237865A1 (zh) 2019-12-19

Family

ID=68842777

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/086497 WO2019237865A1 (zh) 2018-06-12 2019-05-11 一种数据保护方法及计算装置

Country Status (2)

Country Link
CN (1) CN110598406B (zh)
WO (1) WO2019237865A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112948000A (zh) * 2021-03-17 2021-06-11 星汉智能科技股份有限公司 栈空间统计方法、装置及介质

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117688552B (zh) * 2024-01-30 2024-04-12 龙芯中科技术股份有限公司 栈空间防护方法、电子设备、存储介质及计算机程序产品

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2015011436A (ja) * 2013-06-27 2015-01-19 株式会社デンソー プロセッサ
CN105303104A (zh) * 2012-01-16 2016-02-03 高通股份有限公司 用以禁止返回定向编程的动态执行阻止
CN107209826A (zh) * 2015-02-02 2017-09-26 高通股份有限公司 经认证的控制堆栈
CN107667372A (zh) * 2015-06-26 2018-02-06 英特尔公司 用于保护影子栈的处理器、方法、系统和指令

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5634046A (en) * 1994-09-30 1997-05-27 Microsoft Corporation General purpose use of a stack pointer register
US6282625B1 (en) * 1997-06-25 2001-08-28 Micron Electronics, Inc. GART and PTES defined by configuration registers
EP1304620A1 (en) * 2001-10-17 2003-04-23 Texas Instruments Incorporated Cache with selective write allocation
JP3931646B2 (ja) * 2001-12-11 2007-06-20 株式会社デンソー 情報処理装置
US7082507B1 (en) * 2002-04-18 2006-07-25 Advanced Micro Devices, Inc. Method of controlling access to an address translation data structure of a computer system
US11188651B2 (en) * 2016-03-07 2021-11-30 Crowdstrike, Inc. Hypervisor-based interception of memory accesses

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105303104A (zh) * 2012-01-16 2016-02-03 高通股份有限公司 用以禁止返回定向编程的动态执行阻止
JP2015011436A (ja) * 2013-06-27 2015-01-19 株式会社デンソー プロセッサ
CN107209826A (zh) * 2015-02-02 2017-09-26 高通股份有限公司 经认证的控制堆栈
CN107667372A (zh) * 2015-06-26 2018-02-06 英特尔公司 用于保护影子栈的处理器、方法、系统和指令

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112948000A (zh) * 2021-03-17 2021-06-11 星汉智能科技股份有限公司 栈空间统计方法、装置及介质

Also Published As

Publication number Publication date
CN110598406A (zh) 2019-12-20
CN110598406B (zh) 2022-08-23

Similar Documents

Publication Publication Date Title
TWI797347B (zh) 使用儲存在記憶體系統中的記憶體保護表的記憶體保護單元以控制對記憶體的存取的裝置、方法和電腦程式
JP5571201B2 (ja) ハードウェアモードおよびセキュリティフラグに基づく、読み出される命令用のメモリエリアの制限
US7529916B2 (en) Data processing apparatus and method for controlling access to registers
TWI726925B (zh) 用於管理有界指標的裝置和方法
TWI725059B (zh) 用於控制有界指標的使用之設備及方法
JP4939387B2 (ja) データ処理装置及びアドレス空間保護方法
TWI808261B (zh) 使用轉換禁用指示符的設備、資料處理方法、電腦程式和電腦可讀取存儲媒體
US20220366036A1 (en) An apparatus and method for handling exceptions
US20160188493A1 (en) Information processing apparatus
US20080055617A1 (en) Page coloring with color inheritance for memory pages
WO2019237865A1 (zh) 一种数据保护方法及计算装置
CN110647764B (zh) 针对用户态非易失性内存文件系统的保护方法及系统
KR100791815B1 (ko) 컴퓨터 시스템 및 컴퓨터 시스템에서 인스트럭션을 실행하는 방법
WO2019237862A1 (zh) 一种线性地址空间的布局方法及计算装置
EP1842135B1 (en) Generic low cost hardware mechanism for memory protection
CN110008726B (zh) 一种运行时访问控制装置和方法
TW202131191A (zh) 用於控制對一組記憶體映射的控制暫存器的存取的設備及方法
GB2623800A (en) Stack pointer switch validity checking
JPS6054691B2 (ja) 情報処理装置の記憶保護方式
JPH01240947A (ja) 主記憶の記憶保護方式

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19818781

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19818781

Country of ref document: EP

Kind code of ref document: A1