diff options
author | Paul Moore <pmoore@redhat.com> | 2012-11-08 10:39:12 -0500 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2013-01-16 15:25:06 -0500 |
commit | 37700ac08d01fb8d8d8448f4a46591bbe1020043 (patch) | |
tree | db3ed0b193645830630e5ffe2a9aab379942e9d3 | |
parent | ce7bb153c6253b0a33beb1ddd1a7bf775c27c65d (diff) | |
download | libseccomp-37700ac08d01fb8d8d8448f4a46591bbe1020043.tar.gz |
tests: add a basic whitelist test
Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/18-basic-whitelist.c | 73 | ||||
-rwxr-xr-x | tests/18-basic-whitelist.py | 45 | ||||
-rw-r--r-- | tests/18-basic-whitelist.tests | 27 | ||||
-rw-r--r-- | tests/Makefile | 3 |
5 files changed, 148 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index ee1cf17..879bff5 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -17,3 +17,4 @@ util.pyc 15-resolver 16-arch-basic 17-arch-merge +18-basic-whitelist diff --git a/tests/18-basic-whitelist.c b/tests/18-basic-whitelist.c new file mode 100644 index 0000000..5deefe7 --- /dev/null +++ b/tests/18-basic-whitelist.c @@ -0,0 +1,73 @@ +/** + * 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 <unistd.h> + +#include <seccomp.h> + +#include "util.h" + +int main(int argc, char *argv[]) +{ + int rc; + struct util_options opts; + scmp_filter_ctx ctx; + + rc = util_getopt(argc, argv, &opts); + if (rc < 0) + goto out; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + goto out; + + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 1, + SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO)); + if (rc != 0) + goto out; + + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(write), 1, + SCMP_A0(SCMP_CMP_EQ, STDOUT_FILENO)); + if (rc != 0) + goto out; + + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(write), 1, + SCMP_A0(SCMP_CMP_EQ, STDERR_FILENO)); + if (rc != 0) + goto out; + + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(close), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add_exact(ctx, + SCMP_ACT_KILL, SCMP_SYS(rt_sigreturn), 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/18-basic-whitelist.py b/tests/18-basic-whitelist.py new file mode 100755 index 0000000..a7b9cb7 --- /dev/null +++ b/tests/18-basic-whitelist.py @@ -0,0 +1,45 @@ +#!/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 sys + +import util + +from seccomp import * + +def test(args): + f = SyscallFilter(ALLOW) + f.add_rule_exactly(KILL, "read", Arg(0, EQ, sys.stdin.fileno())); + f.add_rule_exactly(KILL, "write", Arg(0, EQ, sys.stdout.fileno())); + f.add_rule_exactly(KILL, "write", Arg(0, EQ, sys.stderr.fileno())); + f.add_rule_exactly(KILL, "close"); + f.add_rule_exactly(KILL, "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/18-basic-whitelist.tests b/tests/18-basic-whitelist.tests new file mode 100644 index 0000000..31649ec --- /dev/null +++ b/tests/18-basic-whitelist.tests @@ -0,0 +1,27 @@ +# +# libseccomp regression test automation data +# +# Copyright (c) 2013 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 +18-basic-whitelist all read 0 0x856B008 10 N N N KILL +18-basic-whitelist all read 1-10 0x856B008 10 N N N ALLOW +18-basic-whitelist all write 1-2 0x856B008 10 N N N KILL +18-basic-whitelist all write 3-10 0x856B008 10 N N N ALLOW +18-basic-whitelist all close N N N N N N KILL +18-basic-whitelist all rt_sigreturn N N N N N N KILL +18-basic-whitelist all open 0x856B008 4 N N N N ALLOW +18-basic-whitelist x86 0-2 N N N N N N ALLOW +18-basic-whitelist x86 7-172 N N N N N N ALLOW +18-basic-whitelist x86 174-350 N N N N N N ALLOW +18-basic-whitelist x86_64 4-14 N N N N N N ALLOW +18-basic-whitelist x86_64 16-350 N N N N N N ALLOW + +test type: bpf-sim-fuzz + +# Testname StressCount +18-basic-whitelist 150 diff --git a/tests/Makefile b/tests/Makefile index e3714f2..8b1ba1b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -52,7 +52,8 @@ TESTS = 01-allow \ 14-reset \ 15-resolver \ 16-arch-basic \ - 17-arch-merge + 17-arch-merge \ + 18-basic-whitelist DEPS_OBJS = $(OBJS:%.o=%.d) DEPS_TESTS = $(TESTS:%=%.d) |