Blame

Date:
Sat Mar 19 11:02:42 2022 UTC
Message:
const-ify some tables matches found with % grep -R '=[ ]*{' . | fgrep -v const

001
2021-01-23
op
/*
002
2021-01-23
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
003
2021-01-23
op
*
004
2021-01-23
op
* Permission to use, copy, modify, and distribute this software for any
005
2021-01-23
op
* purpose with or without fee is hereby granted, provided that the above
006
2021-01-23
op
* copyright notice and this permission notice appear in all copies.
007
2021-01-23
op
*
008
2021-01-23
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
009
2021-01-23
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
010
2021-01-23
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
011
2021-01-23
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
012
2021-01-23
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
013
2021-01-23
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
014
2021-01-23
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
015
2021-01-23
op
*/
016
2021-01-23
op
017
2021-01-15
op
#include "gmid.h"
018
2021-01-15
op
019
2021-07-02
op
#if DISABLE_SANDBOX
020
2021-01-15
op
021
2021-07-02
op
#warning "Sandbox disabled! Please report issues upstream instead of disabling the sandbox."
022
2021-07-02
op
023
2021-07-02
op
void
024
2021-07-02
op
sandbox_server_process(void)
025
2021-07-02
op
{
026
2021-07-02
op
return;
027
2021-07-02
op
}
028
2021-07-02
op
029
2021-07-02
op
void
030
2021-07-02
op
sandbox_executor_process(void)
031
2021-07-02
op
{
032
2021-10-18
op
log_notice(NULL, "Sandbox disabled! "
033
2021-07-02
op
"Please report issues upstream instead of disabling the sandbox.");
034
2021-07-02
op
}
035
2021-07-02
op
036
2021-07-02
op
void
037
2021-07-02
op
sandbox_logger_process(void)
038
2021-07-02
op
{
039
2021-07-02
op
return;
040
2021-07-02
op
}
041
2021-07-02
op
042
2021-07-02
op
#elif defined(__FreeBSD__)
043
2021-07-02
op
044
2021-01-15
op
#include <sys/capsicum.h>
045
2021-01-15
op
046
2021-01-15
op
void
047
2021-03-20
op
sandbox_server_process(void)
048
2021-01-15
op
{
049
2021-01-15
op
if (cap_enter() == -1)
050
2021-02-11
op
fatal("cap_enter");
051
2021-01-15
op
}
052
2021-01-15
op
053
2021-03-20
op
void
054
2021-03-20
op
sandbox_executor_process(void)
055
2021-03-20
op
{
056
2021-07-07
op
/*
057
2021-07-07
op
* We cannot capsicum the executor process because it needs to
058
2021-07-07
op
* fork(2)+execve(2) cgi scripts
059
2021-07-07
op
*/
060
2021-03-20
op
return;
061
2021-03-20
op
}
062
2021-03-20
op
063
2021-03-20
op
void
064
2021-03-20
op
sandbox_logger_process(void)
065
2021-03-20
op
{
066
2021-03-20
op
if (cap_enter() == -1)
067
2021-03-20
op
fatal("cap_enter");
068
2021-03-20
op
}
069
2021-03-20
op
070
2021-01-15
op
#elif defined(__linux__)
071
2021-01-15
op
072
2021-09-26
op
#include <sys/ioctl.h>
073
2021-01-17
op
#include <sys/prctl.h>
074
2021-01-17
op
#include <sys/syscall.h>
075
2021-01-17
op
#include <sys/syscall.h>
076
2021-01-17
op
#include <sys/types.h>
077
2021-01-17
op
078
2021-01-17
op
#include <linux/audit.h>
079
2021-01-17
op
#include <linux/filter.h>
080
2021-01-17
op
#include <linux/seccomp.h>
081
2021-01-17
op
082
2021-01-17
op
#include <errno.h>
083
2021-01-20
op
#include <fcntl.h>
084
2021-01-17
op
#include <stddef.h>
085
2021-01-17
op
#include <stdio.h>
086
2021-01-17
op
#include <string.h>
087
2021-09-19
op
088
2021-09-19
op
#if HAVE_LANDLOCK
089
2021-09-19
op
# include "landlock_shim.h"
090
2021-09-19
op
#endif
091
2021-01-17
op
092
2021-07-02
op
/* uncomment to enable debugging. ONLY FOR DEVELOPMENT */
093
2021-07-02
op
/* #define SC_DEBUG */
094
2021-07-02
op
095
2021-07-02
op
#ifdef SC_DEBUG
096
2021-07-02
op
# define SC_FAIL SECCOMP_RET_TRAP
097
2021-07-02
op
#else
098
2021-07-02
op
# define SC_FAIL SECCOMP_RET_KILL
099
2021-07-02
op
#endif
100
2021-07-02
op
101
2021-07-02
op
#if (BYTE_ORDER == LITTLE_ENDIAN)
102
2021-07-02
op
# define SC_ARG_LO 0
103
2021-07-02
op
# define SC_ARG_HI sizeof(uint32_t)
104
2021-07-02
op
#elif (BYTE_ORDER == BIG_ENDIAN)
105
2021-07-02
op
# define SC_ARG_LO sizeof(uint32_t)
106
2021-07-02
op
# define SC_ARG_HI 0
107
2021-07-02
op
#else
108
2021-07-02
op
# error "Uknown endian"
109
2021-07-02
op
#endif
110
2021-07-02
op
111
2021-07-02
op
/* make the filter more readable */
112
2021-07-02
op
#define SC_ALLOW(nr) \
113
2021-07-02
op
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_##nr, 0, 1), \
114
2021-07-02
op
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW)
115
2021-07-02
op
116
2021-07-02
op
/*
117
2021-07-02
op
* SC_ALLOW_ARG and the SECCOMP_AUDIT_ARCH below are courtesy of
118
2021-07-02
op
* https://roy.marples.name/git/dhcpcd/blob/HEAD:/src/privsep-linux.c
119
2021-07-02
op
*/
120
2021-07-02
op
#define SC_ALLOW_ARG(_nr, _arg, _val) \
121
2021-07-02
op
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (_nr), 0, 6), \
122
2021-07-02
op
BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
123
2021-07-02
op
offsetof(struct seccomp_data, args[(_arg)]) + SC_ARG_LO), \
124
2021-07-02
op
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, \
125
2021-07-02
op
((_val) & 0xffffffff), 0, 3), \
126
2021-07-02
op
BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
127
2021-07-02
op
offsetof(struct seccomp_data, args[(_arg)]) + SC_ARG_HI), \
128
2021-07-02
op
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, \
129
2021-07-02
op
(((uint32_t)((uint64_t)(_val) >> 32)) & 0xffffffff), 0, 1), \
130
2021-07-02
op
BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), \
131
2021-07-02
op
BPF_STMT(BPF_LD + BPF_W + BPF_ABS, \
132
2021-07-02
op
offsetof(struct seccomp_data, nr))
133
2021-07-02
op
134
2021-07-02
op
/*
135
2021-07-02
op
* I personally find this quite nutty. Why can a system header not
136
2021-07-02
op
* define a default for this?
137
2021-07-02
op
*/
138
2021-01-17
op
#if defined(__i386__)
139
2021-01-17
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_I386
140
2021-01-17
op
#elif defined(__x86_64__)
141
2021-01-17
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_X86_64
142
2021-07-02
op
#elif defined(__arc__)
143
2021-07-02
op
# if defined(__A7__)
144
2021-07-02
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
145
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCOMPACT
146
2021-07-02
op
# else
147
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCOMPACTBE
148
2021-07-02
op
# endif
149
2021-07-02
op
# elif defined(__HS__)
150
2021-07-02
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
151
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV2
152
2021-07-02
op
# else
153
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARCV2BE
154
2021-07-02
op
# endif
155
2021-07-02
op
# else
156
2021-07-02
op
# error "Platform does not support seccomp filter yet"
157
2021-07-02
op
# endif
158
2021-01-17
op
#elif defined(__arm__)
159
2021-07-02
op
# ifndef EM_ARM
160
2021-07-02
op
# define EM_ARM 40
161
2021-07-02
op
# endif
162
2021-07-02
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
163
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARM
164
2021-07-02
op
# else
165
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARMEB
166
2021-07-02
op
# endif
167
2021-01-17
op
#elif defined(__aarch64__)
168
2021-01-17
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_AARCH64
169
2021-07-02
op
#elif defined(__alpha__)
170
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ALPHA
171
2021-07-02
op
#elif defined(__hppa__)
172
2021-07-02
op
# if defined(__LP64__)
173
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PARISC64
174
2021-07-02
op
# else
175
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PARISC
176
2021-07-02
op
# endif
177
2021-07-02
op
#elif defined(__ia64__)
178
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_IA64
179
2021-07-02
op
#elif defined(__microblaze__)
180
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MICROBLAZE
181
2021-07-02
op
#elif defined(__m68k__)
182
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_M68K
183
2021-01-17
op
#elif defined(__mips__)
184
2021-07-02
op
# if defined(__MIPSEL__)
185
2021-07-02
op
# if defined(__LP64__)
186
2021-01-17
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPSEL64
187
2021-07-02
op
# else
188
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPSEL
189
2021-01-17
op
# endif
190
2021-07-02
op
# elif defined(__LP64__)
191
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPS64
192
2021-01-17
op
# else
193
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_MIPS
194
2021-07-02
op
# endif
195
2021-07-02
op
#elif defined(__nds32__)
196
2021-07-02
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
197
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NDS32
198
2021-07-02
op
#else
199
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NDS32BE
200
2021-07-02
op
#endif
201
2021-07-02
op
#elif defined(__nios2__)
202
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_NIOS2
203
2021-07-02
op
#elif defined(__or1k__)
204
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_OPENRISC
205
2021-07-02
op
#elif defined(__powerpc64__)
206
2021-07-03
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
207
2021-07-03
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC64LE
208
2021-07-03
op
# else
209
2021-07-03
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC64
210
2021-07-03
op
# endif
211
2021-07-02
op
#elif defined(__powerpc__)
212
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_PPC
213
2021-07-02
op
#elif defined(__riscv)
214
2021-07-02
op
# if defined(__LP64__)
215
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_RISCV64
216
2021-07-02
op
# else
217
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_RISCV32
218
2021-07-02
op
# endif
219
2021-07-02
op
#elif defined(__s390x__)
220
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_S390X
221
2021-07-02
op
#elif defined(__s390__)
222
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_S390
223
2021-07-02
op
#elif defined(__sh__)
224
2021-07-02
op
# if defined(__LP64__)
225
2021-07-02
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
226
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SHEL64
227
2021-01-17
op
# else
228
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SH64
229
2021-01-17
op
# endif
230
2021-07-02
op
# else
231
2021-07-02
op
# if (BYTE_ORDER == LITTLE_ENDIAN)
232
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SHEL
233
2021-07-02
op
# else
234
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SH
235
2021-07-02
op
# endif
236
2021-01-17
op
# endif
237
2021-07-02
op
#elif defined(__sparc__)
238
2021-07-02
op
# if defined(__arch64__)
239
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SPARC64
240
2021-07-02
op
# else
241
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_SPARC
242
2021-07-02
op
# endif
243
2021-07-02
op
#elif defined(__xtensa__)
244
2021-07-02
op
# define SECCOMP_AUDIT_ARCH AUDIT_ARCH_XTENSA
245
2021-01-17
op
#else
246
2021-01-17
op
# error "Platform does not support seccomp filter yet"
247
2021-01-17
op
#endif
248
2021-01-17
op
249
2022-03-19
op
static const struct sock_filter filter[] = {
250
2021-07-02
op
/* load the *current* architecture */
251
2021-07-02
op
BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
252
2021-07-02
op
(offsetof(struct seccomp_data, arch))),
253
2021-07-02
op
/* ensure it's the same that we've been compiled on */
254
2021-07-02
op
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K,
255
2021-07-02
op
SECCOMP_AUDIT_ARCH, 1, 0),
256
2021-07-02
op
/* if not, kill the program */
257
2021-07-02
op
BPF_STMT(BPF_RET | BPF_K, SC_FAIL),
258
2021-01-17
op
259
2021-07-02
op
/* load the syscall number */
260
2021-07-02
op
BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
261
2021-07-02
op
(offsetof(struct seccomp_data, nr))),
262
2021-07-02
op
263
2021-07-02
op
#ifdef __NR_accept
264
2021-07-02
op
SC_ALLOW(accept),
265
2021-07-02
op
#endif
266
2021-07-02
op
#ifdef __NR_accept4
267
2021-07-02
op
SC_ALLOW(accept4),
268
2021-07-02
op
#endif
269
2021-07-02
op
#ifdef __NR_brk
270
2021-07-02
op
SC_ALLOW(brk),
271
2021-07-02
op
#endif
272
2021-07-02
op
#ifdef __NR_clock_gettime
273
2021-07-02
op
SC_ALLOW(clock_gettime),
274
2021-07-02
op
#endif
275
2021-07-02
op
#if defined(__x86_64__) && defined(__ILP32__) && defined(__X32_SYSCALL_BIT)
276
2021-07-02
op
SECCOMP_ALLOW(__NR_clock_gettime & ~__X32_SYSCALL_BIT),
277
2021-07-02
op
#endif
278
2021-07-02
op
#ifdef __NR_clock_gettime64
279
2021-07-02
op
SC_ALLOW(clock_gettime64),
280
2021-07-02
op
#endif
281
2021-07-02
op
#ifdef __NR_close
282
2021-07-02
op
SC_ALLOW(close),
283
2021-07-02
op
#endif
284
2021-07-02
op
#ifdef __NR_epoll_ctl
285
2021-07-02
op
SC_ALLOW(epoll_ctl),
286
2021-07-02
op
#endif
287
2021-07-02
op
#ifdef __NR_epoll_pwait
288
2021-07-02
op
SC_ALLOW(epoll_pwait),
289
2021-07-02
op
#endif
290
2021-07-02
op
#ifdef __NR_epoll_wait
291
2021-07-02
op
SC_ALLOW(epoll_wait),
292
2021-01-17
op
#endif
293
2021-07-02
op
#ifdef __NR_exit
294
2021-07-02
op
SC_ALLOW(exit),
295
2021-07-02
op
#endif
296
2021-07-02
op
#ifdef __NR_exit_group
297
2021-07-02
op
SC_ALLOW(exit_group),
298
2021-07-02
op
#endif
299
2021-07-02
op
#ifdef __NR_fcntl
300
2021-07-02
op
SC_ALLOW(fcntl),
301
2021-07-02
op
#endif
302
2021-07-02
op
#ifdef __NR_fcntl64
303
2021-07-02
op
SC_ALLOW(fcntl64),
304
2021-07-02
op
#endif
305
2021-07-02
op
#ifdef __NR_fstat
306
2021-07-02
op
SC_ALLOW(fstat),
307
2021-07-02
op
#endif
308
2021-07-23
op
#ifdef __NR_fstat64
309
2021-07-23
op
SC_ALLOW(fstat64),
310
2022-02-13
op
#endif
311
2022-02-13
op
#ifdef __NR_fstatat64
312
2022-02-13
op
SC_ALLOW(fstatat64),
313
2021-07-23
op
#endif
314
2021-07-02
op
#ifdef __NR_getdents64
315
2021-07-02
op
SC_ALLOW(getdents64),
316
2021-07-02
op
#endif
317
2021-07-02
op
#ifdef __NR_getpid
318
2021-07-02
op
SC_ALLOW(getpid),
319
2021-07-02
op
#endif
320
2021-07-02
op
#ifdef __NR_getrandom
321
2021-07-02
op
SC_ALLOW(getrandom),
322
2021-07-02
op
#endif
323
2021-07-02
op
#ifdef __NR_gettimeofday
324
2021-07-02
op
SC_ALLOW(gettimeofday),
325
2021-07-02
op
#endif
326
2021-07-02
op
#ifdef __NR_ioctl
327
2021-09-26
op
/* allow ioctl on fd 1, glibc doing stuff? */
328
2021-10-18
op
SC_ALLOW_ARG(__NR_ioctl, 0, 1),
329
2021-09-26
op
/* allow FIONREAD needed by libevent */
330
2021-09-26
op
SC_ALLOW_ARG(__NR_ioctl, 1, FIONREAD),
331
2021-07-02
op
#endif
332
2022-02-13
op
#ifdef __NR__llseek
333
2022-02-13
op
SC_ALLOW(_llseek),
334
2022-02-13
op
#endif
335
2021-07-02
op
#ifdef __NR_lseek
336
2021-07-02
op
SC_ALLOW(lseek),
337
2021-07-02
op
#endif
338
2021-07-02
op
#ifdef __NR_madvise
339
2021-07-02
op
SC_ALLOW(madvise),
340
2021-07-02
op
#endif
341
2021-07-02
op
#ifdef __NR_mmap
342
2021-07-02
op
SC_ALLOW(mmap),
343
2021-07-02
op
#endif
344
2021-07-02
op
#ifdef __NR_mmap2
345
2021-07-02
op
SC_ALLOW(mmap2),
346
2021-07-02
op
#endif
347
2021-07-02
op
#ifdef __NR_munmap
348
2021-07-02
op
SC_ALLOW(munmap),
349
2021-07-02
op
#endif
350
2021-07-02
op
#ifdef __NR_newfstatat
351
2021-07-02
op
SC_ALLOW(newfstatat),
352
2021-07-02
op
#endif
353
2021-07-02
op
#ifdef __NR_oldfstat
354
2021-07-02
op
SC_ALLOW(oldfstat),
355
2021-07-02
op
#endif
356
2021-07-02
op
#ifdef __NR_openat
357
2022-02-13
op
SC_ALLOW_ARG(__NR_openat, 3, O_RDONLY),
358
2021-07-02
op
#endif
359
2021-07-02
op
#ifdef __NR_prlimit64
360
2021-07-02
op
SC_ALLOW(prlimit64),
361
2021-07-02
op
#endif
362
2021-07-02
op
#ifdef __NR_read
363
2021-07-02
op
SC_ALLOW(read),
364
2021-07-02
op
#endif
365
2021-07-02
op
#ifdef __NR_recvmsg
366
2021-07-02
op
SC_ALLOW(recvmsg),
367
2021-07-02
op
#endif
368
2021-07-23
op
#ifdef __NR_readv
369
2021-07-23
op
SC_ALLOW(readv),
370
2021-07-02
op
#endif
371
2021-07-02
op
#ifdef __NR_rt_sigaction
372
2021-07-02
op
SC_ALLOW(rt_sigaction),
373
2021-07-02
op
#endif
374
2021-07-02
op
#ifdef __NR_rt_sigreturn
375
2021-07-02
op
SC_ALLOW(rt_sigreturn),
376
2021-07-02
op
#endif
377
2021-07-02
op
#ifdef __NR_sendmsg
378
2021-07-02
op
SC_ALLOW(sendmsg),
379
2021-07-02
op
#endif
380
2022-02-13
op
#ifdef __NR_sigreturn
381
2022-02-13
op
SC_ALLOW(sigreturn),
382
2022-02-13
op
#endif
383
2021-07-02
op
#ifdef __NR_statx
384
2021-07-02
op
SC_ALLOW(statx),
385
2021-07-02
op
#endif
386
2021-12-11
vdrummer
#ifdef __NR_ugetrlimit
387
2021-12-11
vdrummer
SC_ALLOW(ugetrlimit),
388
2021-12-11
vdrummer
#endif
389
2021-07-02
op
#ifdef __NR_write
390
2021-07-02
op
SC_ALLOW(write),
391
2021-07-02
op
#endif
392
2021-07-02
op
#ifdef __NR_writev
393
2021-07-02
op
SC_ALLOW(writev),
394
2021-07-02
op
#endif
395
2021-01-17
op
396
2021-07-03
op
/* disallow everything else */
397
2021-07-02
op
BPF_STMT(BPF_RET | BPF_K, SC_FAIL),
398
2021-07-02
op
};
399
2021-01-17
op
400
2021-01-17
op
#ifdef SC_DEBUG
401
2021-01-17
op
402
2021-01-17
op
#include <signal.h>
403
2021-01-17
op
#include <unistd.h>
404
2021-01-17
op
405
2021-01-17
op
static void
406
2021-01-17
op
sandbox_seccomp_violation(int signum, siginfo_t *info, void *ctx)
407
2021-01-17
op
{
408
2021-01-17
op
fprintf(stderr, "%s: unexpected system call (arch:0x%x,syscall:%d @ %p)\n",
409
2021-01-17
op
__func__, info->si_arch, info->si_syscall, info->si_call_addr);
410
2021-01-17
op
_exit(1);
411
2021-01-17
op
}
412
2021-01-17
op
413
2021-01-17
op
static void
414
2021-01-17
op
sandbox_seccomp_catch_sigsys(void)
415
2021-01-17
op
{
416
2021-01-17
op
struct sigaction act;
417
2021-01-17
op
sigset_t mask;
418
2021-01-17
op
419
2021-01-17
op
memset(&act, 0, sizeof(act));
420
2021-01-17
op
sigemptyset(&mask);
421
2021-01-17
op
sigaddset(&mask, SIGSYS);
422
2021-01-17
op
423
2021-01-17
op
act.sa_sigaction = &sandbox_seccomp_violation;
424
2021-01-17
op
act.sa_flags = SA_SIGINFO;
425
2021-02-11
op
if (sigaction(SIGSYS, &act, NULL) == -1)
426
2021-02-11
op
fatal("%s: sigaction(SIGSYS): %s",
427
2021-01-17
op
__func__, strerror(errno));
428
2021-02-11
op
429
2021-02-11
op
if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)
430
2021-02-11
op
fatal("%s: sigprocmask(SIGSYS): %s\n",
431
2021-01-17
op
__func__, strerror(errno));
432
2021-01-17
op
}
433
2021-01-17
op
#endif /* SC_DEBUG */
434
2021-09-19
op
435
2021-09-19
op
#if HAVE_LANDLOCK
436
2021-09-19
op
static inline int
437
2021-09-25
op
open_landlock(void)
438
2021-09-19
op
{
439
2021-09-19
op
int fd;
440
2021-09-19
op
441
2022-03-19
op
const struct landlock_ruleset_attr attr = {
442
2022-02-10
op
.handled_access_fs = LANDLOCK_ACCESS_FS_EXECUTE |
443
2022-02-10
op
LANDLOCK_ACCESS_FS_READ_FILE |
444
2022-02-10
op
LANDLOCK_ACCESS_FS_READ_DIR |
445
2022-02-10
op
LANDLOCK_ACCESS_FS_WRITE_FILE |
446
2022-02-10
op
LANDLOCK_ACCESS_FS_REMOVE_DIR |
447
2022-02-10
op
LANDLOCK_ACCESS_FS_REMOVE_FILE |
448
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_CHAR |
449
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_DIR |
450
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_REG |
451
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_SOCK |
452
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_FIFO |
453
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
454
2022-02-10
op
LANDLOCK_ACCESS_FS_MAKE_SYM,
455
2021-09-25
op
};
456
2021-09-25
op
457
2021-09-25
op
fd = landlock_create_ruleset(&attr, sizeof(attr), 0);
458
2021-09-19
op
if (fd == -1) {
459
2021-09-19
op
switch (errno) {
460
2021-09-19
op
case ENOSYS:
461
2021-09-19
op
fatal("%s: failed to create ruleset. "
462
2021-09-19
op
"Landlock doesn't seem to be supported by the "
463
2021-09-19
op
"current kernel.", __func__);
464
2021-09-19
op
case EOPNOTSUPP:
465
2021-09-19
op
log_warn(NULL, "%s: failed to create ruleset. "
466
2021-09-19
op
"Landlock seems to be currently disabled; "
467
2021-09-19
op
"continuing without it.", __func__);
468
2021-09-19
op
break;
469
2021-09-19
op
default:
470
2021-09-19
op
fatal("%s: failed to create ruleset: %s",
471
2021-09-19
op
__func__, strerror(errno));
472
2021-09-19
op
}
473
2021-09-19
op
}
474
2021-09-19
op
475
2021-09-19
op
return fd;
476
2021-09-25
op
}
477
2021-09-25
op
478
2021-09-25
op
static int
479
2021-09-25
op
landlock_unveil_path(int landlock_fd, const char *path, int perms)
480
2021-09-25
op
{
481
2021-09-25
op
struct landlock_path_beneath_attr pb;
482
2021-09-25
op
int err, saved_errno;
483
2021-09-25
op
484
2021-09-25
op
pb.allowed_access = perms;
485
2021-09-25
op
486
2021-09-25
op
if ((pb.parent_fd = open(path, O_PATH)) == -1)
487
2021-09-25
op
return -1;
488
2021-09-25
op
489
2021-09-25
op
err = landlock_add_rule(landlock_fd, LANDLOCK_RULE_PATH_BENEATH,
490
2021-09-25
op
&pb, 0);
491
2021-09-25
op
saved_errno = errno;
492
2021-09-25
op
close(pb.parent_fd);
493
2021-09-25
op
errno = saved_errno;
494
2021-09-25
op
return err ? -1 : 0;
495
2021-09-25
op
}
496
2021-09-25
op
497
2021-09-25
op
static int
498
2021-09-25
op
landlock_apply(int fd)
499
2021-09-25
op
{
500
2021-09-25
op
int r, saved_errno;
501
2021-09-25
op
502
2021-09-25
op
if (fd == -1)
503
2021-09-25
op
return 0;
504
2021-09-25
op
505
2021-09-25
op
r = landlock_restrict_self(fd, 0);
506
2021-09-25
op
saved_errno = errno;
507
2021-09-25
op
close(fd);
508
2021-09-25
op
errno = saved_errno;
509
2021-09-25
op
return r ? -1 : 0;
510
2021-09-19
op
}
511
2021-09-19
op
512
2021-09-19
op
static int
513
2021-09-19
op
server_landlock(void)
514
2021-09-19
op
{
515
2021-09-25
op
int fd, perms;
516
2021-09-19
op
struct vhost *h;
517
2021-09-19
op
struct location *l;
518
2021-01-17
op
519
2021-09-19
op
/*
520
2021-09-19
op
* These are all the actions allowed for the root directories
521
2021-09-25
op
* of the vhosts.
522
2021-09-19
op
*/
523
2021-09-25
op
perms = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR;
524
2021-09-19
op
525
2021-09-25
op
if ((fd = open_landlock()) == -1)
526
2021-09-25
op
return 0;
527
2021-09-19
op
528
2021-09-19
op
TAILQ_FOREACH(h, &hosts, vhosts) {
529
2021-09-19
op
TAILQ_FOREACH(l, &h->locations, locations) {
530
2021-09-19
op
if (l->dir == NULL)
531
2021-09-19
op
continue;
532
2021-09-19
op
533
2021-09-25
op
if (landlock_unveil_path(fd, l->dir, perms) == -1)
534
2021-09-25
op
fatal("%s: landlock_unveil_path(%s): %s",
535
2021-09-19
op
__func__, l->dir, strerror(errno));
536
2021-09-19
op
}
537
2021-09-19
op
}
538
2021-09-19
op
539
2021-09-25
op
return landlock_apply(fd);
540
2021-09-19
op
}
541
2021-09-19
op
542
2021-09-19
op
static int
543
2021-09-19
op
logger_landlock(void)
544
2021-09-19
op
{
545
2021-09-25
op
int fd;
546
2021-09-19
op
547
2021-09-25
op
if ((fd = open_landlock()) == -1)
548
2021-09-25
op
return 0;
549
2021-09-19
op
550
2021-09-25
op
/* no rules. the logger doesn't need fs access at all. */
551
2021-09-19
op
552
2021-09-25
op
return landlock_apply(fd);
553
2021-09-19
op
}
554
2021-09-19
op
#endif
555
2021-09-19
op
556
2021-01-15
op
void
557
2021-03-20
op
sandbox_server_process(void)
558
2021-01-15
op
{
559
2022-03-19
op
const struct sock_fprog prog = {
560
2021-01-17
op
.len = (unsigned short) (sizeof(filter) / sizeof(filter[0])),
561
2021-01-17
op
.filter = filter,
562
2021-01-17
op
};
563
2021-01-17
op
564
2021-01-17
op
#ifdef SC_DEBUG
565
2021-01-17
op
sandbox_seccomp_catch_sigsys();
566
2021-01-17
op
#endif
567
2021-01-17
op
568
2021-02-11
op
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
569
2021-02-11
op
fatal("%s: prctl(PR_SET_NO_NEW_PRIVS): %s",
570
2021-01-17
op
__func__, strerror(errno));
571
2021-01-17
op
572
2021-09-19
op
#if HAVE_LANDLOCK
573
2021-09-25
op
if (server_landlock() == -1)
574
2021-09-25
op
fatal("%s: server_landlock: %s",
575
2021-09-25
op
__func__, strerror(errno));
576
2021-09-19
op
#endif
577
2021-09-19
op
578
2021-02-11
op
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) == -1)
579
2021-02-11
op
fatal("%s: prctl(PR_SET_SECCOMP): %s\n",
580
2021-01-17
op
__func__, strerror(errno));
581
2021-01-15
op
}
582
2021-01-15
op
583
2021-03-20
op
void
584
2021-03-20
op
sandbox_executor_process(void)
585
2021-03-20
op
{
586
2021-07-07
op
/*
587
2021-07-07
op
* We cannot use seccomp for the executor process because we
588
2021-03-20
op
* don't know what the child will do. Also, our filter will
589
2021-03-20
op
* be inherited so the child cannot set its own seccomp
590
2021-07-07
op
* policy.
591
2021-07-07
op
*/
592
2021-03-20
op
return;
593
2021-03-20
op
}
594
2021-03-20
op
595
2021-03-20
op
void
596
2021-03-20
op
sandbox_logger_process(void)
597
2021-03-20
op
{
598
2021-07-07
op
/*
599
2021-09-19
op
* Here we could use a seccomp filter to allow only recvfd,
600
2021-09-19
op
* write/writev and memory allocations, but syslog is a beast
601
2021-09-19
op
* and I don't know what syscalls it could end up doing.
602
2021-09-19
op
* Landlock is a simpler beast, use it to disallow any file
603
2021-09-19
op
* sytsem access.
604
2021-07-07
op
*/
605
2021-10-02
op
606
2021-10-02
op
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
607
2021-10-02
op
fatal("%s: prctl(PR_SET_NO_NEW_PRIVS): %s",
608
2021-10-02
op
__func__, strerror(errno));
609
2021-09-19
op
610
2021-09-19
op
#if HAVE_LANDLOCK
611
2021-09-25
op
if (logger_landlock() == -1)
612
2021-09-25
op
fatal("%s: logger_landlock: %s",
613
2021-09-19
op
__func__, strerror(errno));
614
2021-09-19
op
#endif
615
2021-09-19
op
616
2021-03-20
op
return;
617
2021-03-20
op
}
618
2021-03-20
op
619
2021-01-15
op
#elif defined(__OpenBSD__)
620
2021-01-15
op
621
2021-01-15
op
#include <unistd.h>
622
2021-01-15
op
623
2021-01-15
op
void
624
2021-03-20
op
sandbox_server_process(void)
625
2021-01-15
op
{
626
2021-04-30
op
struct vhost *h;
627
2021-04-30
op
struct location *l;
628
2021-01-15
op
629
2021-03-31
op
TAILQ_FOREACH(h, &hosts, vhosts) {
630
2021-04-30
op
TAILQ_FOREACH(l, &h->locations, locations) {
631
2021-04-30
op
if (l->dir == NULL)
632
2021-04-30
op
continue;
633
2021-04-30
op
634
2021-04-30
op
if (unveil(l->dir, "r") == -1)
635
2021-04-30
op
fatal("unveil %s for domain %s",
636
2021-04-30
op
l->dir,
637
2021-04-30
op
h->domain);
638
2021-04-30
op
}
639
2021-01-15
op
}
640
2021-01-15
op
641
2021-01-16
op
if (pledge("stdio recvfd rpath inet", NULL) == -1)
642
2021-02-11
op
fatal("pledge");
643
2021-01-15
op
}
644
2021-01-15
op
645
2021-01-15
op
void
646
2021-03-20
op
sandbox_executor_process(void)
647
2021-01-15
op
{
648
2021-03-31
op
struct vhost *h;
649
2021-04-30
op
struct location *l;
650
2021-05-09
op
struct fcgi *f;
651
2021-05-09
op
size_t i;
652
2021-03-20
op
653
2021-03-31
op
TAILQ_FOREACH(h, &hosts, vhosts) {
654
2021-04-30
op
TAILQ_FOREACH(l, &h->locations, locations) {
655
2021-04-30
op
if (l->dir == NULL)
656
2021-04-30
op
continue;
657
2021-04-30
op
658
2021-07-09
op
/* r so we can chdir into the directory */
659
2021-04-30
op
if (unveil(l->dir, "rx") == -1)
660
2021-04-30
op
fatal("unveil %s for domain %s",
661
2021-04-30
op
l->dir, h->domain);
662
2021-04-30
op
}
663
2021-03-20
op
}
664
2021-03-20
op
665
2021-05-09
op
for (i = 0; i < FCGI_MAX; i++) {
666
2021-10-18
op
f = &fcgi[i];
667
2021-05-09
op
if (f->path != NULL) {
668
2021-05-09
op
if (unveil(f->path, "rw") == -1)
669
2021-05-09
op
fatal("unveil %s", f->path);
670
2021-05-09
op
}
671
2021-05-09
op
672
2021-05-09
op
if (f->prog != NULL) {
673
2021-05-09
op
if (unveil(f->prog, "rx") == -1)
674
2021-05-09
op
fatal("unveil %s", f->prog);
675
2021-05-09
op
}
676
2021-05-09
op
}
677
2021-05-09
op
678
2021-05-09
op
/*
679
2021-05-09
op
* rpath: to chdir into the correct directory
680
2021-05-09
op
* proc exec: CGI
681
2021-05-09
op
* dns inet unix: FastCGI
682
2021-05-09
op
*/
683
2021-05-09
op
if (pledge("stdio rpath sendfd proc exec dns inet unix", NULL))
684
2021-03-20
op
err(1, "pledge");
685
2021-03-20
op
}
686
2021-03-20
op
687
2021-03-20
op
void
688
2021-03-20
op
sandbox_logger_process(void)
689
2021-03-20
op
{
690
2021-06-15
op
if (pledge("stdio recvfd", NULL) == -1)
691
2021-03-20
op
err(1, "pledge");
692
2021-03-20
op
}
693
2021-03-20
op
694
2021-03-20
op
#else
695
2021-03-20
op
696
2021-03-20
op
#warning "No sandbox method known for this OS"
697
2021-03-20
op
698
2021-03-20
op
void
699
2021-03-20
op
sandbox_server_process(void)
700
2021-03-20
op
{
701
2021-03-20
op
return;
702
2021-03-20
op
}
703
2021-03-20
op
704
2021-03-20
op
void
705
2021-03-20
op
sandbox_executor_process(void)
706
2021-03-20
op
{
707
2021-02-11
op
log_notice(NULL, "no sandbox method known for this OS");
708
2021-01-15
op
}
709
2021-01-15
op
710
2021-03-20
op
void
711
2021-03-20
op
sandbox_logger_process(void)
712
2021-03-20
op
{
713
2021-03-20
op
return;
714
2021-03-20
op
}
715
2021-03-20
op
716
2021-01-15
op
#endif