为什么我的未打补丁的系统*似乎*不容易受到 Spectre 的攻击?

信息安全 linux 幽灵 英特尔
2021-09-07 07:08:38

由于相应的研究论文公开提供了相当明确的描述,我认为在下面发布我的代码不被视为鼓励或认可漏洞利用。尽管如此,我知道有些回答者可能更愿意保持含糊不清......

我对各种测试感到困惑,无论我的系统在打补丁后是否没有受到 Spectre(和 Meltdown)漏洞的保护:他们有时似乎不同意,或者不清楚额外的软件是否还需要另一个补丁。因此,我打算通过实际利用漏洞来进行自己的测试 - 与大多数所说的测试工具相反,它们宁愿读取几种 CPU 和状态信息。

考虑以下代码片段...

#define CACHELINESIZE   4096
typedef char line[CACHELINESIZE];
line A[512];

char secret = 'H';
char any = 'X';

#define REP     100
char* pcheck[REP];
line* pwrite[REP];
for (int i=0; i<REP; i++) {
  pcheck[i] = &any; 
  pwrite[i] = A; 
}
pcheck[REP-1] = &secret;
pwrite[REP-1] = A+256;
char dummy;
for (int i=0; i<REP; i++) {
  if (i != (REP-1)) {
    dummy = pwrite[i][*pcheck[i]][0];
  }
}

连续计算99 次(if导致truealineother提取到缓存和读取),然后一次到false. 因此,我假设在最后一次运行中,分支预测被欺骗以推测性地执行(但后来放弃)分配。特别是,line由 的内容确定的asecret被提取到高速缓存中,即使 的内容secret从未“真正”(即非推测地)读取。

之后,我对各行的访问时间进行了调整,并期望line由内容确定的时间会显着缩短secret(即,读取 fromA[256+'H']应该比访问 other 更快A[256+c])。

但是,我始终为所有测试访问测量 > 1000 个周期,而我预计访问已缓存行的周期为 < 100 个。(我可以通过更改if条件并使访问“真实”而不仅仅是推测性来验证更短的时间)。

对我来说,这看起来好像 Spectre 漏洞根本不存在,即推测性缓存获取不会发生!?但我专门在尚未更新内核/编译器/BIOS/固件/微码的系统上尝试了这个至少这spectre-meltdown-checker.sh似乎证实了这一点:

Spectre and Meltdown mitigation detection tool v0.29

Checking for vulnerabilities against running kernel Linux 4.4.0-104-generic #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64
CPU is Intel(R) Celeron(R) CPU G530 @ 2.40GHz

CVE-2017-5753 [bounds check bypass] aka 'Spectre Variant 1'
* Checking count of LFENCE opcodes in kernel:  NO 
> STATUS:  VULNERABLE  (only 33 opcodes found, should be >= 70, heuristic to be improved when official patches become available)

CVE-2017-5715 [branch target injection] aka 'Spectre Variant 2'
* Mitigation 1
*   Hardware (CPU microcode) support for mitigation:  NO 
*   Kernel support for IBRS:  NO 
*   IBRS enabled for Kernel space:  NO 
*   IBRS enabled for User space:  NO 
* Mitigation 2
*   Kernel compiled with retpoline option:  NO 
*   Kernel compiled with a retpoline-aware compiler:  NO 
> STATUS:  VULNERABLE  (IBRS hardware + kernel support OR kernel with retpoline are needed to mitigate the vulnerability)

CVE-2017-5754 [rogue data cache load] aka 'Meltdown' aka 'Variant 3'
* Kernel supports Page Table Isolation (PTI):  NO 
* PTI enabled and active:  NO 
> STATUS:  VULNERABLE  (PTI is needed to mitigate the vulnerability)

A false sense of security is worse than no security at all, see --disclaimer

所以 - 具有讽刺意味的是 - 此输出的最后一行似乎适用于我的本土测试:即使系统易受攻击,它也无法暴露漏洞。问:但是为什么我的测试会以这种方式失败?我在“证明”它应该暴露漏洞之上的论点有什么问题?

备注:,当然,我编译我的代码没有优化,所以请放心,生成的汇编程序与源代码的结构匹配(我用 验证了这一点objdump)。另外,以上只是我尝试过的最基本的代码版本;为了“鼓励”推测,我if依赖于相对冗长的计算,并且then-body 由一条指令组成(反汇编为

   imul   -0x66c(%rbp),%eax
   cmp    %eax,%edx
   je     4006d7 <main+0xf5>
   movzbq (%rdi),%rdi
4006d7: ...
1个回答

您未打补丁的系统似乎不易受到 Spectre(和 Meltdown)攻击的原因是您的处理器不受该漏洞的影响¹。您的处理器 Intel(R) Celeron(R) CPU G530 不在 Intel [1] 发布的受影响产品列表中。Spectre/Meltdown [2] 网站仅声明“每个实现乱序执行的英特尔处理器都可能受到影响,这实际上是自 1995 年以来的所有处理器(除了 2013 年之前的英特尔安腾和英特尔凌动)”[2]。Celeron G530 要么不实施乱序执行,要么不受漏洞利用或漏洞的影响。关于第二种情况,它可能是易受攻击的,但不能被您的漏洞利用,或者在论文描述的(确切)方式中不易受攻击。

¹根据英特尔

[1] https://security-center.intel.com/advisory.aspx?intelid=intel-sa-00088&languageid=en-fr
[2] https://meltdownattack.com/