Skip to content

Commit 50d5eb9

Browse files
committed
Enable SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV for reliable notifications
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 8f05edf commit 50d5eb9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/sandlock/_notif.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
OFFSET_ARCH,
3838
OFFSET_NR,
3939
SECCOMP_FILTER_FLAG_NEW_LISTENER,
40+
SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV,
4041
SECCOMP_RET_ALLOW,
4142
SECCOMP_RET_ERRNO,
4243
SECCOMP_RET_KILL_PROCESS,
@@ -244,14 +245,25 @@ def install_notif_filter(
244245
prog.len = n_insns
245246
prog.filter = ctypes.addressof(buf)
246247

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.
248251
__NR_seccomp = _SYSCALL_NR["seccomp"]
252+
flags = SECCOMP_FILTER_FLAG_NEW_LISTENER | SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV
249253
fd = _libc.syscall(
250254
ctypes.c_long(__NR_seccomp),
251255
ctypes.c_uint(SECCOMP_SET_MODE_FILTER),
252-
ctypes.c_uint(SECCOMP_FILTER_FLAG_NEW_LISTENER),
256+
ctypes.c_uint(flags),
253257
ctypes.byref(prog),
254258
)
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+
)
255267
if fd < 0:
256268
err = ctypes.get_errno()
257269
raise NotifError(f"seccomp(SET_MODE_FILTER, NEW_LISTENER): {os.strerror(err)}")

src/sandlock/_seccomp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
# seccomp() syscall constants (not prctl — needed for USER_NOTIF)
5151
SECCOMP_SET_MODE_FILTER = 1
5252
SECCOMP_FILTER_FLAG_NEW_LISTENER = 1 << 3
53+
SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV = 1 << 5 # Linux 5.19+
5354

5455
# seccomp_data offsets (architecture-independent layout)
5556
# struct seccomp_data { u32 nr, u32 arch, u64 instruction_pointer, u64 args[6] }

0 commit comments

Comments
 (0)