CN108491694A - A kind of method of dynamic randomization defence Cache attacks - Google Patents
A kind of method of dynamic randomization defence Cache attacks Download PDFInfo
- Publication number
- CN108491694A CN108491694A CN201810252891.8A CN201810252891A CN108491694A CN 108491694 A CN108491694 A CN 108491694A CN 201810252891 A CN201810252891 A CN 201810252891A CN 108491694 A CN108491694 A CN 108491694A
- Authority
- CN
- China
- Prior art keywords
- randomization
- function
- stack
- heap
- space
- 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.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/10—Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
- G06F21/12—Protecting executable software
- G06F21/121—Restricting unauthorised execution of programs
- G06F21/125—Restricting unauthorised execution of programs by manipulating the program code, e.g. source code, compiled code, interpreted code, machine code
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/50—Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
- G06F21/55—Detecting local intrusion or implementing counter-measures
- G06F21/56—Computer malware detection or handling, e.g. anti-virus arrangements
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Computer Security & Cryptography (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Physics & Mathematics (AREA)
- Virology (AREA)
- Health & Medical Sciences (AREA)
- General Health & Medical Sciences (AREA)
- Multimedia (AREA)
- Technology Law (AREA)
- Executing Machine-Instructions (AREA)
Abstract
Description
技术领域technical field
本发明属于计算机系统安全领域,具体涉及针对Cache攻击进行动态随机化防御的方法。The invention belongs to the field of computer system security, and in particular relates to a method for dynamic randomization defense against Cache attacks.
背景技术Background technique
随着网络技术的发展,计算机的安全性已经越来越受到人们的重视,如系统入侵、信息窃取、病毒等各种安全漏洞会对个人及社会造成重大损失。近年来,研究人员提出了一种利用密码设备在运行过程中所泄露的物理信息,例如电磁辐射、功率、时间等作为密码分析渠道,而这种攻击方法我们称之为旁道攻击,也叫侧信道攻击。Cache攻击是一种严重威胁到系统安全的旁道攻击,涉及到服务器、桌面以及嵌入式等各种领域的主流计算机系统。目前基于Last-level cache(LLC)的旁道攻击具有高带宽、低噪声的特点,同时,由于最后一级缓存具有包容性和多核共享性,所以可以在不需要中断程序的情况下实现对整个或者特定的Cache行进行攻击。在该环境下,Cache攻击呈现上升的趋势并且攻击者所使用的攻击技术更加的“精湛”。随着云服务和虚拟化的大规模普及,将来Cache攻击会更具有杀伤力。同时,缓存攻击正在逐渐渗透到我们的日常应用中,比如扩展到智能手机的可信环境中,对操作系统的安全构成了极大的威胁。With the development of network technology, people have paid more and more attention to computer security. Various security vulnerabilities such as system intrusion, information theft, and viruses will cause great losses to individuals and society. In recent years, researchers have proposed a way to use the physical information leaked during the operation of cryptographic equipment, such as electromagnetic radiation, power, time, etc., as a channel for cryptographic analysis, and this attack method is called side-channel attack, also known as Side channel attack. Cache attack is a side-channel attack that seriously threatens system security, and involves mainstream computer systems in various fields such as servers, desktops, and embedded systems. At present, side-channel attacks based on Last-level cache (LLC) have the characteristics of high bandwidth and low noise. At the same time, because the last-level cache is inclusive and multi-core sharing, it can be realized without interrupting the program. Or a specific Cache line to attack. In this environment, Cache attacks are on the rise and the attack techniques used by attackers are more "sophisticated". With the large-scale popularization of cloud services and virtualization, Cache attacks will be more lethal in the future. At the same time, cache attacks are gradually penetrating into our daily applications, such as extending to the trusted environment of smartphones, posing a great threat to the security of the operating system.
现代CPU的缓存结构一般分为三层,分别是L1、L2和L3缓存,L1cache为每个核单独占有,是最接近CPU的,它容量最小,速度最快,一般分为Data Cache(数据缓存)和Instruction Cache(指令缓存)。L2cache更大一些,速度要慢一些,一般情况下每个核上都有一个独立的L2cache。L3cache是三级缓存中最大的一级,同时也是最慢的一级,一般在多核CPU中是所有核心共有的。在CPU开始执行任务的时候,它首先去L1中寻找它所需的数据,之后去L2,然后去L3。如果存在(命中),则不经内存直接返回该数据;如果不存在(失效),则先把内存中的相应数据载入缓存,再将其返回处理器。The cache structure of modern CPUs is generally divided into three layers, which are L1, L2 and L3 caches. L1cache is occupied by each core separately and is the closest to the CPU. It has the smallest capacity and the fastest speed. It is generally divided into Data Cache (data cache ) and Instruction Cache (instruction cache). The L2cache is larger and slower. Generally, each core has an independent L2cache. L3cache is the largest level in the three-level cache, and it is also the slowest level. Generally, it is shared by all cores in multi-core CPUs. When the CPU starts executing a task, it first goes to L1 to find the data it needs, then to L2, and then to L3. If it exists (hit), the data is directly returned without going through the memory; if it does not exist (failure), the corresponding data in the memory is first loaded into the cache, and then returned to the processor.
为方便阐述攻击过程,以下为操作系统相关内容的一些基本定义:To facilitate the description of the attack process, the following are some basic definitions of operating system-related content:
共享内存:为两个正在运行的进程之间共享和传递数据的一种非常有效的方式。不同进程之间共享的内存通常为同一段物理内存。进程可以将同一段共享内存映射到他们自己的地址空间中。在操作系统中存在一种内存优化机制:对于共享库,操作系统会将存储该库的同一段物理内存映射到每一个应用的地址空间中。Shared memory: A very efficient way to share and pass data between two running processes. The memory shared between different processes is usually the same piece of physical memory. Processes can map the same shared memory into their own address space. There is a memory optimization mechanism in the operating system: for a shared library, the operating system will map the same piece of physical memory storing the library into the address space of each application.
mmaps:为内存映射函数,使得进程之间通过映射同一个普通文件实现共享内存。mmaps: It is a memory mapping function that enables processes to share memory by mapping the same ordinary file.
迄今为止,主要有FLUSH+RELOAD,EVICT+RELOAD,PRIME+PROBE,FLUSH+FLUSH这四种缓存攻击方式。其中,FLUSH+RELOAD是基于共享内存实现的,分为三个阶段。过程如图1,在Flush阶段,目标进程和攻击者进程进行页面共享,即攻击者诱使目标进程将内存映射函数mmaps应用到目标可执行程序,令其进入到攻击者进程的虚拟地址空间,完成映射文件的内存共享。然后,攻击者进程监控某个特定的Cache行,并将其内容从Cache中擦除。在Wait阶段等待受害者访问共享内存,之后,在Reload阶段,攻击者重新载入特定的共享内存块。如果在Wait阶段,目标进程访问了指定的内存块,那么这个内存空间就会在Cache中有记录,因为访问Cache中数据很快,所以在Reload阶段的重新载入过程只需要很短的时间。否则,如果目标进程没有访问指定的内存空间,那么攻击者就需要从主内存中获取数据,因为访问主内存中数据很慢,所以在Reload阶段得花费更多的时间。因此,攻击者可以根据二次访问时间的长短,确定观察期间受害者是否访问了特定的内存块。这种方法使攻击者确定目标程序使用了哪些具体的指令和访问了哪些数据。So far, there are mainly four cache attack methods: FLUSH+RELOAD, EVICT+RELOAD, PRIME+PROBE, and FLUSH+FLUSH. Among them, FLUSH+RELOAD is implemented based on shared memory and is divided into three stages. The process is shown in Figure 1. In the Flush phase, the target process and the attacker process share pages, that is, the attacker induces the target process to apply the memory mapping function mmaps to the target executable program, allowing it to enter the virtual address space of the attacker process. Complete memory sharing of mapped files. The attacker process then monitors a particular cache line and wipes its contents from the cache. The Wait phase waits for the victim to access the shared memory, and then, in the Reload phase, the attacker reloads a specific shared memory block. If in the Wait stage, the target process accesses the specified memory block, then this memory space will be recorded in the Cache, because accessing the data in the Cache is very fast, so the reloading process in the Reload stage only takes a short time. Otherwise, if the target process does not access the specified memory space, the attacker needs to obtain data from the main memory, because accessing data in the main memory is very slow, so it takes more time in the Reload phase. Therefore, the attacker can determine whether the victim accessed a specific memory block during the observation period based on the length of the secondary access. This method allows an attacker to determine which specific instructions were used and which data was accessed by the target program.
目前针对缓存攻击FLUSH+RELOAD提出的防御措施,例如删除clflush指令、禁用共享内存、Cache与主存采用全相联地址映射等方式都不尽如人意。因此,本发明提出一个动态随机化系统来充分随机化代码、栈、堆,尽可能地使攻击者所获得的信息失效。At present, the defense measures proposed for the cache attack FLUSH+RELOAD, such as deleting the clflush instruction, disabling shared memory, and using fully associative address mapping between cache and main memory, are not satisfactory. Therefore, the present invention proposes a dynamic randomization system to fully randomize the code, stack, and heap, so as to invalidate the information obtained by the attacker as much as possible.
发明内容Contents of the invention
本发明针对Cache攻击方式FLUSH+RELOAD,提出了一种基于动态随机化的系统级别的防御方法,能够动态随机化程序函数、栈帧和堆。Aiming at the Cache attack mode FLUSH+RELOAD, the present invention proposes a system-level defense method based on dynamic randomization, which can dynamically randomize program functions, stack frames and heaps.
一个进程的地址空间组成包括:ELF的Executable File和Shared Object File生成的对象:代码段、静态数据段、动态共享库等,和动态对象:运行时刻产生和变化的堆和栈。对地址空间比较大的对象进行整体随机化称之为基址随机化,而对比较细粒度的地址空间对象进行随机化,例如代码段中的单个函数、栈帧等,随机化效果更强。The address space of a process consists of: objects generated by ELF's Executable File and Shared Object File: code segments, static data segments, dynamic shared libraries, etc., and dynamic objects: heaps and stacks generated and changed at runtime. The overall randomization of objects with a relatively large address space is called base address randomization, while the randomization of finer-grained address space objects, such as individual functions and stack frames in a code segment, has a stronger randomization effect.
目前的地址空间随机化技术(address space randomization)就是使得进程虚拟空间的布局位于随机的位置,以此来降低被攻击的可能性,这种方案存在随机化粒度太大、随机性不高、只能随机化虚拟地址等缺陷。通过细化随机化粒度、将随机化时刻推迟到运行时、随机化物理地址这些方法,消除了现有随机化方案的缺陷。The current address space randomization technology (address space randomization) is to make the layout of the process virtual space in a random position, so as to reduce the possibility of being attacked. This scheme has too large randomization granularity, low randomness, and only Can randomize defects such as virtual addresses. By refining the randomization granularity, postponing the randomization moment to runtime, and randomizing the physical address, the defects of the existing randomization schemes are eliminated.
本方法从三个方面增强了防御能力:第一,针对随机化粒度粗的问题,本发明的代码随机化以函数为粒度、栈空间随机化以函数栈帧为单位进行。第二,考虑到随机化时刻问题,当前的随机化机制的一个特点是:当系统启动时,随机化会生效,而我们将随机化时刻推迟到各个函数运行时。随机化的时机越靠近运行时刻,所能获得的随机效果越好。但是,要在运行时刻随机化一个地址空间对象,首先要分析这个对象在地址空间内被引用的情况。对于在运行时刻才建立的地址空间对象堆和栈而言,其中的引用都是通过绝对地址进行的。如果在运行时刻移动这些对象的位置,就需要修改这些引用,在实现中,系统使用迁移表去记录这些信息,使得这种随机化具有可行性。第三,通过随机化物理地址来降低攻击者成功猜测空间位置的可能性。The method enhances the defense capability from three aspects: first, for the problem of coarse randomization granularity, the code randomization of the present invention takes function as the granularity, and stack space randomization takes function stack frame as the unit. Second, considering the randomization time problem, one of the characteristics of the current randomization mechanism is that when the system starts, the randomization will take effect, and we postpone the randomization time until each function is running. The closer the timing of randomization is to the runtime, the better the random effect can be obtained. However, to randomize an address space object at runtime, it is first necessary to analyze how the object is referenced in the address space. For the address space object heap and stack that are only established at runtime, the references therein are all made through absolute addresses. If the location of these objects is moved at runtime, these references need to be modified. In the implementation, the system uses a migration table to record this information, making this randomization feasible. Third, randomize physical addresses to reduce the likelihood of an attacker successfully guessing spatial locations.
以下为该随机化系统的一些基本定义:Here are some basic definitions of this randomization system:
符号表:在编译程序中,符号表用于存放程序语言中出现的有关标识符的属性信息。Symbol table: In a compiled program, the symbol table is used to store attribute information about identifiers that appear in the programming language.
构造函数:是一种方法,主要用于在创建对象时初始化对象,即为对象成员变量赋值。编译器一般会提供一个默认的构造函数,不过此默认构造函数是不带参数的。Constructor: It is a method that is mainly used to initialize the object when creating the object, that is, to assign values to the object member variables. The compiler generally provides a default constructor, but this default constructor does not take parameters.
libc:是Linux下的ANSI C的函数库,ANSI C是基本的C语言函数库,包含了C语言最基本的库函数。libc: It is the ANSI C function library under Linux. ANSI C is the basic C language function library, including the most basic library functions of the C language.
构造器:用于在创建对象时执行初始化,当创建一个对象时,系统会为这个对象的实例进行默认的初始化,如果想改变这种默认的初始化,就可以通过自定义构造器来实现。Constructor: It is used to perform initialization when creating an object. When an object is created, the system will perform default initialization for the instance of this object. If you want to change this default initialization, you can implement it through a custom constructor.
栈帧:CPU以函数为单位动态分配内存,每次子函数的调用都会在栈中分配一定空间以存储其运行信息,这段空间称为该函数的栈帧。一个函数的栈帧通常包含:函数参数、返回地址、前一个函数的基址寄存器(前帧指针)、局部变量等。Stack frame: The CPU dynamically allocates memory in units of functions. Every time a sub-function is called, a certain space will be allocated in the stack to store its operation information. This space is called the stack frame of the function. The stack frame of a function usually includes: function parameters, return address, base address register (previous frame pointer) of the previous function, local variables, etc.
位图:是一个单Bit的简单向量,每一Bit对应内存的一个字或者一个特定的大小。Bitmap: It is a simple vector of a single Bit, and each Bit corresponds to a word of memory or a specific size.
动态随机化系统能运行在x86,x86_64和PowerPC架构上,大部分的实现细节都是相同的。该系统能够高效地重复随机化代码、栈、堆,使得攻击者在Reload阶段重新加载共享内存的数据时,该数据的空间位置已经发生变化,最后达到的效果如图2所示,设计的具体细节包含以下内容:The dynamic randomization system can run on x86, x86_64 and PowerPC architectures, most of the implementation details are the same. The system can efficiently repeat the randomized code, stack, and heap, so that when the attacker reloads the data in the shared memory during the Reload phase, the spatial position of the data has changed. The final effect is shown in Figure 2. The specific design Details include the following:
1.代码随机化1. Code randomization
该方法以函数为粒度随机化代码,体现在以下四个方面:第一,函数采用malloc、calloc、realloc这种分配内存的函数在堆上随机分配地址空间。第二,每一个转换函数有一个迁移表,里面放置的是一些迁移信息,跟随着函数代码。同时,迁移表不是以系统编译后的二进制形式存在的,而是在运行时创建的。因此,攻击者想要以迁移表作为爆破点,获得函数相关地址信息的这一方法失效。第三,因为函数的大小在程序的符号表内没有相关说明,所以系统用下一个函数的地址去决定当前函数的结束点。第四,函数通过使用相对偏移来引用相邻的偏移表。这就意味着相同函数的两个随机放置的副本不会共享同一个迁移表。以上四点使得在程序运行过程中,函数地址变得不可猜测。该随机化过程如图3,包括:This method uses function as the granularity to randomize the code, which is reflected in the following four aspects: First, the function uses functions such as malloc, calloc, and realloc to allocate memory randomly on the heap. Second, each conversion function has a migration table, which contains some migration information, followed by the function code. At the same time, the migration table does not exist in the binary form compiled by the system, but is created at runtime. Therefore, the attacker wants to use the migration table as a breach point, and the method of obtaining function-related address information is invalid. Third, because the size of the function is not specified in the symbol table of the program, the system uses the address of the next function to determine the end point of the current function. Fourth, functions refer to adjacent offset tables by using relative offsets. This means that two randomly placed copies of the same function will not share the same migration table. The above four points make the function address impossible to guess during the running of the program. The randomization process is shown in Figure 3, including:
(1)初始化阶段。在编译时,动态随机化系统用自己的构造函数替换掉操作系统模块的libc构造函数。在启动的时候,构造器从原始程序中注册模块的函数和构造函数,之后,执行程序重写的构造函数进行初始化。定义在系统运行时的main函数用一个断点重写了每个重定位函数的开头,即在每个函数的开头放置了一个陷阱指令,用于触发迁移表工作,当陷阱函数被调用的时候,它按需迁移,如图3中(a)所示。(1) Initialization phase. At compile time, the dynamic randomization system replaces the libc constructor of the operating system module with its own constructor. At startup, the constructor registers the functions and constructors of the module from the original program, and then executes the rewritten constructor for initialization. The main function defined when the system is running rewrites the beginning of each relocation function with a breakpoint, that is, a trap instruction is placed at the beginning of each function to trigger the work of the migration table. When the trap function is called , it migrates on demand, as shown in (a) in Figure 3.
(2)函数迁移阶段。每个随机化函数有一个临近的迁移表,内容是指针,指向所有引用全局变量和函数,如图3中(b)所示。当陷阱函数执行的时候,动态随机化系统在运行时接收一个SIGTRAP信号并迁移函数。这个过程分为以下三个阶段:(2) Function migration stage. Each randomization function has an adjacent migration table, the contents of which are pointers to all referenced global variables and functions, as shown in (b) in Figure 3. When the trap function executes, the dynamic randomization system receives a SIGTRAP signal at runtime and migrates the function. This process is divided into the following three stages:
1)该系统从代码堆中申请一个足够大的内存块,并将函数的主体部分复制过去。1) The system applies for a large enough memory block from the code heap, and copies the main part of the function to it.
2)相应的,也将函数的迁移表迁移到新的位置。系统通过将陷阱指令替换为跳转指令,将函数迁移到新位置,这样相当于改写了函数原始基地址。2) Correspondingly, the migration table of the function is also migrated to a new location. The system migrates the function to a new location by replacing the trap instruction with a jump instruction, which is equivalent to rewriting the original base address of the function.
3)系统将新位置的函数添加到活跃着的函数集合中,旧位置的函数失效。3) The system adds the function at the new location to the active function set, and the function at the old location becomes invalid.
(3)重复随机化进行阶段。如图3中(c)所示。系统每隔一个固定时间段再次随机化函数,默认是500ms。当这个时间截止时,系统在每一个活跃着的函数的开头放置一个陷阱指令,并在下一个陷阱指令执行时重新启动随机化过程。(3) Repeat the randomization progress stage. As shown in (c) in Figure 3. The system randomizes the function again every fixed time period, the default is 500ms. When this time expires, the system places a trap instruction at the beginning of each active function and restarts the randomization process when the next trap instruction executes.
(4)重复随机化完成阶段。当陷阱函数执行的时候,系统将活函数所使用的内存归结到一个集合中,然后遍历栈,在活函数集合中,如果里面的某一个对象被栈上返回地址所指向,那么该对象就会被标记,而该集合中没有被标记的对象则会被释放到堆中,例如图3中(d)所示ex3′函数内存被释放了,剩下的函数例如ex1′一旦不在栈上,就会在将来的某一次随机化过程之后被释放。而之后对于函数ex1的任何调用都会指向迁移函数ex1″的新位置。(4) Repeat the randomization completion phase. When the trap function is executed, the system puts the memory used by the active function into a collection, and then traverses the stack. In the active function collection, if an object inside is pointed to by the return address on the stack, then the object will be Marked, and the unmarked objects in the collection will be released to the heap, for example, the ex3' function memory is released as shown in (d) in Figure 3, and the remaining functions such as ex1' will be released once they are not on the stack. Will be released after some future randomization process. Any subsequent calls to the function ex1 will point to the new location of the migration function ex1″.
2.栈随机化2. Stack randomization
传统的栈随函数的调用依次生成相邻的栈帧,其中返回地址的位置恒定不变,因此,程序在较长时间内仍然存在相似性,这就有被突破的风险,如图4中(a)所示。针对这一缺陷,本系统在函数进行调用时启用栈帧布局随机化策略,在帧初始化阶段向栈中加入随机大小的填充空间,让每个返回地址的位置具有随机性和不确定性,进而使得程序能够获得函数周期间的随机性。填充空间的大小、填充空间的位置和随机化时刻这些都确保了栈的充分随机化。The traditional stack generates adjacent stack frames sequentially with the call of the function, in which the position of the return address is constant. Therefore, there is still a similarity in the program for a long time, which has the risk of being broken, as shown in Figure 4 ( a) as shown. In response to this defect, this system enables the stack frame layout randomization strategy when the function is called, and adds a random size padding space to the stack during the frame initialization stage, so that the position of each return address is random and uncertain, and then Enables programs to obtain randomness between function cycles. The size of the padding space, the position of the padding space, and the randomization time all ensure sufficient randomization of the stack.
(1)栈随机填充空间的大小。因为Linux系统要求的是栈指针SP是32位对齐,因此随机空间的大小不能没有任何限制,应该为4的整数倍,取值范围可以是{4,8,...,4i,…,N},上限是N=4096字节,同时还应该结合Linux系统中设置的线程的栈空间大小,在范围内进行随机取值。(1) The size of the random filling space of the stack. Because the Linux system requires that the stack pointer SP is 32-bit aligned, the size of the random space cannot be unlimited, it should be an integer multiple of 4, and the value range can be {4,8,...,4i,...,N }, the upper limit is N=4096 bytes, and the value should be randomly selected within the range in combination with the stack space size of the thread set in the Linux system.
(2)栈随机填充空间的位置。在运行期间,系统在每次重新随机化期间用随机字节大小、周期性地填充安全缓冲区域,填充区域位于函数参数前方。在运行栈空间的随机化时,当栈缓冲索引溢出的情况下,会回滚到第一个缓存索引位置,这就导致在重复随机化期间,函数可能会多次重用一个随机的栈安全缓冲区,这对攻击者对栈帧的定位带来了不确定性。(2) The position where the stack randomly fills the space. During runtime, the system periodically fills the safe buffer area with a random byte size during each re-randomization, before the function parameters. When running randomization of stack space, when the stack buffer index overflows, it will roll back to the first buffer index position, which leads to the possibility that the function may reuse a random stack safe buffer multiple times during repeated randomization area, which brings uncertainty to the attacker's positioning of the stack frame.
(3)随机化时刻。此时间点越是靠近运行时刻,系统越能取得较好的随机化效果。现有的防御策略要么是在程序运行前,要么是在进程启动时刻实施随机化布局,这两者方式都存在一定缺陷。动态随机化系统将随机化时刻推迟到各个函数运行时,这样每个函数每次运行时的栈帧布局都不相同,攻击者很难从中获得栈帧布局信息。(3) Randomize the moment. The closer this time point is to the running time, the better randomization effect the system can achieve. Existing defense strategies either implement randomized layout before the program runs or when the process starts, both of which have certain defects. The dynamic randomization system delays the randomization moment until each function is running, so that the stack frame layout of each function is different each time it is run, and it is difficult for an attacker to obtain stack frame layout information from it.
(4)栈随机填充空间过程。该系统在运行时刻,每次函数调用时,动态随机化系统在两个栈帧之间填充随机大小空间,起到一个类似安全缓冲区的作用。如图4中(b)所示。该过程如下:(4) The stack fills the space randomly. When the system is running, every time a function is called, the dynamic randomization system fills a space of random size between two stack frames, which acts like a safety buffer. As shown in Figure 4(b). The process is as follows:
1)系统在每个函数调用之前移动栈,大小为该函数加载的索引字节乘以x86_64架构上要求的栈对齐标准16。1) The system moves the stack before each function call, and the size is the index byte loaded by the function multiplied by the stack alignment standard 16 required on the x86_64 architecture.
2)定位参数压栈指令。2) Positioning parameter push instruction.
3)将代码添加到待填充区域。3) Add the code to the area to be filled.
4)最后函数参数压栈。4) Finally, the function parameters are pushed onto the stack.
这种方法对于函数参数和局部变量的访问方式没有任何影响。因为如果填充区域置于帧指针和局部变量之间,那么在访问局部变量之前,需要将帧指针加上填充区域的大小作为偏移。This approach has no effect on how function parameters and local variables are accessed. Because if the padding area is placed between the frame pointer and the local variable, then the frame pointer plus the size of the padding area needs to be used as an offset before accessing the local variable.
3.堆随机化3. Heap randomization
本发明使用一种新的堆空间随机化技术使得运行时堆空间的分布不再有规律。动态随机化系统采用了两个大小隔离的分配器。系统最初是用DieHard分配器实现的,该分配器是基于位图的随机化分配器。The present invention uses a new heap space randomization technique to make the distribution of the heap space no longer regular during operation. The dynamic randomization system employs two size-isolated allocators. The system was originally implemented with a DieHard allocator, which is a bitmap-based randomization allocator.
(1)不同于传统的分配器,DieHard分配器不使用最近释放的内存作为后续的分配资源。当程序尝试访问先前已经被释放的内存时,会出现著名的Use-After-Free安全漏洞。尽管系统的基本分配器比DieHard分配器更高效,但是前者随机化程度低于后者。因此,选择DieHard分配器才更合理。(1) Unlike traditional allocators, DieHard allocators do not use recently freed memory as subsequent allocation resources. The famous Use-After-Free security hole occurs when a program attempts to access memory that has been previously freed. Although the system's base allocator is more efficient than the DieHard allocator, the former is less randomized than the latter. Therefore, it is more reasonable to choose DieHard dispenser.
(2)堆随机化工作原理如图5所示,动态随机化系统通过在洗牌层包裹基础分配器来随机化堆,而洗牌层是由大小为N的数组指针组成,元素来自于基本堆的对象。为了实现充分的随机化,洗牌层的大小N必须足够大,但是N过大也会增大开销。因此,我们最终选取N=256作为一个折中的考虑。malloc函数负责产生一个随机的索引,移除洗牌层对应的索引对象,并用一个基本堆的对象替代。同样,free函数产生一个随机索引并将对应的索引对象释放到基本堆中。在堆空间,当通过对基础分配器中malloc的调用完成洗牌层中数组的初始化后,数组就使用洗牌算法对数组进行随机化处理:首先调用洗牌层中malloc函数,然后在基础分配器中使用malloc函数,进而得到一个新的对象p和一个随机索引i,其中i∈[0,N],并用该索引对应的数组元素和p交换,返回交换后的指针对象。同理free函数的洗牌原理也是如此。(2) The working principle of heap randomization is shown in Figure 5. The dynamic randomization system randomizes the heap by wrapping the basic allocator in the shuffling layer, and the shuffling layer is composed of array pointers with a size of N. heap of objects. In order to achieve sufficient randomization, the size N of the shuffling layer must be large enough, but too large N will also increase the overhead. Therefore, we finally choose N=256 as a compromise consideration. The malloc function is responsible for generating a random index, removing the index object corresponding to the shuffling layer, and replacing it with a basic heap object. Similarly, the free function generates a random index and releases the corresponding index object to the basic heap. In the heap space, after the initialization of the array in the shuffling layer is completed by calling malloc in the basic allocator, the array uses the shuffling algorithm to randomize the array: first call the malloc function in the shuffling layer, and then allocate The malloc function is used in the device to obtain a new object p and a random index i, where i∈[0, N], and exchange the array element corresponding to the index with p, and return the exchanged pointer object. The same is true for the shuffling principle of the free function.
附图说明Description of drawings
图1:Flush+Reload攻击原理图Figure 1: Schematic diagram of Flush+Reload attack
图2:防御Flush+Reload攻击效果图Figure 2: Effect diagram of defense against Flush+Reload attack
图3:代码随机化图Figure 3: Code Randomization Diagram
图4:栈随机化图Figure 4: Stack Randomization Diagram
图5:堆随机化图Figure 5: Heap Randomization Diagram
具体实施方式Detailed ways
本发明的硬件环境主要是一台PC主机。其中,PC主机的CPU为Intel(R)Core(TM)i5-4590,3.30GHz,内存为8GB RAM,64位操作系统。The hardware environment of the present invention is mainly a PC host. Among them, the CPU of the PC host is Intel(R) Core(TM) i5-4590, 3.30GHz, the memory is 8GB RAM, and the 64-bit operating system.
本发明的软件实现以Ubuntu14.04为平台,使用C++语言开发。GCC版本为4.6,Llvm、Clang版本为3.1,Dragonegg插件版本为3.1。The software implementation of the present invention takes Ubuntu 14.04 as a platform, and is developed using C++ language. The GCC version is 4.6, the Llvm and Clang versions are 3.1, and the Dragonegg plugin version is 3.1.
操作主要分为两部分,第一部分为对具体应用发起Cache攻击,第二部分是搭建一个动态随机化系统对其进行防御。The operation is mainly divided into two parts. The first part is to launch a Cache attack on a specific application, and the second part is to build a dynamic randomization system to defend against it.
1.Cache攻击1. Cache attack
(1)Flush:攻击者从Cache中驱逐出去一个共享的Cache行。(1) Flush: The attacker evicts a shared Cache line from the Cache.
(2)Wait:调度目标进程访问共享内存,更新Cache。(2) Wait: Schedule the target process to access the shared memory and update the Cache.
(3)Reload:攻击者重新加载Flush阶段驱逐的内存块,测量并记录特定Cache行的加载时间。通过缓存命中和缓存失效的时间信息差异推测具体应用所访问的Cache行。(3) Reload: The attacker reloads the memory block evicted in the Flush phase, and measures and records the loading time of a specific Cache line. The Cache line accessed by a specific application is speculated based on the difference in time information between a cache hit and a cache invalidation.
在缓存攻击过程中,以Flush+Reload攻击为例。其关键伪代码如下所示:In the cache attack process, take the Flush+Reload attack as an example. Its key pseudocode is as follows:
上述伪代码中系统阈值是根据事先进行的标准化测量出来的周期数,需要根据系统的评测结果进行设置,阈值越偏低,最后统计数据的假阳性越低。在经过多次测量后,在本实验环境下得到的周期数在125左右。同时,为了确保结果更加精确,加密次数也应该合理设置,在实验中,将其设为10000就足以显现出缓存失效和缓存命中的时间差异性了。The system threshold in the above pseudo code is the number of cycles measured according to the standardization in advance, and needs to be set according to the evaluation results of the system. The lower the threshold, the lower the false positive of the final statistical data. After several measurements, the number of cycles obtained in this experimental environment is around 125. At the same time, in order to ensure more accurate results, the number of encryption times should also be set reasonably. In the experiment, setting it to 10000 is enough to show the time difference between cache invalidation and cache hit.
2.防御Cache攻击2. Defense against Cache attacks
(1)下面为防御Cache攻击关键部分的伪代码:(1) The following is the pseudocode of the key part of defending against Cache attacks:
(2)代码随机化主要体现为函数位置的不断迁移,伪代码如下:(2) Code randomization is mainly reflected in the continuous migration of function positions. The pseudo code is as follows:
(3)栈随机化伪代码:(3) Stack randomization pseudocode:
(4)堆随机化伪代码:(4) Heap randomization pseudocode:
Claims (5)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810252891.8A CN108491694A (en) | 2018-03-26 | 2018-03-26 | A kind of method of dynamic randomization defence Cache attacks |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810252891.8A CN108491694A (en) | 2018-03-26 | 2018-03-26 | A kind of method of dynamic randomization defence Cache attacks |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN108491694A true CN108491694A (en) | 2018-09-04 |
Family
ID=63337847
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201810252891.8A Pending CN108491694A (en) | 2018-03-26 | 2018-03-26 | A kind of method of dynamic randomization defence Cache attacks |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN108491694A (en) |
Cited By (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109858239A (en) * | 2019-01-16 | 2019-06-07 | 四川大学 | CPU loophole attacker detection method in the container that a kind of sound state combines |
| CN110309652A (en) * | 2019-06-28 | 2019-10-08 | 兆讯恒达微电子技术(北京)有限公司 | A kind of method of configuration management Initiative Defense |
| CN110442469A (en) * | 2019-07-23 | 2019-11-12 | 浙江大学 | A kind of caching side-channel attack defence method based on local Random Maps |
| CN110782934A (en) * | 2019-09-27 | 2020-02-11 | 东南大学 | Cache line mapping and replacing method adopting time sequence speculative SRAM array |
| CN111797388A (en) * | 2020-06-12 | 2020-10-20 | 武汉大学 | A JavaScript engine memory information leak defense method and system based on runtime randomization |
| CN113051563A (en) * | 2021-02-25 | 2021-06-29 | 中国科学院信息工程研究所 | Cross-container software operation detection method and system |
| CN113196267A (en) * | 2018-12-05 | 2021-07-30 | 美光科技公司 | Preventing timing-based security attacks against reorder buffers |
| CN113573308A (en) * | 2021-09-22 | 2021-10-29 | 四川创智联恒科技有限公司 | Method and module for improving air interface security |
| CN114238942A (en) * | 2021-12-21 | 2022-03-25 | 中原工学院 | An overflow attack defense method and system based on stack randomization |
| CN114254400A (en) * | 2021-12-27 | 2022-03-29 | 中国人民解放军战略支援部队信息工程大学 | Method and system for stack buffer overflow attack defense based on dynamic shadow stack |
| WO2023178857A1 (en) * | 2022-03-23 | 2023-09-28 | 东南大学 | Function address space layout randomization method for deep embedded system |
Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105022956A (en) * | 2015-08-14 | 2015-11-04 | 中国科学院计算技术研究所 | Method for protecting against code reuse attack |
| US20170213039A1 (en) * | 2016-01-22 | 2017-07-27 | The University Of North Carolina At Chapel Hill | Methods, systems, and computer readable media for preventing code reuse attacks |
-
2018
- 2018-03-26 CN CN201810252891.8A patent/CN108491694A/en active Pending
Patent Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105022956A (en) * | 2015-08-14 | 2015-11-04 | 中国科学院计算技术研究所 | Method for protecting against code reuse attack |
| US20170213039A1 (en) * | 2016-01-22 | 2017-07-27 | The University Of North Carolina At Chapel Hill | Methods, systems, and computer readable media for preventing code reuse attacks |
Non-Patent Citations (1)
| Title |
|---|
| 王烨 等: "基于代码防泄漏的代码复用攻击防御技术", 《计算机研究与发展》 * |
Cited By (14)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| EP3891635A4 (en) * | 2018-12-05 | 2022-09-14 | Micron Technology, Inc. | Protection against timing-based security attacks on re-order buffers |
| CN113196267A (en) * | 2018-12-05 | 2021-07-30 | 美光科技公司 | Preventing timing-based security attacks against reorder buffers |
| CN109858239A (en) * | 2019-01-16 | 2019-06-07 | 四川大学 | CPU loophole attacker detection method in the container that a kind of sound state combines |
| CN110309652A (en) * | 2019-06-28 | 2019-10-08 | 兆讯恒达微电子技术(北京)有限公司 | A kind of method of configuration management Initiative Defense |
| CN110442469A (en) * | 2019-07-23 | 2019-11-12 | 浙江大学 | A kind of caching side-channel attack defence method based on local Random Maps |
| CN110442469B (en) * | 2019-07-23 | 2020-06-30 | 浙江大学 | A Cache Side-Channel Attack Defense Method Based on Local Random Mapping |
| CN110782934A (en) * | 2019-09-27 | 2020-02-11 | 东南大学 | Cache line mapping and replacing method adopting time sequence speculative SRAM array |
| CN111797388A (en) * | 2020-06-12 | 2020-10-20 | 武汉大学 | A JavaScript engine memory information leak defense method and system based on runtime randomization |
| CN113051563A (en) * | 2021-02-25 | 2021-06-29 | 中国科学院信息工程研究所 | Cross-container software operation detection method and system |
| CN113573308A (en) * | 2021-09-22 | 2021-10-29 | 四川创智联恒科技有限公司 | Method and module for improving air interface security |
| CN114238942A (en) * | 2021-12-21 | 2022-03-25 | 中原工学院 | An overflow attack defense method and system based on stack randomization |
| CN114254400A (en) * | 2021-12-27 | 2022-03-29 | 中国人民解放军战略支援部队信息工程大学 | Method and system for stack buffer overflow attack defense based on dynamic shadow stack |
| CN114254400B (en) * | 2021-12-27 | 2024-05-03 | 中国人民解放军战略支援部队信息工程大学 | Stack buffer overflow attack defense method and system based on dynamic shadow stack |
| WO2023178857A1 (en) * | 2022-03-23 | 2023-09-28 | 东南大学 | Function address space layout randomization method for deep embedded system |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108491694A (en) | A kind of method of dynamic randomization defence Cache attacks | |
| KR102287758B1 (en) | System protecting caches from side-channel attacks | |
| Frigo et al. | Grand pwning unit: Accelerating microarchitectural attacks with the GPU | |
| Pichai et al. | Architectural support for address translation on gpus: Designing memory management units for cpu/gpus with unified address spaces | |
| Yaniv et al. | Hash, don't cache (the page table) | |
| Yan et al. | Secdir: a secure directory to defeat directory side-channel attacks | |
| Saileshwar et al. | Bespoke cache enclaves: Fine-grained and scalable isolation from cache side-channels via flexible set-partitioning | |
| KR20090035523A (en) | Hardware Access Provisioning System and Access Management Method for Avoiding Cache Line Sharing in Virtual Machines | |
| JP2020527777A (en) | Invalidating the target realm in the realm hierarchy | |
| KR20210070936A (en) | Dynamic designation of instructions as sensitive | |
| US11886332B2 (en) | Dynamic memory allocation methods and systems | |
| Karnagel et al. | Big data causing big (TLB) problems: Taming random memory accesses on the GPU | |
| US11061829B2 (en) | Prefetch support with address space randomization | |
| Vavouliotis et al. | Page size aware cache prefetching | |
| Wei et al. | Lazytainter: Memory-efficient taint tracking in managed runtimes | |
| Ramkrishnan et al. | First time miss: Low overhead mitigation for shared memory cache side channels | |
| Stolz et al. | Risky translations: Securing tlbs against timing side channels | |
| Guo et al. | {GPU} Memory Exploitation for Fun and Profit | |
| Mahling et al. | Fetch Me If You Can: Evaluating CPU Cache Prefetching and Its Reliability on High Latency Memory | |
| Bölcskei et al. | Rubicon: Precise Microarchitectural Attacks with Page-Granular Massaging | |
| Mateescu et al. | Optimizing matrix transposes using a POWER7 cache model and explicit prefetching | |
| Seo et al. | ZOMETAG: Zone-based memory tagging for fast, deterministic detection of spatial memory violations on ARM | |
| Mukhtar et al. | IE-Cache: Counteracting Eviction-Based Cache Side-Channel Attacks Through Indirect Eviction | |
| Bang et al. | Enhancing a Lock-and-Key Scheme With MTE to Mitigate Use-After-Frees | |
| Ge | Principled elimination of microarchitectural timing channels through operating-system enforced time protection |
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 | ||
| WD01 | Invention patent application deemed withdrawn after publication | ||
| WD01 | Invention patent application deemed withdrawn after publication |
Application publication date: 20180904 |