diff options
author | Paul Moore <pmoore@redhat.com> | 2013-01-21 15:34:02 -0500 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2013-01-22 18:08:43 -0500 |
commit | f38160bed5e31b421e803df490981e56e0216e0c (patch) | |
tree | 5eeb55ab557f96e2af77b930c8f1a955dd6fb6d8 | |
parent | affce10eef52b1bcd7d15ce8e572272f8c0b6d56 (diff) | |
download | libseccomp-f38160bed5e31b421e803df490981e56e0216e0c.tar.gz |
tests: test for missing syscalls on an architecture
Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/19-missing-syscalls.c | 66 | ||||
-rwxr-xr-x | tests/19-missing-syscalls.py | 48 | ||||
-rw-r--r-- | tests/19-missing-syscalls.tests | 16 | ||||
-rw-r--r-- | tests/Makefile | 3 |
5 files changed, 134 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 879bff5..69a083c 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,4 +1,5 @@ *.bpf +*.pfc util.pyc 01-allow 02-basic @@ -18,3 +19,4 @@ util.pyc 16-arch-basic 17-arch-merge 18-basic-whitelist +19-missing-syscalls diff --git a/tests/19-missing-syscalls.c b/tests/19-missing-syscalls.c new file mode 100644 index 0000000..0ccb0f5 --- /dev/null +++ b/tests/19-missing-syscalls.c @@ -0,0 +1,66 @@ +/** + * 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 <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_KILL); + if (ctx == NULL) + goto out; + + if (seccomp_arch_native() != SCMP_ARCH_X86) { + rc = seccomp_arch_add(ctx, SCMP_ARCH_X86); + if (rc != 0) + goto out; + rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); + if (rc != 0) + goto out; + } + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(tuxcall), 0); + if (rc != 0) + goto out; + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(tuxcall), 0); + if (rc != -EDOM) + 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/19-missing-syscalls.py b/tests/19-missing-syscalls.py new file mode 100755 index 0000000..38408b1 --- /dev/null +++ b/tests/19-missing-syscalls.py @@ -0,0 +1,48 @@ +#!/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(KILL) + if not system_arch() == Arch.X86: + f.add_arch(Arch.X86) + f.remove_arch(Arch.NATIVE) + f.add_rule(ALLOW, "tuxcall") + try: + f.add_rule_exactly(ALLOW, "tuxcall") + except RuntimeError: + pass + 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/19-missing-syscalls.tests b/tests/19-missing-syscalls.tests new file mode 100644 index 0000000..7b34f0d --- /dev/null +++ b/tests/19-missing-syscalls.tests @@ -0,0 +1,16 @@ +# +# 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 +19-missing-syscalls +x86 0-350 N N N N N N KILL + +test type: bpf-sim-fuzz + +# Testname StressCount +19-missing-syscalls 50 diff --git a/tests/Makefile b/tests/Makefile index 8b1ba1b..98b5fe4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -53,7 +53,8 @@ TESTS = 01-allow \ 15-resolver \ 16-arch-basic \ 17-arch-merge \ - 18-basic-whitelist + 18-basic-whitelist \ + 19-missing-syscalls DEPS_OBJS = $(OBJS:%.o=%.d) DEPS_TESTS = $(TESTS:%=%.d) |