mirror of
https://github.com/speed47/spectre-meltdown-checker.git
synced 2025-07-15 23:31:22 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
96dfa03c00 | |||
05c79425ab | |||
9def0c949a | |||
64eb1d005c | |||
bffda8b3e7 | |||
13f2133a97 | |||
8c2fd0f0bb | |||
761c2b80e4 | |||
d6977928e5 | |||
bd4c74331e | |||
82972f8790 |
24
README.md
24
README.md
@ -28,24 +28,24 @@ Example of the output of the script:
|
|||||||
|
|
||||||
```
|
```
|
||||||
$ sudo ./spectre-meltdown-checker.sh
|
$ sudo ./spectre-meltdown-checker.sh
|
||||||
Spectre and Meltdown mitigation detection tool v0.02
|
Spectre and Meltdown mitigation detection tool v0.07
|
||||||
|
|
||||||
CVE-2017-5753 [bounds check bypass] aka 'Spectre Variant 1'
|
CVE-2017-5753 [bounds check bypass] aka 'Spectre Variant 1'
|
||||||
* Kernel compiled with LFENCE opcode inserted at the proper places: NO (only 38 opcodes found, should be >= 60)
|
* Kernel compiled with LFENCE opcode inserted at the proper places: NO (only 38 opcodes found, should be >= 60)
|
||||||
> STATUS: VULNERABLE
|
> STATUS: VULNERABLE
|
||||||
|
|
||||||
CVE-2017-5715 [branch target injection] aka 'Spectre Variant 2'
|
CVE-2017-5715 [branch target injection] aka 'Spectre Variant 2'
|
||||||
* Mitigation 1
|
* Mitigation 1
|
||||||
* Hardware (CPU microcode) support for mitigation: NO
|
* Hardware (CPU microcode) support for mitigation: NO
|
||||||
* Kernel support for IBRS: NO
|
* Kernel support for IBRS: NO
|
||||||
* IBRS enabled for Kernel space: NO
|
* IBRS enabled for Kernel space: NO
|
||||||
* IBRS enabled for User space: NO
|
* IBRS enabled for User space: NO
|
||||||
* Mitigation 2
|
* Mitigation 2
|
||||||
* Kernel recompiled with retpolines: UNKNOWN (check not yet implemented)
|
* Kernel compiled with retpolines: NO
|
||||||
> STATUS: VULNERABLE (IBRS hardware + kernel support OR retpolines-compiled kernel are needed to mitigate the vulnerability)
|
> STATUS: VULNERABLE (IBRS hardware + kernel support OR kernel with retpolines are needed to mitigate the vulnerability)
|
||||||
|
|
||||||
CVE-2017-5754 [rogue data cache load] aka 'Meltdown' aka 'Variant 3'
|
CVE-2017-5754 [rogue data cache load] aka 'Meltdown' aka 'Variant 3'
|
||||||
* Kernel supports Page Table Isolation (PTI): YES
|
* Kernel supports Page Table Isolation (PTI): YES
|
||||||
* PTI enabled and active: YES
|
* PTI enabled and active: YES
|
||||||
> STATUS: NOT VULNERABLE (PTI mitigates the vulnerability)
|
> STATUS: NOT VULNERABLE (PTI mitigates the vulnerability)
|
||||||
```
|
```
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# Spectre & Meltdown checker
|
# Spectre & Meltdown checker
|
||||||
# Stephane Lesimple
|
# Stephane Lesimple
|
||||||
VERSION=0.03
|
VERSION=0.09
|
||||||
|
|
||||||
pstatus()
|
pstatus()
|
||||||
{
|
{
|
||||||
@ -11,7 +11,7 @@ pstatus()
|
|||||||
yellow) col="\033[103m\033[30m";;
|
yellow) col="\033[103m\033[30m";;
|
||||||
*) col="";;
|
*) col="";;
|
||||||
esac
|
esac
|
||||||
/bin/echo -ne "$col$2\033[0m"
|
/bin/echo -ne "$col $2 \033[0m"
|
||||||
[ -n "$3" ] && /bin/echo -n " ($3)"
|
[ -n "$3" ] && /bin/echo -n " ($3)"
|
||||||
/bin/echo
|
/bin/echo
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ try_decompress()
|
|||||||
do
|
do
|
||||||
pos=${pos%%:*}
|
pos=${pos%%:*}
|
||||||
tail -c+$pos "$img" | $3 > $vmlinuxtmp 2> /dev/null
|
tail -c+$pos "$img" | $3 > $vmlinuxtmp 2> /dev/null
|
||||||
check_vmlinux $vmlinuxtmp && echo $vmlinuxtmp || rm -f $vmlinuxtmp
|
check_vmlinux $vmlinuxtmp && echo $vmlinuxtmp && return 0
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,11 @@ extract_vmlinux()
|
|||||||
vmlinuxtmp=$(mktemp /tmp/vmlinux-XXX)
|
vmlinuxtmp=$(mktemp /tmp/vmlinux-XXX)
|
||||||
|
|
||||||
# Initial attempt for uncompressed images or objects:
|
# Initial attempt for uncompressed images or objects:
|
||||||
check_vmlinux $img
|
if check_vmlinux $img; then
|
||||||
|
cat $img > $vmlinuxtmp
|
||||||
|
echo $vmlinuxtmp
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# That didn't work, so retry after decompression.
|
# That didn't work, so retry after decompression.
|
||||||
try_decompress '\037\213\010' xy gunzip || \
|
try_decompress '\037\213\010' xy gunzip || \
|
||||||
@ -73,9 +77,11 @@ extract_vmlinux()
|
|||||||
/bin/echo -e "\033[1;34mCVE-2017-5753 [bounds check bypass] aka 'Spectre Variant 1'\033[0m"
|
/bin/echo -e "\033[1;34mCVE-2017-5753 [bounds check bypass] aka 'Spectre Variant 1'\033[0m"
|
||||||
/bin/echo -n "* Kernel compiled with LFENCE opcode inserted at the proper places: "
|
/bin/echo -n "* Kernel compiled with LFENCE opcode inserted at the proper places: "
|
||||||
|
|
||||||
|
status=0
|
||||||
img=''
|
img=''
|
||||||
[ -e /boot/vmlinuz-$(uname -r) ] && img=/boot/vmlinuz-$(uname -r)
|
[ -e /boot/vmlinuz-$(uname -r) ] && img=/boot/vmlinuz-$(uname -r)
|
||||||
[ -e /boot/vmlinux-$(uname -r) ] && img=/boot/vmlinux-$(uname -r)
|
[ -e /boot/vmlinux-$(uname -r) ] && img=/boot/vmlinux-$(uname -r)
|
||||||
|
[ -e /boot/kernel-$( uname -r) ] && img=/boot/kernel-$( uname -r)
|
||||||
[ -e /boot/bzImage-$(uname -r) ] && img=/boot/bzImage-$(uname -r)
|
[ -e /boot/bzImage-$(uname -r) ] && img=/boot/bzImage-$(uname -r)
|
||||||
if [ -z "$img" ]; then
|
if [ -z "$img" ]; then
|
||||||
pstatus yellow UNKNOWN "couldn't find your kernel image in /boot"
|
pstatus yellow UNKNOWN "couldn't find your kernel image in /boot"
|
||||||
@ -94,7 +100,6 @@ else
|
|||||||
pstatus green YES "$nb_lfence opcodes found, which is >= 60"
|
pstatus green YES "$nb_lfence opcodes found, which is >= 60"
|
||||||
status=2
|
status=2
|
||||||
fi
|
fi
|
||||||
rm -f $vmlinux
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -115,14 +120,13 @@ fi
|
|||||||
if [ ! -e /dev/cpu/0/msr ]; then
|
if [ ! -e /dev/cpu/0/msr ]; then
|
||||||
pstatus yellow UNKNOWN "couldn't read /dev/cpu/0/msr, is msr support enabled in your kernel?"
|
pstatus yellow UNKNOWN "couldn't read /dev/cpu/0/msr, is msr support enabled in your kernel?"
|
||||||
else
|
else
|
||||||
dd if=/dev/cpu/0/msr of=/dev/null bs=1 count=8 skip=72 2>/dev/null
|
# same that rdmsr 0x48 but without needing the rdmsr tool
|
||||||
|
dd if=/dev/cpu/0/msr of=/dev/null bs=8 count=1 skip=9 2>/dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
pstatus green YES
|
pstatus green YES
|
||||||
else
|
else
|
||||||
pstatus red NO
|
pstatus red NO
|
||||||
fi
|
fi
|
||||||
#dd if=/dev/cpu/0/msr of=/dev/null bs=1 count=8 skip=73 2>/dev/null
|
|
||||||
#/bin/echo $?
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$insmod_msr" = 1 ]; then
|
if [ "$insmod_msr" = 1 ]; then
|
||||||
@ -162,16 +166,35 @@ if [ "$mounted_debugfs" = 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
/bin/echo "* Mitigation 2"
|
/bin/echo "* Mitigation 2"
|
||||||
/bin/echo -n "* Kernel recompiled with retpolines: "
|
/bin/echo -n "* Kernel compiled with retpolines: "
|
||||||
pstatus yellow UNKNOWN "check not yet implemented"
|
# XXX this doesn't mean the kernel has been compiled with a retpoline-aware gcc
|
||||||
|
if [ -e /proc/config.gz ]; then
|
||||||
|
if zgrep -q '^CONFIG_RETPOLINE=y' /proc/config.gz; then
|
||||||
|
pstatus green YES
|
||||||
|
retpoline=1
|
||||||
|
else
|
||||||
|
pstatus red NO
|
||||||
|
fi
|
||||||
|
elif [ -e /boot/config-$(uname -r) ]; then
|
||||||
|
if grep -q '^CONFIG_RETPOLINE=y' /boot/config-$(uname -r); then
|
||||||
|
pstatus green YES
|
||||||
|
retpoline=1
|
||||||
|
else
|
||||||
|
pstatus red NO
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
pstatus yellow UNKNOWN "couldn't read your kernel configuration"
|
||||||
|
fi
|
||||||
|
|
||||||
/bin/echo -ne "> \033[46m\033[30mSTATUS:\033[0m "
|
/bin/echo -ne "> \033[46m\033[30mSTATUS:\033[0m "
|
||||||
if grep -q AMD /proc/cpuinfo; then
|
if grep -q AMD /proc/cpuinfo; then
|
||||||
pstatus green "NOT VULNERABLE" "your CPU is not vulnerable as per the vendor"
|
pstatus green "NOT VULNERABLE" "your CPU is not vulnerable as per the vendor"
|
||||||
elif [ "$ibrs_enabled" = 1 -o "$ibrs_enabled" = 2 ]; then
|
elif [ "$ibrs_enabled" = 1 -o "$ibrs_enabled" = 2 ]; then
|
||||||
pstatus green "NOT VULNERABLE" "IBRS mitigates the vulnerability"
|
pstatus green "NOT VULNERABLE" "IBRS mitigates the vulnerability"
|
||||||
|
elif [ "$retpoline" = 1 ]; then
|
||||||
|
pstatus green "NOT VULNERABLE" "retpolines mitigate the vulnerability"
|
||||||
else
|
else
|
||||||
pstatus red VULNERABLE "IBRS hardware + kernel support OR retpolines-compiled kernel are needed to mitigate the vulnerability"
|
pstatus red VULNERABLE "IBRS hardware + kernel support OR kernel with retpolines are needed to mitigate the vulnerability"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# MELTDOWN
|
# MELTDOWN
|
||||||
@ -199,15 +222,23 @@ elif [ -e /boot/System.map-$(uname -r) ]; then
|
|||||||
else
|
else
|
||||||
pstatus red NO
|
pstatus red NO
|
||||||
fi
|
fi
|
||||||
|
elif [ -n "$vmlinux" ]; then
|
||||||
|
# some backports don't have the option but still have the patch, try to find out
|
||||||
|
if strings "$vmlinux" | grep -qw nopti; then
|
||||||
|
pstatus green YES
|
||||||
|
kpti_support=1
|
||||||
|
else
|
||||||
|
pstatus red NO
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
pstatus yellow UNKNOWN
|
pstatus yellow UNKNOWN "couldn't read your kernel configuration"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
/bin/echo -n "* PTI enabled and active: "
|
/bin/echo -n "* PTI enabled and active: "
|
||||||
if grep ^flags /proc/cpuinfo | grep -qw pti; then
|
if grep ^flags /proc/cpuinfo | grep -qw pti; then
|
||||||
pstatus green YES
|
pstatus green YES
|
||||||
kpti_enabled=1
|
kpti_enabled=1
|
||||||
elif dmesg | grep -q 'Kernel/User page tables isolation: enabled'; then
|
elif dmesg | grep -Eq 'Kernel/User page tables isolation: enabled|Kernel page table isolation enabled'; then
|
||||||
pstatus green YES
|
pstatus green YES
|
||||||
kpti_enabled=1
|
kpti_enabled=1
|
||||||
else
|
else
|
||||||
@ -230,3 +261,5 @@ if [ "$USER" != root ]; then
|
|||||||
/bin/echo "You can try the following command: sudo $0"
|
/bin/echo "You can try the following command: sudo $0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -n "$vmlinux" -a -f "$vmlinux" ] && rm -f "$vmlinux"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user