Signed-off-by: Paul Moore <[email protected]>
---
 tests/.gitignore              |    1 
 tests/24-live-arg_allow.c     |   93 +++++++++++++++++++++++++++++++++++++++++
 tests/24-live-arg_allow.py    |   60 ++++++++++++++++++++++++++
 tests/24-live-arg_allow.tests |   11 +++++
 tests/Makefile                |    3 +
 5 files changed, 167 insertions(+), 1 deletion(-)
 create mode 100644 tests/24-live-arg_allow.c
 create mode 100755 tests/24-live-arg_allow.py
 create mode 100644 tests/24-live-arg_allow.tests

diff --git a/tests/.gitignore b/tests/.gitignore
index fd4ac43..8080469 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -24,3 +24,4 @@ util.pyc
 21-live-basic_allow
 22-sim-basic_chains_array
 23-sim-arch_all_basic
+24-live-arg_allow
diff --git a/tests/24-live-arg_allow.c b/tests/24-live-arg_allow.c
new file mode 100644
index 0000000..fd6e289
--- /dev/null
+++ b/tests/24-live-arg_allow.c
@@ -0,0 +1,93 @@
+/**
+ * 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>.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <seccomp.h>
+
+#include "util.h"
+
+int main(int argc, char *argv[])
+{
+       int rc;
+       int fd;
+       scmp_filter_ctx ctx;
+       const char buf[] = "testing";
+       ssize_t buf_len = strlen(buf);
+
+       rc = util_action_parse(argv[1]);
+       if (rc != SCMP_ACT_ALLOW) {
+               rc = 1;
+               goto out;
+       }
+
+       rc = util_trap_install();
+       if (rc != 0)
+               goto out;
+
+       fd = open("/dev/null", O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
+       if (fd < 0) {
+               rc = errno;
+               goto out;
+       }
+
+       ctx = seccomp_init(SCMP_ACT_TRAP);
+       if (ctx == NULL)
+               goto out;
+       rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1,
+                                   SCMP_A0(SCMP_CMP_EQ, fd));
+       if (rc != 0)
+               goto out;
+       rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0);
+       if (rc != 0)
+               goto out;
+       rc = seccomp_rule_add_exact(ctx,
+                                   SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0);
+       if (rc != 0)
+               goto out;
+       rc = seccomp_rule_add_exact(ctx,
+                                   SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
+       if (rc != 0)
+               goto out;
+       rc = seccomp_load(ctx);
+       if (rc != 0)
+               goto out;
+
+       if (write(fd, buf, buf_len) < buf_len) {
+               rc = errno;
+               goto out;
+       }
+       if (close(fd) < 0) {
+               rc = errno;
+               goto out;
+       }
+
+       rc = 160;
+
+out:
+       seccomp_release(ctx);
+       return (rc < 0 ? -rc : rc);
+}
diff --git a/tests/24-live-arg_allow.py b/tests/24-live-arg_allow.py
new file mode 100755
index 0000000..32c63ec
--- /dev/null
+++ b/tests/24-live-arg_allow.py
@@ -0,0 +1,60 @@
+#!/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>.
+#
+
+import argparse
+import os
+import sys
+
+import util
+
+from seccomp import *
+
+def test():
+    action = util.parse_action(sys.argv[1])
+    if not action == ALLOW:
+        quit(1)
+    util.install_trap()
+
+    fd = os.open("/dev/null", os.O_WRONLY|os.O_CREAT, 0600)
+
+    f = SyscallFilter(TRAP)
+    # NOTE: additional syscalls required for python
+    f.add_rule_exactly(ALLOW, "write", Arg(0, EQ, fd))
+    f.add_rule_exactly(ALLOW, "close")
+    f.add_rule_exactly(ALLOW, "rt_sigaction")
+    f.add_rule_exactly(ALLOW, "rt_sigreturn")
+    f.add_rule_exactly(ALLOW, "exit_group")
+    f.load()
+
+    try:
+        if not os.write(fd, "testing") == len("testing"):
+            raise IOError("failed to write the full test string")
+        quit(160)
+    except OSError as ex:
+        quit(ex.errno)
+    os.close(fd)
+
+test()
+
+# kate: syntax python;
+# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;
diff --git a/tests/24-live-arg_allow.tests b/tests/24-live-arg_allow.tests
new file mode 100644
index 0000000..e383e6a
--- /dev/null
+++ b/tests/24-live-arg_allow.tests
@@ -0,0 +1,11 @@
+#
+# libseccomp regression test automation data
+#
+# Copyright (c) 2013 Red Hat <[email protected]>
+# Author: Paul Moore <[email protected]
+#
+
+test type: live
+
+# Testname             Result
+24-live-arg_allow      ALLOW
diff --git a/tests/Makefile b/tests/Makefile
index 818caeb..048e332 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -58,7 +58,8 @@ TESTS = 01-sim-allow \
        20-live-basic_die \
        21-live-basic_allow \
        22-sim-basic_chains_array \
-       23-sim-arch_all_basic
+       23-sim-arch_all_basic \
+       24-live-arg_allow
 
 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