sodcalculator

10 Tech How-To

How to Check Your Linux Kernel for Spectre

Guide 10-46839 · Updated · Step by step

This guide shows you how to determine whether your Linux system is protected against the Spectre CPU vulnerabilities (CVE-2017-5753 and CVE-2017-5715). You’ll check kernel configuration, runtime mitigation status, and system logs—no special tools needed beyond a terminal.

What You’ll Need

  • A Linux system with a terminal (local or SSH).
  • Root or sudo access for some commands (though many checks work as a normal user).
  • Basic familiarity with the command line.

Step-by-Step

  1. Open a terminal. If you’re on a desktop, press Ctrl+Alt+T. Over SSH, just log in as usual.
  2. Check your kernel version. Run uname -r. Spectre mitigations were added in kernel 4.15 and backported to many LTS kernels. If your kernel is older than 4.15 (or an older LTS like 4.4 or 4.9 without backports), you’re likely unprotected. Note the version for later reference.
  3. Inspect kernel config for Spectre mitigations. Run grep -i spectre /boot/config-$(uname -r). Look for CONFIG_SPECULATION_MITIGATIONS=y or CONFIG_RETPOLINE=y. If you see CONFIG_RETPOLINE=y, the kernel was built with retpoline support. If the file doesn’t exist (common on some distros), check /proc/config.gz with zcat /proc/config.gz | grep -i spectre.
  4. Check runtime mitigation status. Run cat /sys/devices/system/cpu/vulnerabilities/spectre_v1 and cat /sys/devices/system/cpu/vulnerabilities/spectre_v2. These files show whether mitigations are active. A typical output for a patched system is Mitigation: usercopy/swapgs barriers and __user pointer sanitization for v1 and Mitigation: Full generic retpoline, IBPB: conditional, IBRS_FW, STIBP: conditional, RSB filling for v2. If you see Vulnerable, your system is not protected.
  5. Check if the CPU microcode is up to date. Spectre mitigations often require a CPU microcode update. Run dmesg | grep -i microcode (or journalctl -k | grep -i microcode on systemd systems). Look for lines like microcode: updated early or microcode: revision=0x.... If you see microcode: not updated or no microcode lines, your BIOS/UEFI or OS microcode package may be outdated.
  6. Verify that mitigations are not disabled at boot. Run cat /proc/cmdline. If you see nospectre_v1, nospectre_v2, or spectre_v2=off, mitigations were explicitly disabled. Also check for nopti (which disables KPTI, related to Meltdown but often grouped here).
  7. Check if your distribution has applied backports. Even if your kernel is older, distros like Ubuntu, Debian, and RHEL backport Spectre fixes. Run grep -i spectre /var/log/dpkg.log (Debian/Ubuntu) or rpm -q --changelog kernel | grep -i spectre | head (RHEL/Fedora) to see if patches were applied. This is a secondary check; the sysfs files are more authoritative.
  8. Test with a third-party script (optional). Tools like spectre-meltdown-checker (from the spectre-meltdown-checker package on some distros) provide a detailed report. Run sudo spectre-meltdown-checker to see a human-readable summary. Note: this is not official, but widely used.

Common Mistakes

  • Assuming a new kernel means protected. A kernel version alone doesn’t guarantee protection; the sysfs files are the ground truth.
  • Ignoring microcode. Even with a patched kernel, if the CPU microcode is old, some mitigations (like IBRS) may be ineffective or missing.
  • Checking only one vulnerability. Spectre v1 and v2 are separate; you must check both.
  • Misreading Vulnerable as Mitigation. Read the exact wording; Vulnerable means no protection, Mitigation means some protection.
  • Not checking boot parameters. A user or administrator might have disabled mitigations for performance reasons.

Tips

  • Update your system regularly. Kernel and microcode updates are the primary way to get Spectre fixes.
  • Use a long-term support (LTS) kernel if you need stability; LTS kernels receive backported security fixes.
  • For servers, consider enabling spectre_v2=on in boot parameters if it’s not already enabled (check with cat /proc/cmdline). Some distros default to auto, which may be less strict.
  • If you’re on a virtual machine, remember that the host also needs mitigations; your VM’s status depends on the hypervisor.
  • Document your findings. Save the output of the checks for future reference or for auditing.

Troubleshooting

  • If you get “No such file or directory” when reading sysfs files, your kernel is too old (pre-4.15) or the filesystem isn’t mounted. Try mount -t sysfs sysfs /sys (as root) or update your kernel.
  • If /boot/config-$(uname -r) doesn’t exist, your distro may not install kernel configs by default. Use zcat /proc/config.gz instead, or install the kernel-devel/linux-headers package.
  • If dmesg shows no microcode lines, it’s possible the microcode is loaded by the BIOS, not the OS. Check dmesg | grep -i "microcode" at the very beginning of the boot log; if nothing, check your BIOS settings for CPU microcode updates.
  • If the spectre-meltdown-checker script isn’t available, you can download it from its official GitHub repository (search for “spectre-meltdown-checker”). Ensure you trust the source.
  • If you see Vulnerable but your kernel is recent, check if your CPU is affected by a variant that hasn’t been mitigated yet (e.g., Spectre-BTB). Some older CPUs have no full mitigation, and the kernel may report Vulnerable despite best efforts. In that case, consider hardware replacement or additional isolation.

Frequently Asked Questions

Q: What is Spectre?
Spectre is a hardware vulnerability that allows programs to potentially steal data from the memory of other programs by exploiting speculative execution in CPUs. It has two main variants: v1 (bounds check bypass) and v2 (branch target injection).

Q: How do I know if my CPU is affected?
Most CPUs made before 2018 are affected. You can check the sysfs files as described; if they say Vulnerable, your CPU is affected and no mitigation is active.

Q: Can I disable Spectre mitigations to improve performance?
Yes, you can add nospectre_v1 and nospectre_v2 to the kernel command line, but this is strongly discouraged unless you fully trust all code running on the system. Spectre exploits can be triggered by malicious JavaScript in a browser.

Q: Do I need to update my BIOS/UEFI?
Yes, a BIOS/UEFI update may provide a CPU microcode update that enables certain mitigations. Check your motherboard or system vendor’s website for updates.

Q: Is my system safe if the sysfs files show Mitigation?
It means the kernel is applying the known mitigations. However, no mitigation is perfect, and new attack variants may emerge. Keep your system updated and follow security best practices.

Q: Does Spectre affect all Linux distributions equally?
No, the level of protection depends on the kernel version, CPU microcode, and whether the distro has backported fixes. Always check the sysfs files on your specific system.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →