diff options
author | Luca Bruno <lucab@debian.org> | 2016-05-29 09:47:27 +0200 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2016-06-02 15:31:40 -0400 |
commit | 5e0a33f8f5c086204451041c43010e4ab51b5c6e (patch) | |
tree | 3e68084a2104ff420e6a52e377da1272974440f7 | |
parent | c86e1f565537b28b73ebd63f0239b4a446925534 (diff) | |
download | libseccomp-5e0a33f8f5c086204451041c43010e4ab51b5c6e.tar.gz |
tests: sort out simulation blacklist/whitelist
This commit sorts out a mismatch between simulation tests,
properly laying down a blacklist and a whitelist simulation.
Signed-off-by: Luca Bruno <lucab@debian.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/18-sim-basic_whitelist.c | 12 | ||||
-rwxr-xr-x | tests/18-sim-basic_whitelist.py | 12 | ||||
-rw-r--r-- | tests/18-sim-basic_whitelist.tests | 24 | ||||
-rw-r--r-- | tests/34-sim-basic_blacklist.c | 74 | ||||
-rwxr-xr-x | tests/34-sim-basic_blacklist.py | 45 | ||||
-rw-r--r-- | tests/34-sim-basic_blacklist.tests | 32 | ||||
-rw-r--r-- | tests/Makefile.am | 9 |
8 files changed, 182 insertions, 27 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index b282fa4..ba08212 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -38,3 +38,4 @@ util.pyc 31-basic-version_check 32-live-tsync_allow 33-sim-socket_syscalls_be +34-sim-basic_blacklist diff --git a/tests/18-sim-basic_whitelist.c b/tests/18-sim-basic_whitelist.c index e17406f..e30274f 100644 --- a/tests/18-sim-basic_whitelist.c +++ b/tests/18-sim-basic_whitelist.c @@ -36,31 +36,31 @@ int main(int argc, char *argv[]) if (rc < 0) goto out; - ctx = seccomp_init(SCMP_ACT_ALLOW); + ctx = seccomp_init(SCMP_ACT_KILL); if (ctx == NULL) return ENOMEM; - rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 1, + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 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, + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 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, + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 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); + 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_KILL, SCMP_SYS(rt_sigreturn), 0); + SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0); if (rc != 0) goto out; diff --git a/tests/18-sim-basic_whitelist.py b/tests/18-sim-basic_whitelist.py index 05a202d..dbee3ac 100755 --- a/tests/18-sim-basic_whitelist.py +++ b/tests/18-sim-basic_whitelist.py @@ -29,12 +29,12 @@ 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") + 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() diff --git a/tests/18-sim-basic_whitelist.tests b/tests/18-sim-basic_whitelist.tests index e02b183..2d46660 100644 --- a/tests/18-sim-basic_whitelist.tests +++ b/tests/18-sim-basic_whitelist.tests @@ -8,18 +8,18 @@ test type: bpf-sim # Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result -18-sim-basic_whitelist all read 0 0x856B008 10 N N N KILL -18-sim-basic_whitelist all read 1-10 0x856B008 10 N N N ALLOW -18-sim-basic_whitelist all write 1-2 0x856B008 10 N N N KILL -18-sim-basic_whitelist all write 3-10 0x856B008 10 N N N ALLOW -18-sim-basic_whitelist all close N N N N N N KILL -18-sim-basic_whitelist all rt_sigreturn N N N N N N KILL -18-sim-basic_whitelist all open 0x856B008 4 N N N N ALLOW -18-sim-basic_whitelist x86 0-2 N N N N N N ALLOW -18-sim-basic_whitelist x86 7-172 N N N N N N ALLOW -18-sim-basic_whitelist x86 174-350 N N N N N N ALLOW -18-sim-basic_whitelist x86_64 4-14 N N N N N N ALLOW -18-sim-basic_whitelist x86_64 16-350 N N N N N N ALLOW +18-sim-basic_whitelist all read 0 0x856B008 10 N N N ALLOW +18-sim-basic_whitelist all read 1-10 0x856B008 10 N N N KILL +18-sim-basic_whitelist all write 1-2 0x856B008 10 N N N ALLOW +18-sim-basic_whitelist all write 3-10 0x856B008 10 N N N KILL +18-sim-basic_whitelist all close N N N N N N ALLOW +18-sim-basic_whitelist all rt_sigreturn N N N N N N ALLOW +18-sim-basic_whitelist all open 0x856B008 4 N N N N KILL +18-sim-basic_whitelist x86 0-2 N N N N N N KILL +18-sim-basic_whitelist x86 7-172 N N N N N N KILL +18-sim-basic_whitelist x86 174-350 N N N N N N KILL +18-sim-basic_whitelist x86_64 4-14 N N N N N N KILL +18-sim-basic_whitelist x86_64 16-350 N N N N N N KILL test type: bpf-sim-fuzz diff --git a/tests/34-sim-basic_blacklist.c b/tests/34-sim-basic_blacklist.c new file mode 100644 index 0000000..e17406f --- /dev/null +++ b/tests/34-sim-basic_blacklist.c @@ -0,0 +1,74 @@ +/** + * Seccomp Library test program + * + * Copyright (c) 2013 Red Hat <pmoore@redhat.com> + * Author: Paul Moore <paul@paul-moore.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 <unistd.h> + +#include <seccomp.h> + +#include "util.h" + +int main(int argc, char *argv[]) +{ + int rc; + struct util_options opts; + scmp_filter_ctx ctx = NULL; + + rc = util_getopt(argc, argv, &opts); + if (rc < 0) + goto out; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return ENOMEM; + + 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/34-sim-basic_blacklist.py b/tests/34-sim-basic_blacklist.py new file mode 100755 index 0000000..05a202d --- /dev/null +++ b/tests/34-sim-basic_blacklist.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# +# Seccomp Library test program +# +# Copyright (c) 2013 Red Hat <pmoore@redhat.com> +# Author: Paul Moore <paul@paul-moore.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/34-sim-basic_blacklist.tests b/tests/34-sim-basic_blacklist.tests new file mode 100644 index 0000000..0ae3433 --- /dev/null +++ b/tests/34-sim-basic_blacklist.tests @@ -0,0 +1,32 @@ +# +# libseccomp regression test automation data +# +# Copyright (c) 2013 Red Hat <pmoore@redhat.com> +# Author: Paul Moore <paul@paul-moore.com> +# + +test type: bpf-sim + +# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result +34-sim-basic_blacklist all read 0 0x856B008 10 N N N KILL +34-sim-basic_blacklist all read 1-10 0x856B008 10 N N N ALLOW +34-sim-basic_blacklist all write 1-2 0x856B008 10 N N N KILL +34-sim-basic_blacklist all write 3-10 0x856B008 10 N N N ALLOW +34-sim-basic_blacklist all close N N N N N N KILL +34-sim-basic_blacklist all rt_sigreturn N N N N N N KILL +34-sim-basic_blacklist all open 0x856B008 4 N N N N ALLOW +34-sim-basic_blacklist x86 0-2 N N N N N N ALLOW +34-sim-basic_blacklist x86 7-172 N N N N N N ALLOW +34-sim-basic_blacklist x86 174-350 N N N N N N ALLOW +34-sim-basic_blacklist x86_64 4-14 N N N N N N ALLOW +34-sim-basic_blacklist x86_64 16-350 N N N N N N ALLOW + +test type: bpf-sim-fuzz + +# Testname StressCount +34-sim-basic_blacklist 50 + +test type: bpf-valgrind + +# Testname +34-sim-basic_blacklist diff --git a/tests/Makefile.am b/tests/Makefile.am index ee4e41b..6ed3d06 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -61,7 +61,8 @@ check_PROGRAMS = \ 30-sim-socket_syscalls \ 31-basic-version_check \ 32-live-tsync_allow \ - 33-sim-socket_syscalls_be + 33-sim-socket_syscalls_be \ + 34-sim-basic_blacklist EXTRA_DIST_TESTPYTHON = \ util.py \ @@ -97,7 +98,8 @@ EXTRA_DIST_TESTPYTHON = \ 30-sim-socket_syscalls.py \ 31-basic-version_check.py \ 32-live-tsync_allow.py \ - 33-sim-socket_syscalls_be.py + 33-sim-socket_syscalls_be.py \ + 34-sim-basic_blacklist.py EXTRA_DIST_TESTCFGS = \ 01-sim-allow.tests \ @@ -132,7 +134,8 @@ EXTRA_DIST_TESTCFGS = \ 30-sim-socket_syscalls.tests \ 31-basic-version_check.tests \ 32-live-tsync_allow.tests \ - 33-sim-socket_syscalls_be.tests + 33-sim-socket_syscalls_be.tests \ + 34-sim-basic_blacklist.tests EXTRA_DIST_TESTSCRIPTS = regression testdiff testgen |