summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Vi Shukela <vi0oss@gmail.com>2013-03-26 17:22:08 -0400
committerPaul Moore <pmoore@redhat.com>2013-03-26 17:22:08 -0400
commite086d439fe8a5cc428de1144d3ee13ea71da5121 (patch)
tree2128c1cd7c73e794e09874bc618b585c83a4fd2c
parentff207702dce7a3191e1509870f887bdd1f84b118 (diff)
downloadlibseccomp-e086d439fe8a5cc428de1144d3ee13ea71da5121.tar.gz
tests: add 22-sim-basic_chains_array
Like 03-sim-basic_chains, but with seccomp_rule_add_array instead of seccomp_rule_add. Signed-off-by: Vitaly Vi Shukela <vi0oss@gmail.com> Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/22-sim-basic_chains_array.c77
-rwxr-xr-xtests/22-sim-basic_chains_array.py48
-rw-r--r--tests/22-sim-basic_chains_array.tests26
-rw-r--r--tests/Makefile3
5 files changed, 154 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 8bbb158..3b68512 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -22,3 +22,4 @@ util.pyc
19-sim-missing_syscalls
20-live-basic_die
21-live-basic_allow
+22-sim-basic_chains_array
diff --git a/tests/22-sim-basic_chains_array.c b/tests/22-sim-basic_chains_array.c
new file mode 100644
index 0000000..7eba836
--- /dev/null
+++ b/tests/22-sim-basic_chains_array.c
@@ -0,0 +1,77 @@
+/**
+ * Seccomp Library test program
+ *
+ * Author: Paul Moore <pmoore@redhat.com>, Vitaly Shukela <vi0oss@gmail.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 <unistd.h>
+
+#include <seccomp.h>
+
+#include "util.h"
+
+int main(int argc, char *argv[])
+{
+ int rc;
+ struct util_options opts;
+ scmp_filter_ctx ctx;
+ struct scmp_arg_cmp arg_cmp;
+
+ rc = util_getopt(argc, argv, &opts);
+ if (rc < 0)
+ goto out;
+
+ ctx = seccomp_init(SCMP_ACT_KILL);
+ if (ctx == NULL)
+ goto out;
+
+ arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO);
+ rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
+ SCMP_SYS(read), 1, &arg_cmp);
+ if (rc != 0)
+ goto out;
+
+ arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDOUT_FILENO);
+ rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
+ SCMP_SYS(write), 1, &arg_cmp);
+ if (rc != 0)
+ goto out;
+
+ arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDERR_FILENO);
+ rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
+ SCMP_SYS(write), 1, &arg_cmp);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
+ SCMP_SYS(close), 0, NULL);
+ if (rc != 0)
+ goto out;
+
+ rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
+ SCMP_SYS(rt_sigreturn), 0, NULL);
+ 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/22-sim-basic_chains_array.py b/tests/22-sim-basic_chains_array.py
new file mode 100755
index 0000000..dfc3a58
--- /dev/null
+++ b/tests/22-sim-basic_chains_array.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+#
+# Seccomp Library test program
+#
+# Copyright (c) 2013 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>.
+#
+
+# NOTE: this is identical to 03-sim-basic_chains.py but is here to satisfy the
+# need for an equivalent Python test for each native C test
+
+import argparse
+import sys
+
+import util
+
+from seccomp import *
+
+def test(args):
+ f = SyscallFilter(KILL)
+ f.add_rule_exactly(ALLOW, "read", Arg(0, EQ, sys.stdin.fileno()));
+ f.add_rule_exactly(ALLOW, "write", Arg(0, EQ, sys.stdout.fileno()));
+ f.add_rule_exactly(ALLOW, "write", Arg(0, EQ, sys.stderr.fileno()));
+ f.add_rule_exactly(ALLOW, "close");
+ f.add_rule_exactly(ALLOW, "rt_sigreturn");
+ 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/22-sim-basic_chains_array.tests b/tests/22-sim-basic_chains_array.tests
new file mode 100644
index 0000000..6785152
--- /dev/null
+++ b/tests/22-sim-basic_chains_array.tests
@@ -0,0 +1,26 @@
+#
+# libseccomp regression test automation data
+#
+# Author: Vitaly Shukela <vi0oss@gmail.com>
+#
+
+test type: bpf-sim
+
+# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result
+22-sim-basic_chains_array all read 0 0x856B008 10 N N N ALLOW
+22-sim-basic_chains_array all read 1-10 0x856B008 10 N N N KILL
+22-sim-basic_chains_array all write 1-2 0x856B008 10 N N N ALLOW
+22-sim-basic_chains_array all write 3-10 0x856B008 10 N N N KILL
+22-sim-basic_chains_array all close N N N N N N ALLOW
+22-sim-basic_chains_array all rt_sigreturn N N N N N N ALLOW
+22-sim-basic_chains_array all open 0x856B008 4 N N N N KILL
+22-sim-basic_chains_array x86 0-2 N N N N N N KILL
+22-sim-basic_chains_array x86 7-172 N N N N N N KILL
+22-sim-basic_chains_array x86 174-350 N N N N N N KILL
+22-sim-basic_chains_array x86_64 4-14 N N N N N N KILL
+22-sim-basic_chains_array x86_64 16-350 N N N N N N KILL
+
+test type: bpf-sim-fuzz
+
+# Testname StressCount
+22-sim-basic_chains_array 50
diff --git a/tests/Makefile b/tests/Makefile
index 5d0a16f..57b7b5f 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -56,7 +56,8 @@ TESTS = 01-sim-allow \
18-sim-basic_whitelist \
19-sim-missing_syscalls \
20-live-basic_die \
- 21-live-basic_allow
+ 21-live-basic_allow \
+ 22-sim-basic_chains_array
DEPS_OBJS = $(OBJS:%.o=%.d)
DEPS_TESTS = $(TESTS:%=%.d)