|
37 | 37 | OFFSET_ARCH, |
38 | 38 | OFFSET_NR, |
39 | 39 | SECCOMP_FILTER_FLAG_NEW_LISTENER, |
| 40 | + SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV, |
40 | 41 | SECCOMP_RET_ALLOW, |
41 | 42 | SECCOMP_RET_ERRNO, |
42 | 43 | SECCOMP_RET_KILL_PROCESS, |
@@ -244,14 +245,25 @@ def install_notif_filter( |
244 | 245 | prog.len = n_insns |
245 | 246 | prog.filter = ctypes.addressof(buf) |
246 | 247 |
|
247 | | - # seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog) |
| 248 | + # seccomp(SECCOMP_SET_MODE_FILTER, flags, &prog) |
| 249 | + # WAIT_KILLABLE_RECV (5.19+) prevents signals from aborting |
| 250 | + # notifications while the supervisor is handling them. |
248 | 251 | __NR_seccomp = _SYSCALL_NR["seccomp"] |
| 252 | + flags = SECCOMP_FILTER_FLAG_NEW_LISTENER | SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV |
249 | 253 | fd = _libc.syscall( |
250 | 254 | ctypes.c_long(__NR_seccomp), |
251 | 255 | ctypes.c_uint(SECCOMP_SET_MODE_FILTER), |
252 | | - ctypes.c_uint(SECCOMP_FILTER_FLAG_NEW_LISTENER), |
| 256 | + ctypes.c_uint(flags), |
253 | 257 | ctypes.byref(prog), |
254 | 258 | ) |
| 259 | + if fd < 0: |
| 260 | + # Fall back without WAIT_KILLABLE_RECV on older kernels |
| 261 | + fd = _libc.syscall( |
| 262 | + ctypes.c_long(__NR_seccomp), |
| 263 | + ctypes.c_uint(SECCOMP_SET_MODE_FILTER), |
| 264 | + ctypes.c_uint(SECCOMP_FILTER_FLAG_NEW_LISTENER), |
| 265 | + ctypes.byref(prog), |
| 266 | + ) |
255 | 267 | if fd < 0: |
256 | 268 | err = ctypes.get_errno() |
257 | 269 | raise NotifError(f"seccomp(SET_MODE_FILTER, NEW_LISTENER): {os.strerror(err)}") |
|
0 commit comments