]> git.proxmox.com Git - mirror_libseccomp.git/commitdiff
all: add tests to ensure that syscall -1 is handled correctly
authorPaul Moore <paul@paul-moore.com>
Wed, 15 Feb 2017 22:56:21 +0000 (17:56 -0500)
committerPaul Moore <paul@paul-moore.com>
Thu, 23 Feb 2017 17:17:32 +0000 (12:17 -0500)
Signed-off-by: Paul Moore <paul@paul-moore.com>
tests/.gitignore
tests/35-sim-negative_one.c [new file with mode: 0644]
tests/35-sim-negative_one.py [new file with mode: 0755]
tests/35-sim-negative_one.tests [new file with mode: 0644]
tests/Makefile.am
tests/miniseq.c
tests/regression

index ba08212d702a1f3e3f453587d46a0cf29e4dd828..49465755aecf72a3d25001a0a080ee1de3ba2ad5 100644 (file)
@@ -39,3 +39,4 @@ util.pyc
 32-live-tsync_allow
 33-sim-socket_syscalls_be
 34-sim-basic_blacklist
+35-sim-negative_one
diff --git a/tests/35-sim-negative_one.c b/tests/35-sim-negative_one.c
new file mode 100644 (file)
index 0000000..7406307
--- /dev/null
@@ -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 (executable)
index 0000000..d94fda5
--- /dev/null
@@ -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 (file)
index 0000000..3735eee
--- /dev/null
@@ -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
index 5ce4c430fb497da89856816842a229213bdb5a59..683f7b67932531f2fd2a6c8975ed282c046d78b0 100644 (file)
@@ -71,7 +71,8 @@ check_PROGRAMS = \
        31-basic-version_check \
        32-live-tsync_allow \
        33-sim-socket_syscalls_be \
-       34-sim-basic_blacklist
+       34-sim-basic_blacklist \
+       35-sim-negative_one
 
 EXTRA_DIST_TESTPYTHON = \
        util.py \
@@ -108,7 +109,8 @@ EXTRA_DIST_TESTPYTHON = \
        31-basic-version_check.py \
        32-live-tsync_allow.py \
        33-sim-socket_syscalls_be.py \
-       34-sim-basic_blacklist.py
+       34-sim-basic_blacklist.py \
+       35-sim-negative_one.py
 
 EXTRA_DIST_TESTCFGS = \
        01-sim-allow.tests \
@@ -144,7 +146,8 @@ EXTRA_DIST_TESTCFGS = \
        31-basic-version_check.tests \
        32-live-tsync_allow.tests \
        33-sim-socket_syscalls_be.tests \
-       34-sim-basic_blacklist.tests
+       34-sim-basic_blacklist.tests \
+       35-sim-negative_one.tests
 
 EXTRA_DIST_TESTSCRIPTS = regression testdiff testgen
 
index 7addc708620e3830114660e129a0d6120479e2c9..120fdb2353d9d95deb478487be9f7980a610b70d 100644 (file)
@@ -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;
 }
index 48bd3d06801b09bacd6d2b40b08f547209742b8b..683a36de15d2b54cf611fa876bc1e5e091806ff2 100755 (executable)
@@ -476,7 +476,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
@@ -487,7 +487,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