From: Vitaly Vi Shukela <[email protected]>

Like 03-sim-basic_chains, but with seccomp_rule_add_array instead of
seccomp_rule_add.

Signed-off-by: Vitaly Vi Shukela <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
---
 tests/.gitignore                      |    1 
 tests/22-sim-basic_chains_array.c     |   77 +++++++++++++++++++++++++++++++++
 tests/22-sim-basic_chains_array.py    |   48 +++++++++++++++++++++
 tests/22-sim-basic_chains_array.tests |   26 +++++++++++
 tests/Makefile                        |    3 +
 5 files changed, 154 insertions(+), 1 deletion(-)
 create mode 100644 tests/22-sim-basic_chains_array.c
 create mode 100755 tests/22-sim-basic_chains_array.py
 create mode 100644 tests/22-sim-basic_chains_array.tests

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 <[email protected]>, Vitaly Shukela <[email protected]>
+ */
+
+/*
+ * 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 <[email protected]>
+# Author: Paul Moore <[email protected]>
+#
+
+#
+# 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 <[email protected]>
+#
+
+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)


------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
libseccomp-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libseccomp-discuss

Reply via email to