mirror of
https://github.com/speed47/spectre-meltdown-checker
synced 2025-01-03 18:15:57 +01:00
feat(extract_vmlinux): look for ELF magic in decompressed blob and cut at found offset
This commit is contained in:
parent
2d993812ab
commit
6a94c3f158
@ -18,6 +18,7 @@ exit_cleanup()
|
|||||||
# cleanup the temp decompressed config & kernel image
|
# cleanup the temp decompressed config & kernel image
|
||||||
[ -n "$dumped_config" ] && [ -f "$dumped_config" ] && rm -f "$dumped_config"
|
[ -n "$dumped_config" ] && [ -f "$dumped_config" ] && rm -f "$dumped_config"
|
||||||
[ -n "$vmlinuxtmp" ] && [ -f "$vmlinuxtmp" ] && rm -f "$vmlinuxtmp"
|
[ -n "$vmlinuxtmp" ] && [ -f "$vmlinuxtmp" ] && rm -f "$vmlinuxtmp"
|
||||||
|
[ -n "$vmlinuxtmp2" ] && [ -f "$vmlinuxtmp2" ] && rm -f "$vmlinuxtmp2"
|
||||||
[ "$mounted_debugfs" = 1 ] && umount /sys/kernel/debug 2>/dev/null
|
[ "$mounted_debugfs" = 1 ] && umount /sys/kernel/debug 2>/dev/null
|
||||||
[ "$insmod_cpuid" = 1 ] && rmmod cpuid 2>/dev/null
|
[ "$insmod_cpuid" = 1 ] && rmmod cpuid 2>/dev/null
|
||||||
[ "$insmod_msr" = 1 ] && rmmod msr 2>/dev/null
|
[ "$insmod_msr" = 1 ] && rmmod msr 2>/dev/null
|
||||||
@ -572,6 +573,7 @@ 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
|
||||||
|
_debug "try_decompress: looking for $3 magic in $6"
|
||||||
for pos in $(tr "$1\n$2" "\n$2=" < "$6" | grep -abo "^$2")
|
for pos in $(tr "$1\n$2" "\n$2=" < "$6" | grep -abo "^$2")
|
||||||
do
|
do
|
||||||
_debug "try_decompress: magic for $3 found at offset $pos"
|
_debug "try_decompress: magic for $3 found at offset $pos"
|
||||||
@ -581,13 +583,22 @@ try_decompress()
|
|||||||
fi
|
fi
|
||||||
pos=${pos%%:*}
|
pos=${pos%%:*}
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
tail -c+$pos "$6" 2>/dev/null | $3 $4 > "$vmlinuxtmp" 2>/dev/null
|
tail -c+$pos "$6" 2>/dev/null | $3 $4 > "$vmlinuxtmp" 2>/dev/null; ret=$?
|
||||||
if check_vmlinux "$vmlinuxtmp"; then
|
if [ ! -s "$vmlinuxtmp" ]; then
|
||||||
|
# don't rely on $ret, sometimes it's != 0 but worked
|
||||||
|
# (e.g. gunzip ret=2 just means there was trailing garbage)
|
||||||
|
_debug "try_decompress: decompression with $3 failed (err=$ret)"
|
||||||
|
elif check_vmlinux "$vmlinuxtmp"; then
|
||||||
vmlinux="$vmlinuxtmp"
|
vmlinux="$vmlinuxtmp"
|
||||||
_debug "try_decompress: decompressed with $3 successfully!"
|
_debug "try_decompress: decompressed with $3 successfully!"
|
||||||
return 0
|
return 0
|
||||||
|
elif [ "$3" != "cat" ]; then
|
||||||
|
_debug "try_decompress: decompression with $3 worked but result is not a kernel, trying with an offset"
|
||||||
|
[ -z "$vmlinuxtmp2" ] && vmlinuxtmp2=$(mktemp /tmp/vmlinux-XXXXXX)
|
||||||
|
cat "$vmlinuxtmp" > "$vmlinuxtmp2"
|
||||||
|
try_decompress '\177ELF' xxy 'cat' '' cat "$vmlinuxtmp2" && return 0
|
||||||
else
|
else
|
||||||
_debug "try_decompress: decompression with $3 did not work"
|
_debug "try_decompress: decompression with $3 worked but result is not a kernel"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
@ -614,6 +625,7 @@ extract_vmlinux()
|
|||||||
try_decompress '\211\114\132' xy 'lzop' '-d' lzop "$1" && return 0
|
try_decompress '\211\114\132' xy 'lzop' '-d' lzop "$1" && return 0
|
||||||
try_decompress '\002\041\114\030' xyy 'lz4' '-d -l' liblz4-tool "$1" && return 0
|
try_decompress '\002\041\114\030' xyy 'lz4' '-d -l' liblz4-tool "$1" && return 0
|
||||||
try_decompress '\177ELF' xxy 'cat' '' cat "$1" && return 0
|
try_decompress '\177ELF' xxy 'cat' '' cat "$1" && return 0
|
||||||
|
_verbose "Couldn't extract the kernel image, accuracy might be reduced"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user