Website-Suche

Überprüfen Sie Linux auf Meltdown- und Spectre-Schwachstellen und patchen Sie sie


Anfang dieser Woche hat ein Forscherteam von Googles Project Zero etwa Meltdown- und Spectre-Schwachstellen entdeckt, die viele moderne Prozessoren betreffen, darunter bestimmte Prozessoren von Intel, AMD und ARM. Obwohl AMD behauptet hat, dass die Chance, dass ihre Prozessoren von diesen Schwachstellen betroffen sind, null ist, haben die Forscher darauf hingewiesen, dass die Meltdown-Schwachstelle ausschließlich Intel-Prozessoren betrifft, während die Spectre-Schwachstelle möglicherweise einige Intel-, AMD- und ARM-Prozessoren betreffen kann.

Laut Wired, "arbeiten die Hersteller Intel, AMD und ARM eng zusammen und kooperieren mit Hardwareunternehmen, die ihre Prozessoren ausliefern, sowie mit Softwareunternehmen wie Apple, Google, Microsoft, der Linux Foundation, um Patches für diese Sicherheitslücken zu veröffentlichen. Wir können nicht garantieren, dass die Patches diese Probleme vollständig lösen werden. Aber zumindest ist es besser, als es zunächst schien."

Was kannst du gerade tun?

Greg Kroah-Hartman hat bereits die Veröffentlichung der stabilen Kernel 4.14.12, 4.9.75 und 4.4.110 angekündigt, die Meltdown- und Spectre-Fehlerbehebungen enthalten. Wenn Sie also einen Intel-, AMD- oder ARM-Prozessor verwenden, wird dringend empfohlen zu prüfen, ob Ihr Linux-System von den Meltdown- und Spectre-Sicherheitslücken betroffen ist, und es sofort durch ein Update auf den neuesten Linux-Kernel zu patchen. Wenn Ihre Linux-Distribution noch nicht die neuesten Linux-Kernel-Updates hat, wird dringend empfohlen, sofort Ihre Linux-Distribution zu wechseln.

Überprüfen Sie auf Meltdown- und Spectre-Sicherheitslücken

Auf Arch Linux und dessen Derivaten können Sie herausfinden, ob Ihr System von den Meltdown/Spectre-Sicherheitslücken betroffen ist, indem Sie die folgenden zwei Befehle verwenden.

$ zgrep CONFIG_PAGE_TABLE_ISOLATION /proc/config.gz
$ dmesg | grep iso

Wenn die obigen Befehle NICHTS zurückgeben, ist Ihr System noch nicht gepatcht. Daher müssen Sie Ihr Arch-basiertes System mit dem Befehl aktualisieren:

$ sudo pacman -Syu

Nachdem Sie Ihr Arch-System vollständig aktualisiert haben, starten Sie neu und führen Sie die oben genannten Befehle erneut aus. Wenn Ihr System gepatcht ist, sollten Sie für den ersten Befehl die folgende Ausgabe sehen:

CONFIG_PAGE_TABLE_ISOLATION=y

Und Sie werden diese Ausgabe für den zweiten Befehl erhalten.

[ 0.000000] Kernel/User page tables isolation: enabled

Ich habe den Kernel in meinem Arch-System bereits aktualisiert. Wie Sie im obigen Ausgabe sehen, ist mein Linux-Kernel 4.14.12-1-ARCH und er ist bereits gepatcht. Wenn Sie Ihr Arch-System noch nicht aktualisiert haben, werden Sie keine Ausgabe erhalten.

Die oben genannten Befehle funktionieren möglicherweise nicht unter Ubuntu. Zum Glück haben einige gute Samariter im Askubuntu-Forum eine Lösung veröffentlicht, um festzustellen, ob Ihre Ubuntu-Systeme gepatcht oder nicht gepatcht sind, indem Sie einen der folgenden Befehle verwenden.

$ grep CONFIG_PAGE_TABLE_ISOLATION=y /boot/config-`uname -r` && echo "patched :)" || echo "unpatched :("
$ grep cpu_insecure /proc/cpuinfo && echo "patched :)" || echo "unpatched :("
$ dmesg | grep "Kernel/User page tables isolation: enabled" && echo "patched :)" || echo "unpatched :("

Wenn die Ausgabe unpatched ist, ist Ihr System noch nicht gepatcht. Aktualisieren Sie sofort den Kernel, um die Patches anzuwenden.

Ich verwende in meinem Ubuntu-System immer noch 4.4.0-104-generic, daher erhalte ich bei allen Befehlen das Ergebnis 'ungepatcht'.

Gehe sofort dein Kernel mit folgendem Befehl aktualisieren:

$ sudo apt-get update
$ sudo apt-get dist-upgrade

Oder, wie im folgenden Link beschrieben.

  • Linux-Kernel-Dienstprogramme – Skripte zum Kompilieren und Aktualisieren des neuesten Linux-Kernels für Debian und Derivate

