GNU/Linux >> Belajar Linux >  >> Linux

Cara Memeriksa Kerentanan Meltdown Dan Spectre Dan Menambalnya Di Linux

Awal pekan ini, tim peneliti di Project Zero Google telah menemukan tentang Kehancuran dan Hantu kerentanan yang mempengaruhi banyak prosesor modern, termasuk prosesor tertentu oleh Intel, AMD dan ARM. Meskipun AMD telah mengklaim bahwa tidak ada peluang bagi prosesor mereka untuk terpengaruh oleh kekurangan ini, para peneliti telah mengindikasikan bahwa kerentanan Meltdown eksklusif untuk prosesor Intel, sedangkan kerentanan Spectre mungkin dapat memengaruhi beberapa prosesor Intel, AMD, dan ARM.

Menurut Berkabel , "produsen Intel, AMD, dan ARM bekerja erat dan berkolaborasi dengan perusahaan perangkat keras yang mengirimkan prosesor dan perusahaan perangkat lunak mereka seperti Apple, Google, Microsoft, yayasan Linux untuk merilis patch untuk kelemahan keamanan ini. Kami tidak dapat memastikan patch akan menyelesaikan masalah ini sepenuhnya. Tapi, setidaknya, lebih baik dari yang terlihat sebelumnya".

Apa yang bisa kamu lakukan sekarang?

Greg Kroah-Hartman telah mengumumkan rilis kernel stabil 4.14.12, 4.9.75, dan 4.4.110 yang dilengkapi dengan perbaikan krisis dan Spectre. Jadi, jika Anda menggunakan prosesor Intel atau AMD atau ARM, sangat disarankan untuk memeriksa apakah sistem Linux Anda terpengaruh dengan kerentanan Meltdown And Spectre dan segera menambalnya dengan memperbarui kernel Linux terbaru. Jika distro Linux Anda belum memiliki pembaruan kernel Linux terbaru, sangat disarankan untuk mengubah distribusi Linux Anda sekarang juga.

Periksa Kerentanan Meltdown dan Spectre

Di Arch Linux dan turunannya, Anda dapat mengetahui apakah sistem Anda terpengaruh dengan kerentanan meltdown/spectre menggunakan dua perintah berikut.

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

Jika perintah di atas tidak menghasilkan apa-apa, sistem Anda belum ditambal. Jadi, Anda perlu memperbarui sistem berbasis Arch Anda menggunakan perintah:

$ sudo pacman -Syu

Setelah sepenuhnya memperbarui sistem Arch Anda, reboot dan jalankan perintah di atas lagi. Jika sistem Anda ditambal, Anda akan melihat output berikut untuk perintah pertama:

CONFIG_PAGE_TABLE_ISOLATION=y

Dan Anda akan mendapatkan output ini untuk perintah kedua.

[ 0.000000] Kernel/User page tables isolation: enabled

Saya sudah memperbarui Kernel di sistem Arch saya. Seperti yang Anda lihat pada output di atas, kernel Linux saya adalah 4.14.12-1-ARCH dan sudah ditambal. Jika Anda belum memperbarui sistem Arch, Anda tidak akan mendapatkan hasil apa pun.

Perintah di atas mungkin tidak berfungsi di Ubuntu. Untungnya, beberapa orang Samaria yang baik di Askubuntu forum telah memposting solusi untuk menemukan apakah sistem Ubuntu Anda ditambal atau tidak ditambal menggunakan salah satu dari perintah berikut.

