summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Moore <paul@paul-moore.com>2017-02-23 12:25:17 -0500
committerPaul Moore <paul@paul-moore.com>2017-02-23 12:25:17 -0500
commit882e772fe8a8eaab1c562b7557e8828e5f5f0b4e (patch)
treea6b2461cf4766dd82d59cf0a9d1f481e6a18b9f9
parent10dd41eac56d08a27afe355e51675050feb13e18 (diff)
downloadlibseccomp-882e772fe8a8eaab1c562b7557e8828e5f5f0b4e.tar.gz
all: add tests to ensure that syscall -1 is handled correctly
Signed-off-by: Paul Moore <paul@paul-moore.com> (imported from commit 11e21098e0c3b5481fb0f6e6bdbb266bdd0fc24c)
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/35-sim-negative_one.c78
-rwxr-xr-xtests/35-sim-negative_one.py46
-rw-r--r--tests/35-sim-negative_one.tests23
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/miniseq.c5
-rwxr-xr-xtests/regression4
7 files changed, 159 insertions, 7 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index b282fa4..cb5d69e 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -38,3 +38,4 @@ util.pyc
31-basic-version_check
32-live-tsync_allow
33-sim-socket_syscalls_be
+35-sim-negative_one
diff --git a/tests/35-sim-negative_one.c b/tests/35-sim-negative_one.c
new file mode 100644
index 0000000..7406307
--- /dev/null
+++ b/tests/35-sim-negative_one.c
@@ -0,0 +1,78 @@
+/**
+ * Seccomp Library test program
+ *
+ * Copyright (c) 2017 Red Hat <pmoore@redhat.com>
+ * Author: Paul Moore <paul@paul-moore.com>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+
+/*
+ * Just like mode 1 seccomp we allow 4 syscalls:
+ * read, write, exit, and rt_sigreturn
+ */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <seccomp.h>
+
+#include "util.h"
+
+int main(int argc, char *argv[])
+{
+ int rc;
+ struct util_options opts;
+ scmp_filter_ctx ctx = NULL;
+
+ rc = util_getopt(argc, argv, &opts);
+ if (rc < 0)
+ goto out;
+
+ ctx = seccomp_init(SCMP_ACT_KILL);
+ if (ctx == NULL)
+ return ENOMEM;
+
+ rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_arch_add(ctx, SCMP_ARCH_X86);
+ if (rc != 0)
+ goto out;
+ rc = seccomp_arch_add(ctx, SCMP_ARCH_X86_64);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_attr_set(ctx, SCMP_FLTATR_API_TSKIP, 1);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_syscall_priority(ctx, -1, 100);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, -1, 0);
+ if (rc != 0)
+ goto out;
+
+ rc = util_filter_output(&opts, ctx);
+ if (rc)
+ goto out;
+
+out:
+ seccomp_release(ctx);
+ return (rc < 0 ? -rc : rc);
+}
diff --git a/tests/35-sim-negative_one.py b/tests/35-sim-negative_one.py
new file mode 100755
index 0000000..d94fda5
--- /dev/null
+++ b/tests/35-sim-negative_one.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+#
+# Seccomp Library test program
+#
+# Copyright (c) 2017 Red Hat <pmoore@redhat.com>
+# Author: Paul Moore <paul@paul-moore.com>
+#
+
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of version 2.1 of the GNU Lesser General Public License as
+# published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, see <http://www.gnu.org/licenses>.
+#
+
+import argparse
+import sys
+
+import util
+
+from seccomp import *
+
+def test(args):
+ f = SyscallFilter(KILL)
+ f.remove_arch(Arch())
+ f.add_arch(Arch("x86"))
+ f.add_arch(Arch("x86_64"))
+ f.set_attr(Attr.API_TSKIP, 1)
+ f.syscall_priority(-1, 100)
+ f.add_rule(ALLOW, -1)
+ return f
+
+args = util.get_opt()
+ctx = test(args)
+util.filter_output(args, ctx)
+
+# kate: syntax python;
+# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;
diff --git a/tests/35-sim-negative_one.tests b/tests/35-sim-negative_one.tests
new file mode 100644
index 0000000..3735eee
--- /dev/null
+++ b/tests/35-sim-negative_one.tests
@@ -0,0 +1,23 @@
+#
+# libseccomp regression test automation data
+#
+# Copyright (c) 2017 Red Hat <pmoore@redhat.com>
+# Author: Paul Moore <paul@paul-moore.com>
+#
+
+test type: bpf-sim
+
+# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result
+35-sim-negative_one +x86 -1 N N N N N N ALLOW
+35-sim-negative_one +x86_64 -1 N N N N N N ALLOW
+35-sim-negative_one +x32 -1 N N N N N N ALLOW
+
+test type: bpf-sim-fuzz
+
+# Testname StressCount
+35-sim-negative_one 50
+
+test type: bpf-valgrind
+
+# Testname
+35-sim-negative_one
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f81388b..9bc3308 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -70,7 +70,8 @@ check_PROGRAMS = \
30-sim-socket_syscalls \
31-basic-version_check \
32-live-tsync_allow \
- 33-sim-socket_syscalls_be
+ 33-sim-socket_syscalls_be \
+ 35-sim-negative_one
EXTRA_DIST_TESTPYTHON = \
util.py \
@@ -106,7 +107,8 @@ EXTRA_DIST_TESTPYTHON = \
30-sim-socket_syscalls.py \
31-basic-version_check.py \
32-live-tsync_allow.py \
- 33-sim-socket_syscalls_be.py
+ 33-sim-socket_syscalls_be.py \
+ 35-sim-negative_one.py
EXTRA_DIST_TESTCFGS = \
01-sim-allow.tests \
@@ -141,7 +143,8 @@ EXTRA_DIST_TESTCFGS = \
30-sim-socket_syscalls.tests \
31-basic-version_check.tests \
32-live-tsync_allow.tests \
- 33-sim-socket_syscalls_be.tests
+ 33-sim-socket_syscalls_be.tests \
+ 35-sim-negative_one.tests
EXTRA_DIST_TESTSCRIPTS = regression testdiff testgen
diff --git a/tests/miniseq.c b/tests/miniseq.c
index 7addc70..120fdb2 100644
--- a/tests/miniseq.c
+++ b/tests/miniseq.c
@@ -50,8 +50,9 @@ int main(int argc, char *argv[])
if (get_number(argv[1], &first) || get_number(argv[2], &last))
return 1;
- for (cur = first; cur <= last; cur++)
- printf("%" PRIu64 "\n", cur);
+ for (cur = first; cur != last; cur++)
+ printf("%" PRId64 "\n", cur);
+ printf("%" PRId64 "\n", cur);
return 0;
}
diff --git a/tests/regression b/tests/regression
index 94aec19..10890cc 100755
--- a/tests/regression
+++ b/tests/regression
@@ -475,7 +475,7 @@ function run_test_bpf_sim() {
# get low and high syscall values and convert them to numbers
low_syscall=$(get_range $LOW "${line[2]}")
- if [[ ! $low_syscall =~ ^[0-9]+$ ]]; then
+ if [[ ! $low_syscall =~ ^\-?[0-9]+$ ]]; then
low_syscall=$($GLBL_SYS_RESOLVER -a $simarch -t \
$low_syscall)
if [[ $? -ne 0 ]]; then
@@ -486,7 +486,7 @@ function run_test_bpf_sim() {
fi
fi
high_syscall=$(get_range $HIGH "${line[2]}")
- if [[ ! $high_syscall =~ ^[0-9]+$ ]]; then
+ if [[ ! $high_syscall =~ ^\-?[0-9]+$ ]]; then
high_syscall=$($GLBL_SYS_RESOLVER -a $simarch -t \
$high_syscall)
if [[ $? -ne 0 ]]; then