Nachdem Sie Ihren Kernel aktualisiert haben, führen Sie diese drei Befehle erneut aus, und Sie werden sehen, dass Ihr Ubuntu-System gepatcht ist!

Für andere Linux-Distributionen gibt es ein Skript namens "Spectre & Meltdown Checker", um die Meltdown/Spectre-Sicherheitslücken zu überprüfen. Dieses Skript hilft dabei herauszufinden, ob Ihre Linux-Installation gegenüber den 3 "speculative execution" CVEs verwundbar ist.

Klone dieses Skript:

$ git clone https://github.com/speed47/spectre-meltdown-checker.git

Dies wird alle Inhalte in einem Verzeichnis mit dem Namen "spectre-meltdown-checker" in Ihrem aktuellen Arbeitsverzeichnis klonen.

Gehe zu diesem Verzeichnis:

$ cd spectre-meltdown-checker/

Machen Sie das Skript ausführbar:

$ chmod +x spectre-meltdown-checker.sh

Führe es schließlich aus, um die Schwachstellen zu finden:

$ sudo ./spectre-meltdown-checker.sh

Hier ist die Beispielausgabe meines gepatchten Ubuntu-Systems:

Ohne Optionen überprüft es den aktuell laufenden Kernel. Sie können auch ein Kernel-Image über die Kommandozeile angeben, wenn Sie einen Kernel überprüfen möchten, der nicht läuft.

Update:

Das Spectre-Meltdown-Checker-Skript ist in den offiziellen Repositories einiger Linux-Distributionen verfügbar.

Auf Debian, Ubuntu:

$ sudo apt install spectre-meltdown-checker

Auf CentOS, RHEL:

$ sudo yum install epel-release
$ sudo yum install spectre-meltdown-checker

Auf Fedora:

$ sudo dnf install $ sudo apt install spectre-meltdown-checker

Nach der Installation von spectre-meltdown-checker, führen Sie es als Root-Benutzer oder mit sudo-Rechten aus, um auf Spectre- und Meltdown-Sicherheitslücken zu überprüfen:

$ sudo spectre-meltdown-checker

Beispielausgabe:

Spectre and Meltdown mitigation detection tool v0.37

Checking for vulnerabilities on current system
Kernel is Linux 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64
CPU is Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz

Hardware check
* Hardware support (CPU microcode) for mitigation techniques
  * Indirect Branch Restricted Speculation (IBRS)
    * SPEC_CTRL MSR is available:  NO 
    * CPU indicates IBRS capability:  NO 
  * Indirect Branch Prediction Barrier (IBPB)
    * PRED_CMD MSR is available:  NO 
    * CPU indicates IBPB capability:  NO 
  * Single Thread Indirect Branch Predictors (STIBP)
    * SPEC_CTRL MSR is available:  NO 
    * CPU indicates STIBP capability:  NO 
  * Enhanced IBRS (IBRS_ALL)
    * CPU indicates ARCH_CAPABILITIES MSR availability:  NO 
    * ARCH_CAPABILITIES MSR advertises IBRS_ALL capability:  NO 
  * CPU explicitly indicates not being vulnerable to Meltdown (RDCL_NO):  NO 
  * CPU microcode is known to cause stability problems:  NO  (model 42 stepping 7 ucode  cpuid 0x206a7)
* CPU vulnerability to the three speculative execution attack variants
  * Vulnerable to Variant 1:  YES 
  * Vulnerable to Variant 2:  YES 
  * Vulnerable to Variant 3:  YES 

CVE-2017-5753 [bounds check bypass] aka 'Spectre Variant 1'
* Mitigated according to the /sys interface:  NO  (Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers)
* Kernel has array_index_mask_nospec (x86):  UNKNOWN  (couldn't check (missing 'readelf' tool, please install it, usually it's in the 'binutils' package))
* Kernel has the Red Hat/Ubuntu patch:  UNKNOWN  (missing 'strings' tool, please install it, usually it's in the binutils package)
* Kernel has mask_nospec64 (arm):  UNKNOWN  (couldn't check (missing 'readelf' tool, please install it, usually it's in the 'binutils' package))
* Checking count of LFENCE instructions following a jump in kernel...  UNKNOWN  (couldn't check (missing 'readelf' tool, please install it, usually it's in the 'binutils' package))
> STATUS:  VULNERABLE  (Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers)

CVE-2017-5715 [branch target injection] aka 'Spectre Variant 2'
* Mitigated according to the /sys interface:  NO  (Vulnerable, STIBP: disabled)
* Mitigation 1
  * Kernel is compiled with IBRS support:  YES 
    * IBRS enabled and active:  UNKNOWN 
  * Kernel is compiled with IBPB support:  UNKNOWN  (in offline mode, we need the kernel image to be able to tell)
    * IBPB enabled and active:  NO 
