seccomp: Make duplicate listener detection non-racy
authorJann Horn <jannh@google.com>
Mon, 5 Oct 2020 01:44:01 +0000 (03:44 +0200)
committerKees Cook <keescook@chromium.org>
Thu, 8 Oct 2020 20:17:47 +0000 (13:17 -0700)
commitdfe719fef03d752f1682fa8aeddf30ba501c8555
tree7695a6683c814dbfd5174b10d55f51e071825bad
parent282a181b1a0d66de1f0894d82f395fcd478f51d1
seccomp: Make duplicate listener detection non-racy

Currently, init_listener() tries to prevent adding a filter with
SECCOMP_FILTER_FLAG_NEW_LISTENER if one of the existing filters already
has a listener. However, this check happens without holding any lock that
would prevent another thread from concurrently installing a new filter
(potentially with a listener) on top of the ones we already have.

Theoretically, this is also a data race: The plain load from
current->seccomp.filter can race with concurrent writes to the same
location.

Fix it by moving the check into the region that holds the siglock to guard
against concurrent TSYNC.

(The "Fixes" tag points to the commit that introduced the theoretical
data race; concurrent installation of another filter with TSYNC only
became possible later, in commit 51891498f2da ("seccomp: allow TSYNC and
USER_NOTIF together").)

Fixes: 6a21cc50f0c7 ("seccomp: add a return code to trap to userspace")
Reviewed-by: Tycho Andersen <tycho@tycho.pizza>
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20201005014401.490175-1-jannh@google.com
kernel/seccomp.c