]>
Commit | Line | Data |
---|---|---|
8befd5cc MG |
1 | /** |
2 | * Seccomp Library test program | |
3 | * | |
4 | * Author: Markos Chandras <markos.chandras@imgtec.com> | |
5 | */ | |
6 | ||
7 | /* | |
8 | * This library is free software; you can redistribute it and/or modify it | |
9 | * under the terms of version 2.1 of the GNU Lesser General Public License as | |
10 | * published by the Free Software Foundation. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
15 | * for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public License | |
18 | * along with this library; if not, see <http://www.gnu.org/licenses>. | |
19 | */ | |
20 | ||
21 | #include <errno.h> | |
22 | #include <unistd.h> | |
23 | ||
24 | #include <seccomp.h> | |
25 | ||
26 | #include "util.h" | |
27 | ||
28 | int main(int argc, char *argv[]) | |
29 | { | |
30 | int rc; | |
31 | struct util_options opts; | |
32 | scmp_filter_ctx ctx = NULL; | |
33 | ||
34 | rc = util_getopt(argc, argv, &opts); | |
35 | if (rc < 0) | |
36 | goto out; | |
37 | ||
38 | ctx = seccomp_init(SCMP_ACT_KILL); | |
39 | if (ctx == NULL) | |
40 | return ENOMEM; | |
41 | ||
42 | rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); | |
43 | if (rc != 0) | |
44 | goto out; | |
45 | ||
46 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("mips")); | |
47 | if (rc != 0) | |
48 | goto out; | |
49 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("mips64")); | |
50 | if (rc != 0) | |
51 | goto out; | |
52 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("mips64n32")); | |
53 | if (rc != 0) | |
54 | goto out; | |
55 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("ppc")); | |
56 | if (rc != 0) | |
57 | goto out; | |
58 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("ppc64")); | |
59 | if (rc != 0) | |
60 | goto out; | |
61 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("s390")); | |
62 | if (rc != 0) | |
63 | goto out; | |
64 | rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("s390x")); | |
65 | if (rc != 0) | |
66 | goto out; | |
67 | ||
68 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 1, | |
69 | SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO)); | |
70 | if (rc != 0) | |
71 | goto out; | |
72 | ||
73 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1, | |
74 | SCMP_A0(SCMP_CMP_EQ, STDOUT_FILENO)); | |
75 | if (rc != 0) | |
76 | goto out; | |
77 | ||
78 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1, | |
79 | SCMP_A0(SCMP_CMP_EQ, STDERR_FILENO)); | |
80 | if (rc != 0) | |
81 | goto out; | |
82 | ||
83 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0); | |
84 | if (rc != 0) | |
85 | goto out; | |
86 | ||
87 | rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0); | |
88 | if (rc != 0) | |
89 | goto out; | |
90 | ||
91 | rc = util_filter_output(&opts, ctx); | |
92 | if (rc) | |
93 | goto out; | |
94 | ||
95 | out: | |
96 | seccomp_release(ctx); | |
97 | return (rc < 0 ? -rc : rc); | |
98 | } |