mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] seccomp: Use wq_has_sleeper() when an unused filter wakes its waiters
@ 2026-11-29  2:46 Zhenwen Liang
  0 siblings, 0 replies; only message in thread
From: Zhenwen Liang @ 2026-11-29  2:46 UTC (permalink / raw)
  To: Kees Cook
  Cc: Andy Lutomirski, Will Drewry, Christian Brauner, Andrei Vagin,
	linux-kernel

__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.

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-29  2:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29  2:46 [PATCH] seccomp: Use wq_has_sleeper() when an unused filter wakes its waiters Zhenwen Liang

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®