aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/seccomp (follow)
AgeCommit message (Collapse)AuthorFilesLines
2017-09-05selftests: Enhance kselftest_harness.h to print which assert failedMickaël Salaün1-1/+1
When a test process is not able to write to TH_LOG_STREAM, this step mechanism enable to print the assert number which triggered the failure. This can be enabled by setting _metadata->no_print to true at the beginning of the test sequence. Update the seccomp-bpf test to return 0 if a test succeeded. This feature is needed for the Landlock tests. Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Kees Cook <keescook@chromium.org> Cc: Shuah Khan <shuah@kernel.org> Cc: Will Drewry <wad@chromium.org> Link: https://lkml.kernel.org/r/CAGXu5j+D-FP8Kt9unNOqKrQJP4DYTpmgkJxWykZyrYiVPz3Y3Q@mail.gmail.com Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-07Merge tag 'linux-kselftest-4.13-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftestLinus Torvalds3-537/+4
Pull Kselftest updates from Shuah Khan: "This update consists of: - TAP13 framework and changes to some tests to convert to TAP13. Converting kselftest output to standard format will help identify run to run differences and pin point failures easily. TAP13 format has been in use for several years and the output is human friendly. Please find the specification: https://testanything.org/tap-version-13-specification.html Credit goes to Tim Bird for recommending TAP13 as a suitable format, and to Grag KH for kick starting the work with help from Paul Elder and Alice Ferrazzi The first phase of the TAp13 conversion is included in this update. Future updates will include updates to rest of the tests. - Masami Hiramatsu fixed ftrace to run on 4.9 stable kernels. - Kselftest documnetation has been converted to ReST format. Document now has a new home under Documentation/dev-tools. - kselftest_harness.h is now available for general use as a result of Mickaël Salaün's work. - Several fixes to skip and/or fail tests gracefully on older releases" * tag 'linux-kselftest-4.13-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (48 commits) selftests: membarrier: use ksft_* var arg msg api selftests: breakpoints: breakpoint_test_arm64: convert test to use TAP13 selftests: breakpoints: step_after_suspend_test use ksft_* var arg msg api selftests: breakpoint_test: use ksft_* var arg msg api kselftest: add ksft_print_msg() function to output general information kselftest: make ksft_* output functions variadic selftests/capabilities: Fix the test_execve test selftests: intel_pstate: add .gitignore selftests: fix memory-hotplug test selftests: add missing test name in memory-hotplug test selftests: check percentage range for memory-hotplug test selftests: check hot-pluggagble memory for memory-hotplug test selftests: typo correction for memory-hotplug test selftests: ftrace: Use md5sum to take less time of checking logs tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict kselftest.rst: do some adjustments after ReST conversion selftest/net/Makefile: Specify output with $(OUTPUT) selftest/intel_pstate/aperf: Use LDLIBS instead of LDFLAGS selftest/memfd/Makefile: Fix build error selftests: lib: Skip tests on missing test modules ...
2017-06-26seccomp: Adjust selftests to avoid double-joinKees Cook1-17/+34
While glibc's pthread implementation is rather forgiving about repeat thread joining, Bionic has recently become much more strict. To deal with this, actually track which threads have been successfully joined and kill the rest at teardown. Based on a patch from Paul Lawrence. Cc: Paul Lawrence <paullawrence@google.com> Signed-off-by: Kees Cook <keescook@chromium.org>
2017-06-12selftests: kselftest_harness: Fix compile warningMickaël Salaün1-1/+1
Do not confuse the compiler with a semicolon preceding a block. Replace the semicolon with an empty block to avoid a warning: gcc -Wl,-no-as-needed -Wall -lpthread seccomp_bpf.c -o /.../linux/tools/testing/selftests/seccomp/seccomp_bpf In file included from seccomp_bpf.c:40:0: seccomp_bpf.c: In function ‘change_syscall’: ../kselftest_harness.h:558:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation] for (; _metadata->trigger; _metadata->trigger = __bail(_assert)) ^ ../kselftest_harness.h:574:14: note: in expansion of macro ‘OPTIONAL_HANDLER’ } while (0); OPTIONAL_HANDLER(_assert) ^~~~~~~~~~~~~~~~ ../kselftest_harness.h:440:2: note: in expansion of macro ‘__EXPECT’ __EXPECT(expected, seen, ==, 0) ^~~~~~~~ seccomp_bpf.c:1313:2: note: in expansion of macro ‘EXPECT_EQ’ EXPECT_EQ(0, ret); ^~~~~~~~~ seccomp_bpf.c:1317:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘for’ { ^ Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Kees Cook <keescook@chromium.org> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Will Drewry <wad@chromium.org> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-06-07selftests/seccomp: Force rebuild according to dependenciesMickaël Salaün1-0/+2
Rebuild the seccomp tests when kselftest_harness.h is updated. Signed-off-by: Mickaël Salaün <mic@digikod.net> Acked-by: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Shuah Khan <shuah@kernel.org> Cc: Will Drewry <wad@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-06-07selftests: Make test_harness.h more generally availableMickaël Salaün2-536/+1
The seccomp/test_harness.h file contains useful helpers to build tests. Moving it to the selftest directory should benefit to other test components. Keep seccomp maintainers for this file. Signed-off-by: Mickaël Salaün <mic@digikod.net> Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Will Drewry <wad@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Shuah Khan <shuah@kernel.org> Link: https://lkml.kernel.org/r/CAGXu5j+8CVz8vL51DRYXqOY=xc3zuKFf=PTENe88XYHzFYidUQ@mail.gmail.com Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-01-05selftests: remove duplicated all and clean targetbamvor.zhangjian@huawei.com1-5/+1
Currently, kselftest use TEST_PROGS, TEST_PROGS_EXTENDED, TEST_FILES to indicate the test program, extended test program and test files. It is easy to understand the purpose of these files. But mix of compiled and uncompiled files lead to duplicated "all" and "clean" targets. In order to remove the duplicated targets, introduce TEST_GEN_PROGS, TEST_GEN_PROGS_EXTENDED, TEST_GEN_FILES to indicate the compiled objects. Also, the later patch will make use of TEST_GEN_XXX to redirect these files to output directory indicated by KBUILD_OUTPUT or O. And add this changes to "Contributing new tests(details)" of Documentation/kselftest.txt. Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2016-06-14seccomp: add tests for ptrace holeKees Cook1-11/+165
One problem with seccomp was that ptrace could be used to change a syscall after seccomp filtering had completed. This was a well documented limitation, and it was recommended to block ptrace when defining a filter to avoid this problem. This can be quite a limitation for containers or other places where ptrace is desired even under seccomp filters. This adds tests for both SECCOMP_RET_TRACE and PTRACE_SYSCALL manipulations. Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@kernel.org>
2016-05-22parisc: Add ARCH_TRACEHOOK and regset supportHelge Deller1-1/+7
By adding TRACEHOOK support we now get a clean user interface to access registers via PTRACE_GETREGS, PTRACE_SETREGS, PTRACE_GETFPREGS and PTRACE_SETFPREGS. The user-visible regset struct user_regs_struct and user_fp_struct are modelled similiar to x86 and can be accessed via PTRACE_GETREGSET. Signed-off-by: Helge Deller <deller@gmx.de>
2016-05-13selftests/seccomp: add MIPS self-test supportMatt Redfearn1-2/+28
This adds self-test support on MIPS, based on RFC patch from Kees Cook. Modifications from the RFC: - support the O32 syscall which passes the real syscall number in a0. - Use PTRACE_{GET,SET}REGS - Because SYSCALL_NUM and SYSCALL_RET are the same register, it is not possible to test modifying the syscall return value when skipping, since both would need to set the same register. Therefore modify that test case to just detect the skipped test. Tested on MIPS32r2 / MIPS64r2 with O32, N32 and N64 userlands. Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com> Acked-by: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Will Drewry <wad@chromium.org> Cc: IMG-MIPSLinuxKerneldevelopers@imgtec.com Cc: linux-kernel@vger.kernel.org Cc: linux-kselftest@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/12977/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2016-03-29selftest/seccomp: Fix the seccomp(2) signatureMickaël Salaün1-2/+2
Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Kees Cook <keescook@chromium.org> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Will Drewry <wad@chromium.org> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2016-03-29selftest/seccomp: Fix the flag name SECCOMP_FILTER_FLAG_TSYNCMickaël Salaün1-9/+9
Rename SECCOMP_FLAG_FILTER_TSYNC to SECCOMP_FILTER_FLAG_TSYNC to match the UAPI. Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Kees Cook <keescook@chromium.org> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Will Drewry <wad@chromium.org> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2016-02-25selftests: create test-specific kconfig fragmentsBamvor Jian Zhang1-0/+2
Create the config file in each directory of testcase which need more kernel configuration than the default defconfig. User could use these configs with merge_config.sh script: Enable config for specific testcase: (export ARCH=xxx #for cross compiling) ./scripts/kconfig/merge_config.sh .config \ tools/testing/selftests/xxx/config Enable configs for all testcases: (export ARCH=xxx #for cross compiling) ./scripts/kconfig/merge_config.sh .config \ tools/testing/selftests/*/config Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org> Reviewed-by: Shuah Khan <shuahkh@osg.samsung.com> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2016-01-17Merge tag 'linux-kselftest-4.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftestLinus Torvalds1-2/+3
Pull kselftest updates from Shuah Khan: "This 14 patch update: - adds a new test for intel_pstate driver - adds empty string and async test cases to firmware class tests - fixes and cleans up several existing tests" * tag 'linux-kselftest-4.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests: firmware: add empty string and async tests firmware: actually return NULL on failed request_firmware_nowait() test: firmware_class: add asynchronous request trigger test: firmware_class: use kstrndup() where appropriate test: firmware_class: report errors properly on failure selftests/seccomp: fix 32-bit build warnings add breakpoints/.gitignore add ptrace/.gitignore update .gitignore in selftests/timers update .gitignore in selftests/vm tools, testing, add test for intel_pstate driver selftest/ipc: actually test it selftests/capabilities: actually test it selftests/capabilities: clean up for Makefile
2016-01-10selftests/seccomp: Remove the need for HAVE_ARCH_TRACEHOOKMickaël Salaün1-3/+24
Some architectures do not implement PTRACE_GETREGSET nor PTRACE_SETREGSET (required by HAVE_ARCH_TRACEHOOK) but only implement PTRACE_GETREGS and PTRACE_SETREGS (e.g. User-mode Linux). This improve seccomp selftest portability for architectures without HAVE_ARCH_TRACEHOOK support by defining a new trigger HAVE_GETREGS. For now, this is only enabled for i386 and x86_64 architectures. This is required to be able to run this tests on User-mode Linux. Signed-off-by: Mickaël Salaün <mic@digikod.net> Cc: Jeff Dike <jdike@addtoit.com> Cc: Richard Weinberger <richard@nod.at> Cc: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Will Drewry <wad@chromium.org> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Meredydd Luff <meredydd@senatehouse.org> Cc: David Drysdale <drysdale@google.com> Signed-off-by: Richard Weinberger <richard@nod.at> Acked-by: Kees Cook <keescook@chromium.org>
2016-01-07selftests/seccomp: fix 32-bit build warningsKees Cook1-2/+3
The casting was done incorrectly for 32-bit builds. Fixed to use uintptr_t. Reported-by: Eric Adams <adamse@google.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2015-11-18selftests/seccomp: Get page size from sysconfBamvor Jian Zhang1-4/+7
The commit fd88d16c58c2 ("selftests/seccomp: Be more precise with syscall arguments.") use PAGE_SIZE directly which lead to build failure on arm64. Replace it with generic interface(sysconf(_SC_PAGESIZE)) to fix this failure. Build and test successful on x86_64 and arm64. Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org> Acked-by: Kees Cook <keescook@chromium.org> Tested-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2015-11-02selftests/seccomp: Be more precise with syscall arguments.Robert Sesek1-11/+35
Certain syscall emulation layers strictly check that the number of arguments match what the syscall handler expects. The KILL_one_arg_one and KILL_one_arg_six tests passed more parameters than expected to various syscalls, causing failures in this emulation mode. Instead, test using syscalls that take the appropriate number of arguments. Signed-off-by: Robert Sesek <rsesek@google.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2015-10-15selftests/seccomp: build and pass on arm64Kees Cook1-22/+49
Changing arm64 syscalls is done via a specific register set, more like s390 than like arm (specific ptrace call) and x86 (part of general registers). Since (restarting) poll doesn't exist on arm64, switch to using nanosleep for testing restart_syscall. And since it looks like the syscall ABI is inconsistent on arm-compat, so we must work around it (and document it) in the test. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2015-09-14selftests/seccomp: add support for s390Kees Cook2-6/+38
This adds support for s390 to the seccomp selftests. Some improvements were made to enhance the accuracy of failure reporting, and additional tests were added to validate assumptions about the currently traced syscall. Also adds early asserts for running on older kernels to avoid noise when the seccomp syscall is not implemented. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2015-07-30selftests/seccomp: Add powerpc supportMichael Ellerman1-1/+8
Wire up the syscall number and regs so the tests work on powerpc. With the powerpc kernel support just merged, all tests pass on ppc64, ppc64 (compat), ppc64le, ppc, ppc64e and ppc64e (compat). Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-07-30selftests/seccomp: Make seccomp tests work on big endianMichael Ellerman1-0/+6
The seccomp_bpf test uses BPF_LD|BPF_W|BPF_ABS to load 32-bit values from seccomp_data->args. On big endian machines this will load the high word of the argument, which is not what the test wants. Borrow a hack from samples/seccomp/bpf-helper.h which changes the offset on big endian to account for this. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Acked-by: Kees Cook <keescook@chromium.org>
2015-06-17selftests: add seccomp suiteKees Cook4-0/+2657
This imports the existing seccomp test suite into the kernel's selftests tree. It contains extensive testing of seccomp features and corner cases. There remain additional tests to move into the kernel tree, but they have not yet been ported to all the architectures seccomp supports: https://github.com/redpig/seccomp/tree/master/tests Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>