Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7074D246778; Mon, 23 Mar 2026 16:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283149; cv=none; b=hTAV2gCKKK/+i4tBEPyNf8cH693yJVGX/GTa2ZCjp9zK6x7MJD76vncSeDVkh1cAscblu0HZ1NCOMB3jm4cIm9fRz9eYx+33zA95trPNIm0MGLMnRqEQQjqsN4FomDzLPzaK1jQpsLKYJXojSnbU9GJwItXb6HQtBXxEZIwu+UY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774283149; c=relaxed/simple; bh=HZwU0wZVdw/6UQNzflGYpjbC0EIRhc9squ0bYu39lMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p2dwM+MOI2ig/0vzOxanUlJsyAtDkZNmBsTpZgiY8al/cRq6YRyEn9JNqldvT0DqTb7VP1CXWL3ecmQnTzz1ZOQYJLoqJlAvTlZKJDtjGCvmrGPmDm9zG+O7wE9/OdbrrsxctPi54+zZetTvTK5NiUx7Rn9plnH27jIJ7gJfapw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=y0sDnu2Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="y0sDnu2Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08E27C4CEF7; Mon, 23 Mar 2026 16:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774283149; bh=HZwU0wZVdw/6UQNzflGYpjbC0EIRhc9squ0bYu39lMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y0sDnu2QUN4PdH078cAoTR24FlP/XutafWrqhqqM+0OvM0pPxcc4H03rCp88rjbq7 LM7Px9Hhotak+OjFb+oGdY7Je+ro7dEawDHFEPhHBwkeHYGyzSWXljJTVIsT9LCeFl A9yWlA+A4w5HnyZYba180QpsYOP8pm7t3GM/6WBA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Biggers , Jakub Kicinski Subject: [PATCH 6.1 376/481] net/tcp-md5: Fix MAC comparison to be constant-time Date: Mon, 23 Mar 2026 14:45:58 +0100 Message-ID: <20260323134534.296568656@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134525.256603107@linuxfoundation.org> References: <20260323134525.256603107@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 46d0d6f50dab706637f4c18a470aac20a21900d3 upstream. To prevent timing attacks, MACs need to be compared in constant time. Use the appropriate helper function for this. Fixes: cfb6eeb4c860 ("[TCP]: MD5 Signature Option (RFC2385) support.") Fixes: 658ddaaf6694 ("tcp: md5: RST: getting md5 key from listener") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Link: https://patch.msgid.link/20260302203409.13388-1-ebiggers@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp.c | 3 ++- net/ipv4/tcp_ipv4.c | 3 ++- net/ipv6/tcp_ipv6.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -243,6 +243,7 @@ #define pr_fmt(fmt) "TCP: " fmt +#include #include #include #include @@ -4680,7 +4681,7 @@ tcp_inbound_md5_hash(const struct sock * hash_expected, NULL, skb); - if (genhash || memcmp(hash_location, newhash, 16) != 0) { + if (genhash || crypto_memneq(hash_location, newhash, 16)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE); if (family == AF_INET) { net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n", --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -78,6 +78,7 @@ #include #include +#include #include #include @@ -776,7 +777,7 @@ static void tcp_v4_send_reset(const stru genhash = tcp_v4_md5_hash_skb(newhash, key, NULL, skb); - if (genhash || memcmp(hash_location, newhash, 16) != 0) + if (genhash || crypto_memneq(hash_location, newhash, 16)) goto out; } --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -63,6 +63,7 @@ #include #include +#include #include #include @@ -1042,7 +1043,7 @@ static void tcp_v6_send_reset(const stru goto out; genhash = tcp_v6_md5_hash_skb(newhash, key, NULL, skb); - if (genhash || memcmp(hash_location, newhash, 16) != 0) + if (genhash || crypto_memneq(hash_location, newhash, 16)) goto out; } #endif