Merge pull request #16 from Alkorin/fixes

Fixes
This commit is contained in:
Stéphane Lesimple 2018-01-08 17:45:59 +01:00 committed by GitHub
commit 1ff437edbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 36 deletions

View File

@ -33,9 +33,11 @@ pstatus()
# Licensed under the GNU General Public License, version 2 (GPLv2). # Licensed under the GNU General Public License, version 2 (GPLv2).
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
vmlinux=''
vmlinux_err=''
check_vmlinux() check_vmlinux()
{ {
file "$1" 2>/dev/null | grep -q ELF || return 1 readelf -h $1 > /dev/null 2>&1 || return 1
return 0 return 0
} }
@ -45,11 +47,15 @@ try_decompress()
# "grep" that report the byte offset of the line instead of the pattern. # "grep" that report the byte offset of the line instead of the pattern.
# Try to find the header ($1) and decompress from here # Try to find the header ($1) and decompress from here
for pos in `tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"` for pos in `tr "$1\n$2" "\n$2=" < "$5" | grep -abo "^$2"`
do 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%%:*} pos=${pos%%:*}
tail -c+$pos "$4" | $3 > $vmlinuxtmp 2> /dev/null tail -c+$pos "$5" | $3 > $vmlinuxtmp 2> /dev/null
check_vmlinux "$vmlinuxtmp" && echo "$vmlinuxtmp" && return 0 check_vmlinux "$vmlinuxtmp" && vmlinux=$vmlinuxtmp && return 0
done done
return 1 return 1
} }
@ -68,11 +74,11 @@ extract_vmlinux()
fi fi
# That didn't work, so retry after decompression. # That didn't work, so retry after decompression.
try_decompress '\037\213\010' xy gunzip "$1" && return 0 try_decompress '\037\213\010' xy gunzip gunzip "$1" && return 0
try_decompress '\3757zXZ\000' abcde unxz "$1" && return 0 try_decompress '\3757zXZ\000' abcde unxz xz-utils "$1" && return 0
try_decompress 'BZh' xy bunzip2 "$1" && return 0 try_decompress 'BZh' xy bunzip2 bzip2 "$1" && return 0
try_decompress '\135\0\0\0' xxx unlzma "$1" && return 0 try_decompress '\135\0\0\0' xxx unlzma xz-utils "$1" && return 0
try_decompress '\211\114\132' xy 'lzop -d' "$1" && return 0 try_decompress '\211\114\132' xy 'lzop -d' lzop "$1" && return 0
return 1 return 1
} }
@ -109,8 +115,13 @@ img=''
if [ -z "$img" ]; then if [ -z "$img" ]; then
pstatus yellow UNKNOWN "couldn't find your kernel image in /boot, if you used netboot, this is normal" pstatus yellow UNKNOWN "couldn't find your kernel image in /boot, if you used netboot, this is normal"
else else
vmlinux=$(extract_vmlinux $img) if ! which readelf >/dev/null 2>&1; then
if [ -z "$vmlinux" -o ! -r "$vmlinux" ]; then pstatus yellow UNKNOWN "missing 'readelf' tool, please install it, usually it's in the 'binutils' package"
else
extract_vmlinux $img
if [ "$vmlinux_err" != "" ]; then
pstatus yellow UNKNOWN "couldn't extract your kernel from $img: $vmlinux_err"
elif [ -z "$vmlinux" -o ! -r "$vmlinux" ]; then
pstatus yellow UNKNOWN "couldn't extract your kernel from $img" pstatus yellow UNKNOWN "couldn't extract your kernel from $img"
elif ! which objdump >/dev/null 2>&1; then elif ! which objdump >/dev/null 2>&1; then
pstatus yellow UNKNOWN "missing 'objdump' tool, please install it, usually it's in the binutils package" pstatus yellow UNKNOWN "missing 'objdump' tool, please install it, usually it's in the binutils package"
@ -131,6 +142,7 @@ else
fi fi
fi fi
fi fi
fi
/bin/echo -ne "> \033[46m\033[30mSTATUS:\033[0m " /bin/echo -ne "> \033[46m\033[30mSTATUS:\033[0m "
[ "$status" = 0 ] && pstatus yellow UNKNOWN [ "$status" = 0 ] && pstatus yellow UNKNOWN
@ -291,7 +303,7 @@ elif [ -e /boot/config-$(uname -r) ]; then
kpti_support=1 kpti_support=1
fi fi
fi fi
if [ -e /boot/System.map-$(uname -r) ]; then if [ "$kpti_support" = 0 -a -e /boot/System.map-$(uname -r) ]; then
# it's not an elif: some backports don't have the PTI config but still include the patch # it's not an elif: some backports don't have the PTI config but still include the patch
# so we try to find an exported symbol that is part of the PTI patch in System.map # so we try to find an exported symbol that is part of the PTI patch in System.map
kpti_can_tell=1 kpti_can_tell=1
@ -299,14 +311,18 @@ if [ -e /boot/System.map-$(uname -r) ]; then
kpti_support=1 kpti_support=1
fi fi
fi fi
if [ -n "$vmlinux" ]; then if [ "$kpti_support" = 0 -a -n "$vmlinux" ]; then
# same as above but in case we don't have System.map and only vmlinux, look for the # same as above but in case we don't have System.map and only vmlinux, look for the
# nopti option that is part of the patch (kernel command line option) # nopti option that is part of the patch (kernel command line option)
kpti_can_tell=1 kpti_can_tell=1
if ! which strings >/dev/null 2>&1; then
pstatus yellow UNKNOWN "missing 'strings' tool, please install it, usually it's in the binutils package"
else
if strings "$vmlinux" | grep -qw nopti; then if strings "$vmlinux" | grep -qw nopti; then
kpti_support=1 kpti_support=1
fi fi
fi fi
fi
if [ "$kpti_support" = 1 ]; then if [ "$kpti_support" = 1 ]; then
pstatus green YES pstatus green YES