From: Bradley Morgan <bradley.morgan@linux.dev>
To: zhenwenliang@google.com
Cc: avagin@google.com, brauner@kernel.org, kees@kernel.org,
linux-kernel@vger.kernel.org, luto@amacapital.net,
wad@chromium.org
Subject: Re: [PATCH] seccomp: Use wq_has_sleeper() when an unused filter wakes its waiters
Date: Sun, 29 Nov 2026 11:21:39 +0000 [thread overview]
Message-ID: <6679D757-5731-43D1-9BC3-B41E396F200D@linux.dev> (raw)
In-Reply-To: <20261129024631.271472-1-zhenwenliang@google.com>
On 29 November 2026 02:46:31 GMT, Zhenwen Liang <zhenwenliang@google.com>
wrote:
>__seccomp_filter_orphan() drops the last user of a filter with
>refcount_dec_and_test() and wakes the notifier's waiters only if
>waitqueue_active() sees them. refcount_dec_and_test() provides release
>ordering, and acquire ordering when it returns true, but it is not a
>full barrier: its store to filter->users is not ordered before the
>later lockless load in waitqueue_active().
>
>The waiters add themselves to filter->wqh before they check users.
>recv_wait_event() calls prepare_to_wait_event(), whose
>set_current_state() is a full barrier, and then refcount_read();
>seccomp_notify_poll() calls poll_wait(), which ends with smp_mb(), and
>then refcount_read(). As the comment above waitqueue_active() explains,
>the waker needs a full barrier too. Without it, a waiter can read the
>old value of users while the waker sees an empty wait queue, and no
>wakeup is sent. SECCOMP_IOCTL_NOTIF_RECV can then sleep until a signal
>arrives; this applies since commit 95036a79e7b5 ("seccomp: interrupt
>SECCOMP_IOCTL_NOTIF_RECV when all users have exited"), which made it
>return once the filter is unused. A poll(), select() or epoll waiter
>can likewise miss EPOLLHUP and sleep until a timeout, a signal or
>another event.
>
>Use wq_has_sleeper(), which issues smp_mb() before it checks the wait
>queue. This covers both waiters, since they share this waker.
>smp_mb__after_atomic() is not used here: it is defined for the atomic_t
>operations, not for the refcount_t API.
>
>For both waiters, the outcome is allowed by the Linux kernel memory
>model for a litmus test derived from the code, and by the AArch64 and
>PPC architecture models for a litmus test of the same pattern. The fix
>was checked with herd7 on litmus tests derived from the patched code
>(LKMM, AArch64, PPC models: forbidden).
>
>Maintainers may want this change for stable.
>
>The problem was found, and this patch prepared, with the help of a
>formal analysis tool we are developing that uses AI assistance; I have
>reviewed the analysis and the patch.
>
>Compile-tested on arm64 (clang) and x86-64 (gcc) with W=1; not
>runtime-tested.
Small bit too verbose. Sigh.. please shorten down the description a bit,
it's a one line fix, nevertheless,
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>
>Fixes: 99cdb8b9a573 ("seccomp: notify about unused filter")
>Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
>---
> kernel/seccomp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/kernel/seccomp.c b/kernel/seccomp.c
>index 3eecba5ccdef..1f48bfdb3076 100644
>--- a/kernel/seccomp.c
>+++ b/kernel/seccomp.c
>@@ -534,7 +534,7 @@ static inline void seccomp_filter_free(struct seccomp_filter *filter)
> static void __seccomp_filter_orphan(struct seccomp_filter *orig)
> {
> while (orig && refcount_dec_and_test(&orig->users)) {
>- if (waitqueue_active(&orig->wqh))
>+ if (wq_has_sleeper(&orig->wqh))
makes sense.
> wake_up_poll(&orig->wqh, EPOLLHUP);
> orig = orig->prev;
> }
>
--- Thanks!
prev parent reply other threads:[~2026-11-29 11:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 2:46 Zhenwen Liang
2026-11-29 11:21 ` Bradley Morgan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6679D757-5731-43D1-9BC3-B41E396F200D@linux.dev \
--to=bradley.morgan@linux.dev \
--cc=avagin@google.com \
--cc=brauner@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=wad@chromium.org \
--cc=zhenwenliang@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®