From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795956733; b=LjmECctCiy3c6YkdLYsbtg74onVHAz2u0bDMmwdtXR1bGXyVsAEDEHx+EbObilApWnbz ALfoNRMqpv1yliDExaUlR68U41XWQvKFW7WjA+rO0G3WjzvTzNB3sqI+nsIIbnEUmylZJ 5umViKxA1FgSZ5lcC3X5FKuWJ6w7/OiJC9RXJPR2CEPm7Hw5yH5RWF+5N2E43I8GWgMpK /1IkSKDt2qEjtxqP/QGCr52nsVnA6AfvbZi1WjzksbRd3M6KMLRePMcGxc3nWPYSFFhop bZNJdOpCYLmAEAfvqBkVBl25EqhJoUIFoRBsuGKxMIfZhHwxAkkSt2x5j1ZdMXKs7Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795956733; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=1Y0JtwhI5zJutsMiptMKzkPnYd9NKPPz5IZbebiZByQ=; b=L/wkw3yo1Mrypp+0osb4HqDObUBRz+Pef0YPxq+M8rq5COosTxPc4HqRWCu+UmKBZSOe z+3xAChDKED3cS5T+a4r/IzsRULNGX8+HnaAtPjHPibPFNb2iBsXZCrG/x8em3u5E4v3x 8hRlzknpN7HAGB1izPPOfwQio38RCKuxQMQ8Ax19WxJ9PZcctiaF/0c1/ebPl4THGDcN7 6E8BS41CLrg0Ai8+vsJohvqeozNr7095h8/TtcQpktzIkatOqXP3V1pOwmjAOZIohUM/U UkZPX75hNwN7oAxgF5pGMZG98CbeApFWJKYE7PCuzwMEOdFETfSWcUGUNy6/jZiI2BQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Nban7fm9; arc=none smtp.remote-ip=209.85.216.71 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44804606A31C for ; Sun, 29 Nov 2026 12:52:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44804606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Nban7fm9 Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-3b41b099809so8012709a91.1 for ; Sun, 29 Nov 2026 04:52:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795956732; x=1796561532; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1Y0JtwhI5zJutsMiptMKzkPnYd9NKPPz5IZbebiZByQ=; b=Nban7fm9cRhqWnw2zG9M3QbF0CNpZs9xdH3NV2VhH5QHvyMyUiSzSYdjCShdrAa5zY 5vShSEVV5ootcG6Z7zx7w8t+EPgVbRpY45FDHP4izu5cWqmmpfgCryKT96Re9znduqvJ v0JjuZ+7T5Rk7uHCLojOoIw8KuzSZeXAREvf/LxswDDwrXTkCHgzskvuFlU6EDXeK4an XMD3Op15G3eSju6C0SrXwenD8dRdiZ+hKygt5fCFiVpoylpnCsxZP9SdPGE/rW7uanCo Igqqim8xyUZ8qz3r8bpUpScBQHLHIkMduQ/f76ArG8fUJ1RtHSl6UEijWdJFN1iEWygD ywaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795956732; x=1796561532; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1Y0JtwhI5zJutsMiptMKzkPnYd9NKPPz5IZbebiZByQ=; b=h4yuZgJuhhWs/ahqol63//rCFKKDD/oM6LIBuGBtOwrSqBPF1SRcdSJCiBZk8N/35C 5Spv/+KzHdJJEwW3B9jVSkhBcEV60kNFgyeD023ggFOEQiUjdpN0UFbyK8c8N0Eguukr cpL8SXs7Gq1r0+DZQ3h/QIEQGHtQ+GwptVLoH3kyhdrIH8QpartWMptFd/G4a6rC32lE cP5KF0fAH1uG1pygfxktjQwo0QMKNqkRHp3SA/DtWGyxeEoxnFqD5ZhdBdhGJMy7bIXP DBeJOen+93B18+3ZeOoXMykaSCD7rTAsBrrG1uwTgYg2rKBtlS8T1gdPxAoo6boaWYJU rwtg== X-Forwarded-Encrypted: i=1; AL+hErFTUcWNFCaF9e/r9aWiQ+J/5XC3FAMqO4tKC2IH2wbn7okcWD3oZ7+qFyFSvAPUxUdZ7AdrUx0pEUQAwOY=@vger.kernel.org X-Gm-Message-State: APuU4Z+b0OitUSFrNsOoI59XiAnww2KuF0Ip4XHKqwEASmXMUvX4HKBQ Y/ZGOfGZ6xJBrR8XgXAJ4mA/88UkFwenETKGia3Nldahq4VTXKjbgnC6mzFYIhz/XuvXMuNEXXT Cy5QXLY62yHccAFTGXxw1lGZylMbJaQ== X-Received: from pjbta8.prod.google.com ([2002:a17:90b:4ec8:b0:3b1:4df2:459b]) (user=zhenwenliang job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5244:b0:3b4:fd89:5f57 with SMTP id 98e67ed59e1d1-3b4fd8969b9mr13945391a91.35.1795956732418; Sun, 29 Nov 2026 04:52:12 -0800 (PST) Date: Sun, 29 Nov 2026 12:52:11 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261129125211.1181693-1-zhenwenliang@google.com> Subject: [PATCH v2] seccomp: Use wq_has_sleeper() when an unused filter wakes its waiters From: Zhenwen Liang To: Kees Cook Cc: Andy Lutomirski , Will Drewry , Christian Brauner , Andrei Vagin , linux-kernel@vger.kernel.org, Bradley Morgan Content-Type: text/plain; charset="UTF-8" __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 Signed-off-by: Zhenwen Liang --- 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