Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/lkdtm: Skip stack-entropy test if lkdtm is not available

Exit with return code 4 if lkdtm is not available like other tests
in order to properly skip the test.

Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210805101236.1140381-1-misono.tomohiro@jp.fujitsu.com

authored by

Misono Tomohiro and committed by
Kees Cook
90091c36 bc93a22a

+15 -1
+15 -1
tools/testing/selftests/lkdtm/stack-entropy.sh
··· 4 4 # Measure kernel stack entropy by sampling via LKDTM's REPORT_STACK test. 5 5 set -e 6 6 samples="${1:-1000}" 7 + TRIGGER=/sys/kernel/debug/provoke-crash/DIRECT 8 + KSELFTEST_SKIP_TEST=4 9 + 10 + # Verify we have LKDTM available in the kernel. 11 + if [ ! -r $TRIGGER ] ; then 12 + /sbin/modprobe -q lkdtm || true 13 + if [ ! -r $TRIGGER ] ; then 14 + echo "Cannot find $TRIGGER (missing CONFIG_LKDTM?)" 15 + else 16 + echo "Cannot write $TRIGGER (need to run as root?)" 17 + fi 18 + # Skip this test 19 + exit $KSELFTEST_SKIP_TEST 20 + fi 7 21 8 22 # Capture dmesg continuously since it may fill up depending on sample size. 9 23 log=$(mktemp -t stack-entropy-XXXXXX) 10 24 dmesg --follow >"$log" & pid=$! 11 25 report=-1 12 26 for i in $(seq 1 $samples); do 13 - echo "REPORT_STACK" >/sys/kernel/debug/provoke-crash/DIRECT 27 + echo "REPORT_STACK" > $TRIGGER 14 28 if [ -t 1 ]; then 15 29 percent=$(( 100 * $i / $samples )) 16 30 if [ "$percent" -ne "$report" ]; then