$ 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 :("

Jika output tidak ditambal , sistem Anda belum ditambal. Perbarui kernel segera untuk menerapkan tambalan.

Saya masih menggunakan 4.4.0-104-generic di sistem Ubuntu saya, jadi saya mendapatkan 'unpatched' dalam hasil untuk semua perintah.

Segera perbarui Kernel Anda menggunakan perintah:

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

Atau, seperti yang dijelaskan dalam tautan berikut.

  • Utilitas Kernel Linux – Skrip Untuk Mengkompilasi Dan Memperbarui Kernel Linux Terbaru Untuk Debian Dan Derivatif

Setelah memperbarui kernel Anda, jalankan ketiga perintah itu lagi, dan Anda akan melihat sistem Ubuntu Anda telah ditambal!

Untuk distro Linux lainnya, ada script bernama "Spectre &Meltdown Checker" untuk memeriksa kerentanan Meltdown/Spectre. Skrip ini akan membantu menemukan apakah instalasi Linux Anda rentan terhadap 3 CVE "eksekusi spekulatif".

Git clone skrip ini:

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

Ini akan mengkloning semua konten dalam direktori bernama "spectre-meltdown-checker" di direktori kerja Anda saat ini.

Buka direktori itu:

$ cd spectre-meltdown-checker/

Jadikan skrip dapat dieksekusi:

$ chmod +x spectre-meltdown-checker.sh

Terakhir jalankan untuk menemukan kerentanannya:

$ sudo ./spectre-meltdown-checker.sh

Berikut adalah contoh keluaran dari sistem Ubuntu saya yang ditambal:

Tanpa opsi, itu akan memeriksa Anda yang sedang menjalankan kernel. Anda juga dapat menentukan imej kernel pada baris perintah, jika Anda ingin memeriksa kernel yang tidak Anda jalankan.

Pembaruan:

Skrip spectre-meltdown-checker tersedia di repositori resmi beberapa distribusi Linux.

Di Debian, Ubuntu:

$ sudo apt install spectre-meltdown-checker

Di CentOS, RHEL:

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

Di Fedora:

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

Setelah menginstal spectre-meltdown-checker, jalankan sebagai pengguna root atau dengan hak sudo untuk memeriksa kerentanan Spectre dan Meltdown:

$ sudo spectre-meltdown-checker

Contoh keluaran:

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

Seperti yang Anda lihat pada output di atas, masalah Spectre dan Meltdown belum ditambal.

Tambalan Meltdown Dan Kerentanan Spectre

Seperti yang telah saya sebutkan, sangat disarankan untuk selalu memperbarui kernel dan sistem Anda serta semua perangkat lunak, karena ini juga mendapatkan banyak perbaikan keamanan lainnya.

Untuk memperbarui/meningkatkan Arch Linux Anda, jalankan:

$ sudo pacman -Syu

Untuk memperbarui Debian, Ubuntu:

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

Untuk memperbarui Fedora:

$ sudo dnf update

Untuk memperbarui RHEL/CentOS:

$ sudo yum update

Setelah memperbarui sistem Linux Anda, jangan lupa untuk me-rebootnya.

Sekali lagi, harap diingat bahwa masalah ini belum sepenuhnya terselesaikan. Anda harus terus memperbarui sistem Linux Anda selama beberapa minggu ke depan, hingga semuanya diperbaiki.

Bacaan yang disarankan:

  • Cara membuat sistem Linux berjalan lebih cepat pada CPU Intel

Linux
  1. Cara Memeriksa Port Terbuka di Linux dengan netstat, lsof, dan nmap

  2. Cara Menginstal ClamAV di Ubuntu 20.04 dan Memindai Kerentanan

  3. Bagaimana cara mengurangi kerentanan Spectre dan Meltdown pada sistem Linux?

  1. Cara memeriksa Versi OS dan Linux

  2. Cara Menyimpan Perintah Linux Dan Menggunakannya Sesuai Permintaan

  3. Linux – Bagaimana Cara Memeriksa Distro Linux Apakah Aman Dan Tidak Memiliki Kode Berbahaya??

  1. Memahami jalur file dan cara menggunakannya di Linux

  2. Langkah-langkah pasca-pemasangan untuk instans Linux baru, dan cara mengotomatiskannya

  3. Cara mengecek OS dan versi menggunakan perintah Linux