]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
57183d11 LP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2014 Lennart Poettering | |
57183d11 LP |
8 | ***/ |
9 | ||
a60e9f7f | 10 | #include <seccomp.h> |
f6281133 | 11 | #include <stdbool.h> |
a8fbdf54 | 12 | #include <stdint.h> |
57183d11 | 13 | |
469830d1 LP |
14 | #include "set.h" |
15 | ||
57183d11 LP |
16 | const char* seccomp_arch_to_string(uint32_t c); |
17 | int seccomp_arch_from_string(const char *n, uint32_t *ret); | |
e9642be2 | 18 | |
469830d1 | 19 | int seccomp_init_for_arch(scmp_filter_ctx *ret, uint32_t arch, uint32_t default_action); |
201c1cc2 | 20 | |
83f12b27 FS |
21 | bool is_seccomp_available(void); |
22 | ||
8130926d LP |
23 | typedef struct SyscallFilterSet { |
24 | const char *name; | |
d5efc18b | 25 | const char *help; |
201c1cc2 | 26 | const char *value; |
8130926d LP |
27 | } SyscallFilterSet; |
28 | ||
29 | enum { | |
40eb6a80 ZJS |
30 | /* Please leave DEFAULT first, but sort the rest alphabetically */ |
31 | SYSCALL_FILTER_SET_DEFAULT, | |
44898c53 | 32 | SYSCALL_FILTER_SET_AIO, |
133ddbbe | 33 | SYSCALL_FILTER_SET_BASIC_IO, |
44898c53 | 34 | SYSCALL_FILTER_SET_CHOWN, |
8130926d LP |
35 | SYSCALL_FILTER_SET_CLOCK, |
36 | SYSCALL_FILTER_SET_CPU_EMULATION, | |
37 | SYSCALL_FILTER_SET_DEBUG, | |
1a1b13c9 | 38 | SYSCALL_FILTER_SET_FILE_SYSTEM, |
8130926d LP |
39 | SYSCALL_FILTER_SET_IO_EVENT, |
40 | SYSCALL_FILTER_SET_IPC, | |
41 | SYSCALL_FILTER_SET_KEYRING, | |
cd0ddf6f | 42 | SYSCALL_FILTER_SET_MEMLOCK, |
8130926d LP |
43 | SYSCALL_FILTER_SET_MODULE, |
44 | SYSCALL_FILTER_SET_MOUNT, | |
45 | SYSCALL_FILTER_SET_NETWORK_IO, | |
46 | SYSCALL_FILTER_SET_OBSOLETE, | |
47 | SYSCALL_FILTER_SET_PRIVILEGED, | |
48 | SYSCALL_FILTER_SET_PROCESS, | |
49 | SYSCALL_FILTER_SET_RAW_IO, | |
bd2ab3f4 | 50 | SYSCALL_FILTER_SET_REBOOT, |
133ddbbe | 51 | SYSCALL_FILTER_SET_RESOURCES, |
6eaaeee9 | 52 | SYSCALL_FILTER_SET_SETUID, |
cd0ddf6f | 53 | SYSCALL_FILTER_SET_SIGNAL, |
bd2ab3f4 | 54 | SYSCALL_FILTER_SET_SWAP, |
44898c53 | 55 | SYSCALL_FILTER_SET_SYNC, |
cd0ddf6f | 56 | SYSCALL_FILTER_SET_TIMER, |
8130926d LP |
57 | _SYSCALL_FILTER_SET_MAX |
58 | }; | |
59 | ||
60 | extern const SyscallFilterSet syscall_filter_sets[]; | |
61 | ||
62 | const SyscallFilterSet *syscall_filter_set_find(const char *name); | |
63 | ||
8cfa775f | 64 | int seccomp_filter_set_add(Hashmap *s, bool b, const SyscallFilterSet *set); |
165a31c0 | 65 | |
960e4569 | 66 | int seccomp_add_syscall_filter_item(scmp_filter_ctx *ctx, const char *name, uint32_t action, char **exclude); |
69b1b241 | 67 | |
469830d1 | 68 | int seccomp_load_syscall_filter_set(uint32_t default_action, const SyscallFilterSet *set, uint32_t action); |
8cfa775f | 69 | int seccomp_load_syscall_filter_set_raw(uint32_t default_action, Hashmap* set, uint32_t action); |
add00535 | 70 | |
13d92c63 LP |
71 | typedef enum SeccompParseFlags { |
72 | SECCOMP_PARSE_INVERT = 1U << 0, | |
73 | SECCOMP_PARSE_WHITELIST = 1U << 1, | |
74 | SECCOMP_PARSE_LOG = 1U << 2, | |
75 | SECCOMP_PARSE_PERMISSIVE = 1U << 3, | |
76 | } SeccompParseFlags; | |
77 | ||
78 | int seccomp_parse_syscall_filter_full( | |
79 | const char *name, int errno_num, Hashmap *filter, SeccompParseFlags flags, | |
80 | const char *unit, const char *filename, unsigned line); | |
81 | ||
82 | static inline int seccomp_parse_syscall_filter(const char *name, int errno_num, Hashmap *filter, SeccompParseFlags flags) { | |
83 | return seccomp_parse_syscall_filter_full(name, errno_num, filter, flags, NULL, NULL, 0); | |
898748d8 YW |
84 | } |
85 | ||
469830d1 | 86 | int seccomp_restrict_archs(Set *archs); |
add00535 | 87 | int seccomp_restrict_namespaces(unsigned long retain); |
469830d1 LP |
88 | int seccomp_protect_sysctl(void); |
89 | int seccomp_restrict_address_families(Set *address_families, bool whitelist); | |
90 | int seccomp_restrict_realtime(void); | |
91 | int seccomp_memory_deny_write_execute(void); | |
78e864e5 | 92 | int seccomp_lock_personality(unsigned long personality); |
469830d1 LP |
93 | |
94 | extern const uint32_t seccomp_local_archs[]; | |
95 | ||
96 | #define SECCOMP_FOREACH_LOCAL_ARCH(arch) \ | |
97 | for (unsigned _i = ({ (arch) = seccomp_local_archs[0]; 0; }); \ | |
98 | seccomp_local_archs[_i] != (uint32_t) -1; \ | |
99 | (arch) = seccomp_local_archs[++_i]) | |
100 | ||
101 | DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release); | |
b16bd535 YW |
102 | |
103 | int parse_syscall_archs(char **l, Set **archs); |