Signed-off-by: Paul Moore <[email protected]> --- tests/.gitignore | 1 + tests/18-basic-whitelist.c | 73 ++++++++++++++++++++++++++++++++++++++++ tests/18-basic-whitelist.py | 45 +++++++++++++++++++++++++ tests/18-basic-whitelist.tests | 27 +++++++++++++++ tests/Makefile | 3 +- 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tests/18-basic-whitelist.c create mode 100755 tests/18-basic-whitelist.py create mode 100644 tests/18-basic-whitelist.tests
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 <[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 <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 <[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 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 <[email protected]> +# Author: Paul Moore <[email protected]> +# + +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) ------------------------------------------------------------------------------ Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery and much more. Keep your Java skills current with LearnJavaNow - 200+ hours of step-by-step video tutorials by Java experts. SALE $49.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122612 _______________________________________________ libseccomp-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libseccomp-discuss
