Blame tests/53-sim-binary_tree.py

Packit Service 10c312
#!/usr/bin/env python
Packit Service 10c312
Packit Service 10c312
#
Packit Service 10c312
# Seccomp Library test program
Packit Service 10c312
#
Packit Service 10c312
# Copyright (c) 2018 Oracle and/or its affiliates.  All rights reserved.
Packit Service 10c312
# Author: Tom Hromatka <tom.hromatka@oracle.com>
Packit Service 10c312
#
Packit Service 10c312
Packit Service 10c312
#
Packit Service 10c312
# This library is free software; you can redistribute it and/or modify it
Packit Service 10c312
# under the terms of version 2.1 of the GNU Lesser General Public License as
Packit Service 10c312
# published by the Free Software Foundation.
Packit Service 10c312
#
Packit Service 10c312
# This library is distributed in the hope that it will be useful, but WITHOUT
Packit Service 10c312
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit Service 10c312
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
Packit Service 10c312
# for more details.
Packit Service 10c312
#
Packit Service 10c312
# You should have received a copy of the GNU Lesser General Public License
Packit Service 10c312
# along with this library; if not, see <http://www.gnu.org/licenses>.
Packit Service 10c312
#
Packit Service 10c312
Packit Service 10c312
import argparse
Packit Service 10c312
import sys
Packit Service 10c312
Packit Service 10c312
import util
Packit Service 10c312
Packit Service 10c312
from seccomp import *
Packit Service 10c312
Packit Service 10c312
table = [
Packit Service 10c312
    {"syscall": "read", "error": 0, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "write", "error": 1, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "open", "error": 2, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "close", "error": 3, "arg_cnt": 2, "arg1": 100, "arg2": 101 },
Packit Service 10c312
    {"syscall": "stat", "error": 4, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "fstat", "error": 5, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "lstat", "error": 6, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "poll", "error": 7, "arg_cnt": 1, "arg1": 102 },
Packit Service 10c312
    {"syscall": "lseek", "error": 8, "arg_cnt": 2, "arg1": 103, "arg2": 104 },
Packit Service 10c312
    {"syscall": "mmap", "error": 9, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "mprotect", "error": 10, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "munmap", "error": 11, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "brk", "error": 12, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "rt_sigaction", "error": 13, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "rt_sigprocmask", "error": 14, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "rt_sigreturn", "error": 15, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "ioctl", "error": 16, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "pread64", "error": 17, "arg_cnt": 1, "arg1": 105 },
Packit Service 10c312
    {"syscall": "pwrite64", "error": 18, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "readv", "error": 19, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "writev", "error": 20, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "access", "error": 21, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "pipe", "error": 22, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "select", "error": 23, "arg_cnt": 2, "arg1": 106, "arg2": 107 },
Packit Service 10c312
    {"syscall": "sched_yield", "error": 24, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "mremap", "error": 25, "arg_cnt": 2, "arg1": 108, "arg2": 109 },
Packit Service 10c312
    {"syscall": "msync", "error": 26, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "mincore", "error": 27, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "madvise", "error": 28, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "dup", "error": 32, "arg_cnt": 1, "arg1": 112 },
Packit Service 10c312
    {"syscall": "dup2", "error": 33, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "pause", "error": 34, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "nanosleep", "error": 35, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "getitimer", "error": 36, "arg_cnt": 0 },
Packit Service 10c312
    {"syscall": "alarm", "error": 37, "arg_cnt": 0 },
Packit Service 10c312
]
Packit Service 10c312
Packit Service 10c312
def test(args):
Packit Service 10c312
    f = SyscallFilter(ALLOW)
Packit Service 10c312
Packit Service 10c312
    f.remove_arch(Arch())
Packit Service 10c312
    f.add_arch(Arch("aarch64"))
Packit Service 10c312
    f.add_arch(Arch("ppc64le"))
Packit Service 10c312
    f.add_arch(Arch("x86_64"))
Packit Service 10c312
Packit Service 10c312
    for entry in table:
Packit Service 10c312
        if entry["arg_cnt"] == 2:
Packit Service 10c312
            f.add_rule(ERRNO(entry["error"]), entry["syscall"],
Packit Service 10c312
                       Arg(0, EQ, entry["arg1"]),
Packit Service 10c312
                       Arg(1, EQ, entry["arg2"]))
Packit Service 10c312
        elif entry["arg_cnt"] == 1:
Packit Service 10c312
            f.add_rule(ERRNO(entry["error"]), entry["syscall"],
Packit Service 10c312
                       Arg(0, EQ, entry["arg1"]))
Packit Service 10c312
        else:
Packit Service 10c312
            f.add_rule(ERRNO(entry["error"]), entry["syscall"])
Packit Service 10c312
Packit Service 10c312
    return f
Packit Service 10c312
Packit Service 10c312
args = util.get_opt()
Packit Service 10c312
ctx = test(args)
Packit Service 10c312
util.filter_output(args, ctx)
Packit Service 10c312
Packit Service 10c312
# kate: syntax python;
Packit Service 10c312
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;