mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhenwen Liang <zhenwenliang@google.com>
To: Kees Cook <kees@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	 Christian Brauner <brauner@kernel.org>,
	Andrei Vagin <avagin@google.com>,
	linux-kernel@vger.kernel.org,
	 Bradley Morgan <bradley.morgan@linux.dev>
Subject: [PATCH v2] seccomp: Use wq_has_sleeper() when an unused filter wakes its waiters
Date: Sun, 29 Nov 2026 12:52:11 +0000	[thread overview]
Message-ID: <20261129125211.1181693-1-zhenwenliang@google.com> (raw)

__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@linux.dev>
Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
---
v2: Shorten the changelog (Bradley Morgan). No code change.
v1: https://lore.kernel.org/r/20261129024631.271472-1-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


                 reply	other threads:[~2026-11-29 12:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261129125211.1181693-1-zhenwenliang@google.com \
    --to=zhenwenliang@google.com \
    --cc=avagin@google.com \
    --cc=bradley.morgan@linux.dev \
    --cc=brauner@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=wad@chromium.org \
    /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®