From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793211362; b=l5WpOEd5ncgqLHR9Pd6tkbC4ryIdzMjO8mcKiHBE5Ef9yeyCdPePLlt8xKbRRAYSL1P/ aU1M7spzs4S/67i6l2IQZsNAQr06e/LQAL13OcDRQoBAMIVkof2l+YCw+qZe1Okb+8+SO CHYSuT/KgpTpItp45/GhzCa/ADsqJkSm4WNQooJnm329HZT+mR4rlURtlQtIn9N1owN7X 18rKegu2w4pTqcGO/I5RXe/hcdvVwzEGzvZxif6rCoWGo+OlPgd9VRtfHSDHVI4fPifx6 DV/F+2WZLfzpuo1gcxQicQ8mVauEhKH+jQbadeNcJmJeM4zLsn422b3wutU5E+7WdNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793211362; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=PiMy7eIb0fyXpBXzUb5jTRvMwOZzYsNP2PhunvE3i1M=; b=R/QXx45fcqw27De9azuUe+t0lE5BIEH7GXXrFlSvtmbw6x3Oq/Zfc2rLDkU/OhkgU8OW mFIG8T97LEKTXRgEDXRyMaZi9OcSYLHDZGSgzVO4+tRuWD4+I5GCIW4B758Y43Bxh1+tL BGMcPlq24D6+HtCCYYRnXfJLK0UFX6EmaJDCsz9Mktv+EHfo66Vh/DoHQ6udJCYq7mM5W kIpiH88w+WUYBeRCEqgRxcbhnugvDrJz8HPR09wnioZg7yeCm+uQqMoFY7P6ew0aAZxkg 2/q4rtAE2ZuvZAw/s+LeHX4BOW+YUzHyZvGU4t7Ax7TCQ95HtwL78nqzUQ91CzctvGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=as+eFuGL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32F85606A32C; Wed, 28 Oct 2026 18:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=as+eFuGL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 842761F01825; Wed, 28 Oct 2026 18:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793211362; bh=PiMy7eIb0fyXpBXzUb5jTRvMwOZzYsNP2PhunvE3i1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=as+eFuGLrfFPKkAmtY5HJH2Ng5ozOkwMiH/XMuIjE4E1QWX0QQ+FqL9oPIJQghC6S ZMslCcKNLkr583p1ezfg0tJWttliLi7ATZni5ezvmvFZuXfANjnheDy6lq2Bkw9yyj 9aVUILcEzRFw3DDqXGJSvDQocscyTE3T8Uyv0jR0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= , "Jason A. Donenfeld" , Jakub Kicinski Subject: [PATCH 5.15 350/571] wireguard: noise: reject response consumption after intermediate initiation Date: Wed, 28 Oct 2026 17:58:17 +0100 Message-ID: <20261028170016.320462147@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170008.009143722@linuxfoundation.org> References: <20261028170008.009143722@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason A. Donenfeld commit d0305f8d90029556260c6824b61c493c424eba9e upstream. Two threads begin processing the identical response message, received twice. The first thread, A, runs. While it's running, the second one, B, gets partway through, and during that slow calculation, or even while blocking on down_write(), A completes and then also a handshake initiation that's already been queued up runs in thread C, which itself takes that same down_write(). The handshake initiation creation succeeds, and sets the state back to waiting-for-response, and calls up_write(), at which point thread B resumes, because either its finished its calculations or was finally allowed to acquire down_write(). Thread B then copies the state back to the peer, and begins a new session, using that state, which is the same session as the one made in thread A. Thread A Thread B Thread C down_read() sA = handshake->state memcpy(cA, handshake->crypto) up_read() if (sA != 1) goto fail slow_crypto(cA) down_read() sB = handshake->state memcpy(cB, handshake->crypto) up_read() if (sB != 1) goto fail slow_crypto(cB) down_write() if (sA != handshake->state) goto fail memcpy(handshake->crypto, cA) handshake->state = 2 up_write() down_write() if (handshake->state != 2) goto fail derive_session(handshake->crypto) up_write() down_write() slow_crypto(handshake->crypto) handshake->state = 1 up_write() down_write() if (sB != handshake->state) goto fail memcpy(handshake->crypto, cB) handshake->state = 2 up_write() down_write() if (handshake->state != 2) goto fail derive_session(handshake->crypto) up_write() This seems basically impossible to hit in a meaningful way in practice, but ensure that it absolutely cannot happen by comparing the ephemeral private key that's on the stack with the latest one that the peer's handshake state has. Cc: stable@vger.kernel.org Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Reported-by: Jérémy Jean Signed-off-by: Jason A. Donenfeld Link: https://patch.msgid.link/20261008130124.724119-4-Jason@zx2c4.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireguard/noise.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/net/wireguard/noise.c +++ b/drivers/net/wireguard/noise.c @@ -784,10 +784,11 @@ wg_noise_handshake_consume_response(stru /* Success! Copy everything to peer */ down_write(&handshake->lock); - /* It's important to check that the state is still the same, while we - * have an exclusive lock. + /* Check that the state is the same and that this is still the + * initiation we started with, while we have an exclusive lock. */ - if (handshake->state != state) { + if (handshake->state != state || + crypto_memneq(handshake->ephemeral_private, ephemeral_private, NOISE_PUBLIC_KEY_LEN)) { up_write(&handshake->lock); goto fail; }