/** * Seccomp Library test program * * Copyright (c) 2012 Red Hat * Author: Paul Moore */ /* * This program is free software: you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /* * A lot like mode 1 seccomp where we allow 4 syscalls: * read, write, exit, and rt_sigreturn * except we only allow read on stdin * and we only allow write on stdout and stderr */ #include #include #include "util.h" int main(int argc, char *argv[]) { int rc; int bpf; rc = util_getopt(argc, argv, &bpf); if (rc < 0) return rc; rc = seccomp_init(SCMP_ACT_KILL); if (rc != 0) return rc; rc = seccomp_add_syscall(SCMP_ACT_ALLOW, SCMP_SYS(read), 1, 0, SCMP_CMP_EQ, STDIN_FILENO); if (rc != 0) return rc; rc = seccomp_add_syscall(SCMP_ACT_ALLOW, SCMP_SYS(write), 1, 0, SCMP_CMP_EQ, STDOUT_FILENO); if (rc != 0) return rc; rc = seccomp_add_syscall(SCMP_ACT_ALLOW, SCMP_SYS(write), 1, 0, SCMP_CMP_EQ, STDERR_FILENO); if (rc != 0) return rc; rc = seccomp_add_syscall(SCMP_ACT_ALLOW, SCMP_SYS(close), 0); if (rc != 0) return rc; rc = seccomp_add_syscall(SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0); if (rc != 0) return rc; if (bpf) rc = seccomp_gen_bpf(STDOUT_FILENO); else rc = seccomp_gen_pfc(STDOUT_FILENO); if (rc != 0) return rc; seccomp_release(); return rc; }