如何检查我的 Ubuntu 上是否启用了 KPTI?

Mar*_*sny 65 security kernel

当前的 Meltdown Intel 处理器漏洞目前已通过启用页表隔离进行补救。有一个问题如何关闭它:如何禁用页表隔离以恢复由于英特尔 CPU 安全漏洞补丁而丢失的性能?

我的问题是相反的:有没有办法检查正在运行的系统上 PTI 机制是否对系统有效,从而保护系统?我专门寻找cat /proc/somethingor cat /sys/something,而不是检查内核版本或配置参数等。

N0r*_*ert 63

  • 按照Raniz 的建议在内核配置中使用 Grepping CONFIG_PAGE_TABLE_ISOLATION对桌面 Ubuntu 没有帮助,但可能对云实例有所帮助:

    grep CONFIG_PAGE_TABLE_ISOLATION=y /boot/config-`uname -r` && \
    echo "patched :)" || echo "unpatched :("
    
    Run Code Online (Sandbox Code Playgroud)



  • 您可以从Raphael Carvalho编译测试程序以进行熔断检测:

    sudo apt-get install git build-essential
    cd /tmp
    git clone https://github.com/raphaelsc/Am-I-affected-by-Meltdown.git
    cd Am-I-affected-by-Meltdown
    make
    sudo sh -c "echo 0  > /proc/sys/kernel/kptr_restrict"
    ./meltdown-checker
    
    Run Code Online (Sandbox Code Playgroud)

在修补系统上,它应该以输出结束

...
so far so good (i.e. meltdown safe) ...

System not affected (take it with a grain of salt though as false negative
may be reported for specific environments; Please consider running it once again).
Run Code Online (Sandbox Code Playgroud)

在修补系统上,它应该显示以下内容:

Spectre and Meltdown mitigation detection tool v0.27

Checking for vulnerabilities against live running kernel Linux 4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018 x86_64
...
CVE-2017-5754 [rogue data cache load] aka 'Meltdown' aka 'Variant 3'
* Kernel supports Page Table Isolation (PTI):  YES 
* PTI enabled and active:  YES 
> STATUS:  NOT VULNERABLE  (PTI mitigates the vulnerability)
Run Code Online (Sandbox Code Playgroud)

不要在 Xenial 上安装 4.4.0-108-generic!它破坏了启动/重启/关机/挂起功能

安装 4.4.0-109-generic(详见 USN-3522-3)!


正如Robie Basak 已经写过的那样,有一个关于Ubuntu 中 Spectre 和 Meltdown 漏洞状态的页面。

还有:

  • “dmesg | grep 隔离”类型的答案比这个更可取,IMO。一些发行版(至少是 Debian 延伸版,也可能是其他发行版)将 PTI 移植到它们的旧内核,但没有将 /proc/cpuinfo 中的 cpu_insecure 标志。在这些系统上,查看 dmesg 日志是检查的唯一方法,AFAICT。 (4认同)
  • 经过进一步调查,这三个建议都被打破了。Grepping for `isolation` 将匹配 `Kernel/User page tables isolation: enabled` 和 `Kernel/User page tables isolation: disabled on command line`。 (4认同)
  • Ubuntu 的更新计划在 Januari 9 进行。它们可能会更早登陆,但我不会指望它。https://insights.ubuntu.com/2018/01/04/ubuntu-updates-for-the-meltdown-spectre-vulnerabilities/ (3认同)
  • 我认为`dmesg | grep 隔离 && 回显“已修补:)” || echo "unpatched :("` 列出的命令是不必要的*危险*:它没有显示实际匹配的行,并且如果匹配了一个随机的其他“隔离”实例,它也会很高兴地打印“patched :)”。 . (3认同)
  • 我会反对第二个建议(grepping `/proc/cpuinfo` for cpu_insecure)。如果你把它放到一个脚本中,并且你将来有一个 CPU 在它的微体系结构中修复了这个问题,`/proc/cpuinfo` 将不再说 `cpu_insecure` 并且你的脚本会相信内核是 **unpatched**即使它被**修补**。我还建议反对第三个建议,因为很有可能在某个时候在 `dmesg` 输出中可能有 `isolation` 这个词,而不是指内核页表隔离。 (2认同)

Aad*_* RF 18

运行以下命令:

dmesg | grep 'page tables isolation'
Run Code Online (Sandbox Code Playgroud)

如果显示已启用,则 PTI 已启用。如果未显示任何内容或您在终端中看到“已禁用”,则 PTI 已禁用。Ubuntu 尚未发布补丁,因此不会显示任何消息。


Jon*_*sCz 13

您可以检查cat /proc/cpuinfo,如果它cpu_insecure在“错误”下报告,则启用了 PTI。

如果它是空白的(或者只是没有列出cpu_insecure),那么很可能你正在运行一个尚未打补丁的内核(Ubuntu 还没有),或者你有一个 AMD 处理器(可以预见这将不会被启用,因为它们'不脆弱)。

目前,所有 CPU在最新的 4.15 内核中都被视为易受攻击的。

  • 内核 4.14.11 将为任何 x86 CPU 设置 `cpu_insecure`;4.14.12 和更新版本只会为 Intel CPU 设置它(包括那些太旧或太原始而容易受到攻击的 CPU。即使 KPTI 被禁用,两者也会设置它。 (2认同)

小智 8

我发现了这个很棒的 sh 脚本来测试您系统上的 Meltdown/Spectre 漏洞:

https://github.com/speed47/spectre-meltdown-checker

该脚本会检查您的系统是否存在系统上已知的 Meltdown 和 Spectre 补丁,以告诉您这些漏洞现在是否已被您的操作系统缓解


Mic*_*icz 7

您可以运行以下命令来查看所有可用的缓解措施(不仅针对 PTI,还针对其他漏洞):

$ cat /sys/devices/system/cpu/vulnerabilities/*
Mitigation: PTE Inversion
Mitigation: Clear CPU buffers; SMT vulnerable
Mitigation: PTI
Mitigation: Speculative Store Bypass disabled via prctl and seccomp
Mitigation: usercopy/swapgs barriers and __user pointer sanitization
Mitigation: Full generic retpoline, IBPB: conditional, IBRS_FW, STIBP: conditional, RSB filling
Run Code Online (Sandbox Code Playgroud)