From: Dmitry V. Levin Date: Fri, 3 Nov 2017 23:10:38 +0000 (+0000) Subject: tests: check signal disposition transparency X-Git-Tag: v4.20~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff1bc06589dba2fd035cbffa956f4f5473f7c08a;p=strace tests: check signal disposition transparency Starting with commit v4.17-8-ge97a66f strace is expected to forward the signal disposition to tracees unchanged. * tests/check_sigign.c: New file. * tests/list_sigaction_signum.c: Likewise. * tests/set_sigign.c: Likewise. * tests/sigign.test: New test. * tests/.gitignore: Add check_sigign, list_sigaction_signum, and set_sigign. * tests/Makefile.am (check_PROGRAMS): Likewise. (MISC_TESTS): Add sigign.test. --- diff --git a/tests/.gitignore b/tests/.gitignore index cd4dcc57..976dd753 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -24,6 +24,7 @@ brk btrfs caps caps-abbrev +check_sigign chmod chown chown32 @@ -162,6 +163,7 @@ lchown32 libtests.a link linkat +list_sigaction_signum llseek lookup_dcookie lseek @@ -366,6 +368,7 @@ sendfile sendfile64 set_mempolicy set_ptracer_any +set_sigign setdomainname setfsgid setfsgid32 diff --git a/tests/Makefile.am b/tests/Makefile.am index b4ba22a6..cd74c828 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -87,6 +87,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ attach-p-cmd-p \ block_reset_raise_run \ caps-abbrev \ + check_sigign \ clone_parent \ clone_ptrace \ count-f \ @@ -106,6 +107,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ ioctl_rtc-v \ is_linux_mips_n64 \ ksysent \ + list_sigaction_signum \ mmsg-silent \ mmsg_name-v \ msg_control-v \ @@ -135,6 +137,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ seccomp-filter-v \ seccomp-strict \ set_ptracer_any \ + set_sigign \ signal_receive \ sleep \ stack-fcall \ @@ -278,6 +281,7 @@ MISC_TESTS = \ redirect-fds.test \ redirect.test \ restart_syscall.test \ + sigign.test \ strace-C.test \ strace-E.test \ strace-S.test \ diff --git a/tests/check_sigign.c b/tests/check_sigign.c new file mode 100644 index 00000000..6dbe0abf --- /dev/null +++ b/tests/check_sigign.c @@ -0,0 +1,49 @@ +/* + * Check that the signal handler for the given signan number is set + * to SIG_IGN/SIG_DFL. + * + * Copyright (c) 2017 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" +#include +#include + +int +main(int ac, char **av) +{ + if (ac != 3) + error_msg_and_fail("usage: check_sigign 0|1 signum"); + + const int ign = !!atoi(av[1]); + const int signum = atoi(av[2]); + struct sigaction act; + + if (sigaction(signum, NULL, &act)) + perror_msg_and_fail("sigaction: %s", av[2]); + + return ign ^ (act.sa_handler == SIG_IGN); +} diff --git a/tests/list_sigaction_signum.c b/tests/list_sigaction_signum.c new file mode 100644 index 00000000..13a78c68 --- /dev/null +++ b/tests/list_sigaction_signum.c @@ -0,0 +1,57 @@ +/* + * List signal numbers that are valid arguments for sigaction syscall. + * + * Copyright (c) 2017 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" + +#include +#include + +int +main(void) +{ + unsigned int i; + + for (i = 1; i < 32; ++i) { + static const struct sigaction ign = { .sa_handler = SIG_IGN }; + static const struct sigaction dfl = { .sa_handler = SIG_DFL }; + struct sigaction act; + + if (sigaction(i, &ign, NULL) || + sigaction(i, NULL, &act) || + ign.sa_handler != act.sa_handler || + sigaction(i, &dfl, NULL) || + sigaction(i, NULL, &act) || + dfl.sa_handler != act.sa_handler) + continue; + + printf("%u\n", i); + } + + return 0; +} diff --git a/tests/set_sigign.c b/tests/set_sigign.c new file mode 100644 index 00000000..0319fed3 --- /dev/null +++ b/tests/set_sigign.c @@ -0,0 +1,49 @@ +/* + * Execute a command with a signal handler set to SIG_IGN/SIG_DFL. + * + * Copyright (c) 2017 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" +#include +#include +#include + +int +main(int ac, char **av) +{ + if (ac < 4) + error_msg_and_fail("usage: set_sigign 0|1 signum path..."); + + const int ign = atoi(av[1]); + const int signum = atoi(av[2]); + + if (signal(signum, ign ? SIG_IGN : SIG_DFL) == SIG_ERR) + perror_msg_and_fail("signal: %s", av[2]); + + execvp(av[3], av + 3); + perror_msg_and_fail("execvp: %s", av[3]); +} diff --git a/tests/sigign.test b/tests/sigign.test new file mode 100755 index 00000000..3164e72e --- /dev/null +++ b/tests/sigign.test @@ -0,0 +1,22 @@ +#!/bin/sh + +# Check signal disposition transparency. +# Starting with commit v4.17-8-ge97a66f strace is expected +# to forward the signal disposition to tracees unchanged. + +. "${srcdir=.}/init.sh" + +run_prog ../list_sigaction_signum > /dev/null +saved_STRACE="$STRACE" + +for sig in $(../list_sigaction_signum); do + for ign in 0 1; do + set_cmd="../set_sigign $ign $sig" + check_cmd="../check_sigign $ign $sig" + run_prog $set_cmd $check_cmd + STRACE="$set_cmd $saved_STRACE" + for i in '' -I1 -I2 -I3 -I4; do + run_strace $i -enone $check_cmd + done + done +done