Commit | Line | Data |
---|---|---|
8befd5cc MG |
1 | /** |
2 | * Seccomp Library test program | |
3 | * | |
4 | * This test triggered a bug in libseccomp erroneously allowing the close() | |
5 | * syscall on x32 instead of 'KILL'ing it, as it should do for unsupported | |
6 | * architectures. | |
7 | * | |
8 | * Copyright (c) 2012 Red Hat <pmoore@redhat.com> | |
9 | * Authors: Paul Moore <pmoore@redhat.com> | |
10 | * Mathias Krause <minipli@googlemail.com> | |
11 | */ | |
12 | ||
13 | /* | |
14 | * This library is free software; you can redistribute it and/or modify it | |
15 | * under the terms of version 2.1 of the GNU Lesser General Public License as | |
16 | * published by the Free Software Foundation. | |
17 | * | |
18 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
19 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
20 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
21 | * for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU Lesser General Public License | |
24 | * along with this library; if not, see <http://www.gnu.org/licenses>. | |
25 | */ | |
26 | ||
27 | #include <errno.h> | |
28 | #include <unistd.h> | |
29 | ||
30 | #include <seccomp.h> | |
31 | ||
32 | #include "util.h" | |
33 | ||
34 | int main(int argc, char *argv[]) | |
35 | { | |
36 | int rc; | |
37 | struct util_options opts; | |
38 | scmp_filter_ctx ctx = NULL; | |
39 | ||
40 | rc = util_getopt(argc, argv, &opts); | |
41 | if (rc < 0) | |
42 | goto out; | |
43 | ||
44 | ctx = seccomp_init(SCMP_ACT_ALLOW); | |
45 | if (ctx == NULL) | |
46 | return ENOMEM; | |
47 | ||
48 | rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); | |
49 | if (rc != 0) | |
50 | goto out; | |
51 | ||
52 | /* add x86-64 and x86 (in that order!) but explicitly leave out x32 */ | |
53 | rc = seccomp_arch_add(ctx, SCMP_ARCH_X86_64); | |
54 | if (rc != 0) | |
55 | goto out; | |
56 | rc = seccomp_arch_add(ctx, SCMP_ARCH_X86); | |
57 | if (rc != 0) | |
58 | goto out; | |
59 | ||
60 | rc = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(1), SCMP_SYS(close), 0); | |
61 | if (rc != 0) | |
62 | goto out; | |
63 | ||
64 | rc = util_filter_output(&opts, ctx); | |
65 | if (rc) | |
66 | goto out; | |
67 | ||
68 | out: | |
69 | seccomp_release(ctx); | |
70 | return (rc < 0 ? -rc : rc); | |
71 | } |