summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Moore <paul@paul-moore.com>2016-02-09 07:21:33 -0500
committerPaul Moore <paul@paul-moore.com>2016-02-09 08:32:30 -0500
commitd76fc6a7aef6855d0a93a303f6c19726390f70b7 (patch)
tree05a3afa0874588a32b398c0bbafb934e8ef15394
parent19ef09ba70aea96863cbeee4fbe5e5253ae07424 (diff)
downloadlibseccomp-working-pcmoore.tar.gz
tests: add a test for the different types of socket syscallsworking-pcmoore
We need to test that we are generating filters that can handle both the legacy multiplexed socket syscalls as well as the new direct wired socket syscalls. Signed-off-by: Paul Moore <paul@paul-moore.com>
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/30-sim-socket_syscalls.c84
-rwxr-xr-xtests/30-sim-socket_syscalls.py49
-rw-r--r--tests/30-sim-socket_syscalls.tests30
-rw-r--r--tests/Makefile.am9
5 files changed, 170 insertions, 3 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index e0297ea..fe51c14 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -34,3 +34,4 @@ util.pyc
27-sim-bpf_blk_state
28-sim-arch_x86
29-sim-pseudo_syscall
+30-sim-socket_syscalls
diff --git a/tests/30-sim-socket_syscalls.c b/tests/30-sim-socket_syscalls.c
new file mode 100644
index 0000000..09977a3
--- /dev/null
+++ b/tests/30-sim-socket_syscalls.c
@@ -0,0 +1,84 @@
+/**
+ * Seccomp Library test program
+ *
+ * Copyright (c) 2016 Red Hat <pmoore@redhat.com>
+ * Author: Paul Moore <pmoore@redhat.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>.
+ */
+
+#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_arch_add(ctx, SCMP_ARCH_X32);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket), 0);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(connect), 0);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(accept), 0);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(accept4), 0);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shutdown), 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/30-sim-socket_syscalls.py b/tests/30-sim-socket_syscalls.py
new file mode 100755
index 0000000..d04f288
--- /dev/null
+++ b/tests/30-sim-socket_syscalls.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+#
+# Seccomp Library test program
+#
+# Copyright (c) 2016 Red Hat <pmoore@redhat.com>
+# Author: Paul Moore <pmoore@redhat.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.add_arch(Arch("x32"))
+ f.add_rule(ALLOW, "socket")
+ f.add_rule(ALLOW, "connect")
+ f.add_rule(ALLOW, "accept")
+ f.add_rule(ALLOW, "accept4")
+ f.add_rule(ALLOW, "shutdown")
+ 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/30-sim-socket_syscalls.tests b/tests/30-sim-socket_syscalls.tests
new file mode 100644
index 0000000..e55e353
--- /dev/null
+++ b/tests/30-sim-socket_syscalls.tests
@@ -0,0 +1,30 @@
+#
+# libseccomp regression test automation data
+#
+# Copyright (c) 2016 Red Hat <pmoore@redhat.com>
+# Author: Paul Moore <pmoore@redhat.com>
+#
+
+test type: bpf-sim
+
+# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result
+30-sim-socket_syscalls +x86 socketcall 1 N N N N N ALLOW
+30-sim-socket_syscalls +x86 socketcall 3 N N N N N ALLOW
+30-sim-socket_syscalls +x86 socketcall 5 N N N N N ALLOW
+30-sim-socket_syscalls +x86 socketcall 13 N N N N N ALLOW
+30-sim-socket_syscalls +x86 359 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86 362 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86 364 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86 373 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86 accept 5 N N N N N ALLOW
+30-sim-socket_syscalls +x86 accept 0 1 2 N N N KILL
+30-sim-socket_syscalls +x86 accept4 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86_64 socket 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86_64 connect 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86_64 accept4 0 1 2 N N N ALLOW
+30-sim-socket_syscalls +x86_64 shutdown 0 1 2 N N N ALLOW
+
+test type: bpf-valgrind
+
+# Testname
+30-sim-socket_syscalls
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 71e18ec..db06031 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,7 +57,8 @@ check_PROGRAMS = \
26-sim-arch_all_be_basic \
27-sim-bpf_blk_state \
28-sim-arch_x86 \
- 29-sim-pseudo_syscall
+ 29-sim-pseudo_syscall \
+ 30-sim-socket_syscalls
EXTRA_DIST_TESTPYTHON = \
util.py \
@@ -89,7 +90,8 @@ EXTRA_DIST_TESTPYTHON = \
26-sim-arch_all_be_basic.py \
27-sim-bpf_blk_state.py \
28-sim-arch_x86.py \
- 29-sim-pseudo_syscall.py
+ 29-sim-pseudo_syscall.py \
+ 30-sim-socket_syscalls.py
EXTRA_DIST_TESTCFGS = \
01-sim-allow.tests \
@@ -120,7 +122,8 @@ EXTRA_DIST_TESTCFGS = \
26-sim-arch_all_be_basic.tests \
27-sim-bpf_blk_state.tests \
28-sim-arch_x86.tests \
- 29-sim-pseudo_syscall.tests
+ 29-sim-pseudo_syscall.tests \
+ 30-sim-socket_syscalls.tests
EXTRA_DIST_TESTSCRIPTS = regression testdiff testgen