2 * Seccomp sandboxing for virtiofsd
4 * Copyright (C) 2019 Red Hat, Inc.
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
18 /* Bodge for libseccomp 2.4.2 which broke ppoll */
19 #if !defined(__SNR_ppoll) && defined(__SNR_brk)
21 #define __SNR_ppoll __NR_ppoll
23 #define __SNR_ppoll __PNR_ppoll
27 static const int syscall_whitelist
[] = {
28 /* TODO ireg sem*() syscalls */
30 SCMP_SYS(capget
), /* For CAP_FSETID */
32 SCMP_SYS(clock_gettime
),
38 SCMP_SYS(copy_file_range
),
51 SCMP_SYS(fremovexattr
),
64 SCMP_SYS(gettimeofday
),
78 SCMP_SYS(prctl
), /* TODO restrict to just PR_SET_NAME? */
88 SCMP_SYS(rt_sigaction
),
89 SCMP_SYS(rt_sigprocmask
),
90 SCMP_SYS(rt_sigreturn
),
94 #ifdef __NR_setresgid32
95 SCMP_SYS(setresgid32
),
97 #ifdef __NR_setresuid32
98 SCMP_SYS(setresuid32
),
100 SCMP_SYS(set_robust_list
),
102 SCMP_SYS(time
), /* Rarely needed, except on static builds */
110 void setup_seccomp(void)
115 #ifdef SCMP_ACT_KILL_PROCESS
116 ctx
= seccomp_init(SCMP_ACT_KILL_PROCESS
);
117 /* Handle a newer libseccomp but an older kernel */
118 if (!ctx
&& errno
== EOPNOTSUPP
) {
119 ctx
= seccomp_init(SCMP_ACT_TRAP
);
122 ctx
= seccomp_init(SCMP_ACT_TRAP
);
125 fuse_log(FUSE_LOG_ERR
, "seccomp_init() failed\n");
129 for (i
= 0; i
< G_N_ELEMENTS(syscall_whitelist
); i
++) {
130 if (seccomp_rule_add(ctx
, SCMP_ACT_ALLOW
,
131 syscall_whitelist
[i
], 0) != 0) {
132 fuse_log(FUSE_LOG_ERR
, "seccomp_rule_add syscall %d",
133 syscall_whitelist
[i
]);
138 /* libvhost-user calls this for post-copy migration, we don't need it */
139 if (seccomp_rule_add(ctx
, SCMP_ACT_ERRNO(ENOSYS
),
140 SCMP_SYS(userfaultfd
), 0) != 0) {
141 fuse_log(FUSE_LOG_ERR
, "seccomp_rule_add userfaultfd failed\n");
145 if (seccomp_load(ctx
) < 0) {
146 fuse_log(FUSE_LOG_ERR
, "seccomp_load() failed\n");
150 seccomp_release(ctx
);