Article View: linux.kernel.netdev
Article #14916[PATCH net] tcp_metrics: hash the destination address with SipHash
From: Juan Agustin Niccolini
Date: Thu, 12 Nov 2026 06:46
Date: Thu, 12 Nov 2026 06:46
147 lines
15877 bytes
15877 bytes
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 host owning an IPv6 /64 can thus compute, without knowing
net_hash_mix(), addresses that collide with a chosen IPv4 or IPv6 peer:
w3 = w2 ^ p0 ^ p1 ^ target /* p0, p1: prefix, w2: free */
A bucket holds six entries and the seventh insert replaces the oldest.
An off-path host can fill a peer's bucket with its own entries and
later tell whether one was evicted, because tcp_init_metrics() seeds
the initial RTO from the cached RTT. This reveals whether that peer,
or another address in the same bucket, connected in the meantime.
XOR and multiply is not a PRF, so net_hash_mix() can be recovered the
same way, after which evictions leak about 14 bits of any 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>
---
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 | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -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,23 @@
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_2u32((__force u32)a->a4.addr, a->a4.vif,
+ &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 +288,13 @@
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);
+ hash = tcpm_addr_hash(&daddr);
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);
+ hash = tcpm_addr_hash(&daddr);
break;
#endif
default:
@@ -310,18 +328,18 @@
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);
+ hash = tcpm_addr_hash(&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);
+ hash = tcpm_addr_hash(&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);
+ hash = tcpm_addr_hash(&daddr);
}
}
#endif
@@ -818,7 +836,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];
@@ -828,7 +846,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:
<20261112064624.15245-1-juanagusnicco@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-361536-linux-kernel-netdev=dewy.ruShow 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-361536-linux-kernel-netdev=dewy.ru
From: juanagusnicco@gmail.com (Juan Agustin Niccolini)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] tcp_metrics: hash the destination address with SipHash
Date: Thu, 12 Nov 2026 01:46:24 -0500
Organization: Usenet Network
Message-ID: <20261112064624.15245-1-juanagusnicco@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1028323"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:MvhFIhBW7xtCBDeuh88i2KKIOdo= sha256:4ooMD0duv9iEOAWMkLj+Kjf5uwTiOjfYgxVrP2xN0hU=
sha1:am4j3alcqLdyn1hB00IkHOvPWmc= sha256:dEMwTc2+WlPfewxU6mVkuH6mVjyBFc16+q99Vl7qKzQ=
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 3BDA711411E; Thu, 12 Nov 2026 09:46:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=gmail.com
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 7-em1MoySyPT;
Thu, 12 Nov 2026 09:46:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-361536-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 875E0114100; Thu, 12 Nov 2026 09:46:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id A34E861E809; Thu, 12 Nov 2026 06:46:36 +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=1794465993;
b=OXMAg+goxP8ydlhUBin0nbMi2eytbTgEZnwq1cTr+ZpmiwQNSMnsQyG3EjZqEBv1/KGK
xTcX9MaKHEBDHfV2BKFsaVi3lgvwV5uQZbxAfr2vokZNTjTzUxlo3c+HESC+kDOMygV5c
ucgLhuE2bucgdSGxtuZhsqMM9Sx5UjPcOaBveS8rU2ls8kUj1YYz2bx/k84wjZCs23J5n
bSgohXoDU45wkzE1z5FPRGADJb7mavRDC9ILtWZcDYOPBgEFtEGldJtyVyjPHFFuvYq8d
lwaIih24Rmm5LQQTN4kAZhW9XTFU6vsRy9NOGYma8pCriKU2mAGe9Tim1Ly4RWeWaOA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794465993;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
bh=ntDd/S6L1RCmt2oOT/IfmwbQKnfoI4o0MqE17OZVDwQ=;
b=n/qOxF1Q602N29OH/LKP6p9iQh0alM8Om7JybHwyyuYkiX/NNtBK/Ectn+V6RLTtkAbc
ztdL+e+PLQQ7I6E58RV+fRPaUAb0ZyDf7eh930ocFDzd/RSjKTSTdynM5lxdJMhI/618j
DhHKTTcpBtUGno/34xrVwHh/wwrPR9D9+lZxpn+nlRQKPOgam1ITDlqgnzu2CmEkgBRQr
iYjGbd0XIGgHfjPM/PTyy1tYXYBljlljWwCUWGXqfuhxiB41Ix/sa51Ur5tDVEmPsgGST
DdaOxEu1uRCb7kwh90DxdmG1kfkvej5jGe88/A35fauRFCpn0pAyRoi8jmDR6bqDNTQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yNBm4s88;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 6790D606A336;
Thu, 12 Nov 2026 06:46:33 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yNBm4s88
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794465992;
b=jCy9TowgU2IxZP1Y6AXEz6kTTUKr2XHXyIZqW8DGJKCMT67xr99Sf92D/bYz8ofOEypN
mweKpu4kw1pvJPhjyiAqUNIyfXWtjYzpX/3m9cJv7ByjFWpSHKiWqSP4ruCeLRo1q0z/F
IYPr96XaGjJx/tdV9yOxAObb5H+r7+PShqtxsbqtc8Tu8Lz0CXYaC4rK8/XfYB2JfbyCA
V0gTXdhrG8oWwWYY7q9QsxLJ6d54IKDie0AYe4PJrhHMEsnTFHgagQj+i4seoTZmckHh4
oNPjUN34cM7BO0ydF3SkSkczN2yjK0bDcT/3+TqqOY+7K/RM8WX6EPc8F51ZTobzQrQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794465992;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding;
bh=ntDd/S6L1RCmt2oOT/IfmwbQKnfoI4o0MqE17OZVDwQ=;
b=BuLTeddCPTw0UzFRXCbs2Q8AMjzcoSYO+ChG7Vr+qkS6yRshVWymtO6Cq09MEszTvHeO
AMM+zvC6vkBjnriUfSnrep/yrEbxa43qlXe3HNzmfLRDLi4nfZybjvc+0jJgsfgWDuuQ6
w3g7nfTKoNX9uschXfkDqyHVhFNWYMnv3CL/UBui87nmXsbGYFIdWvqYJiigWD/mEQdMX
iobatxyw7ZglVLAL8Rk2KiXPVnSKsNZS4AnRXmrFPm2joHZ6KdOY+6UuVDnzkV6QMOmo6
gzxOmlEgWmrpM8+AYeo5DEzklfHVFBhxy/aVlICCSFDtLCvdAXZV7DimDf//e9ukHgA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yNBm4s88;
arc=none smtp.remote-ip=74.125.224.44
X-Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37067606A323
for <netdev@vger.kernel.org>; Thu, 12 Nov 2026 06:46:31 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37067606A323
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-67be5d0e9cbso2832036d50.3
for <netdev@vger.kernel.org>; Wed, 11 Nov 2026 22:46:31 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794465991; x=1795070791; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=ntDd/S6L1RCmt2oOT/IfmwbQKnfoI4o0MqE17OZVDwQ=;
b=yNBm4s88C2IB7zlunIssuy+UbsDs1TkX1LT/9Hh5TZhuYv60Zj3fmnJq1AoJJ24JgZ
AfxQTGrYe9+A8dvjyw7mTXTA23j6RrML62LVYxOKiYAZdLhhxlyOmXmqqRYYM0NIbCVP
qteyyNE3qmAfeCqZOQDx4O1mKifh8jYEFeH2XX+ck7VmBYmuIPLV85J/SVuA7CbEgnzk
PJPaedCgd0w1yeXIAOqcbyCbiLyvPB9L/R5xV3TBzcgMNeWKY1j0jfvVzae0nOjFmH/s
Eg4cSvAWCdoi8qXrog36Y8JaCMNfIVrEUu6b8dD16C7h8gA5tH2f+kGxOAA0nt0X8nDt
JW8Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794465991; x=1795070791;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=ntDd/S6L1RCmt2oOT/IfmwbQKnfoI4o0MqE17OZVDwQ=;
b=toBsDxdA99w/2FUqJDX8FV8l2gM9VIR3GQ+D+MH8nVFnkW32xaSCwSw7Uf1LuEDc03
gPmXPEsoEHwqWl8forfbgecF+AcrSm1pN1Yu3nqbsGF4sWsPtKIZVme0MdDcd7jClL7L
/uITJfUe+2w1115RBtt2bzQQwmyv5dLVqMtwO5nDuSQlfxBDKzvv+FFfoY8o6L1WQv9G
nWa/88dQXDcqhTu9khNO8vqPORolrKv0cHFOQrmkAQ0LZFcslu0pSdOxrjV/6pyvsIxk
qftR9yl+tX1Osfmk32gJ34B74tsAArhwgJCMqg53kyaeqXCQvLoHdFzZeQHjCV/hNgOz
7Duw==
X-Gm-Message-State: APuU4Z9x0uw2QVcO9TuKi1tKWC/LPBXa1LhIrGvMrBWsCM/PwQ6/IVsS
G2Udp4PccnDF8jYqzAGmZipZjixNPtNTaMQsHiAV3z9NjZcKlH7IfJvd
X-Gm-Gg: AYBFou3zjRJL5cvsUL8su6cFszHuKUzo57QgisRrwzLvgxsLbpAhE2XMYwF1JcQSpfu
pGmd8pKWzUTsgBdQISZtL+xHlz7XbplskMsVdvuobIV9S8Z3Mu5q7LkalnWtZ5Z1xh/Y3yRyd14
e9FF+SDsvk+RF/ZelGHj2ocQXuxoZMSnURru0oPP58hHg18k1PLaKZp5v+50i8LAoueKnZL1Vcp
ayw4DEp465ABDsxjXLuSO6dCAJvK/JElkkcUE1PB6sh0NY6KFbidGcc3GBMJ4gL7XGc7T7bawPm
gsKWR2jUJy0crey/qeNJrqcZlwNc6uiSFc2rIv8b4NK8RvoFdw86d9M0KFsQFJxriFg6k7N9OES
XMq0tL6zqlaK88EUvhNWdo44sB1zhhGF5BmEndlSAPgB70gtkrTfJe9BrTBAyAkxeeizVGpqDKX
TxNIztB/N8uzZGjmbqdC8xaLTHMqyrIMtkbN+E/6B3dqv8KoPHxeepuE4BWb8ucM8rnfTyeQpF8
sCq7ZsriaxKvq2wdbtbYdoWXjkZ8EYUdlzpw926mIXFb58m8Fnt9BhDwOhilMXCC5i4O8OM7vB7
aVqStF4G0aVHtaCh1dBjXe8kP5J1ri8PUHPgFuz4bRr38jzdhdbGhw==
X-Received: by 2002:a05:690e:140d:b0:67c:2350:5b8c with SMTP id 956f58d0204a3-67c67fd76acmr2791998d50.26.1794465989718;
Wed, 11 Nov 2026 22:46:29 -0800 (PST)
X-Received: from VPN-156-197.vpn.usf.edu ([2607:fe50:0:f802::4046])
by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67c589a3450sm6629012d50.4.2026.11.11.22.46.27
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Wed, 11 Nov 2026 22:46:28 -0800 (PST)
X-Cc: netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.53.0
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