Skip to content

Commit

Permalink
tests: sort out simulation blacklist/whitelist
Browse files Browse the repository at this point in the history
This commit sorts out a mismatch between simulation tests,
properly laying down a blacklist and a whitelist simulation.

Signed-off-by: Luca Bruno <[email protected]>
  • Loading branch information
lucab committed May 31, 2016
1 parent c86e1f5 commit 0224e62
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 27 deletions.
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ util.pyc
31-basic-version_check
32-live-tsync_allow
33-sim-socket_syscalls_be
34-sim-basic_blacklist
12 changes: 6 additions & 6 deletions tests/18-sim-basic_whitelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions tests/18-sim-basic_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
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()
Expand Down
24 changes: 12 additions & 12 deletions tests/18-sim-basic_whitelist.tests
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
74 changes: 74 additions & 0 deletions tests/34-sim-basic_blacklist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* 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:https://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);
}
45 changes: 45 additions & 0 deletions tests/34-sim-basic_blacklist.py
Original file line number Diff line number Diff line change
@@ -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:https://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;
32 changes: 32 additions & 0 deletions tests/34-sim-basic_blacklist.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# 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
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
9 changes: 6 additions & 3 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0224e62

Please sign in to comment.