From c458ea4d777f60e66b7fe094f665b89f5c8bf11a Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 4 Nov 2017 23:43:55 +0000 Subject: [PATCH] tests: check signal mask transparency Starting with commit v4.17-5-gf83b49b strace is expected to forward the signal mask to tracees unchanged. * tests/check_sigblock.c: New file. * tests/set_sigblock.c: Likewise. * tests/sigblock.test: New test. * tests/.gitignore: Add check_sigblock and set_sigblock. * tests/Makefile.am (check_PROGRAMS): Likewise. (MISC_TESTS): Add sigblock.test. --- tests/.gitignore | 2 ++ tests/Makefile.am | 3 +++ tests/check_sigblock.c | 49 ++++++++++++++++++++++++++++++++++++++ tests/check_sigign.c | 2 +- tests/set_sigblock.c | 53 ++++++++++++++++++++++++++++++++++++++++++ tests/sigblock.test | 22 ++++++++++++++++++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 tests/check_sigblock.c create mode 100644 tests/set_sigblock.c create mode 100755 tests/sigblock.test diff --git a/tests/.gitignore b/tests/.gitignore index 976dd753..dc929302 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -24,6 +24,7 @@ brk btrfs caps caps-abbrev +check_sigblock check_sigign chmod chown @@ -368,6 +369,7 @@ sendfile sendfile64 set_mempolicy set_ptracer_any +set_sigblock set_sigign setdomainname setfsgid diff --git a/tests/Makefile.am b/tests/Makefile.am index cd74c828..f2109fd4 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_sigblock \ check_sigign \ clone_parent \ clone_ptrace \ @@ -137,6 +138,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ seccomp-filter-v \ seccomp-strict \ set_ptracer_any \ + set_sigblock \ set_sigign \ signal_receive \ sleep \ @@ -281,6 +283,7 @@ MISC_TESTS = \ redirect-fds.test \ redirect.test \ restart_syscall.test \ + sigblock.test \ sigign.test \ strace-C.test \ strace-E.test \ diff --git a/tests/check_sigblock.c b/tests/check_sigblock.c new file mode 100644 index 00000000..5637804d --- /dev/null +++ b/tests/check_sigblock.c @@ -0,0 +1,49 @@ +/* + * Check that the specified signal number is blocked/unblocked. + * + * 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_sigblock 0|1 signum"); + + const int block = !!atoi(av[1]); + const int signum = atoi(av[2]); + sigset_t mask; + + sigemptyset(&mask); + if (sigprocmask(SIG_SETMASK, NULL, &mask)) + perror_msg_and_fail("sigprocmask"); + + return block ^ sigismember(&mask, signum); +} diff --git a/tests/check_sigign.c b/tests/check_sigign.c index 6dbe0abf..bace3170 100644 --- a/tests/check_sigign.c +++ b/tests/check_sigign.c @@ -1,5 +1,5 @@ /* - * Check that the signal handler for the given signan number is set + * Check that the signal handler for the specified signal number is set * to SIG_IGN/SIG_DFL. * * Copyright (c) 2017 Dmitry V. Levin diff --git a/tests/set_sigblock.c b/tests/set_sigblock.c new file mode 100644 index 00000000..4786322c --- /dev/null +++ b/tests/set_sigblock.c @@ -0,0 +1,53 @@ +/* + * Execute a command with the specified signal blocked/unblocked. + * + * 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_sigblock 0|1 signum path..."); + + const int block = atoi(av[1]); + const int signum = atoi(av[2]); + sigset_t mask; + + sigemptyset(&mask); + if (sigaddset(&mask, signum)) + perror_msg_and_fail("sigaddset: %s", av[2]); + if (sigprocmask(block ? SIG_BLOCK : SIG_UNBLOCK, &mask, NULL)) + perror_msg_and_fail("sigprocmask"); + + execvp(av[3], av + 3); + perror_msg_and_fail("execvp: %s", av[3]); +} diff --git a/tests/sigblock.test b/tests/sigblock.test new file mode 100755 index 00000000..ddbe2dea --- /dev/null +++ b/tests/sigblock.test @@ -0,0 +1,22 @@ +#!/bin/sh + +# Check signal mask transparency. +# Starting with commit v4.17-5-gf83b49b strace is expected +# to forward the signal mask to tracees unchanged. + +. "${srcdir=.}/init.sh" + +run_prog ../list_sigaction_signum > /dev/null +saved_STRACE="$STRACE" + +for sig in $(../list_sigaction_signum); do + for block in 0 1; do + set_cmd="../set_sigblock $block $sig" + check_cmd="../check_sigblock $block $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 -- 2.40.0