From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 03D0F47A0B2; Tue, 16 Jun 2026 18:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781634355; cv=none; b=ZFzJmjD00V5mb7lg1PfEThOsAPHXOMvgAFaw+/lBGCyj8atKzxETB2g/gJzSuP3pKjL0KNBkgnM0ypMLIY1r+SkckKtbK4a1pEFvNXCI4TnDL/lsJdu+bUPsetM3wxIx8AMcqO1ZPJx/XVn6D6xq39rM5+8ijDyvnzRc5fvLGWc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781634355; c=relaxed/simple; bh=ZVmlDUy08AgrIAaewPYBpHtY9n4DLHQYnvF5Bg0MraI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XlKSB44gqb0NTaVmMZ0xvwHF4cCNdW/FeJeds+XjnA1pc0Ufv8QUhKm/wYiS86hhT6NLqeBME1oIiQ93xvFk+hn1PHX+0T4huEDUjmTelnOru1tpgimm+hdYBOPajDZkCkW6e2WSlEb2Mwe2OKMIzdXGVzOZeh0AeqFVpJipIMo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wiuaJydZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wiuaJydZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B9701F00A3D; Tue, 16 Jun 2026 18:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781634353; bh=/VCCCrBTfFFCjA1RnKUd9/TQiARBDL9xXt3NGEH5fos=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wiuaJydZwCWnLtq6jcX+vrPFtUb5g7p3mOChe9hieBt4D09qJ0QXRO7JQadg0HX9B csvdf3mlFwkalSUAOikJmc0GyJpiVkldlIjLG7ovDzJ2O4M2Ouj3QV+tL/khBp61RF iDZqnq3VQnE/QhbLu4BNFPHcUaAp7XJbWv2VNHPc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Biggers , Jakub Kicinski , Li hongliang <1468888505@139.com> Subject: [PATCH 5.15 249/411] net/tcp-md5: Fix MAC comparison to be constant-time Date: Tue, 16 Jun 2026 20:28:07 +0530 Message-ID: <20260616145114.197619096@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145100.376842714@linuxfoundation.org> References: <20260616145100.376842714@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 5.15-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: Li hongliang <1468888505@139.com> Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_ipv4.c | 5 +++-- net/ipv6/tcp_ipv6.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -78,6 +78,7 @@ #include #include +#include #include #include @@ -763,7 +764,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; } @@ -1467,7 +1468,7 @@ static bool tcp_v4_inbound_md5_hash(cons 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); net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n", &iph->saddr, ntohs(th->source), --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -63,6 +63,7 @@ #include #include +#include #include #include @@ -810,7 +811,7 @@ static bool tcp_v6_inbound_md5_hash(cons 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); net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u L3 index %d\n", genhash ? "failed" : "mismatch", @@ -1088,7 +1089,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