Blame tests/47-live-kill_process.py

Packit 56e23f
#!/usr/bin/env python
Packit 56e23f
Packit 56e23f
#
Packit 56e23f
# Seccomp Library test program
Packit 56e23f
#
Packit 56e23f
# Copyright (c) 2018 Oracle and/or its affiliates.  All rights reserved.
Packit 56e23f
# Author: Tom Hromatka <tom.hromatka@oracle.com>
Packit 56e23f
#
Packit 56e23f
Packit 56e23f
#
Packit 56e23f
# This library is free software; you can redistribute it and/or modify it
Packit 56e23f
# under the terms of version 2.1 of the GNU Lesser General Public License as
Packit 56e23f
# published by the Free Software Foundation.
Packit 56e23f
#
Packit 56e23f
# This library is distributed in the hope that it will be useful, but WITHOUT
Packit 56e23f
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit 56e23f
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
Packit 56e23f
# for more details.
Packit 56e23f
#
Packit 56e23f
# You should have received a copy of the GNU Lesser General Public License
Packit 56e23f
# along with this library; if not, see <http://www.gnu.org/licenses>.
Packit 56e23f
#
Packit 56e23f
Packit 56e23f
import argparse
Packit 56e23f
import os
Packit 56e23f
import sys
Packit 56e23f
import threading
Packit 56e23f
import time
Packit 56e23f
Packit 56e23f
import util
Packit 56e23f
Packit 56e23f
from seccomp import *
Packit 56e23f
Packit 56e23f
def child_start(param):
Packit 56e23f
    param = 1
Packit 56e23f
Packit 56e23f
    try:
Packit 56e23f
        fd = os.open("/dev/null", os.O_WRONLY)
Packit 56e23f
    except IOError as ex:
Packit 56e23f
        param = ex.errno
Packit 56e23f
        quit(ex.errno)
Packit 56e23f
Packit 56e23f
def test():
Packit 56e23f
    f = SyscallFilter(KILL_PROCESS)
Packit 56e23f
    f.add_rule(ALLOW, "clone")
Packit 56e23f
    f.add_rule(ALLOW, "exit")
Packit 56e23f
    f.add_rule(ALLOW, "exit_group")
Packit 56e23f
    f.add_rule(ALLOW, "futex")
Packit 56e23f
    f.add_rule(ALLOW, "madvise")
Packit 56e23f
    f.add_rule(ALLOW, "mmap")
Packit 56e23f
    f.add_rule(ALLOW, "mprotect")
Packit 56e23f
    f.add_rule(ALLOW, "munmap")
Packit 56e23f
    f.add_rule(ALLOW, "nanosleep")
Packit 56e23f
    f.add_rule(ALLOW, "set_robust_list")
Packit 56e23f
    f.load()
Packit 56e23f
Packit 56e23f
    param = 0
Packit 56e23f
    threading.Thread(target = child_start, args = (param, ))
Packit 56e23f
    thread.start()
Packit 56e23f
Packit 56e23f
    time.sleep(1)
Packit 56e23f
Packit 56e23f
    quit(-errno.EACCES)
Packit 56e23f
Packit 56e23f
test()
Packit 56e23f
Packit 56e23f
# kate: syntax python;
Packit 56e23f
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;