diff --git a/tests/.gitignore b/tests/.gitignore index a19b1b305e..5a2f2649d8 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -860,6 +860,7 @@ seccomp_get_action_avail seccomp_get_notif_sizes seccomp_get_notif_sizes-success secontext.am +segv_accerr segv_pkuerr select select-P diff --git a/tests/Makefile.am b/tests/Makefile.am index d0f6947629..22a494539e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -335,6 +335,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ seccomp-filter-v \ seccomp-strict \ seccomp_get_notif_sizes-success \ + segv_accerr \ segv_pkuerr \ select-P \ set_ptracer_any \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index c963c99755..c11d129af2 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -840,6 +840,7 @@ seccomp-filter-v -v -e trace=seccomp seccomp_get_action_avail -e trace=seccomp seccomp_get_notif_sizes -etrace=seccomp -a42 seccomp_get_notif_sizes-success -einject=seccomp:retval=42 -etrace=seccomp -a42 +segv_accerr -qq --trace=none segv_pkuerr -qq --trace=none select -a36 select-P -a36 -e trace=select -P /dev/full 9>>/dev/full diff --git a/tests/segv_accerr.c b/tests/segv_accerr.c new file mode 100644 index 0000000000..f43a906df6 --- /dev/null +++ b/tests/segv_accerr.c @@ -0,0 +1,54 @@ +/* + * Check decoding of SEGV_ACCERR. + * + * Copyright (c) 2022 Dmitry V. Levin + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" +#include + +#ifdef SEGV_ACCERR + +# include +# include +# include +# include + +static void +handler(int sig) +{ + _exit(0); +} + +int +main(void) { + int *p = mmap(NULL, get_page_size(), PROT_NONE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) + perror_msg_and_fail("mmap"); + + const struct sigaction act = { + .sa_handler = handler, + .sa_flags = SA_RESETHAND + }; + if (sigaction(SIGSEGV, &act, NULL)) + perror_msg_and_fail("sigaction"); + + printf("--- SIGSEGV {si_signo=SIGSEGV" + ", si_code=SEGV_ACCERR, si_addr=%p} ---\n", p); + fflush(stdout); + + if (*p) + __asm__ volatile("":::"memory"); + + error_msg_and_skip("PROT_NONE page is readable"); +} + +#else + +SKIP_MAIN_UNDEFINED("SEGV_ACCERR") + +#endif