From e005ff01bfdb653ac2f03614625cb9aefa86fa9c Mon Sep 17 00:00:00 2001 From: Cristian Marussi Date: Wed, 26 Jan 2022 10:32:30 +0000 Subject: selftests/kselftest/runner.sh: Pass optional command parameters in environment Some testcases allow for optional commandline parameters but as of now there is now way to provide such arguments to the runner script. Add support to retrieve such optional command parameters fron environment variables named so as to include the all-uppercase test executable name, sanitized substituting any non-acceptable varname characters with "_", following the pattern: KSELFTEST__ARGS="options" Optional command parameters support is not available if 'tr' is not installed on the test system. Cc: Kees Cook Signed-off-by: Cristian Marussi Signed-off-by: Shuah Khan --- tools/testing/selftests/kselftest/runner.sh | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index a9ba782d8ca0..294619ade49f 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh @@ -18,6 +18,8 @@ if [ -z "$BASE_DIR" ]; then exit 1 fi +TR_CMD=$(command -v tr) + # If Perl is unavailable, we must fall back to line-at-a-time prefixing # with sed instead of unbuffered output. tap_prefix() @@ -49,6 +51,31 @@ run_one() # Reset any "settings"-file variables. export kselftest_timeout="$kselftest_default_timeout" + + # Safe default if tr not available + kselftest_cmd_args_ref="KSELFTEST_ARGS" + + # Optional arguments for this command, possibly defined as an + # environment variable built using the test executable in all + # uppercase and sanitized substituting non acceptable shell + # variable name characters with "_" as in: + # + # KSELFTEST__ARGS="" + # + # e.g. + # + # rtctest --> KSELFTEST_RTCTEST_ARGS="/dev/rtc1" + # + # cpu-on-off-test.sh --> KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10" + # + if [ -n "$TR_CMD" ]; then + BASENAME_SANITIZED=$(echo "$BASENAME_TEST" | \ + $TR_CMD -d "[:blank:][:cntrl:]" | \ + $TR_CMD -c "[:alnum:]_" "_" | \ + $TR_CMD [:lower:] [:upper:]) + kselftest_cmd_args_ref="KSELFTEST_${BASENAME_SANITIZED}_ARGS" + fi + # Load per-test-directory kselftest "settings" file. settings="$BASE_DIR/$DIR/settings" if [ -r "$settings" ] ; then @@ -69,7 +96,8 @@ run_one() echo "# Warning: file $TEST is missing!" echo "not ok $test_num $TEST_HDR_MSG" else - cmd="./$BASENAME_TEST" + eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}" + cmd="./$BASENAME_TEST $kselftest_cmd_args" if [ ! -x "$TEST" ]; then echo "# Warning: file $TEST is not executable" -- cgit From cef757808666de8400d09ac11521418d8122edd5 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:33:32 +0500 Subject: selftests: futex: set DEFAULT_INSTALL_HDR_PATH If only futex selftest is compiled, uapi header files are copied to the selftests/futex/functional directory. This copy isn't needed. Set the DEFAULT_INSTALL_HDR_PATH variable to 1 to use the default header install path only. This removes extra copy of header file. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/futex/functional/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile index 5cc38de9d8ea..9a8c3700d773 100644 --- a/tools/testing/selftests/futex/functional/Makefile +++ b/tools/testing/selftests/futex/functional/Makefile @@ -24,6 +24,7 @@ TEST_PROGS := run.sh top_srcdir = ../../../../.. KSFT_KHDR_INSTALL := 1 +DEFAULT_INSTALL_HDR_PATH := 1 include ../../lib.mk $(TEST_GEN_FILES): $(HEADERS) -- cgit From 5ad51ab618de5d05f4e692ebabeb6fe6289aaa57 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:22 +0500 Subject: selftests: set the BUILD variable to absolute path The build of kselftests fails if relative path is specified through KBUILD_OUTPUT or O= method. BUILD variable is used to determine the path of the output objects. When make is run from other directories with relative paths, the exact path of the build objects is ambiguous and build fails. make[1]: Entering directory '/home/usama/repos/kernel/linux_mainline2/tools/testing/selftests/alsa' gcc mixer-test.c -L/usr/lib/x86_64-linux-gnu -lasound -o build/kselftest/alsa/mixer-test /usr/bin/ld: cannot open output file build/kselftest/alsa/mixer-test Set the BUILD variable to the absolute path of the output directory. Make the logic readable and easy to follow. Use spaces instead of tabs for indentation as if with tab indentation is considered recipe in make. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index d08fe4cfe811..a7b63860b7bc 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -114,19 +114,27 @@ ifdef building_out_of_srctree override LDFLAGS = endif -ifneq ($(O),) - BUILD := $(O)/kselftest +top_srcdir ?= ../../.. + +ifeq ("$(origin O)", "command line") + KBUILD_OUTPUT := $(O) +endif + +ifneq ($(KBUILD_OUTPUT),) + # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot + # expand a shell special character '~'. We use a somewhat tedious way here. + abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) + $(if $(abs_objtree),, \ + $(error failed to create output directory "$(KBUILD_OUTPUT)")) + # $(realpath ...) resolves symlinks + abs_objtree := $(realpath $(abs_objtree)) + BUILD := $(abs_objtree)/kselftest else - ifneq ($(KBUILD_OUTPUT),) - BUILD := $(KBUILD_OUTPUT)/kselftest - else - BUILD := $(shell pwd) - DEFAULT_INSTALL_HDR_PATH := 1 - endif + BUILD := $(CURDIR) + DEFAULT_INSTALL_HDR_PATH := 1 endif # Prepare for headers install -top_srcdir ?= ../../.. include $(top_srcdir)/scripts/subarch.include ARCH ?= $(SUBARCH) export KSFT_KHDR_INSTALL_DONE := 1 -- cgit From 250f8c1137578e6210becaed63ec6e9a8eea430e Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:23 +0500 Subject: selftests: Add and export a kernel uapi headers path Kernel uapi headers can be present at different paths depending upon how the build was invoked. It becomes impossible for the tests to include the correct headers directory. Set and export KHDR_INCLUDES variable to make it possible for sub make files to include the header files. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index a7b63860b7bc..21f983dfd047 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -129,8 +129,11 @@ ifneq ($(KBUILD_OUTPUT),) # $(realpath ...) resolves symlinks abs_objtree := $(realpath $(abs_objtree)) BUILD := $(abs_objtree)/kselftest + KHDR_INCLUDES := -I${abs_objtree}/usr/include else BUILD := $(CURDIR) + abs_srctree := $(shell cd $(top_srcdir) && pwd) + KHDR_INCLUDES := -I${abs_srctree}/usr/include DEFAULT_INSTALL_HDR_PATH := 1 endif @@ -139,6 +142,7 @@ include $(top_srcdir)/scripts/subarch.include ARCH ?= $(SUBARCH) export KSFT_KHDR_INSTALL_DONE := 1 export BUILD +export KHDR_INCLUDES # set default goal to all, so make without a target runs all, even when # all isn't the first target in the file. -- cgit From afe5fba8d10b40fdc517b46a2b59d2172686221e Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:24 +0500 Subject: selftests: Correct the headers install path uapi headers should be installed at the top of the object tree, "/usr/include". There is no need for kernel headers to be present at kselftest build directory, "/kselftest/usr/ include" as well. This duplication can be avoided by correctly specifying the INSTALL_HDR_PATH. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 21f983dfd047..80e5498eab92 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -167,7 +167,7 @@ khdr: ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install else - $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ + $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$(abs_objtree)/usr \ ARCH=$(ARCH) -C $(top_srcdir) headers_install endif -- cgit From bd7d481c37716b21b251e6f8248ed6d8f2183445 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:25 +0500 Subject: selftests: futex: Add the uapi headers include variable Out of tree build of this test fails if relative path of the output directory is specified. KBUILD_OUTPUT also doesn't point to the correct directory when relative path is used. Thus out of tree builds fail. Remove the un-needed include paths and use KHDR_INCLUDES to correctly reach the headers. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/futex/functional/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile index 9a8c3700d773..b8152c573e8a 100644 --- a/tools/testing/selftests/futex/functional/Makefile +++ b/tools/testing/selftests/futex/functional/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -INCLUDES := -I../include -I../../ -I../../../../../usr/include/ \ - -I$(KBUILD_OUTPUT)/kselftest/usr/include -CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES) +INCLUDES := -I../include -I../../ -I../../../../../usr/include/ +CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES) $(KHDR_INCLUDES) LDLIBS := -lpthread -lrt HEADERS := \ -- cgit From 0cc5963b4cc348fc37586ae8cbd91db1398037d1 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:26 +0500 Subject: selftests: kvm: Add the uapi headers include variable Out of tree build of this test fails if relative path of the output directory is specified. Add KHDR_INCLUDES to correctly reach the headers. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/kvm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 17c3f0749f05..b970397f725c 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -149,7 +149,7 @@ endif CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ - -I$( Date: Wed, 19 Jan 2022 15:15:27 +0500 Subject: selftests: landlock: Add the uapi headers include variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Out of tree build of this test fails if relative path of the output directory is specified. Add the KHDR_INCLUDES to correctly reach the headers. Signed-off-by: Muhammad Usama Anjum Reviewed-by: Mickaël Salaün Signed-off-by: Shuah Khan --- tools/testing/selftests/landlock/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/landlock/Makefile b/tools/testing/selftests/landlock/Makefile index a99596ca9882..0b0049e133bb 100644 --- a/tools/testing/selftests/landlock/Makefile +++ b/tools/testing/selftests/landlock/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS += -Wall -O2 +CFLAGS += -Wall -O2 $(KHDR_INCLUDES) src_test := $(wildcard *_test.c) -- cgit From 50f4143df0a63220f2108dc62164c432e07e410b Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:28 +0500 Subject: selftests: net: Add the uapi headers include variable Out of tree build of this test fails if relative path of the output directory is specified. Add the KHDR_INCLUDES to correctly reach the headers. Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/net/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 9897fa9ab953..0b1488616c55 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -2,7 +2,7 @@ # Makefile for net selftests CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -CFLAGS += -I../../../../usr/include/ +CFLAGS += -I../../../../usr/include/ $(KHDR_INCLUDES) TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh \ rtnetlink.sh xfrm_policy.sh test_blackhole_dev.sh -- cgit From 5faa35d0b8cc1403acb6760e9e95905cfd691872 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:29 +0500 Subject: selftests: mptcp: Add the uapi headers include variable Out of tree build of this test fails if relative path of the output directory is specified. Add the KHDR_INCLUDES to correctly reach the headers. Signed-off-by: Muhammad Usama Anjum Reviewed-by: Matthieu Baerts Signed-off-by: Shuah Khan --- tools/testing/selftests/net/mptcp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/selftests/net/mptcp/Makefile index 0356c4501c99..f905d5358e68 100644 --- a/tools/testing/selftests/net/mptcp/Makefile +++ b/tools/testing/selftests/net/mptcp/Makefile @@ -3,7 +3,7 @@ top_srcdir = ../../../../.. KSFT_KHDR_INSTALL := 1 -CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include +CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include $(KHDR_INCLUDES) TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh \ simult_flows.sh mptcp_sockopt.sh -- cgit From 4a8900207abdc629933f07329bd884c60b50f074 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:30 +0500 Subject: selftests: vm: Add the uapi headers include variable Out of tree build of this test fails if relative path of the output directory is specified. Add the KHDR_INCLUDES to correctly reach the headers. Acked-by: Paolo Bonzini Signed-off-by: Muhammad Usama Anjum Tested-by: Alistair Popple Signed-off-by: Shuah Khan --- tools/testing/selftests/vm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index 1607322a112c..033e9e11e2da 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -23,7 +23,7 @@ MACHINE ?= $(shell echo $(uname_M) | sed -e 's/aarch64.*/arm64/' -e 's/ppc64.*/p # LDLIBS. MAKEFLAGS += --no-builtin-rules -CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) +CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS) $(KHDR_INCLUDES) LDLIBS = -lrt -lpthread TEST_GEN_FILES = compaction_test TEST_GEN_FILES += gup_test -- cgit From 681696862bc1823595c05960a83766d1aa965c17 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 19 Jan 2022 15:15:31 +0500 Subject: selftests: vm: remove dependecy from internal kernel macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The defination of swap() is used from kernel's internal header when this test is built in source tree. The build fails when this test is built out of source tree as defination of swap() isn't found. Selftests shouldn't depend on kernel's internal header files. They can only depend on uapi header files. Add the defination of swap() to fix the build error: gcc -Wall -I/linux_mainline2/build/usr/include -no-pie userfaultfd.c -lrt -lpthread -o /linux_mainline2/build/kselftest/vm/userfaultfd userfaultfd.c: In function ‘userfaultfd_stress’: userfaultfd.c:1530:3: warning: implicit declaration of function ‘swap’; did you mean ‘swab’? [-Wimplicit-function-declaration] 1530 | swap(area_src, area_dst); | ^~~~ | swab /usr/bin/ld: /tmp/cclUUH7V.o: in function `userfaultfd_stress': userfaultfd.c:(.text+0x4d64): undefined reference to `swap' /usr/bin/ld: userfaultfd.c:(.text+0x4d82): undefined reference to `swap' collect2: error: ld returned 1 exit status Fixes: 2c769ed7137a ("tools/testing/selftests/vm/userfaultfd.c: use swap() to make code cleaner") Signed-off-by: Muhammad Usama Anjum Reviewed-by: Alistair Popple Signed-off-by: Shuah Khan --- tools/testing/selftests/vm/userfaultfd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 2f49c9af1b58..50476ec6c070 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -119,6 +119,9 @@ struct uffd_stats { ~(unsigned long)(sizeof(unsigned long long) \ - 1))) +#define swap(a, b) \ + do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) + const char *examples = "# Run anonymous memory test on 100MiB region with 99999 bounces:\n" "./userfaultfd anon 100 99999\n\n" -- cgit From 46e50459ea10cbf8a534fc1e6e752408dda191ef Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Mon, 14 Feb 2022 21:07:56 +0500 Subject: selftests: Use -isystem instead of -I to include headers Selftests need kernel headers and glibc for compilation. In compilation of selftests, uapi headers from kernel source are used instead of default ones while glibc has already been compiled with different header files installed in the operating system. So there can be redefination warnings from compiler. These warnings can be suppressed by using -isystem to include the uapi headers. Signed-off-by: Muhammad Usama Anjum Reviewed-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 80e5498eab92..5d9d4ddccccb 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -129,11 +129,11 @@ ifneq ($(KBUILD_OUTPUT),) # $(realpath ...) resolves symlinks abs_objtree := $(realpath $(abs_objtree)) BUILD := $(abs_objtree)/kselftest - KHDR_INCLUDES := -I${abs_objtree}/usr/include + KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include else BUILD := $(CURDIR) abs_srctree := $(shell cd $(top_srcdir) && pwd) - KHDR_INCLUDES := -I${abs_srctree}/usr/include + KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include DEFAULT_INSTALL_HDR_PATH := 1 endif -- cgit From 4893992b6de1be5e0c9f6df747912761e96b4271 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Fri, 11 Feb 2022 03:23:19 +0500 Subject: selftests/exec: Rename file binfmt_script to binfmt_script.py Rename file for readability purpose. Update its usage and references. Signed-off-by: Muhammad Usama Anjum Reviewed-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/exec/Makefile | 2 +- tools/testing/selftests/exec/binfmt_script | 171 -------------------------- tools/testing/selftests/exec/binfmt_script.py | 171 ++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 172 deletions(-) delete mode 100755 tools/testing/selftests/exec/binfmt_script create mode 100755 tools/testing/selftests/exec/binfmt_script.py diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile index 2d7fca446c7f..7f0412a26ba9 100644 --- a/tools/testing/selftests/exec/Makefile +++ b/tools/testing/selftests/exec/Makefile @@ -3,7 +3,7 @@ CFLAGS = -Wall CFLAGS += -Wno-nonnull CFLAGS += -D_GNU_SOURCE -TEST_PROGS := binfmt_script +TEST_PROGS := binfmt_script.py TEST_GEN_PROGS := execveat load_address_4096 load_address_2097152 load_address_16777216 non-regular TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir # Makefile is a run-time dependency, since it's accessed by the execveat test diff --git a/tools/testing/selftests/exec/binfmt_script b/tools/testing/selftests/exec/binfmt_script deleted file mode 100755 index 05f94a741c7a..000000000000 --- a/tools/testing/selftests/exec/binfmt_script +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0 -# -# Test that truncation of bprm->buf doesn't cause unexpected execs paths, along -# with various other pathological cases. -import os, subprocess - -# Relevant commits -# -# b5372fe5dc84 ("exec: load_script: Do not exec truncated interpreter path") -# 6eb3c3d0a52d ("exec: increase BINPRM_BUF_SIZE to 256") - -# BINPRM_BUF_SIZE -SIZE=256 - -NAME_MAX=int(subprocess.check_output(["getconf", "NAME_MAX", "."])) - -test_num=0 - -code='''#!/usr/bin/perl -print "Executed interpreter! Args:\n"; -print "0 : '$0'\n"; -$counter = 1; -foreach my $a (@ARGV) { - print "$counter : '$a'\n"; - $counter++; -} -''' - -## -# test - produce a binfmt_script hashbang line for testing -# -# @size: bytes for bprm->buf line, including hashbang but not newline -# @good: whether this script is expected to execute correctly -# @hashbang: the special 2 bytes for running binfmt_script -# @leading: any leading whitespace before the executable path -# @root: start of executable pathname -# @target: end of executable pathname -# @arg: bytes following the executable pathname -# @fill: character to fill between @root and @target to reach @size bytes -# @newline: character to use as newline, not counted towards @size -# ... -def test(name, size, good=True, leading="", root="./", target="/perl", - fill="A", arg="", newline="\n", hashbang="#!"): - global test_num, tests, NAME_MAX - test_num += 1 - if test_num > tests: - raise ValueError("more binfmt_script tests than expected! (want %d, expected %d)" - % (test_num, tests)) - - middle = "" - remaining = size - len(hashbang) - len(leading) - len(root) - len(target) - len(arg) - # The middle of the pathname must not exceed NAME_MAX - while remaining >= NAME_MAX: - middle += fill * (NAME_MAX - 1) - middle += '/' - remaining -= NAME_MAX - middle += fill * remaining - - dirpath = root + middle - binary = dirpath + target - if len(target): - os.makedirs(dirpath, mode=0o755, exist_ok=True) - open(binary, "w").write(code) - os.chmod(binary, 0o755) - - buf=hashbang + leading + root + middle + target + arg + newline - if len(newline) > 0: - buf += 'echo this is not really perl\n' - - script = "binfmt_script-%s" % (name) - open(script, "w").write(buf) - os.chmod(script, 0o755) - - proc = subprocess.Popen(["./%s" % (script)], shell=True, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - - if proc.returncode == 0 and b'Executed interpreter' in stdout: - if good: - print("ok %d - binfmt_script %s (successful good exec)" - % (test_num, name)) - else: - print("not ok %d - binfmt_script %s succeeded when it should have failed" - % (test_num, name)) - else: - if good: - print("not ok %d - binfmt_script %s failed when it should have succeeded (rc:%d)" - % (test_num, name, proc.returncode)) - else: - print("ok %d - binfmt_script %s (correctly failed bad exec)" - % (test_num, name)) - - # Clean up crazy binaries - os.unlink(script) - if len(target): - elements = binary.split('/') - os.unlink(binary) - elements.pop() - while len(elements) > 1: - os.rmdir("/".join(elements)) - elements.pop() - -tests=27 -print("TAP version 1.3") -print("1..%d" % (tests)) - -### FAIL (8 tests) - -# Entire path is well past the BINFMT_BUF_SIZE. -test(name="too-big", size=SIZE+80, good=False) -# Path is right at max size, making it impossible to tell if it was truncated. -test(name="exact", size=SIZE, good=False) -# Same as above, but with leading whitespace. -test(name="exact-space", size=SIZE, good=False, leading=" ") -# Huge buffer of only whitespace. -test(name="whitespace-too-big", size=SIZE+71, good=False, root="", - fill=" ", target="") -# A good path, but it gets truncated due to leading whitespace. -test(name="truncated", size=SIZE+17, good=False, leading=" " * 19) -# Entirely empty except for #! -test(name="empty", size=2, good=False, root="", - fill="", target="", newline="") -# Within size, but entirely spaces -test(name="spaces", size=SIZE-1, good=False, root="", fill=" ", - target="", newline="") -# Newline before binary. -test(name="newline-prefix", size=SIZE-1, good=False, leading="\n", - root="", fill=" ", target="") - -### ok (19 tests) - -# The original test case that was broken by commit: -# 8099b047ecc4 ("exec: load_script: don't blindly truncate shebang string") -test(name="test.pl", size=439, leading=" ", - root="./nix/store/bwav8kz8b3y471wjsybgzw84mrh4js9-perl-5.28.1/bin", - arg=" -I/nix/store/x6yyav38jgr924nkna62q3pkp0dgmzlx-perl5.28.1-File-Slurp-9999.25/lib/perl5/site_perl -I/nix/store/ha8v67sl8dac92r9z07vzr4gv1y9nwqz-perl5.28.1-Net-DBus-1.1.0/lib/perl5/site_perl -I/nix/store/dcrkvnjmwh69ljsvpbdjjdnqgwx90a9d-perl5.28.1-XML-Parser-2.44/lib/perl5/site_perl -I/nix/store/rmji88k2zz7h4zg97385bygcydrf2q8h-perl5.28.1-XML-Twig-3.52/lib/perl5/site_perl") -# One byte under size, leaving newline visible. -test(name="one-under", size=SIZE-1) -# Two bytes under size, leaving newline visible. -test(name="two-under", size=SIZE-2) -# Exact size, but trailing whitespace visible instead of newline -test(name="exact-trunc-whitespace", size=SIZE, arg=" ") -# Exact size, but trailing space and first arg char visible instead of newline. -test(name="exact-trunc-arg", size=SIZE, arg=" f") -# One bute under, with confirmed non-truncated arg since newline now visible. -test(name="one-under-full-arg", size=SIZE-1, arg=" f") -# Short read buffer by one byte. -test(name="one-under-no-nl", size=SIZE-1, newline="") -# Short read buffer by half buffer size. -test(name="half-under-no-nl", size=int(SIZE/2), newline="") -# One byte under with whitespace arg. leaving wenline visible. -test(name="one-under-trunc-arg", size=SIZE-1, arg=" ") -# One byte under with whitespace leading. leaving wenline visible. -test(name="one-under-leading", size=SIZE-1, leading=" ") -# One byte under with whitespace leading and as arg. leaving newline visible. -test(name="one-under-leading-trunc-arg", size=SIZE-1, leading=" ", arg=" ") -# Same as above, but with 2 bytes under -test(name="two-under-no-nl", size=SIZE-2, newline="") -test(name="two-under-trunc-arg", size=SIZE-2, arg=" ") -test(name="two-under-leading", size=SIZE-2, leading=" ") -test(name="two-under-leading-trunc-arg", size=SIZE-2, leading=" ", arg=" ") -# Same as above, but with buffer half filled -test(name="two-under-no-nl", size=int(SIZE/2), newline="") -test(name="two-under-trunc-arg", size=int(SIZE/2), arg=" ") -test(name="two-under-leading", size=int(SIZE/2), leading=" ") -test(name="two-under-lead-trunc-arg", size=int(SIZE/2), leading=" ", arg=" ") - -if test_num != tests: - raise ValueError("fewer binfmt_script tests than expected! (ran %d, expected %d" - % (test_num, tests)) diff --git a/tools/testing/selftests/exec/binfmt_script.py b/tools/testing/selftests/exec/binfmt_script.py new file mode 100755 index 000000000000..05f94a741c7a --- /dev/null +++ b/tools/testing/selftests/exec/binfmt_script.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +# Test that truncation of bprm->buf doesn't cause unexpected execs paths, along +# with various other pathological cases. +import os, subprocess + +# Relevant commits +# +# b5372fe5dc84 ("exec: load_script: Do not exec truncated interpreter path") +# 6eb3c3d0a52d ("exec: increase BINPRM_BUF_SIZE to 256") + +# BINPRM_BUF_SIZE +SIZE=256 + +NAME_MAX=int(subprocess.check_output(["getconf", "NAME_MAX", "."])) + +test_num=0 + +code='''#!/usr/bin/perl +print "Executed interpreter! Args:\n"; +print "0 : '$0'\n"; +$counter = 1; +foreach my $a (@ARGV) { + print "$counter : '$a'\n"; + $counter++; +} +''' + +## +# test - produce a binfmt_script hashbang line for testing +# +# @size: bytes for bprm->buf line, including hashbang but not newline +# @good: whether this script is expected to execute correctly +# @hashbang: the special 2 bytes for running binfmt_script +# @leading: any leading whitespace before the executable path +# @root: start of executable pathname +# @target: end of executable pathname +# @arg: bytes following the executable pathname +# @fill: character to fill between @root and @target to reach @size bytes +# @newline: character to use as newline, not counted towards @size +# ... +def test(name, size, good=True, leading="", root="./", target="/perl", + fill="A", arg="", newline="\n", hashbang="#!"): + global test_num, tests, NAME_MAX + test_num += 1 + if test_num > tests: + raise ValueError("more binfmt_script tests than expected! (want %d, expected %d)" + % (test_num, tests)) + + middle = "" + remaining = size - len(hashbang) - len(leading) - len(root) - len(target) - len(arg) + # The middle of the pathname must not exceed NAME_MAX + while remaining >= NAME_MAX: + middle += fill * (NAME_MAX - 1) + middle += '/' + remaining -= NAME_MAX + middle += fill * remaining + + dirpath = root + middle + binary = dirpath + target + if len(target): + os.makedirs(dirpath, mode=0o755, exist_ok=True) + open(binary, "w").write(code) + os.chmod(binary, 0o755) + + buf=hashbang + leading + root + middle + target + arg + newline + if len(newline) > 0: + buf += 'echo this is not really perl\n' + + script = "binfmt_script-%s" % (name) + open(script, "w").write(buf) + os.chmod(script, 0o755) + + proc = subprocess.Popen(["./%s" % (script)], shell=True, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout = proc.communicate()[0] + + if proc.returncode == 0 and b'Executed interpreter' in stdout: + if good: + print("ok %d - binfmt_script %s (successful good exec)" + % (test_num, name)) + else: + print("not ok %d - binfmt_script %s succeeded when it should have failed" + % (test_num, name)) + else: + if good: + print("not ok %d - binfmt_script %s failed when it should have succeeded (rc:%d)" + % (test_num, name, proc.returncode)) + else: + print("ok %d - binfmt_script %s (correctly failed bad exec)" + % (test_num, name)) + + # Clean up crazy binaries + os.unlink(script) + if len(target): + elements = binary.split('/') + os.unlink(binary) + elements.pop() + while len(elements) > 1: + os.rmdir("/".join(elements)) + elements.pop() + +tests=27 +print("TAP version 1.3") +print("1..%d" % (tests)) + +### FAIL (8 tests) + +# Entire path is well past the BINFMT_BUF_SIZE. +test(name="too-big", size=SIZE+80, good=False) +# Path is right at max size, making it impossible to tell if it was truncated. +test(name="exact", size=SIZE, good=False) +# Same as above, but with leading whitespace. +test(name="exact-space", size=SIZE, good=False, leading=" ") +# Huge buffer of only whitespace. +test(name="whitespace-too-big", size=SIZE+71, good=False, root="", + fill=" ", target="") +# A good path, but it gets truncated due to leading whitespace. +test(name="truncated", size=SIZE+17, good=False, leading=" " * 19) +# Entirely empty except for #! +test(name="empty", size=2, good=False, root="", + fill="", target="", newline="") +# Within size, but entirely spaces +test(name="spaces", size=SIZE-1, good=False, root="", fill=" ", + target="", newline="") +# Newline before binary. +test(name="newline-prefix", size=SIZE-1, good=False, leading="\n", + root="", fill=" ", target="") + +### ok (19 tests) + +# The original test case that was broken by commit: +# 8099b047ecc4 ("exec: load_script: don't blindly truncate shebang string") +test(name="test.pl", size=439, leading=" ", + root="./nix/store/bwav8kz8b3y471wjsybgzw84mrh4js9-perl-5.28.1/bin", + arg=" -I/nix/store/x6yyav38jgr924nkna62q3pkp0dgmzlx-perl5.28.1-File-Slurp-9999.25/lib/perl5/site_perl -I/nix/store/ha8v67sl8dac92r9z07vzr4gv1y9nwqz-perl5.28.1-Net-DBus-1.1.0/lib/perl5/site_perl -I/nix/store/dcrkvnjmwh69ljsvpbdjjdnqgwx90a9d-perl5.28.1-XML-Parser-2.44/lib/perl5/site_perl -I/nix/store/rmji88k2zz7h4zg97385bygcydrf2q8h-perl5.28.1-XML-Twig-3.52/lib/perl5/site_perl") +# One byte under size, leaving newline visible. +test(name="one-under", size=SIZE-1) +# Two bytes under size, leaving newline visible. +test(name="two-under", size=SIZE-2) +# Exact size, but trailing whitespace visible instead of newline +test(name="exact-trunc-whitespace", size=SIZE, arg=" ") +# Exact size, but trailing space and first arg char visible instead of newline. +test(name="exact-trunc-arg", size=SIZE, arg=" f") +# One bute under, with confirmed non-truncated arg since newline now visible. +test(name="one-under-full-arg", size=SIZE-1, arg=" f") +# Short read buffer by one byte. +test(name="one-under-no-nl", size=SIZE-1, newline="") +# Short read buffer by half buffer size. +test(name="half-under-no-nl", size=int(SIZE/2), newline="") +# One byte under with whitespace arg. leaving wenline visible. +test(name="one-under-trunc-arg", size=SIZE-1, arg=" ") +# One byte under with whitespace leading. leaving wenline visible. +test(name="one-under-leading", size=SIZE-1, leading=" ") +# One byte under with whitespace leading and as arg. leaving newline visible. +test(name="one-under-leading-trunc-arg", size=SIZE-1, leading=" ", arg=" ") +# Same as above, but with 2 bytes under +test(name="two-under-no-nl", size=SIZE-2, newline="") +test(name="two-under-trunc-arg", size=SIZE-2, arg=" ") +test(name="two-under-leading", size=SIZE-2, leading=" ") +test(name="two-under-leading-trunc-arg", size=SIZE-2, leading=" ", arg=" ") +# Same as above, but with buffer half filled +test(name="two-under-no-nl", size=int(SIZE/2), newline="") +test(name="two-under-trunc-arg", size=int(SIZE/2), arg=" ") +test(name="two-under-leading", size=int(SIZE/2), leading=" ") +test(name="two-under-lead-trunc-arg", size=int(SIZE/2), leading=" ", arg=" ") + +if test_num != tests: + raise ValueError("fewer binfmt_script tests than expected! (ran %d, expected %d" + % (test_num, tests)) -- cgit From b22dfec72c377e350c4cafce4078977d3e5bee03 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Fri, 21 Jan 2022 19:51:52 +0500 Subject: selftests/lkdtm: Remove dead config option CONFIG_HARDENED_USERCOPY_FALLBACK config option has been removed in commit 53944f171a89 ("mm: remove HARDENED_USERCOPY_FALLBACK"). Remove it from the lkdtm selftest config. Signed-off-by: Muhammad Usama Anjum Acked-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/lkdtm/config | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/lkdtm/config b/tools/testing/selftests/lkdtm/config index a26a3fa9e925..a7a58f885f52 100644 --- a/tools/testing/selftests/lkdtm/config +++ b/tools/testing/selftests/lkdtm/config @@ -3,7 +3,6 @@ CONFIG_DEBUG_LIST=y CONFIG_SLAB_FREELIST_HARDENED=y CONFIG_FORTIFY_SOURCE=y CONFIG_HARDENED_USERCOPY=y -# CONFIG_HARDENED_USERCOPY_FALLBACK is not set CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y CONFIG_UBSAN_BOUNDS=y -- cgit From 1900be289b598b2c553b3add13e491c0bb8a8550 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Fri, 21 Jan 2022 19:51:53 +0500 Subject: selftests/lkdtm: Add UBSAN config UBSAN_BOUNDS and UBSAN_TRAP depend on UBSAN config option. merge_config.sh script generates following warnings if parent config doesn't have UBSAN config already enabled and UBSAN_BOUNDS/UBSAN_TRAP config options don't get added to the parent config. Value requested for CONFIG_UBSAN_BOUNDS not in final .config Requested value: CONFIG_UBSAN_BOUNDS=y Actual value: Value requested for CONFIG_UBSAN_TRAP not in final .config Requested value: CONFIG_UBSAN_TRAP=y Actual value: Fix this by including UBSAN config. Fixes: c75be56e35b2 ("lkdtm/bugs: Add ARRAY_BOUNDS to selftests") Signed-off-by: Muhammad Usama Anjum Acked-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/lkdtm/config | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/lkdtm/config b/tools/testing/selftests/lkdtm/config index a7a58f885f52..46f39ee76208 100644 --- a/tools/testing/selftests/lkdtm/config +++ b/tools/testing/selftests/lkdtm/config @@ -5,6 +5,7 @@ CONFIG_FORTIFY_SOURCE=y CONFIG_HARDENED_USERCOPY=y CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y +CONFIG_UBSAN=y CONFIG_UBSAN_BOUNDS=y CONFIG_UBSAN_TRAP=y CONFIG_STACKPROTECTOR_STRONG=y -- cgit From 2aaa36e95ea586ad23edfcc1d474e8b735a4d1c3 Mon Sep 17 00:00:00 2001 From: Mateusz Jończyk Date: Sat, 19 Feb 2022 08:27:13 +0100 Subject: selftests/rtc: continuously read RTC in a loop for 30s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some problems with reading the RTC time may happen rarely, for example while the RTC is updating. So read the RTC many times to catch these problems. For example, a previous attempt for my commit ea6fa4961aab ("rtc: mc146818-lib: fix RTC presence check") was incorrect and would have triggered this selftest. To avoid the risk of damaging the hardware, wait 11ms before consecutive reads. In rtc_time_to_timestamp I copied values manually instead of casting - just to be on the safe side. The 11ms wait period was chosen so that it is not a divisor of 1000ms. Signed-off-by: Mateusz Jończyk Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: Shuah Khan Signed-off-by: Shuah Khan --- tools/testing/selftests/rtc/rtctest.c | 66 +++++++++++++++++++++++++++++++++++ tools/testing/selftests/rtc/settings | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c index 66af608fb4c6..2b9d929a24ed 100644 --- a/tools/testing/selftests/rtc/rtctest.c +++ b/tools/testing/selftests/rtc/rtctest.c @@ -20,6 +20,8 @@ #define NUM_UIE 3 #define ALARM_DELTA 3 +#define READ_LOOP_DURATION_SEC 30 +#define READ_LOOP_SLEEP_MS 11 static char *rtc_file = "/dev/rtc0"; @@ -49,6 +51,70 @@ TEST_F(rtc, date_read) { rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); } +static time_t rtc_time_to_timestamp(struct rtc_time *rtc_time) +{ + struct tm tm_time = { + .tm_sec = rtc_time->tm_sec, + .tm_min = rtc_time->tm_min, + .tm_hour = rtc_time->tm_hour, + .tm_mday = rtc_time->tm_mday, + .tm_mon = rtc_time->tm_mon, + .tm_year = rtc_time->tm_year, + }; + + return mktime(&tm_time); +} + +static void nanosleep_with_retries(long ns) +{ + struct timespec req = { + .tv_sec = 0, + .tv_nsec = ns, + }; + struct timespec rem; + + while (nanosleep(&req, &rem) != 0) { + req.tv_sec = rem.tv_sec; + req.tv_nsec = rem.tv_nsec; + } +} + +TEST_F_TIMEOUT(rtc, date_read_loop, READ_LOOP_DURATION_SEC + 2) { + int rc; + long iter_count = 0; + struct rtc_time rtc_tm; + time_t start_rtc_read, prev_rtc_read; + + TH_LOG("Continuously reading RTC time for %ds (with %dms breaks after every read).", + READ_LOOP_DURATION_SEC, READ_LOOP_SLEEP_MS); + + rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm); + ASSERT_NE(-1, rc); + start_rtc_read = rtc_time_to_timestamp(&rtc_tm); + prev_rtc_read = start_rtc_read; + + do { + time_t rtc_read; + + rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm); + ASSERT_NE(-1, rc); + + rtc_read = rtc_time_to_timestamp(&rtc_tm); + /* Time should not go backwards */ + ASSERT_LE(prev_rtc_read, rtc_read); + /* Time should not increase more then 1s at a time */ + ASSERT_GE(prev_rtc_read + 1, rtc_read); + + /* Sleep 11ms to avoid killing / overheating the RTC */ + nanosleep_with_retries(READ_LOOP_SLEEP_MS * 1000000); + + prev_rtc_read = rtc_read; + iter_count++; + } while (prev_rtc_read <= start_rtc_read + READ_LOOP_DURATION_SEC); + + TH_LOG("Performed %ld RTC time reads.", iter_count); +} + TEST_F_TIMEOUT(rtc, uie_read, NUM_UIE + 2) { int i, rc, irq = 0; unsigned long data; diff --git a/tools/testing/selftests/rtc/settings b/tools/testing/selftests/rtc/settings index a953c96aa16e..0c1a2075d5f3 100644 --- a/tools/testing/selftests/rtc/settings +++ b/tools/testing/selftests/rtc/settings @@ -1 +1 @@ -timeout=180 +timeout=210 -- cgit From edcb647b4bfb19674d58bff2e6ef96e0dbcccfdf Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 2 Mar 2022 23:01:18 +0500 Subject: selftests: add kselftest_install to .gitignore Add kselftest_install directory to the .gitignore which is created while creation of tar ball of objects: make -C tools/testing/selftests gen_tar Signed-off-by: Muhammad Usama Anjum Reviewed-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/.gitignore b/tools/testing/selftests/.gitignore index 055a5019b13c..cb24124ac5b9 100644 --- a/tools/testing/selftests/.gitignore +++ b/tools/testing/selftests/.gitignore @@ -3,6 +3,7 @@ gpiogpio-event-mon gpiogpio-hammer gpioinclude/ gpiolsgpio +kselftest_install/ tpm2/SpaceTest.log # Python bytecode and cache -- cgit From c7b9c68fc01b468983c8f4745f400fa74c831005 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 2 Mar 2022 23:01:19 +0500 Subject: selftests/exec: add generated files to .gitignore Add generated files non-regular and null-argv to .gitignore file. Signed-off-by: Muhammad Usama Anjum Reviewed-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/exec/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/exec/.gitignore b/tools/testing/selftests/exec/.gitignore index 9e2f00343f15..90c238ba6a4b 100644 --- a/tools/testing/selftests/exec/.gitignore +++ b/tools/testing/selftests/exec/.gitignore @@ -7,6 +7,8 @@ execveat.moved execveat.path.ephemeral execveat.ephemeral execveat.denatured +non-regular +null-argv /load_address_* /recursion-depth xxxxxxxx* -- cgit From 946ad0499d984be13ec02f8257ca0527ec287bf2 Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Wed, 2 Mar 2022 23:01:20 +0500 Subject: selftests: kvm: add generated file to the .gitignore Add hyperv_svm_test to the .gitignore file. Signed-off-by: Muhammad Usama Anjum Reviewed-by: Kees Cook Signed-off-by: Shuah Khan --- tools/testing/selftests/kvm/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index dce7de7755e6..62f9b781545b 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -20,6 +20,7 @@ /x86_64/hyperv_clock /x86_64/hyperv_cpuid /x86_64/hyperv_features +/x86_64/hyperv_svm_test /x86_64/mmio_warning_test /x86_64/mmu_role_test /x86_64/platform_info_test -- cgit From a50a88f026fb28ece512c50e8ef7cd4ef6d0a291 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Wed, 2 Mar 2022 13:29:13 +0800 Subject: selftests: netfilter: fix a build error on openSUSE This patch fixed the following build error on openSUSE Leap 15.3: ======================================================================= gcc nf-queue.c -lmnl -o tools/testing/selftests/netfilter/nf-queue nf-queue.c:13:10: fatal error: libmnl/libmnl.h: No such file or directory #include ^~~~~~~~~~~~~~~~~ compilation terminated. ======================================================================= It is because libmnl.h is put in the directory of "/usr/include/libmnl/libmnl/" on openSUSE, not "/usr/include/libmnl/": > rpm -ql libmnl-devel /usr/include/libmnl /usr/include/libmnl/libmnl /usr/include/libmnl/libmnl/libmnl.h /usr/lib64/libmnl.so /usr/lib64/pkgconfig/libmnl.pc Suggested-by: Kai Liu Signed-off-by: Geliang Tang Reviewed-by: Shuah Khan Signed-off-by: Shuah Khan --- tools/testing/selftests/netfilter/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/netfilter/Makefile b/tools/testing/selftests/netfilter/Makefile index e4f845dd942b..8136c1fab7ab 100644 --- a/tools/testing/selftests/netfilter/Makefile +++ b/tools/testing/selftests/netfilter/Makefile @@ -8,6 +8,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \ ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \ conntrack_vrf.sh nft_synproxy.sh +CFLAGS += $(shell pkg-config --cflags libmnl 2>/dev/null || echo "-I/usr/include/libmnl") LDLIBS = -lmnl TEST_GEN_FILES = nf-queue -- cgit From f6d344cd5fa6a15e1ec2da350470b35a3f55f74c Mon Sep 17 00:00:00 2001 From: Muhammad Usama Anjum Date: Thu, 17 Feb 2022 03:38:17 +0500 Subject: selftests: Fix build when $(O) points to a relative path Build of bpf and tc-testing selftests fails when the relative path of the build directory is specified. make -C tools/testing/selftests O=build0 make[1]: Entering directory '/linux_mainline/tools/testing/selftests/bpf' ../../../scripts/Makefile.include:4: *** O=build0 does not exist. Stop. make[1]: Entering directory '/linux_mainline/tools/testing/selftests/tc-testing' ../../../scripts/Makefile.include:4: *** O=build0 does not exist. Stop. Makefiles of bpf and tc-testing include scripts/Makefile.include file. This file has sanity checking inside it which checks the output path. The output path is not relative to the bpf or tc-testing. The sanity check fails. Expand the output path to get rid of this error. The fix is the same as mentioned in commit 150a27328b68 ("bpf, preload: Fix build when $(O) points to a relative path"). Signed-off-by: Muhammad Usama Anjum Signed-off-by: Shuah Khan --- tools/testing/selftests/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 5d9d4ddccccb..2319ec87f53d 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -177,6 +177,7 @@ all: khdr BUILD_TARGET=$$BUILD/$$TARGET; \ mkdir $$BUILD_TARGET -p; \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ + O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ ret=$$((ret * $$?)); \ done; exit $$ret; @@ -184,7 +185,8 @@ all: khdr run_tests: all @for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ - $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \ + O=$(abs_objtree); \ done; hotplug: @@ -235,6 +237,7 @@ ifdef INSTALL_PATH for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ + O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ ret=$$((ret * $$?)); \ done; exit $$ret; -- cgit