]> granicus.if.org Git - strace/commitdiff
tests: check signal injection
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 8 Feb 2017 13:51:33 +0000 (13:51 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 8 Feb 2017 13:51:33 +0000 (13:51 +0000)
* tests/qual_inject-signal.c: New file.
* tests/qual_inject-signal.expected: Likewise.
* tests/qual_inject-signal.test: New test.
* tests/.gitignore: Add qual_inject-signal.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add qual_inject-signal.test.
(EXTRA_DIST): Add qual_inject-signal.expected.

tests/.gitignore
tests/Makefile.am
tests/qual_inject-signal.c [new file with mode: 0644]
tests/qual_inject-signal.expected [new file with mode: 0644]
tests/qual_inject-signal.test [new file with mode: 0755]

index 644a0721e3e05642b56c3e0a6e9672ac75617726..88097a4f7aba26faf4c469186624c3b0522bb7fa 100644 (file)
@@ -240,6 +240,7 @@ ptrace
 pwritev
 qual_fault
 qual_inject-retval
+qual_inject-signal
 qual_signal
 quotactl
 quotactl-v
index 6bf2c4d4fd3c0b6957730673566f35c9a9720f96..56cc169926eb036281c74ea5e510a7877a21d2e5 100644 (file)
@@ -299,6 +299,7 @@ check_PROGRAMS = \
        pwritev \
        qual_fault \
        qual_inject-retval \
+       qual_inject-signal \
        qual_signal \
        quotactl \
        quotactl-v \
@@ -846,6 +847,7 @@ MISC_TESTS = \
        qual_fault-syntax.test \
        qual_fault.test \
        qual_inject-retval.test \
+       qual_inject-signal.test \
        qual_inject-syntax.test \
        qual_signal.test \
        qual_syscall.test \
@@ -904,6 +906,7 @@ EXTRA_DIST = init.sh run.sh match.awk \
             ppoll.expected \
             process_vm_readv_writev.c \
             qual_fault-exit_group.expected \
+            qual_inject-signal.expected \
             quotactl.h \
             scno_tampering.sh \
             setfsugid.c \
diff --git a/tests/qual_inject-signal.c b/tests/qual_inject-signal.c
new file mode 100644 (file)
index 0000000..ff56a28
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Check that signal injection works properly.
+ *
+ * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
+ * 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 <signal.h>
+#include <unistd.h>
+#include <asm/unistd.h>
+
+static void
+handler(int sig)
+{
+       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");
+
+       syscall(__NR_chdir, ".");
+       syscall(__NR_exit_group, 1);
+       return 1;
+}
diff --git a/tests/qual_inject-signal.expected b/tests/qual_inject-signal.expected
new file mode 100644 (file)
index 0000000..69a1d97
--- /dev/null
@@ -0,0 +1,4 @@
+chdir(".")  = 0
+--- SIGUSR1 {si_signo=SIGUSR1, si_code=SI_KERNEL} ---
+exit_group(0) = ?
++++ exited with 0 +++
diff --git a/tests/qual_inject-signal.test b/tests/qual_inject-signal.test
new file mode 100755 (executable)
index 0000000..372a08e
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Check signal injection.
+. "${srcdir=.}/init.sh"
+
+run_strace -a12 -echdir,exit_group -einject=chdir:signal=USR1 \
+       ./qual_inject-signal
+match_diff