blob: be23976715fc6533097d7225a82ec44f2da679d7 [file] [log] [blame]
Damien Millere0956e32012-04-04 11:27:54 +10001/*
2 * Copyright (c) 2012 Will Drewry <wad@dataspill.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/*
18 * Uncomment the SANDBOX_SECCOMP_FILTER_DEBUG macro below to help diagnose
19 * filter breakage during development. *Do not* use this in production,
20 * as it relies on making library calls that are unsafe in signal context.
21 *
22 * Instead, live systems the auditctl(8) may be used to monitor failures.
23 * E.g.
24 * auditctl -a task,always -F uid=<privsep uid>
25 */
26/* #define SANDBOX_SECCOMP_FILTER_DEBUG 1 */
27
Damien Miller48abc472014-03-17 14:45:56 +110028/* XXX it should be possible to do logging via the log socket safely */
29
Damien Millere0956e32012-04-04 11:27:54 +100030#ifdef SANDBOX_SECCOMP_FILTER_DEBUG
31/* Use the kernel headers in case of an older toolchain. */
32# include <asm/siginfo.h>
33# define __have_siginfo_t 1
34# define __have_sigval_t 1
35# define __have_sigevent_t 1
36#endif /* SANDBOX_SECCOMP_FILTER_DEBUG */
37
38#include "includes.h"
39
40#ifdef SANDBOX_SECCOMP_FILTER
41
42#include <sys/types.h>
43#include <sys/resource.h>
44#include <sys/prctl.h>
Damien Millerf6906f92019-08-23 10:08:48 +100045#include <sys/mman.h>
Damien Millere0956e32012-04-04 11:27:54 +100046
Damien Miller99f33d72015-06-17 10:50:51 +100047#include <linux/net.h>
Damien Millere0956e32012-04-04 11:27:54 +100048#include <linux/audit.h>
49#include <linux/filter.h>
50#include <linux/seccomp.h>
Damien Miller91f40d82013-02-22 11:37:00 +110051#include <elf.h>
Damien Millere0956e32012-04-04 11:27:54 +100052
53#include <asm/unistd.h>
Damien Miller58b8cfa2017-03-22 12:43:02 +110054#ifdef __s390__
55#include <asm/zcrypt.h>
56#endif
Damien Millere0956e32012-04-04 11:27:54 +100057
58#include <errno.h>
59#include <signal.h>
60#include <stdarg.h>
61#include <stddef.h> /* for offsetof */
62#include <stdio.h>
63#include <stdlib.h>
64#include <string.h>
65#include <unistd.h>
66
67#include "log.h"
68#include "ssh-sandbox.h"
69#include "xmalloc.h"
70
71/* Linux seccomp_filter sandbox */
72#define SECCOMP_FILTER_FAIL SECCOMP_RET_KILL
73
74/* Use a signal handler to emit violations when debugging */
75#ifdef SANDBOX_SECCOMP_FILTER_DEBUG
76# undef SECCOMP_FILTER_FAIL
77# define SECCOMP_FILTER_FAIL SECCOMP_RET_TRAP
78#endif /* SANDBOX_SECCOMP_FILTER_DEBUG */
79
Damien Miller9e96b412017-03-14 12:24:47 +110080#if __BYTE_ORDER == __LITTLE_ENDIAN
81# define ARG_LO_OFFSET 0
82# define ARG_HI_OFFSET sizeof(uint32_t)
83#elif __BYTE_ORDER == __BIG_ENDIAN
84# define ARG_LO_OFFSET sizeof(uint32_t)
85# define ARG_HI_OFFSET 0
86#else
87#error "Unknown endianness"
88#endif
89
Damien Millere0956e32012-04-04 11:27:54 +100090/* Simple helpers to avoid manual errors (but larger BPF programs). */
91#define SC_DENY(_nr, _errno) \
Damien Millere3ea3352017-03-14 17:48:43 +110092 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (_nr), 0, 1), \
Damien Millere0956e32012-04-04 11:27:54 +100093 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO|(_errno))
94#define SC_ALLOW(_nr) \
Damien Millere3ea3352017-03-14 17:48:43 +110095 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (_nr), 0, 1), \
Damien Millere0956e32012-04-04 11:27:54 +100096 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)
Damien Miller99f33d72015-06-17 10:50:51 +100097#define SC_ALLOW_ARG(_nr, _arg_nr, _arg_val) \
Damien Millere3ea3352017-03-14 17:48:43 +110098 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (_nr), 0, 6), \
Damien Millerf6906f92019-08-23 10:08:48 +100099 /* load and test syscall argument, low word */ \
Damien Miller99f33d72015-06-17 10:50:51 +1000100 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
Damien Miller9e96b412017-03-14 12:24:47 +1100101 offsetof(struct seccomp_data, args[(_arg_nr)]) + ARG_LO_OFFSET), \
102 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, \
103 ((_arg_val) & 0xFFFFFFFF), 0, 3), \
Damien Millerf6906f92019-08-23 10:08:48 +1000104 /* load and test syscall argument, high word */ \
Damien Miller9e96b412017-03-14 12:24:47 +1100105 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
106 offsetof(struct seccomp_data, args[(_arg_nr)]) + ARG_HI_OFFSET), \
107 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, \
108 (((uint32_t)((uint64_t)(_arg_val) >> 32)) & 0xFFFFFFFF), 0, 1), \
Damien Miller99f33d72015-06-17 10:50:51 +1000109 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), \
110 /* reload syscall number; all rules expect it in accumulator */ \
111 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
112 offsetof(struct seccomp_data, nr))
Damien Millerf6906f92019-08-23 10:08:48 +1000113/* Allow if syscall argument contains only values in mask */
114#define SC_ALLOW_ARG_MASK(_nr, _arg_nr, _arg_mask) \
115 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (_nr), 0, 8), \
116 /* load, mask and test syscall argument, low word */ \
117 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
118 offsetof(struct seccomp_data, args[(_arg_nr)]) + ARG_LO_OFFSET), \
119 BPF_STMT(BPF_ALU+BPF_AND+BPF_K, ~((_arg_mask) & 0xFFFFFFFF)), \
120 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 4), \
121 /* load, mask and test syscall argument, high word */ \
122 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
123 offsetof(struct seccomp_data, args[(_arg_nr)]) + ARG_HI_OFFSET), \
124 BPF_STMT(BPF_ALU+BPF_AND+BPF_K, \
125 ~(((uint32_t)((uint64_t)(_arg_mask) >> 32)) & 0xFFFFFFFF)), \
126 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 1), \
127 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), \
128 /* reload syscall number; all rules expect it in accumulator */ \
129 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
130 offsetof(struct seccomp_data, nr))
Damien Millere0956e32012-04-04 11:27:54 +1000131
132/* Syscall filtering set for preauth. */
133static const struct sock_filter preauth_insns[] = {
134 /* Ensure the syscall arch convention is as expected. */
135 BPF_STMT(BPF_LD+BPF_W+BPF_ABS,
136 offsetof(struct seccomp_data, arch)),
137 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SECCOMP_AUDIT_ARCH, 1, 0),
138 BPF_STMT(BPF_RET+BPF_K, SECCOMP_FILTER_FAIL),
139 /* Load the syscall number for checking. */
140 BPF_STMT(BPF_LD+BPF_W+BPF_ABS,
141 offsetof(struct seccomp_data, nr)),
Damien Miller99f33d72015-06-17 10:50:51 +1000142
143 /* Syscalls to non-fatally deny */
Damien Millerf64062b2016-05-20 09:56:53 +1000144#ifdef __NR_lstat
Damien Millere3ea3352017-03-14 17:48:43 +1100145 SC_DENY(__NR_lstat, EACCES),
Damien Millerf64062b2016-05-20 09:56:53 +1000146#endif
147#ifdef __NR_lstat64
Damien Millere3ea3352017-03-14 17:48:43 +1100148 SC_DENY(__NR_lstat64, EACCES),
Damien Millerf64062b2016-05-20 09:56:53 +1000149#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000150#ifdef __NR_fstat
Damien Millere3ea3352017-03-14 17:48:43 +1100151 SC_DENY(__NR_fstat, EACCES),
Damien Miller99f33d72015-06-17 10:50:51 +1000152#endif
153#ifdef __NR_fstat64
Damien Millere3ea3352017-03-14 17:48:43 +1100154 SC_DENY(__NR_fstat64, EACCES),
Damien Miller99f33d72015-06-17 10:50:51 +1000155#endif
156#ifdef __NR_open
Damien Millere3ea3352017-03-14 17:48:43 +1100157 SC_DENY(__NR_open, EACCES),
Damien Miller99f33d72015-06-17 10:50:51 +1000158#endif
159#ifdef __NR_openat
Damien Millere3ea3352017-03-14 17:48:43 +1100160 SC_DENY(__NR_openat, EACCES),
Damien Miller99f33d72015-06-17 10:50:51 +1000161#endif
162#ifdef __NR_newfstatat
Damien Millere3ea3352017-03-14 17:48:43 +1100163 SC_DENY(__NR_newfstatat, EACCES),
Damien Miller99f33d72015-06-17 10:50:51 +1000164#endif
165#ifdef __NR_stat
Damien Millere3ea3352017-03-14 17:48:43 +1100166 SC_DENY(__NR_stat, EACCES),
Damien Miller91f40d82013-02-22 11:37:00 +1100167#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000168#ifdef __NR_stat64
Damien Millere3ea3352017-03-14 17:48:43 +1100169 SC_DENY(__NR_stat64, EACCES),
Damien Miller6434cb22014-02-06 11:17:50 +1100170#endif
Lonnie Abelbeck3ef92a62019-10-01 09:05:09 -0500171#ifdef __NR_shmget
172 SC_DENY(__NR_shmget, EACCES),
173#endif
174#ifdef __NR_shmat
175 SC_DENY(__NR_shmat, EACCES),
176#endif
177#ifdef __NR_shmdt
178 SC_DENY(__NR_shmdt, EACCES),
179#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000180
181 /* Syscalls to permit */
182#ifdef __NR_brk
Damien Millere3ea3352017-03-14 17:48:43 +1100183 SC_ALLOW(__NR_brk),
Damien Millere0956e32012-04-04 11:27:54 +1000184#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000185#ifdef __NR_clock_gettime
Damien Millere3ea3352017-03-14 17:48:43 +1100186 SC_ALLOW(__NR_clock_gettime),
Damien Miller99f33d72015-06-17 10:50:51 +1000187#endif
188#ifdef __NR_close
Damien Millere3ea3352017-03-14 17:48:43 +1100189 SC_ALLOW(__NR_close),
Damien Miller99f33d72015-06-17 10:50:51 +1000190#endif
191#ifdef __NR_exit
Damien Millere3ea3352017-03-14 17:48:43 +1100192 SC_ALLOW(__NR_exit),
Damien Miller99f33d72015-06-17 10:50:51 +1000193#endif
194#ifdef __NR_exit_group
Damien Millere3ea3352017-03-14 17:48:43 +1100195 SC_ALLOW(__NR_exit_group),
Damien Miller99f33d72015-06-17 10:50:51 +1000196#endif
Damien Miller149519b2018-09-15 19:37:48 +1000197#ifdef __NR_futex
198 SC_ALLOW(__NR_futex),
199#endif
Damien Miller4ef75922018-05-25 13:36:58 +1000200#ifdef __NR_geteuid
201 SC_ALLOW(__NR_geteuid),
202#endif
203#ifdef __NR_geteuid32
204 SC_ALLOW(__NR_geteuid32),
205#endif
djm@openbsd.org512cadd2015-06-29 22:35:12 +0000206#ifdef __NR_getpgid
Damien Millere3ea3352017-03-14 17:48:43 +1100207 SC_ALLOW(__NR_getpgid),
djm@openbsd.org512cadd2015-06-29 22:35:12 +0000208#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000209#ifdef __NR_getpid
Damien Millere3ea3352017-03-14 17:48:43 +1100210 SC_ALLOW(__NR_getpid),
Damien Miller99f33d72015-06-17 10:50:51 +1000211#endif
Damien Miller26ad1822015-09-10 10:57:41 +1000212#ifdef __NR_getrandom
Damien Millere3ea3352017-03-14 17:48:43 +1100213 SC_ALLOW(__NR_getrandom),
Damien Miller26ad1822015-09-10 10:57:41 +1000214#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000215#ifdef __NR_gettimeofday
Damien Millere3ea3352017-03-14 17:48:43 +1100216 SC_ALLOW(__NR_gettimeofday),
Damien Miller99f33d72015-06-17 10:50:51 +1000217#endif
Damien Miller4ef75922018-05-25 13:36:58 +1000218#ifdef __NR_getuid
219 SC_ALLOW(__NR_getuid),
220#endif
221#ifdef __NR_getuid32
222 SC_ALLOW(__NR_getuid32),
223#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000224#ifdef __NR_madvise
Damien Millere3ea3352017-03-14 17:48:43 +1100225 SC_ALLOW(__NR_madvise),
Damien Miller91f40d82013-02-22 11:37:00 +1100226#endif
227#ifdef __NR_mmap
Damien Millere83c9892019-08-23 10:19:30 +1000228 SC_ALLOW_ARG_MASK(__NR_mmap, 2, PROT_READ|PROT_WRITE|PROT_NONE),
Damien Miller91f40d82013-02-22 11:37:00 +1100229#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000230#ifdef __NR_mmap2
Damien Millere83c9892019-08-23 10:19:30 +1000231 SC_ALLOW_ARG_MASK(__NR_mmap2, 2, PROT_READ|PROT_WRITE|PROT_NONE),
Damien Miller0fa0ed02014-09-10 08:15:34 +1000232#endif
Damien Millerf6906f92019-08-23 10:08:48 +1000233#ifdef __NR_mprotect
234 SC_ALLOW_ARG_MASK(__NR_mprotect, 2, PROT_READ|PROT_WRITE|PROT_NONE),
235#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000236#ifdef __NR_mremap
Damien Millere3ea3352017-03-14 17:48:43 +1100237 SC_ALLOW(__NR_mremap),
Damien Miller99f33d72015-06-17 10:50:51 +1000238#endif
239#ifdef __NR_munmap
Damien Millere3ea3352017-03-14 17:48:43 +1100240 SC_ALLOW(__NR_munmap),
Damien Miller99f33d72015-06-17 10:50:51 +1000241#endif
Darren Tucker0e734282018-04-13 16:06:29 +1000242#ifdef __NR_nanosleep
243 SC_ALLOW(__NR_nanosleep),
244#endif
Darren Tuckerb1c82f42019-11-13 23:19:35 +1100245#ifdef __NR_clock_nanosleep
246 SC_ALLOW(__NR_clock_nanosleep),
247#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000248#ifdef __NR__newselect
Damien Millere3ea3352017-03-14 17:48:43 +1100249 SC_ALLOW(__NR__newselect),
Damien Miller99f33d72015-06-17 10:50:51 +1000250#endif
251#ifdef __NR_poll
Damien Millere3ea3352017-03-14 17:48:43 +1100252 SC_ALLOW(__NR_poll),
Damien Miller99f33d72015-06-17 10:50:51 +1000253#endif
Damien Millerbc202052015-06-25 09:51:39 +1000254#ifdef __NR_pselect6
Damien Millere3ea3352017-03-14 17:48:43 +1100255 SC_ALLOW(__NR_pselect6),
Damien Millerbc202052015-06-25 09:51:39 +1000256#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000257#ifdef __NR_read
Damien Millere3ea3352017-03-14 17:48:43 +1100258 SC_ALLOW(__NR_read),
Damien Miller99f33d72015-06-17 10:50:51 +1000259#endif
Damien Millere0956e32012-04-04 11:27:54 +1000260#ifdef __NR_rt_sigprocmask
Damien Millere3ea3352017-03-14 17:48:43 +1100261 SC_ALLOW(__NR_rt_sigprocmask),
Damien Miller99f33d72015-06-17 10:50:51 +1000262#endif
263#ifdef __NR_select
Damien Millere3ea3352017-03-14 17:48:43 +1100264 SC_ALLOW(__NR_select),
Damien Miller99f33d72015-06-17 10:50:51 +1000265#endif
266#ifdef __NR_shutdown
Damien Millere3ea3352017-03-14 17:48:43 +1100267 SC_ALLOW(__NR_shutdown),
Damien Miller99f33d72015-06-17 10:50:51 +1000268#endif
269#ifdef __NR_sigprocmask
Damien Millere3ea3352017-03-14 17:48:43 +1100270 SC_ALLOW(__NR_sigprocmask),
Damien Millere0956e32012-04-04 11:27:54 +1000271#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000272#ifdef __NR_time
Damien Millere3ea3352017-03-14 17:48:43 +1100273 SC_ALLOW(__NR_time),
Damien Miller99f33d72015-06-17 10:50:51 +1000274#endif
275#ifdef __NR_write
Damien Millere3ea3352017-03-14 17:48:43 +1100276 SC_ALLOW(__NR_write),
Damien Miller99f33d72015-06-17 10:50:51 +1000277#endif
278#ifdef __NR_socketcall
Damien Millere3ea3352017-03-14 17:48:43 +1100279 SC_ALLOW_ARG(__NR_socketcall, 0, SYS_SHUTDOWN),
Darren Tucker17a54a02017-04-25 08:32:27 +1000280 SC_DENY(__NR_socketcall, EACCES),
Damien Miller99f33d72015-06-17 10:50:51 +1000281#endif
Damien Miller5f1596e2017-03-14 13:15:18 +1100282#if defined(__NR_ioctl) && defined(__s390__)
283 /* Allow ioctls for ICA crypto card on s390 */
Damien Millere3ea3352017-03-14 17:48:43 +1100284 SC_ALLOW_ARG(__NR_ioctl, 1, Z90STAT_STATUS_MASK),
285 SC_ALLOW_ARG(__NR_ioctl, 1, ICARSAMODEXPO),
286 SC_ALLOW_ARG(__NR_ioctl, 1, ICARSACRT),
Harald Freudenbergerb3a77b22019-05-24 10:11:15 +0200287 SC_ALLOW_ARG(__NR_ioctl, 1, ZSECSENDCPRB),
Eduardo Barretto8dc7d6b2017-05-09 13:33:30 -0300288 /* Allow ioctls for EP11 crypto card on s390 */
289 SC_ALLOW_ARG(__NR_ioctl, 1, ZSENDEP11CPRB),
Damien Millerf86586b2017-03-14 18:26:29 +1100290#endif
291#if defined(__x86_64__) && defined(__ILP32__) && defined(__X32_SYSCALL_BIT)
292 /*
293 * On Linux x32, the clock_gettime VDSO falls back to the
294 * x86-64 syscall under some circumstances, e.g.
295 * https://bugs.debian.org/849923
296 */
Damien Miller6b853c62017-03-21 08:47:55 +1100297 SC_ALLOW(__NR_clock_gettime & ~__X32_SYSCALL_BIT),
Damien Millerf86586b2017-03-14 18:26:29 +1100298#endif
Damien Miller99f33d72015-06-17 10:50:51 +1000299
300 /* Default deny */
Damien Millere0956e32012-04-04 11:27:54 +1000301 BPF_STMT(BPF_RET+BPF_K, SECCOMP_FILTER_FAIL),
302};
303
304static const struct sock_fprog preauth_program = {
305 .len = (unsigned short)(sizeof(preauth_insns)/sizeof(preauth_insns[0])),
306 .filter = (struct sock_filter *)preauth_insns,
307};
308
309struct ssh_sandbox {
310 pid_t child_pid;
311};
312
313struct ssh_sandbox *
Damien Miller868ea1e2014-01-17 16:47:04 +1100314ssh_sandbox_init(struct monitor *monitor)
Damien Millere0956e32012-04-04 11:27:54 +1000315{
316 struct ssh_sandbox *box;
317
318 /*
319 * Strictly, we don't need to maintain any state here but we need
320 * to return non-NULL to satisfy the API.
321 */
322 debug3("%s: preparing seccomp filter sandbox", __func__);
323 box = xcalloc(1, sizeof(*box));
324 box->child_pid = 0;
325
326 return box;
327}
328
329#ifdef SANDBOX_SECCOMP_FILTER_DEBUG
330extern struct monitor *pmonitor;
331void mm_log_handler(LogLevel level, const char *msg, void *ctx);
332
333static void
334ssh_sandbox_violation(int signum, siginfo_t *info, void *void_context)
335{
336 char msg[256];
337
338 snprintf(msg, sizeof(msg),
339 "%s: unexpected system call (arch:0x%x,syscall:%d @ %p)",
340 __func__, info->si_arch, info->si_syscall, info->si_call_addr);
341 mm_log_handler(SYSLOG_LEVEL_FATAL, msg, pmonitor);
342 _exit(1);
343}
344
345static void
346ssh_sandbox_child_debugging(void)
347{
348 struct sigaction act;
349 sigset_t mask;
350
351 debug3("%s: installing SIGSYS handler", __func__);
352 memset(&act, 0, sizeof(act));
353 sigemptyset(&mask);
354 sigaddset(&mask, SIGSYS);
355
356 act.sa_sigaction = &ssh_sandbox_violation;
357 act.sa_flags = SA_SIGINFO;
358 if (sigaction(SIGSYS, &act, NULL) == -1)
359 fatal("%s: sigaction(SIGSYS): %s", __func__, strerror(errno));
360 if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)
361 fatal("%s: sigprocmask(SIGSYS): %s",
362 __func__, strerror(errno));
363}
364#endif /* SANDBOX_SECCOMP_FILTER_DEBUG */
365
366void
367ssh_sandbox_child(struct ssh_sandbox *box)
368{
369 struct rlimit rl_zero;
Damien Millera0433a72012-07-06 10:27:10 +1000370 int nnp_failed = 0;
Damien Millere0956e32012-04-04 11:27:54 +1000371
372 /* Set rlimits for completeness if possible. */
373 rl_zero.rlim_cur = rl_zero.rlim_max = 0;
374 if (setrlimit(RLIMIT_FSIZE, &rl_zero) == -1)
375 fatal("%s: setrlimit(RLIMIT_FSIZE, { 0, 0 }): %s",
376 __func__, strerror(errno));
377 if (setrlimit(RLIMIT_NOFILE, &rl_zero) == -1)
378 fatal("%s: setrlimit(RLIMIT_NOFILE, { 0, 0 }): %s",
379 __func__, strerror(errno));
380 if (setrlimit(RLIMIT_NPROC, &rl_zero) == -1)
381 fatal("%s: setrlimit(RLIMIT_NPROC, { 0, 0 }): %s",
382 __func__, strerror(errno));
383
384#ifdef SANDBOX_SECCOMP_FILTER_DEBUG
385 ssh_sandbox_child_debugging();
386#endif /* SANDBOX_SECCOMP_FILTER_DEBUG */
387
388 debug3("%s: setting PR_SET_NO_NEW_PRIVS", __func__);
Damien Millera0433a72012-07-06 10:27:10 +1000389 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) {
390 debug("%s: prctl(PR_SET_NO_NEW_PRIVS): %s",
Damien Millere0956e32012-04-04 11:27:54 +1000391 __func__, strerror(errno));
Damien Millera0433a72012-07-06 10:27:10 +1000392 nnp_failed = 1;
393 }
Damien Millere0956e32012-04-04 11:27:54 +1000394 debug3("%s: attaching seccomp filter program", __func__);
395 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &preauth_program) == -1)
Damien Millera0433a72012-07-06 10:27:10 +1000396 debug("%s: prctl(PR_SET_SECCOMP): %s",
Damien Millere0956e32012-04-04 11:27:54 +1000397 __func__, strerror(errno));
Damien Millera0433a72012-07-06 10:27:10 +1000398 else if (nnp_failed)
399 fatal("%s: SECCOMP_MODE_FILTER activated but "
400 "PR_SET_NO_NEW_PRIVS failed", __func__);
Damien Millere0956e32012-04-04 11:27:54 +1000401}
402
403void
404ssh_sandbox_parent_finish(struct ssh_sandbox *box)
405{
406 free(box);
407 debug3("%s: finished", __func__);
408}
409
410void
411ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
412{
413 box->child_pid = child_pid;
414}
415
416#endif /* SANDBOX_SECCOMP_FILTER */