diff options
author | Paul Moore <paul@paul-moore.com> | 2017-02-23 18:09:01 -0500 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2017-02-23 18:09:01 -0500 |
commit | ff34ac33ecd61c27ac26afd87d4f15c93ec7e3ac (patch) | |
tree | 2a8f4f9a2ac28b9c1e9aaf24c590141623d8d35e /tests | |
parent | 1674c6117274b50d5c2c71354723767bb48e16b0 (diff) | |
download | libseccomp-ff34ac33ecd61c27ac26afd87d4f15c93ec7e3ac.tar.gz |
tests: add ipc(2) tests
Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/36-sim-ipc_syscalls.c | 112 | ||||
-rwxr-xr-x | tests/36-sim-ipc_syscalls.py | 56 | ||||
-rw-r--r-- | tests/36-sim-ipc_syscalls.tests | 39 | ||||
-rw-r--r-- | tests/37-sim-ipc_syscalls_be.c | 109 | ||||
-rwxr-xr-x | tests/37-sim-ipc_syscalls_be.py | 55 | ||||
-rw-r--r-- | tests/37-sim-ipc_syscalls_be.tests | 27 | ||||
-rw-r--r-- | tests/Makefile.am | 12 |
8 files changed, 409 insertions, 3 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 4946575..ae228ea 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -40,3 +40,5 @@ util.pyc 33-sim-socket_syscalls_be 34-sim-basic_blacklist 35-sim-negative_one +36-sim-ipc_syscalls +37-sim-ipc_syscalls_be diff --git a/tests/36-sim-ipc_syscalls.c b/tests/36-sim-ipc_syscalls.c new file mode 100644 index 0000000..c3ff332 --- /dev/null +++ b/tests/36-sim-ipc_syscalls.c @@ -0,0 +1,112 @@ +/** + * Seccomp Library test program + * + * Copyright (c) 2017 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_KILL); + if (ctx == NULL) + return ENOMEM; + + rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); + if (rc != 0) + goto out; + + rc = seccomp_arch_add(ctx, SCMP_ARCH_X86); + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_X86_64); + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_X32); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semop), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semtimedop), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semget), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semctl), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgsnd), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgrcv), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgget), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgctl), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmat), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmdt), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmget), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmctl), 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/36-sim-ipc_syscalls.py b/tests/36-sim-ipc_syscalls.py new file mode 100755 index 0000000..369a80e --- /dev/null +++ b/tests/36-sim-ipc_syscalls.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +# +# Seccomp Library test program +# +# Copyright (c) 2017 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(KILL) + f.remove_arch(Arch()) + f.add_arch(Arch("x86")) + f.add_arch(Arch("x86_64")) + f.add_arch(Arch("x32")) + f.add_rule(ALLOW, "semop") + f.add_rule(ALLOW, "semtimedop") + f.add_rule(ALLOW, "semget") + f.add_rule(ALLOW, "semctl") + f.add_rule(ALLOW, "msgsnd") + f.add_rule(ALLOW, "msgrcv") + f.add_rule(ALLOW, "msgget") + f.add_rule(ALLOW, "msgctl") + f.add_rule(ALLOW, "shmat") + f.add_rule(ALLOW, "shmdt") + f.add_rule(ALLOW, "shmget") + f.add_rule(ALLOW, "shmctl") + 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/36-sim-ipc_syscalls.tests b/tests/36-sim-ipc_syscalls.tests new file mode 100644 index 0000000..8e0ded7 --- /dev/null +++ b/tests/36-sim-ipc_syscalls.tests @@ -0,0 +1,39 @@ +# +# libseccomp regression test automation data +# +# Copyright (c) 2017 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 +36-sim-ipc_syscalls +x86 ipc 1 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 2 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 3 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 4 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 11 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 12 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 13 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 14 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 21 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 22 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 23 N N N N N ALLOW +36-sim-ipc_syscalls +x86 ipc 24 N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 semop N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 semget N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 semctl N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 semtimedop N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 msgsnd N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 msgrcv N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 msgget N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 msgctl N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 shmat N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 shmdt N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 shmget N N N N N N ALLOW +36-sim-ipc_syscalls +x86_64 shmctl N N N N N N ALLOW + +test type: bpf-valgrind + +# Testname +36-sim-ipc_syscalls diff --git a/tests/37-sim-ipc_syscalls_be.c b/tests/37-sim-ipc_syscalls_be.c new file mode 100644 index 0000000..e82a2aa --- /dev/null +++ b/tests/37-sim-ipc_syscalls_be.c @@ -0,0 +1,109 @@ +/** + * Seccomp Library test program + * + * Copyright (c) 2017 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_KILL); + if (ctx == NULL) + return ENOMEM; + + rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); + if (rc != 0) + goto out; + + rc = seccomp_arch_add(ctx, SCMP_ARCH_S390); + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_S390X); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semop), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semtimedop), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semget), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(semctl), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgsnd), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgrcv), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgget), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(msgctl), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmat), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmdt), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmget), 0); + if (rc != 0) + goto out; + + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shmctl), 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/37-sim-ipc_syscalls_be.py b/tests/37-sim-ipc_syscalls_be.py new file mode 100755 index 0000000..40ae279 --- /dev/null +++ b/tests/37-sim-ipc_syscalls_be.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +# +# Seccomp Library test program +# +# Copyright (c) 2017 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(KILL) + f.remove_arch(Arch()) + f.add_arch(Arch("s390")) + f.add_arch(Arch("s390x")) + f.add_rule(ALLOW, "semop") + f.add_rule(ALLOW, "semtimedop") + f.add_rule(ALLOW, "semget") + f.add_rule(ALLOW, "semctl") + f.add_rule(ALLOW, "msgsnd") + f.add_rule(ALLOW, "msgrcv") + f.add_rule(ALLOW, "msgget") + f.add_rule(ALLOW, "msgctl") + f.add_rule(ALLOW, "shmat") + f.add_rule(ALLOW, "shmdt") + f.add_rule(ALLOW, "shmget") + f.add_rule(ALLOW, "shmctl") + 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/37-sim-ipc_syscalls_be.tests b/tests/37-sim-ipc_syscalls_be.tests new file mode 100644 index 0000000..ff98cec --- /dev/null +++ b/tests/37-sim-ipc_syscalls_be.tests @@ -0,0 +1,27 @@ +# +# libseccomp regression test automation data +# +# Copyright (c) 2017 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 +37-sim-ipc_syscalls_be +s390,+s390x ipc 1 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 2 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 3 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 4 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 11 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 12 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 13 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 14 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 21 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 22 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 23 N N N N N ALLOW +37-sim-ipc_syscalls_be +s390,+s390x ipc 24 N N N N N ALLOW + +test type: bpf-valgrind + +# Testname +37-sim-ipc_syscalls_be diff --git a/tests/Makefile.am b/tests/Makefile.am index 683f7b6..99ece2b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -72,7 +72,9 @@ check_PROGRAMS = \ 32-live-tsync_allow \ 33-sim-socket_syscalls_be \ 34-sim-basic_blacklist \ - 35-sim-negative_one + 35-sim-negative_one \ + 36-sim-ipc_syscalls \ + 37-sim-ipc_syscalls_be EXTRA_DIST_TESTPYTHON = \ util.py \ @@ -110,7 +112,9 @@ EXTRA_DIST_TESTPYTHON = \ 32-live-tsync_allow.py \ 33-sim-socket_syscalls_be.py \ 34-sim-basic_blacklist.py \ - 35-sim-negative_one.py + 35-sim-negative_one.py \ + 36-sim-ipc_syscalls.py \ + 37-sim-ipc_syscalls_be.py EXTRA_DIST_TESTCFGS = \ 01-sim-allow.tests \ @@ -147,7 +151,9 @@ EXTRA_DIST_TESTCFGS = \ 32-live-tsync_allow.tests \ 33-sim-socket_syscalls_be.tests \ 34-sim-basic_blacklist.tests \ - 35-sim-negative_one.tests + 35-sim-negative_one.tests \ + 36-sim-ipc_syscalls.tests \ + 37-sim-ipc_syscalls_be.tests EXTRA_DIST_TESTSCRIPTS = regression testdiff testgen |