]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/seccomp-util.h
tree-wide: avoid some loaded terms
[thirdparty/systemd.git] / src / shared / seccomp-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
57183d11
LP
2#pragma once
3
a60e9f7f 4#include <seccomp.h>
f6281133 5#include <stdbool.h>
a8fbdf54 6#include <stdint.h>
57183d11 7
469830d1
LP
8#include "set.h"
9
57183d11
LP
10const char* seccomp_arch_to_string(uint32_t c);
11int seccomp_arch_from_string(const char *n, uint32_t *ret);
e9642be2 12
469830d1 13int seccomp_init_for_arch(scmp_filter_ctx *ret, uint32_t arch, uint32_t default_action);
201c1cc2 14
83f12b27
FS
15bool is_seccomp_available(void);
16
8130926d
LP
17typedef struct SyscallFilterSet {
18 const char *name;
d5efc18b 19 const char *help;
201c1cc2 20 const char *value;
8130926d
LP
21} SyscallFilterSet;
22
23enum {
40eb6a80
ZJS
24 /* Please leave DEFAULT first, but sort the rest alphabetically */
25 SYSCALL_FILTER_SET_DEFAULT,
44898c53 26 SYSCALL_FILTER_SET_AIO,
133ddbbe 27 SYSCALL_FILTER_SET_BASIC_IO,
44898c53 28 SYSCALL_FILTER_SET_CHOWN,
8130926d
LP
29 SYSCALL_FILTER_SET_CLOCK,
30 SYSCALL_FILTER_SET_CPU_EMULATION,
31 SYSCALL_FILTER_SET_DEBUG,
1a1b13c9 32 SYSCALL_FILTER_SET_FILE_SYSTEM,
8130926d
LP
33 SYSCALL_FILTER_SET_IO_EVENT,
34 SYSCALL_FILTER_SET_IPC,
35 SYSCALL_FILTER_SET_KEYRING,
cd0ddf6f 36 SYSCALL_FILTER_SET_MEMLOCK,
8130926d
LP
37 SYSCALL_FILTER_SET_MODULE,
38 SYSCALL_FILTER_SET_MOUNT,
39 SYSCALL_FILTER_SET_NETWORK_IO,
40 SYSCALL_FILTER_SET_OBSOLETE,
9493b168 41 SYSCALL_FILTER_SET_PKEY,
8130926d
LP
42 SYSCALL_FILTER_SET_PRIVILEGED,
43 SYSCALL_FILTER_SET_PROCESS,
44 SYSCALL_FILTER_SET_RAW_IO,
bd2ab3f4 45 SYSCALL_FILTER_SET_REBOOT,
133ddbbe 46 SYSCALL_FILTER_SET_RESOURCES,
6eaaeee9 47 SYSCALL_FILTER_SET_SETUID,
cd0ddf6f 48 SYSCALL_FILTER_SET_SIGNAL,
bd2ab3f4 49 SYSCALL_FILTER_SET_SWAP,
44898c53 50 SYSCALL_FILTER_SET_SYNC,
70526841 51 SYSCALL_FILTER_SET_SYSTEM_SERVICE,
cd0ddf6f 52 SYSCALL_FILTER_SET_TIMER,
8130926d
LP
53 _SYSCALL_FILTER_SET_MAX
54};
55
56extern const SyscallFilterSet syscall_filter_sets[];
57
58const SyscallFilterSet *syscall_filter_set_find(const char *name);
59
8cfa775f 60int seccomp_filter_set_add(Hashmap *s, bool b, const SyscallFilterSet *set);
165a31c0 61
b54f36c6 62int seccomp_add_syscall_filter_item(scmp_filter_ctx *ctx, const char *name, uint32_t action, char **exclude, bool log_missing);
69b1b241 63
b54f36c6
ZJS
64int seccomp_load_syscall_filter_set(uint32_t default_action, const SyscallFilterSet *set, uint32_t action, bool log_missing);
65int seccomp_load_syscall_filter_set_raw(uint32_t default_action, Hashmap* set, uint32_t action, bool log_missing);
add00535 66
13d92c63 67typedef enum SeccompParseFlags {
ef31828d 68 SECCOMP_PARSE_INVERT = 1 << 0,
6b000af4 69 SECCOMP_PARSE_ALLOW_LIST = 1 << 1,
ef31828d
LP
70 SECCOMP_PARSE_LOG = 1 << 2,
71 SECCOMP_PARSE_PERMISSIVE = 1 << 3,
13d92c63
LP
72} SeccompParseFlags;
73
58f6ab44
ZJS
74int seccomp_parse_syscall_filter(
75 const char *name,
76 int errno_num,
77 Hashmap *filter,
78 SeccompParseFlags flags,
79 const char *unit,
80 const char *filename, unsigned line);
898748d8 81
469830d1 82int seccomp_restrict_archs(Set *archs);
add00535 83int seccomp_restrict_namespaces(unsigned long retain);
469830d1 84int seccomp_protect_sysctl(void);
620dbdd2 85int seccomp_protect_syslog(void);
6b000af4 86int seccomp_restrict_address_families(Set *address_families, bool allow_list);
469830d1
LP
87int seccomp_restrict_realtime(void);
88int seccomp_memory_deny_write_execute(void);
78e864e5 89int seccomp_lock_personality(unsigned long personality);
aecd5ac6 90int seccomp_protect_hostname(void);
3c27973b 91int seccomp_restrict_suid_sgid(void);
469830d1
LP
92
93extern const uint32_t seccomp_local_archs[];
94
95#define SECCOMP_FOREACH_LOCAL_ARCH(arch) \
96 for (unsigned _i = ({ (arch) = seccomp_local_archs[0]; 0; }); \
97 seccomp_local_archs[_i] != (uint32_t) -1; \
98 (arch) = seccomp_local_archs[++_i])
99
7bc5e0b1
AZ
100/* EACCES: does not have the CAP_SYS_ADMIN or no_new_privs == 1
101 * ENOMEM: out of memory, failed to allocate space for a libseccomp structure, or would exceed a defined constant
102 * EFAULT: addresses passed as args (by libseccomp) are invalid */
103#define ERRNO_IS_SECCOMP_FATAL(r) \
104 IN_SET(abs(r), EPERM, EACCES, ENOMEM, EFAULT)
105
469830d1 106DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release);
b16bd535 107
de7fef4b 108int parse_syscall_archs(char **l, Set **ret_archs);
915fb324
LP
109
110uint32_t scmp_act_kill_process(void);