重用攻击保护 (RAP) 如何工作?

信息安全 攻击预防 防御 反剥削 安全
2021-09-05 21:29:06

grsecurity的乡亲刚刚发布了4.5的Linux内核,其中包括一个测试补丁返回地址重用攻击防护或RAP,对返回导向编程(ROP)保护技术。

在这一点上,我无法理解他们的幻灯片有人可以用外行的话解释 RAP 的工作原理以及它提供多少保护(它是概率性的)吗?

编辑:虽然幻灯片让我相信 RAP 代表“返回地址保护”,但来自 grsecurity 团队的 Brad Spengler 证实它实际上是“重用攻击保护”(多项式的回答也证实了这一点)。

1个回答

RAP 与堆栈金丝雀非常相似,只是旨在防止 ROP。

编辑:在与 grsecurity 的花费者交谈后,事实证明我在这里描述的是 RAP 功能的一个子集,特别是返回指针保护。RAP 实际上被称为“Reuse Attack Protector”,旨在防止各种形式的间接调用。您链接的论文描述了 RAP 中的一些功能,其中返回指针保护和 ICFG 功能都是其中的一部分。

我们可以从论文中看到以下组件:

push %rbx
mov 8(%rsp),%rbx
xor %r12,%rbx
...
xor %r12,%rbx
cmp %rbx,8(%rsp)
jnz .error
pop %rbx
retn
.error:
ud2

那里的第一个块设置 RAP cookie:

; store the old value of rbx
push %rbx
; read the top value on the stack (the return pointer) and put it in rbx
mov 8(%rsp),%rbx
; xor rbx with a random value stored in r12
; rbx now contains the RAP canary
xor %r12,%rbx

然后,在函数结束时,在 ret 之前:

; xor the RAP canary in rbx with the random value in r12
; this "decrypts" the stack pointer from the RAP canary
xor %r12,%rbx
; compare the top value on the stack (the return pointer)
; with the value decrypted from the RAP canary
cmp %rbx,8(%rsp)
; if the comparison fails, jump to error
jnz .error
; restore the original value of rbx
pop %rbx
; return
retn
.error:
; an error occured, quit the process
ud2

ROP 背后的想法是你会找到你想要的指令(小工具),然后是返回指令。此保护功能会重写函数,以便每次返回之前的最后一条指令始终是 a pop %rbx,并且之前的指令用于验证 RAP 金丝雀。这使得很难找到非对齐指令之外的 ROP 小工具(即,由于对正常对齐之外的指令的二进制解释而恰好存在的小工具)。

该保护可以应用于用户模式和内核。cookie 值(%r12 中的值)在某些无限循环(例如事件处理程序和调度循环)中按任务、系统调用和每次迭代重新生成。最后一个原因是无限循环经常使用aret来跳出循环。(这不太正确)。

编辑:在与花费者讨论了更多之后,我建议等待解释出来。该功能的工作原理有很多微妙之处,我不确定我能否准确地从论文和我对 IRC 的简短讨论中涵盖它。一旦它出来,我会重新更新这个答案,让你更好地了解它的作用。