Commit ce7ae9d9 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-5.6-rc1' of...

Merge tag 'linux-kselftest-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull Kselftest update from Shuah Khan:
 "This Kselftest update consists of several fixes to framework and
  individual tests.

  In addition, it enables LKDTM tests adding lkdtm target to kselftest
  Makefile"

* tag 'linux-kselftest-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests/ftrace: fix glob selftest
  selftests: settings: tests can be in subsubdirs
  kselftest: Minimise dependency of get_size on C library interfaces
  selftests/livepatch: Remove unused local variable in set_ftrace_enabled()
  selftests/livepatch: Replace set_dynamic_debug() with setup_config() in README
  selftests/lkdtm: Add tests for LKDTM targets
  selftests: Uninitialized variable in test_cgcore_proc_migration()
  selftests: fix build behaviour on targets' failures
parents 22b17db4 af4ddd60
...@@ -9656,6 +9656,7 @@ LINUX KERNEL DUMP TEST MODULE (LKDTM) ...@@ -9656,6 +9656,7 @@ LINUX KERNEL DUMP TEST MODULE (LKDTM)
M: Kees Cook <keescook@chromium.org> M: Kees Cook <keescook@chromium.org>
S: Maintained S: Maintained
F: drivers/misc/lkdtm/* F: drivers/misc/lkdtm/*
F: tools/testing/selftests/lkdtm/*
LINUX KERNEL MEMORY CONSISTENCY MODEL (LKMM) LINUX KERNEL MEMORY CONSISTENCY MODEL (LKMM)
M: Alan Stern <stern@rowland.harvard.edu> M: Alan Stern <stern@rowland.harvard.edu>
......
...@@ -26,6 +26,7 @@ TARGETS += kexec ...@@ -26,6 +26,7 @@ TARGETS += kexec
TARGETS += kvm TARGETS += kvm
TARGETS += lib TARGETS += lib
TARGETS += livepatch TARGETS += livepatch
TARGETS += lkdtm
TARGETS += membarrier TARGETS += membarrier
TARGETS += memfd TARGETS += memfd
TARGETS += memory-hotplug TARGETS += memory-hotplug
...@@ -146,11 +147,13 @@ else ...@@ -146,11 +147,13 @@ else
endif endif
all: khdr all: khdr
@for TARGET in $(TARGETS); do \ @ret=1; \
BUILD_TARGET=$$BUILD/$$TARGET; \ for TARGET in $(TARGETS); do \
mkdir $$BUILD_TARGET -p; \ BUILD_TARGET=$$BUILD/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ mkdir $$BUILD_TARGET -p; \
done; $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET; \
ret=$$((ret * $$?)); \
done; exit $$ret;
run_tests: all run_tests: all
@for TARGET in $(TARGETS); do \ @for TARGET in $(TARGETS); do \
...@@ -199,10 +202,12 @@ ifdef INSTALL_PATH ...@@ -199,10 +202,12 @@ ifdef INSTALL_PATH
install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
@for TARGET in $(TARGETS); do \ @ret=1; \
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \ BUILD_TARGET=$$BUILD/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
done; ret=$$((ret * $$?)); \
done; exit $$ret;
@# Ask all targets to emit their test scripts @# Ask all targets to emit their test scripts
echo "#!/bin/sh" > $(ALL_SCRIPT) echo "#!/bin/sh" > $(ALL_SCRIPT)
......
...@@ -369,7 +369,7 @@ static void *dummy_thread_fn(void *arg) ...@@ -369,7 +369,7 @@ static void *dummy_thread_fn(void *arg)
static int test_cgcore_proc_migration(const char *root) static int test_cgcore_proc_migration(const char *root)
{ {
int ret = KSFT_FAIL; int ret = KSFT_FAIL;
int t, c_threads, n_threads = 13; int t, c_threads = 0, n_threads = 13;
char *src = NULL, *dst = NULL; char *src = NULL, *dst = NULL;
pthread_t threads[n_threads]; pthread_t threads[n_threads];
......
...@@ -30,7 +30,7 @@ ftrace_filter_check '*schedule*' '^.*schedule.*$' ...@@ -30,7 +30,7 @@ ftrace_filter_check '*schedule*' '^.*schedule.*$'
ftrace_filter_check 'schedule*' '^schedule.*$' ftrace_filter_check 'schedule*' '^schedule.*$'
# filter by *mid*end # filter by *mid*end
ftrace_filter_check '*aw*lock' '.*aw.*lock$' ftrace_filter_check '*pin*lock' '.*pin.*lock$'
# filter by start*mid* # filter by start*mid*
ftrace_filter_check 'mutex*try*' '^mutex.*try.*' ftrace_filter_check 'mutex*try*' '^mutex.*try.*'
......
...@@ -91,7 +91,7 @@ run_one() ...@@ -91,7 +91,7 @@ run_one()
run_many() run_many()
{ {
echo "TAP version 13" echo "TAP version 13"
DIR=$(basename "$PWD") DIR="${PWD#${BASE_DIR}/}"
test_num=0 test_num=0
total=$(echo "$@" | wc -w) total=$(echo "$@" | wc -w)
echo "1..$total" echo "1..$total"
......
...@@ -35,7 +35,7 @@ Adding tests ...@@ -35,7 +35,7 @@ Adding tests
------------ ------------
See the common functions.sh file for the existing collection of utility See the common functions.sh file for the existing collection of utility
functions, most importantly set_dynamic_debug() and check_result(). The functions, most importantly setup_config() and check_result(). The
latter function greps the kernel's ring buffer for "livepatch:" and latter function greps the kernel's ring buffer for "livepatch:" and
"test_klp" strings, so tests be sure to include one of those strings for "test_klp" strings, so tests be sure to include one of those strings for
result comparison. Other utility functions include general module result comparison. Other utility functions include general module
......
...@@ -64,7 +64,6 @@ function set_dynamic_debug() { ...@@ -64,7 +64,6 @@ function set_dynamic_debug() {
} }
function set_ftrace_enabled() { function set_ftrace_enabled() {
local sysctl="$1"
result=$(sysctl kernel.ftrace_enabled="$1" 2>&1 | paste --serial --delimiters=' ') result=$(sysctl kernel.ftrace_enabled="$1" 2>&1 | paste --serial --delimiters=' ')
echo "livepatch: $result" > /dev/kmsg echo "livepatch: $result" > /dev/kmsg
} }
......
# SPDX-License-Identifier: GPL-2.0
# Makefile for LKDTM regression tests
include ../lib.mk
# NOTE: $(OUTPUT) won't get default value if used before lib.mk
TEST_FILES := tests.txt
TEST_GEN_PROGS = $(patsubst %,$(OUTPUT)/%.sh,$(shell awk '{print $$1}' tests.txt | sed -e 's/\#//'))
all: $(TEST_GEN_PROGS)
$(OUTPUT)/%: run.sh tests.txt
install -m 0744 run.sh $@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# This reads tests.txt for the list of LKDTM tests to invoke. Any marked
# with a leading "#" are skipped. The rest of the line after the
# test name is either the text to look for in dmesg for a "success",
# or the rationale for why a test is marked to be skipped.
#
set -e
TRIGGER=/sys/kernel/debug/provoke-crash/DIRECT
KSELFTEST_SKIP_TEST=4
# Verify we have LKDTM available in the kernel.
if [ ! -r $TRIGGER ] ; then
/sbin/modprobe -q lkdtm || true
if [ ! -r $TRIGGER ] ; then
echo "Cannot find $TRIGGER (missing CONFIG_LKDTM?)"
else
echo "Cannot write $TRIGGER (need to run as root?)"
fi
# Skip this test
exit $KSELFTEST_SKIP_TEST
fi
# Figure out which test to run from our script name.
test=$(basename $0 .sh)
# Look up details about the test from master list of LKDTM tests.
line=$(egrep '^#?'"$test"'\b' tests.txt)
if [ -z "$line" ]; then
echo "Skipped: missing test '$test' in tests.txt"
exit $KSELFTEST_SKIP_TEST
fi
# Check that the test is known to LKDTM.
if ! egrep -q '^'"$test"'$' "$TRIGGER" ; then
echo "Skipped: test '$test' missing in $TRIGGER!"
exit $KSELFTEST_SKIP_TEST
fi
# Extract notes/expected output from test list.
test=$(echo "$line" | cut -d" " -f1)
if echo "$line" | grep -q ' ' ; then
expect=$(echo "$line" | cut -d" " -f2-)
else
expect=""
fi
# If the test is commented out, report a skip
if echo "$test" | grep -q '^#' ; then
test=$(echo "$test" | cut -c2-)
if [ -z "$expect" ]; then
expect="crashes entire system"
fi
echo "Skipping $test: $expect"
exit $KSELFTEST_SKIP_TEST
fi
# If no expected output given, assume an Oops with back trace is success.
if [ -z "$expect" ]; then
expect="call trace:"
fi
# Clear out dmesg for output reporting
dmesg -c >/dev/null
# Prepare log for report checking
LOG=$(mktemp --tmpdir -t lkdtm-XXXXXX)
cleanup() {
rm -f "$LOG"
}
trap cleanup EXIT
# Most shells yell about signals and we're expecting the "cat" process
# to usually be killed by the kernel. So we have to run it in a sub-shell
# and silence errors.
($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true
# Record and dump the results
dmesg -c >"$LOG"
cat "$LOG"
# Check for expected output
if egrep -qi "$expect" "$LOG" ; then
echo "$test: saw '$expect': ok"
exit 0
else
if egrep -qi XFAIL: "$LOG" ; then
echo "$test: saw 'XFAIL': [SKIP]"
exit $KSELFTEST_SKIP_TEST
else
echo "$test: missing '$expect': [FAIL]"
exit 1
fi
fi
#PANIC
BUG kernel BUG at
WARNING WARNING:
WARNING_MESSAGE message trigger
EXCEPTION
#LOOP Hangs the system
#EXHAUST_STACK Corrupts memory on failure
#CORRUPT_STACK Crashes entire system on success
#CORRUPT_STACK_STRONG Crashes entire system on success
CORRUPT_LIST_ADD list_add corruption
CORRUPT_LIST_DEL list_del corruption
CORRUPT_USER_DS Invalid address limit on user-mode return
STACK_GUARD_PAGE_LEADING
STACK_GUARD_PAGE_TRAILING
UNSET_SMEP CR4 bits went missing
DOUBLE_FAULT
UNALIGNED_LOAD_STORE_WRITE
#OVERWRITE_ALLOCATION Corrupts memory on failure
#WRITE_AFTER_FREE Corrupts memory on failure
READ_AFTER_FREE
#WRITE_BUDDY_AFTER_FREE Corrupts memory on failure
READ_BUDDY_AFTER_FREE
SLAB_FREE_DOUBLE
SLAB_FREE_CROSS
SLAB_FREE_PAGE
#SOFTLOCKUP Hangs the system
#HARDLOCKUP Hangs the system
#SPINLOCKUP Hangs the system
#HUNG_TASK Hangs the system
EXEC_DATA
EXEC_STACK
EXEC_KMALLOC
EXEC_VMALLOC
EXEC_RODATA
EXEC_USERSPACE
EXEC_NULL
ACCESS_USERSPACE
ACCESS_NULL
WRITE_RO
WRITE_RO_AFTER_INIT
WRITE_KERN
REFCOUNT_INC_OVERFLOW
REFCOUNT_ADD_OVERFLOW
REFCOUNT_INC_NOT_ZERO_OVERFLOW
REFCOUNT_ADD_NOT_ZERO_OVERFLOW
REFCOUNT_DEC_ZERO
REFCOUNT_DEC_NEGATIVE Negative detected: saturated
REFCOUNT_DEC_AND_TEST_NEGATIVE Negative detected: saturated
REFCOUNT_SUB_AND_TEST_NEGATIVE Negative detected: saturated
REFCOUNT_INC_ZERO
REFCOUNT_ADD_ZERO
REFCOUNT_INC_SATURATED Saturation detected: still saturated
REFCOUNT_DEC_SATURATED Saturation detected: still saturated
REFCOUNT_ADD_SATURATED Saturation detected: still saturated
REFCOUNT_INC_NOT_ZERO_SATURATED
REFCOUNT_ADD_NOT_ZERO_SATURATED
REFCOUNT_DEC_AND_TEST_SATURATED Saturation detected: still saturated
REFCOUNT_SUB_AND_TEST_SATURATED Saturation detected: still saturated
#REFCOUNT_TIMING timing only
#ATOMIC_TIMING timing only
USERCOPY_HEAP_SIZE_TO
USERCOPY_HEAP_SIZE_FROM
USERCOPY_HEAP_WHITELIST_TO
USERCOPY_HEAP_WHITELIST_FROM
USERCOPY_STACK_FRAME_TO
USERCOPY_STACK_FRAME_FROM
USERCOPY_STACK_BEYOND
USERCOPY_KERNEL
USERCOPY_KERNEL_DS
STACKLEAK_ERASING OK: the rest of the thread stack is properly erased
CFI_FORWARD_PROTO
...@@ -11,23 +11,35 @@ ...@@ -11,23 +11,35 @@
* own execution. It also attempts to have as few dependencies * own execution. It also attempts to have as few dependencies
* on kernel features as possible. * on kernel features as possible.
* *
* It should be statically linked, with startup libs avoided. * It should be statically linked, with startup libs avoided. It uses
* It uses no library calls, and only the following 3 syscalls: * no library calls except the syscall() function for the following 3
* syscalls:
* sysinfo(), write(), and _exit() * sysinfo(), write(), and _exit()
* *
* For output, it avoids printf (which in some C libraries * For output, it avoids printf (which in some C libraries
* has large external dependencies) by implementing it's own * has large external dependencies) by implementing it's own
* number output and print routines, and using __builtin_strlen() * number output and print routines, and using __builtin_strlen()
*
* The test may crash if any of the above syscalls fails because in some
* libc implementations (e.g. the GNU C Library) errno is saved in
* thread-local storage, which does not get initialized due to avoiding
* startup libs.
*/ */
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h>
#define STDOUT_FILENO 1 #define STDOUT_FILENO 1
static int print(const char *s) static int print(const char *s)
{ {
return write(STDOUT_FILENO, s, __builtin_strlen(s)); size_t len = 0;
while (s[len] != '\0')
len++;
return syscall(SYS_write, STDOUT_FILENO, s, len);
} }
static inline char *num_to_str(unsigned long num, char *buf, int len) static inline char *num_to_str(unsigned long num, char *buf, int len)
...@@ -79,12 +91,12 @@ void _start(void) ...@@ -79,12 +91,12 @@ void _start(void)
print("TAP version 13\n"); print("TAP version 13\n");
print("# Testing system size.\n"); print("# Testing system size.\n");
ccode = sysinfo(&info); ccode = syscall(SYS_sysinfo, &info);
if (ccode < 0) { if (ccode < 0) {
print("not ok 1"); print("not ok 1");
print(test_name); print(test_name);
print(" ---\n reason: \"could not get sysinfo\"\n ...\n"); print(" ---\n reason: \"could not get sysinfo\"\n ...\n");
_exit(ccode); syscall(SYS_exit, ccode);
} }
print("ok 1"); print("ok 1");
print(test_name); print(test_name);
...@@ -100,5 +112,5 @@ void _start(void) ...@@ -100,5 +112,5 @@ void _start(void)
print(" ...\n"); print(" ...\n");
print("1..1\n"); print("1..1\n");
_exit(0); syscall(SYS_exit, 0);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment