From 83b213a915e441623e94464ddc0430582be8c8ac Mon Sep 17 00:00:00 2001 From: Jakub Zakrzewski Date: Sat, 28 Aug 2021 18:22:54 +0200 Subject: [PATCH] Add a testcase. When running under seccomp, sometimes sysexit handlers fail to execute. This is possible when the first syscall a process makes, before seccomp is enabled, gets handled in the SIGTRAP path. However the conditions for this to occur seem fairly random, so we fork out many processes to make it likely that at least some hit this problem. This problem may be related to issue #106. --- test/GNUmakefile | 3 +++ test/test-sysexit.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/test-sysexit.c diff --git a/test/GNUmakefile b/test/GNUmakefile index 8929490f..de9c4d5a 100644 --- a/test/GNUmakefile +++ b/test/GNUmakefile @@ -29,6 +29,9 @@ check-%.c: $(ROOTFS)/bin/% setup $(call check_c,$*,$(PROOT) -b /proc -r $(ROOTFS) /bin/$*) # Special cases. +check-test-sysexit.c: test-sysexit + $(call check_c,$<,env PROOT_FORCE_KOMPAT=1 $(PROOT) -k 3.4242XX ./$<) + check-test-bdc90417.c: test-bdc90417 $(call check_c,$<,$(PROOT) -w . ./$<) diff --git a/test/test-sysexit.c b/test/test-sysexit.c new file mode 100644 index 00000000..820d33d0 --- /dev/null +++ b/test/test-sysexit.c @@ -0,0 +1,35 @@ +/* -*- c-set-style: "K&R"; c-basic-offset: 8 -*- */ +#include +#include +#include /* wait(2), */ +#include +#include + +/* Related to github issue #106. + * Test if sysexit handlers execute, using uname handling + * in the kompat extension. The test case is meant to be + * run with "-k 3.4242XX" cmdline argument. + * The bug could occur during the first traced syscall, + * before seccomp got enabled. + * However there was some kind of a random factor there, + * so we fork out many processes to make it likely that at least + * some would hit this problem. */ + +int main() +{ + int status; + struct utsname s; + for (int i = 0; i < 5; i++) { + fork(); + } + uname(&s); + int child_status; + while ((status = wait(&child_status)) >= 0) { + if (!WIFEXITED(child_status) || (WEXITSTATUS(child_status) == EXIT_FAILURE)) + exit(EXIT_FAILURE); + } + if (strcmp("3.4242XX", s.release) == 0) { + exit(EXIT_SUCCESS); + } + exit(EXIT_FAILURE); +}