X-Git-Url: http://git.ieval.ro/?p=linux-seccomp.git;a=blobdiff_plain;f=libseccomp%2Ftests%2F11-basic-basic_errors.c;fp=libseccomp%2Ftests%2F11-basic-basic_errors.c;h=f6155840b26313bf08f5726573e0ad9f16813ef9;hp=0000000000000000000000000000000000000000;hb=8befd5cc4d2b478c697d81a5ac191083c203d081;hpb=bcf524c10c0ad85fcef711acffc3251bb8472352 diff --git a/libseccomp/tests/11-basic-basic_errors.c b/libseccomp/tests/11-basic-basic_errors.c new file mode 100644 index 0000000..f615584 --- /dev/null +++ b/libseccomp/tests/11-basic-basic_errors.c @@ -0,0 +1,176 @@ +/** + * Seccomp Library test program + * + * Copyright IBM Corp. 2012 + * Author: Corey Bryant + */ + +/* + * 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 . + */ + +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + int rc; + scmp_filter_ctx ctx; + + /* seccomp_init errors */ + ctx = seccomp_init(SCMP_ACT_ALLOW + 1); + if (ctx != NULL) + return -1; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + seccomp_release(ctx); + ctx = NULL; + + /* seccomp_reset error */ + rc = seccomp_reset(ctx, SCMP_ACT_KILL + 1); + if (rc != -EINVAL) + return -1; + rc = seccomp_reset(ctx, SCMP_ACT_KILL); + if (rc != -EINVAL) + return -1; + + /* seccomp_load error */ + rc = seccomp_load(ctx); + if (rc != -EINVAL) + return -1; + + /* seccomp_syscall_priority errors */ + rc = seccomp_syscall_priority(ctx, SCMP_SYS(read), 1); + if (rc != -EINVAL) + return -1; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + else { + rc = seccomp_syscall_priority(ctx, -10, 1); + if (rc != -EINVAL) + return -1; + } + seccomp_release(ctx); + ctx = NULL; + + /* seccomp_rule_add errors */ + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 1, + SCMP_A0(SCMP_CMP_EQ, 0)); + if (rc != -EINVAL) + return -1; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + else { + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0); + if (rc != -EPERM) + return -1; + rc = seccomp_rule_add(ctx, SCMP_ACT_KILL - 1, SCMP_SYS(read), 0); + if (rc != -EINVAL) + return -1; + rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 7); + if (rc != -EINVAL) + return -1; + rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 7, + SCMP_A0(SCMP_CMP_EQ, 0), + SCMP_A1(SCMP_CMP_EQ, 0), + SCMP_A2(SCMP_CMP_EQ, 0), + SCMP_A3(SCMP_CMP_EQ, 0), + SCMP_A4(SCMP_CMP_EQ, 0), + SCMP_A5(SCMP_CMP_EQ, 0), + SCMP_CMP(6, SCMP_CMP_EQ, 0)); + if (rc != -EINVAL) + return -1; + rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 1, + SCMP_A0(_SCMP_CMP_MIN, 0)); + if (rc != -EINVAL) + return -1; + rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 1, + SCMP_A0(_SCMP_CMP_MAX, 0)); + if (rc != -EINVAL) + return -1; + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, -10001, 0); + if (rc != -EDOM) + return -1; + } + seccomp_release(ctx); + ctx = NULL; + + /* seccomp_rule_add_exact error */ + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); + if (rc != 0) + return -1; + rc = seccomp_arch_add(ctx, SCMP_ARCH_X86); + if (rc != 0) + return -1; + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(socket), 1, + SCMP_A0(SCMP_CMP_EQ, 2)); + if (rc != -EINVAL) + return -1; + seccomp_release(ctx); + ctx = NULL; + + /* errno values beyond MAX_ERRNO */ + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + rc = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(0xffff), 0, 0); + if (rc != -EINVAL) + return -1; + seccomp_release(ctx); + ctx = NULL; + + /* seccomp_export_pfc errors */ + rc = seccomp_export_pfc(ctx, STDOUT_FILENO); + if (rc != -EINVAL) + return -1; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + else { + rc = seccomp_export_pfc(ctx, sysconf(_SC_OPEN_MAX) - 1); + if (rc != EBADF) + return -1; + } + seccomp_release(ctx); + ctx = NULL; + + /* seccomp_export_bpf errors */ + rc = seccomp_export_bpf(ctx, STDOUT_FILENO); + if (rc != -EINVAL) + return -1; + + ctx = seccomp_init(SCMP_ACT_ALLOW); + if (ctx == NULL) + return -1; + else { + rc = seccomp_export_bpf(ctx, sysconf(_SC_OPEN_MAX) - 1); + if (rc != -EBADF) + return -1; + } + seccomp_release(ctx); + ctx = NULL; + + return 0; +}