diff options
author | Vincent Brillault <vincent.brillault@cern.ch> | 2018-01-09 13:04:49 +0100 |
---|---|---|
committer | Vincent Brillault <vincent.brillault@cern.ch> | 2018-01-09 14:18:02 +0100 |
commit | b6bfcdbd4551257f924a7e84d60c93a063dd5d0a (patch) | |
tree | 43ecdaa4bcc095d312c72c3a72357637c7503b1f | |
parent | 19b01078c2b2636c77677813321c70fa5663e6bd (diff) | |
download | spectre-meltdown-checker-b6bfcdbd4551257f924a7e84d60c93a063dd5d0a.tar.lz spectre-meltdown-checker-b6bfcdbd4551257f924a7e84d60c93a063dd5d0a.tar.xz spectre-meltdown-checker-b6bfcdbd4551257f924a7e84d60c93a063dd5d0a.zip |
Move configuration at the beginning of the script
-rwxr-xr-x | spectre-meltdown-checker.sh | 191 |
1 files changed, 96 insertions, 95 deletions
diff --git a/spectre-meltdown-checker.sh b/spectre-meltdown-checker.sh index 820c10c..a6cb99f 100755 --- a/spectre-meltdown-checker.sh +++ b/spectre-meltdown-checker.sh @@ -10,93 +10,7 @@ # VERSION=0.19 -# print status function -pstatus() -{ - if [ "$opt_no_color" = 1 ]; then - _echo_nol "$2" - else - case "$1" in - red) col="\033[101m\033[30m";; - green) col="\033[102m\033[30m";; - yellow) col="\033[103m\033[30m";; - blue) col="\033[104m\033[30m";; - *) col="";; - esac - _echo_nol "$col $2 \033[0m" - fi - [ -n "$3" ] && _echo_nol " ($3)" - _echo -} - -# The 3 below functions are taken from the extract-linux script, available here: -# https://github.com/torvalds/linux/blob/master/scripts/extract-vmlinux -# The functions have been modified for better integration to this script -# The original header of the file has been retained below - -# ---------------------------------------------------------------------- -# extract-vmlinux - Extract uncompressed vmlinux from a kernel image -# -# Inspired from extract-ikconfig -# (c) 2009,2010 Dick Streefland <dick@streefland.net> -# -# (c) 2011 Corentin Chary <corentin.chary@gmail.com> -# -# Licensed under the GNU General Public License, version 2 (GPLv2). -# ---------------------------------------------------------------------- - -vmlinux='' -vmlinux_err='' -check_vmlinux() -{ - readelf -h $1 > /dev/null 2>&1 || return 1 - return 0 -} - -try_decompress() -{ - # The obscure use of the "tr" filter is to work around older versions of - # "grep" that report the byte offset of the line instead of the pattern. - - # Try to find the header ($1) and decompress from here - for pos in `tr "$1\n$2" "\n$2=" < "$5" | grep -abo "^$2"` - do - if ! which $3 >/dev/null 2>&1; then - vmlinux_err="missing '$3' tool, please install it, usually it's in the '$4' package" - return 0 - fi - pos=${pos%%:*} - tail -c+$pos "$5" | $3 > $vmlinuxtmp 2> /dev/null - check_vmlinux "$vmlinuxtmp" && vmlinux=$vmlinuxtmp && return 0 - done - return 1 -} - -extract_vmlinux() -{ - [ -n "$1" ] || return 1 - # Prepare temp files: - vmlinuxtmp="$(mktemp /tmp/vmlinux-XXXXXX)" - trap "rm -f $vmlinuxtmp" EXIT - - # Initial attempt for uncompressed images or objects: - if check_vmlinux "$1"; then - cat "$1" > "$vmlinuxtmp" - vmlinux=$vmlinuxtmp - return 0 - fi - - # That didn't work, so retry after decompression. - try_decompress '\037\213\010' xy gunzip gunzip "$1" && return 0 - try_decompress '\3757zXZ\000' abcde unxz xz-utils "$1" && return 0 - try_decompress 'BZh' xy bunzip2 bzip2 "$1" && return 0 - try_decompress '\135\0\0\0' xxx unlzma xz-utils "$1" && return 0 - try_decompress '\211\114\132' xy 'lzop -d' lzop "$1" && return 0 - return 1 -} - -# end of extract-vmlinux functions - +# Script configuration show_usage() { cat <<EOF @@ -123,6 +37,14 @@ show_usage() EOF } +# parse options +opt_kernel='' +opt_config='' +opt_map='' +opt_live_explicit=0 +opt_live=1 +opt_no_color=0 + __echo() { opt="$1" @@ -197,14 +119,6 @@ is_cpu_vulnerable() _echo "\033[1;34mSpectre and Meltdown mitigation detection tool v$VERSION\033[0m" _echo -# parse options -opt_kernel='' -opt_config='' -opt_map='' -opt_live_explicit=0 -opt_live=1 -opt_no_color=0 - parse_opt_file() { # parse_opt_file option_name option_value @@ -260,6 +174,93 @@ while [ -n "$1" ]; do fi done +# print status function +pstatus() +{ + if [ "$opt_no_color" = 1 ]; then + _echo_nol "$2" + else + case "$1" in + red) col="\033[101m\033[30m";; + green) col="\033[102m\033[30m";; + yellow) col="\033[103m\033[30m";; + blue) col="\033[104m\033[30m";; + *) col="";; + esac + _echo_nol "$col $2 \033[0m" + fi + [ -n "$3" ] && _echo_nol " ($3)" + _echo +} + +# The 3 below functions are taken from the extract-linux script, available here: +# https://github.com/torvalds/linux/blob/master/scripts/extract-vmlinux +# The functions have been modified for better integration to this script +# The original header of the file has been retained below + +# ---------------------------------------------------------------------- +# extract-vmlinux - Extract uncompressed vmlinux from a kernel image +# +# Inspired from extract-ikconfig +# (c) 2009,2010 Dick Streefland <dick@streefland.net> +# +# (c) 2011 Corentin Chary <corentin.chary@gmail.com> +# +# Licensed under the GNU General Public License, version 2 (GPLv2). +# ---------------------------------------------------------------------- + +vmlinux='' +vmlinux_err='' +check_vmlinux() +{ + readelf -h $1 > /dev/null 2>&1 || return 1 + return 0 +} + +try_decompress() +{ + # The obscure use of the "tr" filter is to work around older versions of + # "grep" that report the byte offset of the line instead of the pattern. + + # Try to find the header ($1) and decompress from here + for pos in `tr "$1\n$2" "\n$2=" < "$5" | grep -abo "^$2"` + do + if ! which $3 >/dev/null 2>&1; then + vmlinux_err="missing '$3' tool, please install it, usually it's in the '$4' package" + return 0 + fi + pos=${pos%%:*} + tail -c+$pos "$5" | $3 > $vmlinuxtmp 2> /dev/null + check_vmlinux "$vmlinuxtmp" && vmlinux=$vmlinuxtmp && return 0 + done + return 1 +} + +extract_vmlinux() +{ + [ -n "$1" ] || return 1 + # Prepare temp files: + vmlinuxtmp="$(mktemp /tmp/vmlinux-XXXXXX)" + trap "rm -f $vmlinuxtmp" EXIT + + # Initial attempt for uncompressed images or objects: + if check_vmlinux "$1"; then + cat "$1" > "$vmlinuxtmp" + vmlinux=$vmlinuxtmp + return 0 + fi + + # That didn't work, so retry after decompression. + try_decompress '\037\213\010' xy gunzip gunzip "$1" && return 0 + try_decompress '\3757zXZ\000' abcde unxz xz-utils "$1" && return 0 + try_decompress 'BZh' xy bunzip2 bzip2 "$1" && return 0 + try_decompress '\135\0\0\0' xxx unlzma xz-utils "$1" && return 0 + try_decompress '\211\114\132' xy 'lzop -d' lzop "$1" && return 0 + return 1 +} + +# end of extract-vmlinux functions + # check for mode selection inconsistency if [ "$opt_live_explicit" = 1 ]; then if [ -n "$opt_kernel" -o -n "$opt_config" -o -n "$opt_map" ]; then |