Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CISOfy/lynis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Boelen <michael.boelen@cisofy.com>2022-01-31 19:07:41 +0300
committerMichael Boelen <michael.boelen@cisofy.com>2022-01-31 19:07:41 +0300
commitb0ca58895bf72b432b75989426859ca84b678acc (patch)
tree4bfb54b0d270b637a5f97bfa2e0720b7c2462151
parent83296d6e8f9eb07ac48bfa2190f8cec8ce9de2f5 (diff)
[KRNL-5788] Only run relevant tests and improved logging
-rw-r--r--include/tests_kernel77
1 files changed, 42 insertions, 35 deletions
diff --git a/include/tests_kernel b/include/tests_kernel
index 569b2b89..c1977985 100644
--- a/include/tests_kernel
+++ b/include/tests_kernel
@@ -368,14 +368,14 @@
#
# Test : KRNL-5788
# Description : Checking availability new kernel
- if [ "${LINUX_VERSION}" = "Debian" ] || [ "${LINUX_VERSION}" = "Ubuntu" ] ||
- [ "${LINUX_VERSION_LIKE}" = "Debian" ] || [ "${LINUX_VERSION_LIKE}" = "Ubuntu" ]; then
+ if [ "${LINUX_VERSION}" = "Debian" ] || [ "${LINUX_VERSION}" = "Ubuntu" ] || [ "${LINUX_VERSION_LIKE}" = "Debian" ] || [ "${LINUX_VERSION_LIKE}" = "Ubuntu" ]; then
PREQS_MET="YES"
else
PREQS_MET="NO"
fi
Register --test-no KRNL-5788 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking availability new Linux kernel"
if [ ${SKIPTEST} -eq 0 ]; then
+ FINDKERNEL=""
HAS_VMLINUZ=0
LogText "Test: Searching apt-cache, to determine if a newer kernel is available"
if [ -x ${ROOTDIR}usr/bin/apt-cache ]; then
@@ -384,62 +384,69 @@
if [ -f ${ROOTDIR}vmlinuz -o -f ${ROOTDIR}boot/vmlinuz ]; then
HAS_VMLINUZ=1
if [ -f ${ROOTDIR}vmlinuz ]; then
- FINDVMLINUZ=${ROOTDIR}vmlinuz
+ FINDVMLINUZ="${ROOTDIR}vmlinuz"
else
- FINDVMLINUZ=${ROOTDIR}boot/vmlinuz
+ FINDVMLINUZ="${ROOTDIR}boot/vmlinuz"
fi
LogText "Result: found ${FINDVMLINUZ}"
LogText "Test: checking readlink location of ${FINDVMLINUZ}"
FINDKERNFILE=$(readlink -f ${FINDVMLINUZ})
LogText "Output: readlink reported file ${FINDKERNFILE}"
- LogText "Test: checking package from dpkg -S"
+ LogText "Test: checking relevant package using output from dpkg -S"
FINDKERNEL=$(dpkg -S ${FINDKERNFILE} 2> /dev/null | ${AWKBINARY} -F : '{print $1}')
LogText "Output: dpkg -S reported package ${FINDKERNEL}"
elif [ -e ${ROOTDIR}dev/grsec ]; then
- FINDKERNEL=linux-image-$(uname -r)
+ FINDKERNEL="linux-image-$(uname -r)"
LogText "Result: ${ROOTDIR}vmlinuz missing due to grsecurity; assuming ${FINDKERNEL}"
elif [ -e ${ROOTDIR}etc/rpi-issue ]; then
- FINDKERNEL=raspberrypi-kernel
+ FINDKERNEL="raspberrypi-kernel"
LogText "Result: ${ROOTDIR}vmlinuz missing due to Raspbian"
- elif `${EGREPBINARY} -q 'do_symlinks.*=.*No' ${ROOTDIR}etc/kernel-img.conf`; then
- FINDKERNEL=linux-image-$(uname -r)
+ elif $(${EGREPBINARY} -q 'do_symlinks.*=.*No' ${ROOTDIR}etc/kernel-img.conf); then
+ FINDKERNEL="linux-image-$(uname -r)"
LogText "Result: ${ROOTDIR}vmlinuz missing due to /etc/kernel-img.conf item do_symlinks = No"
else
- LogText "This system is missing ${ROOTDIR}vmlinuz or ${ROOTDIR}boot/vmlinuz. Unable to check whether kernel is up-to-date."
+ LogText "This system is missing ${ROOTDIR}vmlinuz or ${ROOTDIR}boot/vmlinuz. Unable to check whether kernel is up-to-date."
ReportSuggestion "${TEST_NO}" "Determine why ${ROOTDIR}vmlinuz or ${ROOTDIR}boot/vmlinuz is missing on this Debian/Ubuntu system." "/vmlinuz or /boot/vmlinuz"
fi
- LogText "Test: Using apt-cache policy to determine if there is an update available"
- FINDINST=$(apt-cache policy ${FINDKERNEL} | ${EGREPBINARY} 'Installed' | ${CUTBINARY} -d ':' -f2 | ${TRBINARY} -d ' ')
- FINDCAND=$(apt-cache policy ${FINDKERNEL} | ${EGREPBINARY} 'Candidate' | ${CUTBINARY} -d ':' -f2 | ${TRBINARY} -d ' ')
- LogText "Kernel installed: ${FINDINST}"
- LogText "Kernel candidate: ${FINDCAND}"
- if IsEmpty "${FINDINST}"; then
- Display --indent 2 --text "- Checking for available kernel update" --result "${STATUS_UNKNOWN}" --color YELLOW
- LogText "Result: Exception occurred, no output from apt-cache policy"
- if [ ${HAS_VMLINUZ} -eq 1 ]; then
- ReportException "${TEST_NO}:01"
- ReportSuggestion "${TEST_NO}" "Check the output of apt-cache policy to determine why its output is empty"
- fi
- LogText "Result: apt-cache policy did not return an installed kernel version"
+
+ if IsEmpty "${FINDKERNEL}"; then
+ LogText "Result: could not check kernel update status as kernel is unknown"
else
- if [ "${FINDINST}" = "${FINDCAND}" ]; then
- if [ -e /dev/grsec ]; then
- Display --indent 2 --text "- Checking for available kernel update" --result GRSEC --color GREEN
- LogText "Result: Grsecurity is installed; unable to determine if there's a newer kernel available"
- ReportManual "Manually check to confirm you're using a recent kernel and grsecurity patch"
- else
- Display --indent 2 --text "- Checking for available kernel update" --result "${STATUS_OK}" --color GREEN
- LogText "Result: no kernel update available"
+ LogText "Result: found kernel '${FINDKERNEL}' which will be used for further testing"
+ LogText "Test: Using apt-cache policy to determine if there is an update available"
+ FINDINSTALLED=$(apt-cache policy ${FINDKERNEL} | ${EGREPBINARY} 'Installed' | ${CUTBINARY} -d ':' -f2 | ${TRBINARY} -d ' ')
+ FINDCANDIDATE=$(apt-cache policy ${FINDKERNEL} | ${EGREPBINARY} 'Candidate' | ${CUTBINARY} -d ':' -f2 | ${TRBINARY} -d ' ')
+ LogText "Kernel installed: ${FINDINSTALLED}"
+ LogText "Kernel candidate: ${FINDCANDIDATE}"
+ if IsEmpty "${FINDINSTALLED}"; then
+ Display --indent 2 --text "- Checking for available kernel update" --result "${STATUS_UNKNOWN}" --color YELLOW
+ LogText "Result: Exception occurred, no output from apt-cache policy"
+ if [ ${HAS_VMLINUZ} -eq 1 ]; then
+ ReportException "${TEST_NO}:01" "Found vmlinuz (${FINDVMLINUZ}) but could not determine the installed kernel using apt-cache policy"
+ ReportSuggestion "${TEST_NO}" "Check the output of apt-cache policy to determine why its output is empty"
fi
+ LogText "Result: apt-cache policy did not return an installed kernel version"
else
- Display --indent 2 --text "- Checking for available kernel update" --result "UPDATE AVAILABLE" --color YELLOW
- LogText "Result: kernel update available according 'apt-cache policy'."
- ReportSuggestion "${TEST_NO}" "Determine priority for available kernel update"
+ if [ "${FINDINSTALLED}" = "${FINDCANDIDATE}" ]; then
+ if [ -e /dev/grsec ]; then
+ Display --indent 2 --text "- Checking for available kernel update" --result GRSEC --color GREEN
+ LogText "Result: Grsecurity is installed; unable to determine if there's a newer kernel available"
+ ReportManual "Manually check to confirm you're using a recent kernel and grsecurity patch"
+ else
+ Display --indent 2 --text "- Checking for available kernel update" --result "${STATUS_OK}" --color GREEN
+ LogText "Result: no kernel update available"
+ fi
+ else
+ Display --indent 2 --text "- Checking for available kernel update" --result "UPDATE AVAILABLE" --color YELLOW
+ LogText "Result: kernel update available according 'apt-cache policy'."
+ ReportSuggestion "${TEST_NO}" "Determine priority for available kernel update"
+ fi
fi
fi
else
- LogText "Result: could NOT find /usr/bin/apt-cache, skipped other tests."
+ LogText "Result: could NOT find ${ROOTDIR}usr/bin/apt-cache, skipped other tests."
fi
+ unset FINDCANDIDATE FINDINSTALLED FINDKERNEL HAS_VMLINUZ
fi
#
#################################################################################