diff options
author | Paul Moore <pmoore@redhat.com> | 2013-02-19 17:32:57 -0500 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2013-03-28 11:33:14 -0400 |
commit | 5d059846f6e7352cf06b74bf2642d86d45970897 (patch) | |
tree | 6947f1068877273705344be5875ca10b009fb5cc | |
parent | cecb030e75f3c996fda0e2753c998e50b92bb09a (diff) | |
download | libseccomp-5d059846f6e7352cf06b74bf2642d86d45970897.tar.gz |
tests: add a live test to exercise the syscall argument matching
Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/24-live-arg_allow.c | 93 | ||||
-rwxr-xr-x | tests/24-live-arg_allow.py | 60 | ||||
-rw-r--r-- | tests/24-live-arg_allow.tests | 11 | ||||
-rw-r--r-- | tests/Makefile | 3 |
5 files changed, 167 insertions, 1 deletions
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 <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 <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 <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 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 <pmoore@redhat.com> +# Author: Paul Moore <pmoore@redhat.com +# + +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) |