1 /*
2 * Check that syscall numbers do not conflict with seccomp filter flags.
3 *
4 * Copyright (c) 2019 Paul Chaignon <paul.chaignon@gmail.com>
5 * Copyright (c) 2018-2021 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "arch_defs.h"
13 #include "sysent.h"
14 #include "scno.h"
15
16 /* PERSONALITY*_AUDIT_ARCH definitions depend on AUDIT_ARCH_* constants. */
17 #include <linux/audit.h>
18 #define XLAT_MACROS_ONLY
19 # include "xlat/elf_em.h"
20 # include "xlat/audit_arch.h"
21 #undef XLAT_MACROS_ONLY
22
23 /* Define these shorthand notations to simplify the syscallent files. */
24 #include "sysent_shorthand_defs.h"
25
26 const struct_sysent sysent0[] = {
27 #include "syscallent.h"
28 };
29
30 #if SUPPORTED_PERSONALITIES > 1
31 const struct_sysent sysent1[] = {
32 # include "syscallent1.h"
33 };
34 #endif
35
36 #if SUPPORTED_PERSONALITIES > 2
37 const struct_sysent sysent2[] = {
38 # include "syscallent2.h"
39 };
40 #endif
41
42 const unsigned int nsyscall_vec[SUPPORTED_PERSONALITIES] = {
43 ARRAY_SIZE(sysent0),
44 #if SUPPORTED_PERSONALITIES > 1
45 ARRAY_SIZE(sysent1),
46 #endif
47 #if SUPPORTED_PERSONALITIES > 2
48 ARRAY_SIZE(sysent2),
49 #endif
50 };
51
52 struct audit_arch_t {
53 unsigned int arch;
54 unsigned int flag;
55 };
56
57 static const struct audit_arch_t audit_arch_vec[SUPPORTED_PERSONALITIES] = {
58 #if SUPPORTED_PERSONALITIES > 1
59 PERSONALITY0_AUDIT_ARCH,
60 PERSONALITY1_AUDIT_ARCH,
61 # if SUPPORTED_PERSONALITIES > 2
62 PERSONALITY2_AUDIT_ARCH,
63 # endif
64 #endif
65 };
66
67 int
68 main(void)
69 {
70 for (unsigned int p = 0; p < SUPPORTED_PERSONALITIES; ++p) {
71 if (!audit_arch_vec[p].flag)
72 continue;
73 for (unsigned int nr = 1; nr < nsyscall_vec[p]; ++nr) {
74 if (!(audit_arch_vec[p].flag & nr))
75 continue;
76 error_msg_and_fail("system call number %u of"
77 " personality %u conflicts with"
78 " seccomp filter flag %#x",
79 nr, p, audit_arch_vec[p].flag);
80 }
81 }
82 return 0;
83 }