From mboxrd@z Thu Jan 1 00:00:00 1970 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 88A3931619A; Mon, 13 Apr 2026 16:51:05 +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=1776099065; cv=none; b=WGZP/cYJnCefO1jiFluVCT5ymbtr2d/Ov/JydtSr/RfhGwI7z3Y4WIpbho0kfw/tuVhqBNDEgq7Uw/gIoaD3pTImX0ZI0NX8sbqh6PoeKZLHhVzw/bG/gX7a9KwxFpkNuxM1iFrOkJe7FwJH0htBkZmDNnM7ifjtBjm8eH75iQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776099065; c=relaxed/simple; bh=xtEJ5hODABsJ29DXxJeaMFdjjVK0S0D6e4i1Xo1h7Yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l4w5plJlWxWEuL2zeMgWEoGm0DEpBhIP3EzW8YoW1gYStN1YgzlcXbQd4J0gRfdfMot+Yset4UiKm0w7sj1uFOAPTy+6s8fei+e6Nv3gnDRJR7mkAnt0xw3qUFiPXiEX2Q5vVn4K5UgOViUbUxuEm49PJllxTiKo58aFB/5Ylzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UFltcBR3; 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="UFltcBR3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DE45C2BCAF; Mon, 13 Apr 2026 16:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776099065; bh=xtEJ5hODABsJ29DXxJeaMFdjjVK0S0D6e4i1Xo1h7Yw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UFltcBR38nE5eUXV1Y3pgi7Bu6aOUqxZM+wxnMm/pKBHZAkZfhoukpsw+lkeb3bUe Ub6nP9W/SnXF6NPCkwxfSnGLnNcKz6rDHLv1qk31Txt1CFjOyIznueH8VerGJ/aT65 X1oi9EWJcqpaeMnZ0v0KVX96mVIfjk04TaL8/n18= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Biggers , Jakub Kicinski Subject: [PATCH 5.10 196/491] net/tcp-md5: Fix MAC comparison to be constant-time Date: Mon, 13 Apr 2026 17:57:21 +0200 Message-ID: <20260413155826.410096907@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155819.042779211@linuxfoundation.org> References: <20260413155819.042779211@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.10-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_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 @@ -764,7 +765,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; } @@ -1451,7 +1452,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", @@ -1071,7 +1072,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