mirror of
https://github.com/speed47/spectre-meltdown-checker.git
synced 2026-04-09 10:13:18 +02:00
fix: better detect kernel lockdown & no longer require cap_flush_cmd to deem CVE-2018-3615 as mitigated (fix #296)
This commit is contained in:
@@ -17,7 +17,8 @@ VERSION='1.0.0'
|
||||
|
||||
# --- Common paths and basedirs ---
|
||||
readonly VULN_SYSFS_BASE="/sys/devices/system/cpu/vulnerabilities"
|
||||
readonly DEBUGFS_BASE="/sys/kernel/debug"
|
||||
readonly SYSKERNEL_BASE="/sys/kernel"
|
||||
readonly DEBUGFS_BASE="$SYSKERNEL_BASE/debug"
|
||||
readonly SYS_MODULE_BASE="/sys/module"
|
||||
readonly CPU_DEV_BASE="/dev/cpu"
|
||||
readonly BSD_CPUCTL_DEV_BASE="/dev/cpuctl"
|
||||
|
||||
@@ -58,6 +58,19 @@ write_msr_one_core() {
|
||||
return "$(eval echo \$$mockvarname)"
|
||||
fi
|
||||
|
||||
# proactive lockdown detection via sysfs (vanilla 5.4+, CentOS 8+, Rocky 9+):
|
||||
# if the kernel lockdown is set to integrity or confidentiality, MSR writes will be denied,
|
||||
# so we can skip the write attempt entirely and avoid relying on dmesg parsing
|
||||
if [ -e "$SYSKERNEL_BASE/security/lockdown" ]; then
|
||||
if grep -qE '\[integrity\]|\[confidentiality\]' "$SYSKERNEL_BASE/security/lockdown" 2>/dev/null; then
|
||||
pr_debug "write_msr: kernel lockdown detected via $SYSKERNEL_BASE/security/lockdown"
|
||||
g_mockme=$(printf "%b\n%b" "$g_mockme" "SMC_MOCK_WRMSR_${msr}_RET=$WRITE_MSR_RET_LOCKDOWN")
|
||||
g_msr_locked_down=1
|
||||
ret_write_msr_msg="your kernel is locked down, please reboot with lockdown=none in the kernel cmdline and retry"
|
||||
return $WRITE_MSR_RET_LOCKDOWN
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e $CPU_DEV_BASE/0/msr ] && [ ! -e ${BSD_CPUCTL_DEV_BASE}0 ]; then
|
||||
# try to load the module ourselves (and remember it so we can rmmod it afterwards)
|
||||
load_msr
|
||||
@@ -231,6 +244,19 @@ read_msr_one_core() {
|
||||
return "$(eval echo \$$mockvarname)"
|
||||
fi
|
||||
|
||||
# proactive lockdown detection via sysfs (vanilla 5.4+, CentOS 8+, Rocky 9+):
|
||||
# if the kernel lockdown is set to integrity or confidentiality, MSR writes will be denied,
|
||||
# so we can skip the write attempt entirely and avoid relying on dmesg parsing
|
||||
if [ -e "$SYSKERNEL_BASE/security/lockdown" ]; then
|
||||
if grep -qE '\[integrity\]|\[confidentiality\]' "$SYSKERNEL_BASE/security/lockdown" 2>/dev/null; then
|
||||
pr_debug "write_msr: kernel lockdown detected via $SYSKERNEL_BASE/security/lockdown"
|
||||
g_mockme=$(printf "%b\n%b" "$g_mockme" "SMC_MOCK_WRMSR_${msr}_RET=$WRITE_MSR_RET_LOCKDOWN")
|
||||
g_msr_locked_down=1
|
||||
ret_write_msr_msg="your kernel is locked down, please reboot with lockdown=none in the kernel cmdline and retry"
|
||||
return $WRITE_MSR_RET_LOCKDOWN
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e $CPU_DEV_BASE/0/msr ] && [ ! -e ${BSD_CPUCTL_DEV_BASE}0 ]; then
|
||||
# try to load the module ourselves (and remember it so we can rmmod it afterwards)
|
||||
load_msr
|
||||
|
||||
@@ -626,17 +626,16 @@ check_cpu() {
|
||||
if [ "$opt_allow_msr_write" = 1 ]; then
|
||||
pr_info_nol " * FLUSH_CMD MSR is available: "
|
||||
# the new MSR 'FLUSH_CMD' is at offset 0x10b, write-only
|
||||
# this is probed for informational purposes only, the CPUID L1D flush bit
|
||||
# (cap_l1df) is the authoritative indicator per Intel guidance
|
||||
write_msr 0x10b
|
||||
ret=$?
|
||||
if [ $ret = $WRITE_MSR_RET_OK ]; then
|
||||
pstatus green YES
|
||||
cap_flush_cmd=1
|
||||
elif [ $ret = $WRITE_MSR_RET_KO ]; then
|
||||
pstatus yellow NO
|
||||
cap_flush_cmd=0
|
||||
else
|
||||
pstatus yellow UNKNOWN "$ret_write_msr_msg"
|
||||
cap_flush_cmd=-1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -655,12 +654,6 @@ check_cpu() {
|
||||
cap_l1df=-1
|
||||
fi
|
||||
|
||||
# if we weren't allowed to probe the write-only MSR but the CPUID
|
||||
# bit says that it shoul be there, make the assumption that it is
|
||||
if [ "$opt_allow_msr_write" != 1 ]; then
|
||||
cap_flush_cmd=$cap_l1df
|
||||
fi
|
||||
|
||||
if is_intel; then
|
||||
pr_info " * Microarchitectural Data Sampling"
|
||||
pr_info_nol " * VERW instruction is available: "
|
||||
|
||||
Reference in New Issue
Block a user