[PATCH v2] seccomp: Use wq_has_sleeper() when an unused filter wakes its waiters

From: Zhenwen Liang

Date: Sun Nov 29 2026 - 07:52:20 EST


__seccomp_filter_orphan() checks waitqueue_active() after
refcount_dec_and_test(), which is not a full barrier, so a waiter in
recv_wait_event() or seccomp_notify_poll() can read the old users count
while the waker sees an empty queue. The wakeup is then lost and
SECCOMP_IOCTL_NOTIF_RECV or poll() keeps sleeping. Use wq_has_sleeper(),
which issues the smp_mb() the waker needs.

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.

Fixes: 99cdb8b9a573 ("seccomp: notify about unused filter")
Reviewed-by: Bradley Morgan <bradley.morgan@xxxxxxxxx>
Signed-off-by: Zhenwen Liang <zhenwenliang@xxxxxxxxxx>
---
v2: Shorten the changelog (Bradley Morgan). No code change.
v1: https://lore.kernel.org/r/20261129024631.271472-1-zhenwenliang@xxxxxxxxxx/

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))
wake_up_poll(&orig->wqh, EPOLLHUP);
orig = orig->prev;
}
--
2.56.1.839.g22a8290db9-goog