Article View: linux.kernel.netdev
Article #17732Re: [PATCH net v2] tcp_metrics: hash the destination address with SipHash
From: Eric Dumazet
Date: Tue, 17 Nov 2026 09:20
Date: Tue, 17 Nov 2026 09:20
220 lines
17612 bytes
17612 bytes
Le mar. 17 nov. 2026 ร 05:10, Juan Agustin Niccolini
<juanagusnicco@gmail.com> a รฉcrit :
>
> The tcp_metrics bucket is derived from a fold of the peer address.
> For IPv4 the fold is ipv4_addr_hash(), which returns the address
> unchanged. For IPv6 it is ipv6_addr_hash(), which XORs the four
> 32-bit words of the address. net_hash_mix() is only XORed in after
> that fold, so two addresses of either family with the same fold share
> a bucket in every netns.
>
> A remote attacker with an IPv6 /64 can thus compute, without knowing
> net_hash_mix(), addresses that collide with a chosen IPv4 or IPv6 address:
>
> w3 = w2 ^ p0 ^ p1 ^ target /* p0, p1: prefix, w2: free */
>
> A bucket holds six entries and the seventh insert replaces the oldest.
> tcp_init_metrics() seeds the initial RTO from the cached RTT, so the
> attacker can tell whether an entry it planted was evicted. Filling the
> bucket of a chosen address with such entries reveals whether that
> address, or another one in the same bucket, connected in the meantime.
Note that entries are created from tcp_update_metrics(), when the
flow is closed, not when the victim connects.
>
> The same test, with six entries of one fold and a seventh of another,
> shows whether two folds share a bucket. Each answer rules out values
> of net_hash_mix(), the only unknown, and since XOR and multiply is not
> a PRF a few hundred answers recover it. The attacker can then fill
> every bucket and see which one any client's connection evicts from.
How many connections does your reproducer need, for each phase ?
1) Recovering net_hash_mix().
2) Filling the table (16384 * 6 flows with the default size ?),
then each sweep to find which bucket was hit.
Each probe also has to wait for an RTO, so wall time matters too.
Also, how does this behave on a server with real traffic ? Every
other client closing a flow evicts entries as well. You mention
a test against Ubuntu 24.04 over the internet, was this host
serving anything else ?
Please add these numbers to the changelog, they are needed
to evaluate how practical this is, and if this is net or net-next
material.
Note that many servers (including Google ones) have tcp_no_metrics_save=1
> The multiplication in hash_32() is invertible, so that bucket leaks
> about 14 bits of the client's address, depending on the number of
> buckets.
>
> Hash the address with SipHash and a random key instead, as commit
> 2ee66e948717 ("inetpeer: randomize RB-tree node comparison using SipHash")
> did for inet_peer. net_hash_mix() and hash_32() are kept, to separate
> namespaces and to reduce the result to the table size.
>
> Fixes: 51c5d0c4b169 ("tcp: Maintain dynamic metrics in local cache.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Juan Agustin Niccolini <juanagusnicco@gmail.com>
> ---
> v2: - use siphash_1u32() for IPv4, a4.vif is always zero in tcp_metrics
> (Kuniyuki)
> - call tcpm_addr_hash() once after the address family branches
> - changelog: explain more clearly why net_hash_mix() and addresses
> are recoverable
> v1: https://lore.kernel.org/netdev/20261112064624.15245-1-juanagusnicco@gmail.com/
>
> Comments below are the same as on v1.
>
> This can be exploited remotely to recover a client's IPv4 address.
> A single host narrows the address to about 262 thousand candidates,
> and because each netns keys the hash differently, intersecting buckets
> extracted from multiple hosts converges quickly into one candidate;
> 3-5 are enough. The net_hash_mix() value only needs to be extracted
> once per boot per host.
>
> Many common cases facilitate this. For instance, a browser loading
> one page connects to several hosts within the same second. That
> supplies the buckets needed to converge, and the shared timing shows
> they belong to the same client.
>
> I reproduced the bug on a QEMU guest running mainline (2a500a04d6f9) and
> against Ubuntu 24.04 over the internet. With the patch applied, the
> reproducer no longer finds addresses that share a bucket. The
> reproducer is available on request.
>
> For stable: 5.10 and 5.15 lack siphash_aligned_key_t;
> "static siphash_key_t tcpm_hash_key __read_mostly __aligned(16);" can
> be used there.
>
> This bug was discovered during an LLM-based code review.
>
> net/ipv4/tcp_metrics.c | 28 +++++++++++++++++++++-------
> 1 file changed, 21 insertions(+), 7 deletions(-)
>
> --- a/net/ipv4/tcp_metrics.c
> +++ b/net/ipv4/tcp_metrics.c
Your patch lacks the "diff --git" and "index" lines, and the hunk
headers have no function context. Please use plain git format-patch
for the next version.
The code itself looks good to me.
Thanks.
> @@ -8,6 +8,7 @@
> #include <linux/init.h>
> #include <linux/tcp.h>
> #include <linux/hash.h>
> +#include <linux/siphash.h>
> #include <linux/tcp_metrics.h>
> #include <linux/vmalloc.h>
>
> @@ -94,6 +95,22 @@
>
> static DEFINE_SPINLOCK(tcp_metrics_lock);
> static DEFINE_SEQLOCK(fastopen_seqlock);
> +
> +static siphash_aligned_key_t tcpm_hash_key __read_mostly;
> +
> +static u32 tcpm_addr_hash(const struct inetpeer_addr *a)
> +{
> + net_get_random_once(&tcpm_hash_key, sizeof(tcpm_hash_key));
> +
> + if (a->family == AF_INET)
> + return siphash_1u32((__force u32)a->a4.addr, &tcpm_hash_key);
> +
> + return siphash_4u32((__force u32)a->a6.s6_addr32[0],
> + (__force u32)a->a6.s6_addr32[1],
> + (__force u32)a->a6.s6_addr32[2],
> + (__force u32)a->a6.s6_addr32[3],
> + &tcpm_hash_key);
> +}
>
> static void tcpm_suck_dst(struct tcp_metrics_block *tm,
> const struct dst_entry *dst,
> @@ -270,13 +287,11 @@
> case AF_INET:
> inetpeer_set_addr_v4(&saddr, inet_rsk(req)->ir_loc_addr);
> inetpeer_set_addr_v4(&daddr, inet_rsk(req)->ir_rmt_addr);
> - hash = ipv4_addr_hash(inet_rsk(req)->ir_rmt_addr);
> break;
> #if IS_ENABLED(CONFIG_IPV6)
> case AF_INET6:
> inetpeer_set_addr_v6(&saddr, &inet_rsk(req)->ir_v6_loc_addr);
> inetpeer_set_addr_v6(&daddr, &inet_rsk(req)->ir_v6_rmt_addr);
> - hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr);
> break;
> #endif
> default:
> @@ -284,6 +299,7 @@
> }
>
> net = sock_net(req_to_sk(req));
> + hash = tcpm_addr_hash(&daddr);
> hash ^= net_hash_mix(net);
> hash = hash_32(hash, tcp_metrics_hash_log);
>
> @@ -310,18 +326,15 @@
> if (sk->sk_family == AF_INET) {
> inetpeer_set_addr_v4(&saddr, inet_sk(sk)->inet_saddr);
> inetpeer_set_addr_v4(&daddr, inet_sk(sk)->inet_daddr);
> - hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr);
> }
> #if IS_ENABLED(CONFIG_IPV6)
> else if (sk->sk_family == AF_INET6) {
> if (ipv6_addr_v4mapped(&sk->sk_v6_daddr)) {
> inetpeer_set_addr_v4(&saddr, inet_sk(sk)->inet_saddr);
> inetpeer_set_addr_v4(&daddr, inet_sk(sk)->inet_daddr);
> - hash = ipv4_addr_hash(inet_sk(sk)->inet_daddr);
> } else {
> inetpeer_set_addr_v6(&saddr, &sk->sk_v6_rcv_saddr);
> inetpeer_set_addr_v6(&daddr, &sk->sk_v6_daddr);
> - hash = ipv6_addr_hash(&sk->sk_v6_daddr);
> }
> }
> #endif
> @@ -329,6 +342,7 @@
> return NULL;
>
> net = sock_net(sk);
> + hash = tcpm_addr_hash(&daddr);
> hash ^= net_hash_mix(net);
> hash = hash_32(hash, tcp_metrics_hash_log);
>
> @@ -819,7 +833,7 @@
> if (a) {
> inetpeer_set_addr_v4(addr, nla_get_in_addr(a));
> if (hash)
> - *hash = ipv4_addr_hash(inetpeer_get_addr_v4(addr));
> + *hash = tcpm_addr_hash(addr);
> return 0;
> }
> a = info->attrs[v6];
> @@ -829,7 +843,7 @@
> in6 = nla_get_in6_addr(a);
> inetpeer_set_addr_v6(addr, &in6);
> if (hash)
> - *hash = ipv6_addr_hash(inetpeer_get_addr_v6(addr));
> + *hash = tcpm_addr_hash(addr);
> return 0;
> }
> return optional ? 1 : -EAFNOSUPPORT;
Technical Details
Message-ID:
<CAL4WiiptsFQ6dinHeAGrpxeXxdn0meRSR9tkEQaTkopPJiub7A@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365096-linux-kernel-netdev=dewy.ruReferences:
<20261117041029.80543-1-juanagusnicco@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365096-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tcp_metrics: hash the destination address with SipHash
Date: Tue, 17 Nov 2026 10:20:47 +0100
Organization: Usenet Network
Message-ID: <CAL4WiiptsFQ6dinHeAGrpxeXxdn0meRSR9tkEQaTkopPJiub7A@mail.gmail.com>
References: <20261117041029.80543-1-juanagusnicco@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2289802"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:jIX6aiLM/P8HAwt05MNhTuZN4aQ= sha256:yLT9cDzXZYGlU69b5FVgq21gUzNEZymvNOK/bDSnvj8=
sha1:n3bJTmJmzj9kY+QeSQQdEeXP7ME= sha256:X7xbbpN45nf3dPdoIzKGs7P6fUSiIjBaio/DSLNkiRI=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 8D50D114EBE; Tue, 17 Nov 2026 12:21:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id d5Sp0x0wKQgl;
Tue, 17 Nov 2026 12:21:14 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365096-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 09B2E114EAB; Tue, 17 Nov 2026 12:21:04 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 4B963333E6; Tue, 17 Nov 2026 09:21:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794907260;
b=2EhoMfUjsBjhrXt1EbiN4Wqc0dZDr39k3MhYArWk8XDVj9kS5EO78NbM24GmG6w7RZSH
9+dqNgqTmbhTLMXVUyS+8grjOub/3lC41OG/91xOx0ATDLNcSUgJi3y+fFn2hTFw3aoLA
pxkEsPJ1hWimpOrs1Q4tYE2VomnEOaN2jd6j6MQ0/kp9Wo7TzpEP/9P4Zevi8xTOSRfz8
i3NMPNwLLkzFPTIhLrnWgEtVTVNhyZRciPoEwTGtoI1sEbNYX69pzVltMINUktxpB4Lqj
1RsdGScDHwEXjNsmaRbvQ6++jvzzl4KUUFfFMP0o6TVqYYkcMWuE5ywH5PDs0HqTZUQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794907260;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=GHb3MG4ar21Ji9AsYm3wR9uXYPAPEdFfHbmibMl1wnw=;
b=NGqopkfYk/XyKw6x2bnlef2RQ6lYp3CDLX9j8L2kHeG7F73cQWbLvS5tnIVpJtdIGKdA
TaApj11gIH0v3/QnK+KiFXoVTuw3oAxjE3F5tT3toXj8h8gc8+oUE2UHj99puwZyzTO5m
kM6/I+ZfQWQ+Q41q6t3NhOMrpIezkygYStS23sH4UT4UnQrL1L5q531M7JFDzYogHrw98
nRHSbAavdXrl8Ua7jqyaDTsqiJ6M6RyAs9lMtQJRV0QwB3frQNNgAymfzNCA6lLMFsrTl
GNgyaCOrbhHdbida3YyoUvTk6O+mrP2BCh5NdcnSqegA5M3wTCw7SvTPy8e1ZowCDFg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P3+peLbh;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A340606A33A;
Tue, 17 Nov 2026 09:21:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P3+peLbh
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794907259;
b=pC8EebVZU75l2wwUiRPn4Jo0ZZ7nOai+ki6aIAsnetbCxAWlVtJ8g3IxMKksZFl0obga
ITp61nAa+o5HAD8q81dnTr80gakI4N+OvwMjexpiXTEXYGGtVYMHsK042aJgKRVjboGs5
yTys0eyufCHCMi9aT+jypYZrxMLpmcdVtSJuTH8FgH/GIpdolmQK9ULXOSzitLZ23obOq
FLM1awXa8/uonF8MajmzW7ljKjwDm2ItdLwxRVH81d1whsTBpRtWbLaaCb3U8cQlhH4pR
55ZAdk8z4QGBNchRZGyNn61ErFUSGXfwf3iUhkdVM3nXlb+lNVmdOWkGOArOgtOzUOA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794907259;
h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
bh=GHb3MG4ar21Ji9AsYm3wR9uXYPAPEdFfHbmibMl1wnw=;
b=dmLXP8/hB8blNh0FshMX2hNj6zRPkK2wCHXXeHEzuGYsbQpRjTGOHgLJN3+ZOHxdwFMe
hZGuJGGhLJ99XJwxH13w50eUZqd9P5QAhuEXhDrxtZWpN+zZKI8aJet1D6r80uituDAfA
46FgSmM7NYgmbTR6vla4QmO18PB4SkHTd8S/6oUSZtYm2f5MWLze0kol8dxJDIPKUaDq3
oMJhZvLWpgJHvD3x6iOxZka3IMcOj3/7miLRT3f8Y5TYmz6nRU0Q6no7EugkxyMDMb3Oe
GzhcJcL1xgmTIDO3rjz/iKgm1OBj7EZJinEK1ZH14337JkjGg5esVPaC3Q4RkVhexHw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P3+peLbh;
arc=none smtp.remote-ip=100.103.45.18
X-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 BC55B606A32A
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 09:20:59 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 475621F000CB
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 09:20:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1794907259;
bh=GHb3MG4ar21Ji9AsYm3wR9uXYPAPEdFfHbmibMl1wnw=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=P3+peLbhVPkT5lkGdgB7/HVy4oaUes6i9lRf2E1TJSPddf2QGN4en8JmxjB9t7LV8
xK3QnX4wjy245nh9wCkbThws3xgUe1dP5ZzhWkpK0SGfJRG1uQ0t2gatN5MiZxKrBg
7TSX6vN6xMF4rMpZgpbw5Gx2Pg1Zeoa5qC2A+5qnSb5zMBkRc4M767pPH6G8QZHK4l
4yrNBwE6RaKWkjxKOxEUqz2zjWkMWfveTgY8ahvUitkTZ7yF5QeSUVYvNbeJjlFllO
YpznL7Jm2bJSIKOYQ2RECfuKTbewytcUgDyke4rmO0OB+UkmJQMHeX1sNYcSijiu7m
v3JmTDZr0d7Yg==
X-Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-71acdd32a53so1270280eaf.3
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 01:20:59 -0800 (PST)
X-Forwarded-Encrypted: i=1; AL+hErHw3cJUBcLJIB/t+o+/TcG/ZPxpjQcI6dVg2MOJX5bYw0ckjPzIvjYTWQtBJhDZaRGdtYlkDfo=@vger.kernel.org
X-Gm-Message-State: APuU4Z80yyz2xgTdS8xPvMgKsC2G6aB2bNjK+A2+TXCMB2EyLdIcSQrZ
sSAIzzaV620F+KMJdQ4C6J6xQllStaQGcaorw+P1+vAD0PB3QpsiK9Bb/wtdFGC2r+riCfpxVNQ
CrYqcqlfh9Z/p/8NApbNkES5LrNazcRU=
X-Received: by 2002:a05:6820:168c:b0:6dd:bc51:888d with SMTP id
006d021491bc7-71acc1970cemr6535008eaf.87.1794907258431; Tue, 17 Nov 2026
01:20:58 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261117041029.80543-1-juanagusnicco@gmail.com>
X-Gmail-Original-Message-ID: <CAL4WiiptsFQ6dinHeAGrpxeXxdn0meRSR9tkEQaTkopPJiub7A@mail.gmail.com>
X-Gm-Features: AclHuK_1jsrjd0rFQKTxUrwhKy8SYCc-iBIqOUG61SFod-auZpaFVEhEMskdUeE
X-Cc: Neal Cardwell <ncardwell@google.com>, Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org