* Mitigation 2
  * Kernel has branch predictor hardening (arm):  NO 
  * Kernel compiled with retpoline option:  YES 
> STATUS:  VULNERABLE  (IBRS+IBPB or retpoline+IBPB is needed to mitigate the vulnerability)

> How to fix: To mitigate this vulnerability, you need either IBRS + IBPB, both requiring hardware support from your CPU microcode in addition to kernel support, or a kernel compiled with retpoline and IBPB, with retpoline requiring a retpoline-aware compiler (re-run this script with -v to know if your version of gcc is retpoline-aware) and IBPB requiring hardware support from your CPU microcode. The retpoline + IBPB approach is generally preferred as the performance impact is lower. More information about how to enable the missing bits for those two possible mitigations on your system follow. You only need to take one of the two approaches.

> How to fix: The microcode of your CPU needs to be upgraded to be able to use IBPB. This is usually done at boot time by your kernel (the upgrade is not persistent across reboots which is why it's done at each boot). If you're using a distro, make sure you are up to date, as microcode updates are usually shipped alongside with the distro kernel. Availability of a microcode update for you CPU model depends on your CPU vendor. You can usually find out online if a microcode update is available for your CPU by searching for your CPUID (indicated in the Hardware Check section). An updated CPU microcode will have IBRS/IBPB capabilities indicated in the Hardware Check section above. If you're running under an hypervisor (KVM, Xen, VirtualBox, VMware, ...), the hypervisor needs to be up to date to be able to export the new host CPU flags to the guest. You can run this script on the host to check if the host CPU is IBRS/IBPB. If it is, and it doesn't show up in the guest, upgrade the hypervisor.

> How to fix: Your kernel doesn't have IBPB support, so you need to either upgrade your kernel (if you're using a distro) or recompiling a more recent kernel.

> How to fix: The microcode of your CPU needs to be upgraded to be able to use IBRS. This is usually done at boot time by your kernel (the upgrade is not persistent across reboots which is why it's done at each boot). If you're using a distro, make sure you are up to date, as microcode updates are usually shipped alongside with the distro kernel. Availability of a microcode update for you CPU model depends on your CPU vendor. You can usually find out online if a microcode update is available for your CPU by searching for your CPUID (indicated in the Hardware Check section). An updated CPU microcode will have IBRS/IBPB capabilities indicated in the Hardware Check section above. If you're running under an hypervisor (KVM, Xen, VirtualBox, VMware, ...), the hypervisor needs to be up to date to be able to export the new host CPU flags to the guest. You can run this script on the host to check if the host CPU is IBRS/IBPB. If it is, and it doesn't show up in the guest, upgrade the hypervisor.

CVE-2017-5754 [rogue data cache load] aka 'Meltdown' aka 'Variant 3'
* Mitigated according to the /sys interface:  NO  (Vulnerable)
* Kernel supports Page Table Isolation (PTI):  YES 
  * PTI enabled and active:  NO 
  * Reduced performance impact of PTI:  NO  (PCID/INVPCID not supported, performance impact of PTI will be significant)
* Running as a Xen PV DomU:  NO 
> STATUS:  VULNERABLE  (PTI is needed to mitigate the vulnerability)

> How to fix: If you're using a distro kernel, upgrade your distro to get the latest kernel available. Otherwise, recompile the kernel with the CONFIG_PAGE_TABLE_ISOLATION option (named CONFIG_KAISER for some kernels), or the CONFIG_UNMAP_KERNEL_AT_EL0 option (for ARM64)

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

Wie Sie im obigen Output sehen können, sind die Spectre- und Meltdown-Probleme noch nicht gepatcht.

Meltdown- und Spectre-Sicherheitslücken patchen

Wie ich bereits erwähnt habe, wird dringend empfohlen, den Kernel sowie Ihr System und alle Software auf dem neuesten Stand zu halten, da dadurch auch viele andere Sicherheitsupdates erhalten werden.

Um Ihr Arch Linux zu aktualisieren/aufzurüsten, führen Sie aus:

$ sudo pacman -Syu

Um Debian, Ubuntu zu aktualisieren:

$ sudo apt-get update && sudo apt-get dist-upgrade

Um Fedora zu aktualisieren:

$ sudo dnf update

Um RHEL/CentOS zu aktualisieren:

$ sudo yum update

Vergessen Sie nach dem Aktualisieren Ihres Linux-Systems nicht, es neu zu starten.

Bitte denken Sie erneut daran, dass diese Probleme noch nicht vollständig gelöst sind. Sie müssen Ihre Linux-Systeme in den nächsten Wochen weiter aktualisieren, bis alles behoben ist.

Vorgeschlagene Lektüre:

  • Wie man ein Linux-System dazu bringt, auf Intel-CPUs schneller zu laufen

Ressourcen:

  • /r/archlinux
  • NixCraft
  • Askubuntu