Skip to content

Commit cce436a

Browse files
mixikees
authored andcommitted
seccomp: Fix a race with WAIT_KILLABLE_RECV if the tracer replies too fast
Normally the tracee starts in SECCOMP_NOTIFY_INIT, sends an event to the tracer, and starts to wait interruptibly. With SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV, if the tracer receives the message (SECCOMP_NOTIFY_SENT is reached) while the tracee was waiting and is subsequently interrupted, the tracee begins to wait again uninterruptibly (but killable). This fails if SECCOMP_NOTIFY_REPLIED is reached before the tracee is interrupted, as the check only considered SECCOMP_NOTIFY_SENT as a condition to begin waiting again. In this case the tracee is interrupted even though the tracer already acted on its behalf. This breaks the assumption SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV wanted to ensure, namely that the tracer can be sure the syscall is not interrupted or restarted on the tracee after it is received on the tracer. Fix this by also considering SECCOMP_NOTIFY_REPLIED when evaluating whether to switch to uninterruptible waiting. With the condition changed the loop in seccomp_do_user_notification() would exit immediately after deciding that noninterruptible waiting is required if the operation already reached SECCOMP_NOTIFY_REPLIED, skipping the code that processes pending addfd commands first. Prevent this by executing the remaining loop body one last time in this case. Fixes: c2aa2df ("seccomp: Add wait_killable semantic to seccomp user notifier") Reported-by: Ali Polatel <alip@chesswob.org> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220291 Signed-off-by: Johannes Nixdorf <johannes@nixdorf.dev> Link: https://lore.kernel.org/r/20250725-seccomp-races-v2-1-cf8b9d139596@nixdorf.dev Signed-off-by: Kees Cook <kees@kernel.org>
1 parent e04c78d commit cce436a

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

kernel/seccomp.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ static void seccomp_handle_addfd(struct seccomp_kaddfd *addfd, struct seccomp_kn
11391139
static bool should_sleep_killable(struct seccomp_filter *match,
11401140
struct seccomp_knotif *n)
11411141
{
1142-
return match->wait_killable_recv && n->state == SECCOMP_NOTIFY_SENT;
1142+
return match->wait_killable_recv && n->state >= SECCOMP_NOTIFY_SENT;
11431143
}
11441144

11451145
static int seccomp_do_user_notification(int this_syscall,
@@ -1186,13 +1186,11 @@ static int seccomp_do_user_notification(int this_syscall,
11861186

11871187
if (err != 0) {
11881188
/*
1189-
* Check to see if the notifcation got picked up and
1190-
* whether we should switch to wait killable.
1189+
* Check to see whether we should switch to wait
1190+
* killable. Only return the interrupted error if not.
11911191
*/
1192-
if (!wait_killable && should_sleep_killable(match, &n))
1193-
continue;
1194-
1195-
goto interrupted;
1192+
if (!(!wait_killable && should_sleep_killable(match, &n)))
1193+
goto interrupted;
11961194
}
11971195

11981196
addfd = list_first_entry_or_null(&n.addfd,

0 commit comments

Comments
 (0)