diff options
author | Dmitry V. Levin <ldv@strace.io> | 2022-02-03 08:00:00 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2022-02-03 08:00:00 +0000 |
commit | beed7451b02c7c63c6199ac6b027beca7eef097f (patch) | |
tree | df69bbead3fe7760780b294ce647bd0de89d7bfe | |
parent | d8bf3805d12f64d408946e10d8dbf67a7d2330e0 (diff) | |
download | strace-beed7451b02c7c63c6199ac6b027beca7eef097f.tar.gz |
tests: check decoding of SEGV_PKUERR
* tests/segv_pkuerr.c: New file.
* tests/gen_tests.in (segv_pkuerr): New test.
* tests/Makefile.am (check_PROGRAMS): Add segv_pkuerr.
* tests/.gitignore: Likewise.
* tests/ptrace.c (main) [HAVE_SIGINFO_T_SI_PKEY]: Check decoding
of SEGV_PKUERR.
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/gen_tests.in | 1 | ||||
-rw-r--r-- | tests/ptrace.c | 16 | ||||
-rw-r--r-- | tests/segv_pkuerr.c | 55 |
5 files changed, 74 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index a636eceb3..a19b1b305 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_pkuerr select select-P semop diff --git a/tests/Makefile.am b/tests/Makefile.am index 9623e672d..d0f694762 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_pkuerr \ select-P \ set_ptracer_any \ set_sigblock \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 23b9bce1d..c963c9975 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_pkuerr -qq --trace=none select -a36 select-P -a36 -e trace=select -P /dev/full 9>>/dev/full semop -a32 diff --git a/tests/ptrace.c b/tests/ptrace.c index 0ecd3c7b7..5266f0c06 100644 --- a/tests/ptrace.c +++ b/tests/ptrace.c @@ -1854,6 +1854,22 @@ main(void) XLAT_ARGS(PTRACE_SETSIGINFO), pid, bad_request, XLAT_ARGS(SIGPROF), sip->si_code, sip->si_errno, errstr); +#ifdef HAVE_SIGINFO_T_SI_PKEY + memset(sip, -1, sizeof(*sip)); + sip->si_signo = SIGSEGV; + sip->si_code = SEGV_PKUERR; + sip->si_errno = 0; + sip->si_addr = (void *) (unsigned long) 0xfacefeeddeadbeefULL; + sip->si_pkey = 0xbadc0ded; + + do_ptrace(PTRACE_SETSIGINFO, pid, bad_request, (uintptr_t) sip); + printf("ptrace(" XLAT_FMT ", %d, %#lx, {si_signo=" XLAT_FMT_U + ", si_code=" XLAT_FMT ", si_addr=%p, si_pkey=%u}) = %s\n", + XLAT_ARGS(PTRACE_SETSIGINFO), pid, bad_request, + XLAT_ARGS(SIGSEGV), XLAT_ARGS(SEGV_PKUERR), + sip->si_addr, sip->si_pkey, errstr); +#endif + #ifdef HAVE_SIGINFO_T_SI_SYSCALL memset(sip, -1, sizeof(*sip)); sip->si_signo = SIGSYS; diff --git a/tests/segv_pkuerr.c b/tests/segv_pkuerr.c new file mode 100644 index 000000000..92b867e60 --- /dev/null +++ b/tests/segv_pkuerr.c @@ -0,0 +1,55 @@ +/* + * Check decoding of SEGV_PKUERR. + * + * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io> + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" +#include <signal.h> + +#if defined HAVE_SIGINFO_T_SI_PKEY && defined SEGV_PKUERR + +# include <stdio.h> +# include <stdlib.h> +# include <unistd.h> +# include <sys/mman.h> + +static void +handler(int sig, siginfo_t *info, void *ucontext) +{ + if (info->si_code != SEGV_PKUERR) + error_msg_and_skip("SIGSEGV: si_code = %d", info->si_code); + + printf("--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_PKUERR" + ", si_addr=%p, si_pkey=%u} ---\n", + info->si_addr, info->si_pkey); + exit(0); +} + +int +main(void) { + int *p = mmap(NULL, get_page_size(), PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) + perror_msg_and_fail("mmap"); + + const struct sigaction act = { + .sa_sigaction = handler, + .sa_flags = SA_SIGINFO | SA_RESETHAND + }; + if (sigaction(SIGSEGV, &act, NULL)) + perror_msg_and_fail("sigaction"); + + __asm__ volatile("":: "r" (*p)); + + error_msg_and_skip("PROT_EXEC page is readable"); +} + +#else + +SKIP_MAIN_UNDEFINED("HAVE_SIGINFO_T_SI_PKEY && SEGV_PKUERR") + +#endif |