From: Dmitry V. Levin Date: Thu, 9 Feb 2017 22:26:14 +0000 (+0000) Subject: tests: check signal injection along with fault injection X-Git-Tag: v4.16~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98313939b3d08f1ede8459630a1f5de934c29a36;p=strace tests: check signal injection along with fault injection * tests/qual_inject-error-signal.c: New file. * tests/qual_inject-error-signal.expected: Likewise. * tests/qual_inject-error-signal.test: New test. * tests/.gitignore: Add qual_inject-error-signal. * tests/Makefile.am (check_PROGRAMS): Likewise. (MISC_TESTS): Add qual_inject-error-signal.test. (EXTRA_DIST): Add qual_inject-error-signal.expected. --- diff --git a/tests/.gitignore b/tests/.gitignore index 88097a4f..1765ac70 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -239,6 +239,7 @@ pselect6 ptrace pwritev qual_fault +qual_inject-error-signal qual_inject-retval qual_inject-signal qual_signal diff --git a/tests/Makefile.am b/tests/Makefile.am index 56cc1699..11eec013 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -298,6 +298,7 @@ check_PROGRAMS = \ ptrace \ pwritev \ qual_fault \ + qual_inject-error-signal \ qual_inject-retval \ qual_inject-signal \ qual_signal \ @@ -846,6 +847,7 @@ MISC_TESTS = \ pc.test \ qual_fault-syntax.test \ qual_fault.test \ + qual_inject-error-signal.test \ qual_inject-retval.test \ qual_inject-signal.test \ qual_inject-syntax.test \ @@ -906,6 +908,7 @@ EXTRA_DIST = init.sh run.sh match.awk \ ppoll.expected \ process_vm_readv_writev.c \ qual_fault-exit_group.expected \ + qual_inject-error-signal.expected \ qual_inject-signal.expected \ quotactl.h \ scno_tampering.sh \ diff --git a/tests/qual_inject-error-signal.c b/tests/qual_inject-error-signal.c new file mode 100644 index 00000000..f4ccd824 --- /dev/null +++ b/tests/qual_inject-error-signal.c @@ -0,0 +1,69 @@ +/* + * Check fault injection along with signal injection. + * + * 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 +#include + +static struct stat before, after; + +static void +handler(int sig) +{ + if (stat(".", &after)) + syscall(__NR_exit_group, 2); + + if (before.st_dev != after.st_dev || before.st_ino != after.st_ino) + syscall(__NR_exit_group, 3); + + syscall(__NR_exit_group, 0); +} + +int +main(void) +{ + const struct sigaction act = { .sa_handler = handler }; + if (sigaction(SIGUSR1, &act, NULL)) + perror_msg_and_fail("sigaction"); + + sigset_t mask; + sigemptyset(&mask); + sigaddset(&mask, SIGUSR1); + if (sigprocmask(SIG_UNBLOCK, &mask, NULL)) + perror_msg_and_fail("sigprocmask"); + + if (stat(".", &before)) + perror_msg_and_fail("stat"); + + syscall(__NR_chdir, "."); + syscall(__NR_exit_group, 1); + return 1; +} diff --git a/tests/qual_inject-error-signal.expected b/tests/qual_inject-error-signal.expected new file mode 100644 index 00000000..24389b37 --- /dev/null +++ b/tests/qual_inject-error-signal.expected @@ -0,0 +1,4 @@ +chdir(".") = -1 ENOENT (No such file or directory) (INJECTED) +--- SIGUSR1 {si_signo=SIGUSR1, si_code=SI_KERNEL} --- +exit_group(0) = ? ++++ exited with 0 +++ diff --git a/tests/qual_inject-error-signal.test b/tests/qual_inject-error-signal.test new file mode 100755 index 00000000..fcbcc398 --- /dev/null +++ b/tests/qual_inject-error-signal.test @@ -0,0 +1,8 @@ +#!/bin/sh + +# Check fault injection along with signal injection. +. "${srcdir=.}/scno_tampering.sh" + +run_strace -a12 -echdir,exit_group -einject=chdir:error=ENOENT:signal=USR1 \ + "./$NAME" +match_diff