]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/seccomp-util.h
grypt-util: drop two emacs modelines
[thirdparty/systemd.git] / src / shared / seccomp-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2014 Lennart Poettering
6 ***/
7
8 #include <seccomp.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11
12 #include "set.h"
13
14 const char* seccomp_arch_to_string(uint32_t c);
15 int seccomp_arch_from_string(const char *n, uint32_t *ret);
16
17 int seccomp_init_for_arch(scmp_filter_ctx *ret, uint32_t arch, uint32_t default_action);
18
19 bool is_seccomp_available(void);
20
21 typedef struct SyscallFilterSet {
22 const char *name;
23 const char *help;
24 const char *value;
25 } SyscallFilterSet;
26
27 enum {
28 /* Please leave DEFAULT first, but sort the rest alphabetically */
29 SYSCALL_FILTER_SET_DEFAULT,
30 SYSCALL_FILTER_SET_AIO,
31 SYSCALL_FILTER_SET_BASIC_IO,
32 SYSCALL_FILTER_SET_CHOWN,
33 SYSCALL_FILTER_SET_CLOCK,
34 SYSCALL_FILTER_SET_CPU_EMULATION,
35 SYSCALL_FILTER_SET_DEBUG,
36 SYSCALL_FILTER_SET_FILE_SYSTEM,
37 SYSCALL_FILTER_SET_IO_EVENT,
38 SYSCALL_FILTER_SET_IPC,
39 SYSCALL_FILTER_SET_KEYRING,
40 SYSCALL_FILTER_SET_MEMLOCK,
41 SYSCALL_FILTER_SET_MODULE,
42 SYSCALL_FILTER_SET_MOUNT,
43 SYSCALL_FILTER_SET_NETWORK_IO,
44 SYSCALL_FILTER_SET_OBSOLETE,
45 SYSCALL_FILTER_SET_PRIVILEGED,
46 SYSCALL_FILTER_SET_PROCESS,
47 SYSCALL_FILTER_SET_RAW_IO,
48 SYSCALL_FILTER_SET_REBOOT,
49 SYSCALL_FILTER_SET_RESOURCES,
50 SYSCALL_FILTER_SET_SETUID,
51 SYSCALL_FILTER_SET_SIGNAL,
52 SYSCALL_FILTER_SET_SWAP,
53 SYSCALL_FILTER_SET_SYNC,
54 SYSCALL_FILTER_SET_TIMER,
55 _SYSCALL_FILTER_SET_MAX
56 };
57
58 extern const SyscallFilterSet syscall_filter_sets[];
59
60 const SyscallFilterSet *syscall_filter_set_find(const char *name);
61
62 int seccomp_filter_set_add(Hashmap *s, bool b, const SyscallFilterSet *set);
63
64 int seccomp_add_syscall_filter_item(scmp_filter_ctx *ctx, const char *name, uint32_t action, char **exclude);
65
66 int seccomp_load_syscall_filter_set(uint32_t default_action, const SyscallFilterSet *set, uint32_t action);
67 int seccomp_load_syscall_filter_set_raw(uint32_t default_action, Hashmap* set, uint32_t action);
68
69 typedef enum SeccompParseFlags {
70 SECCOMP_PARSE_INVERT = 1 << 0,
71 SECCOMP_PARSE_WHITELIST = 1 << 1,
72 SECCOMP_PARSE_LOG = 1 << 2,
73 SECCOMP_PARSE_PERMISSIVE = 1 << 3,
74 } SeccompParseFlags;
75
76 int seccomp_parse_syscall_filter_full(
77 const char *name, int errno_num, Hashmap *filter, SeccompParseFlags flags,
78 const char *unit, const char *filename, unsigned line);
79
80 static inline int seccomp_parse_syscall_filter(const char *name, int errno_num, Hashmap *filter, SeccompParseFlags flags) {
81 return seccomp_parse_syscall_filter_full(name, errno_num, filter, flags, NULL, NULL, 0);
82 }
83
84 int seccomp_restrict_archs(Set *archs);
85 int seccomp_restrict_namespaces(unsigned long retain);
86 int seccomp_protect_sysctl(void);
87 int seccomp_restrict_address_families(Set *address_families, bool whitelist);
88 int seccomp_restrict_realtime(void);
89 int seccomp_memory_deny_write_execute(void);
90 int seccomp_lock_personality(unsigned long personality);
91
92 extern const uint32_t seccomp_local_archs[];
93
94 #define SECCOMP_FOREACH_LOCAL_ARCH(arch) \
95 for (unsigned _i = ({ (arch) = seccomp_local_archs[0]; 0; }); \
96 seccomp_local_archs[_i] != (uint32_t) -1; \
97 (arch) = seccomp_local_archs[++_i])
98
99 DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release);
100
101 int parse_syscall_archs(char **l, Set **archs);