|
| 1 | +/** |
| 2 | + * Seccomp Library test program |
| 3 | + * |
| 4 | + * Copyright (c) 2019 Cisco Systems, Inc. <pmoore2@cisco.com> |
| 5 | + * Author: Paul Moore <paul@paul-moore.com> |
| 6 | + * Additions: Michael Weiser <michael.weiser@gmx.de> |
| 7 | + */ |
| 8 | + |
| 9 | +/* |
| 10 | + * This library is free software; you can redistribute it and/or modify it |
| 11 | + * under the terms of version 2.1 of the GNU Lesser General Public License as |
| 12 | + * published by the Free Software Foundation. |
| 13 | + * |
| 14 | + * This library is distributed in the hope that it will be useful, but WITHOUT |
| 15 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 17 | + * for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Lesser General Public License |
| 20 | + * along with this library; if not, see <http://www.gnu.org/licenses>. |
| 21 | + */ |
| 22 | + |
| 23 | +#include <errno.h> |
| 24 | +#include <unistd.h> |
| 25 | +#include <inttypes.h> |
| 26 | + |
| 27 | +#include <seccomp.h> |
| 28 | + |
| 29 | +#include "util.h" |
| 30 | + |
| 31 | +int main(int argc, char *argv[]) |
| 32 | +{ |
| 33 | + int rc; |
| 34 | + struct util_options opts; |
| 35 | + scmp_filter_ctx ctx = NULL; |
| 36 | + |
| 37 | + rc = util_getopt(argc, argv, &opts); |
| 38 | + if (rc < 0) |
| 39 | + goto out; |
| 40 | + |
| 41 | + ctx = seccomp_init(SCMP_ACT_KILL); |
| 42 | + if (ctx == NULL) |
| 43 | + return ENOMEM; |
| 44 | + |
| 45 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1001, 1, |
| 46 | + SCMP_A0(SCMP_CMP_NE | SCMP_CMP_32BIT, 0x10)); |
| 47 | + if (rc != 0) |
| 48 | + goto out; |
| 49 | + |
| 50 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1002, 1, |
| 51 | + SCMP_A0(SCMP_CMP_LT | SCMP_CMP_32BIT, 0x10)); |
| 52 | + if (rc != 0) |
| 53 | + goto out; |
| 54 | + |
| 55 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1003, 1, |
| 56 | + SCMP_A0(SCMP_CMP_LE | SCMP_CMP_32BIT, 0x10)); |
| 57 | + if (rc != 0) |
| 58 | + goto out; |
| 59 | + |
| 60 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1004, 1, |
| 61 | + SCMP_A0(SCMP_CMP_EQ | SCMP_CMP_32BIT, 0x10)); |
| 62 | + if (rc != 0) |
| 63 | + goto out; |
| 64 | + |
| 65 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1005, 1, |
| 66 | + SCMP_A0(SCMP_CMP_GE | SCMP_CMP_32BIT, 0x10)); |
| 67 | + if (rc != 0) |
| 68 | + goto out; |
| 69 | + |
| 70 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1006, 1, |
| 71 | + SCMP_A0(SCMP_CMP_GT | SCMP_CMP_32BIT, 0x10)); |
| 72 | + if (rc != 0) |
| 73 | + goto out; |
| 74 | + |
| 75 | + rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1007, 1, |
| 76 | + SCMP_A0(SCMP_CMP_MASKED_EQ | SCMP_CMP_32BIT, 0xff, 0x10)); |
| 77 | + if (rc != 0) |
| 78 | + goto out; |
| 79 | + |
| 80 | + rc = util_filter_output(&opts, ctx); |
| 81 | + if (rc) |
| 82 | + goto out; |
| 83 | + |
| 84 | +out: |
| 85 | + seccomp_release(ctx); |
| 86 | + return (rc < 0 ? -rc : rc); |
| 87 | +} |
0 commit comments