Skip to contentSkip to conversation

tcp_metrics: hash the destination address with SipHash

PATCH Superseded Juan Agustin Niccolini 3 participants 4 messages Nov 17 – Nov 19

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tcp_metrics: hash the destination address with SipHash

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.

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. 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.")

---
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/[email protected]/

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(-)
net/ipv4/tcp_metrics.c +21 -7
@@ -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;
maintainer
#1 lore raw
Quoted 11 lines · Juan Agustin Niccolini

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:

Quoted 7 lines

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.

Quoted 6 lines

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

net/ipv4/tcp_metrics.c

Quoted 50 lines

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.")

---
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/[email protected]/

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(-)
net/ipv4/tcp_metrics.c +0 -0

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.

Quoted 98 lines
net/ipv4/tcp_metrics.c +21 -7
@@ -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;
#2 lore raw
In reply to Juan Agustin Niccolini
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In net/ipv4/tcp_metrics.c, tcpm_addr_hash() hashes only the peer address, with one global key (tcpm_hash_key) shared by every…

--

tcp_metrics: hash the destination address with SipHash

This commit changes how a tcp_metrics bucket is picked. It used the ipv4_addr_hash()/ipv6_addr_hash() fold of the peer address and now uses SipHash of the address with a random key. The goal is to stop attackers from computing colliding addresses and recovering net_hash_mix(), which is still XORed in afterwards to separate namespaces.

Quoted 4 lines
net/ipv4/tcp_metrics.c +0 -0
index ae551546422fe..1d6c88bc35cc8 100644

[ ... ]

Quoted 20 lines
net/ipv4/tcp_metrics.c +16 -0
@@ -95,6 +96,22 @@ static unsigned int		tcp_metrics_hash_log __read_mostly;
 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);
+}
+

[ ... ]

net/ipv4/tcp_metrics.c static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, · line 347

Quoted 7 lines
net/ipv4/tcp_metrics.c +1 -0
@@ -329,6 +342,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
 		return NULL;
 
 	net = sock_net(sk);
+	hash = tcpm_addr_hash(&daddr);
 	hash ^= net_hash_mix(net);
 	hash = hash_32(hash, tcp_metrics_hash_log);

[Severity: Medium]

Is net_hash_mix() still enough to keep the namespaces apart here?

tcpm_addr_hash() takes no netns input and uses one global tcpm_hash_key. So S(addr) = siphash(addr, tcpm_hash_key) is the same in every netns. The namespace only comes in after that, in tcp_get_metrics(), __tcp_get_metrics_req() and the netlink paths through __parse_nl_addr().

For two namespaces A and B, the bucket maps then differ only by the constant mix_A ^ mix_B. That constant is applied before the invertible multiply in hash_32(). This is the XOR-then-multiply structure the changelog calls not a PRF.

tcp_metrics_hash is global. A local user who owns a netns (a container, or unshare -Urn where unprivileged user namespaces are allowed) seems to have both oracles the attack needs:

- tcpm_new() reclaim reuses the oldest entry in the bucket no matter which netns owns it. So another netns, such as init_net, can evict the user's own entries.

- TCP_METRICS_CMD_GET has no GENL_ADMIN_PERM and the family is netnsok. tcp_metrics_nl_dump() returns the caller's own entries in bucket order.

Because S(X) is shared, take an address X that the attacker controls. If X collides with a victim address V in the attacker's own namespaces, it also collides in the victim's netns.

Another route is to solve for mix_A ^ mix_B from cross-netns evictions. Either way, the attacker could watch V's bucket in the victim netns and tell whether V connected.

It isn't clear how cheap this is in practice. The S-collision route needs on the order of 2^32 own-netns tests. The other route needs more than the few hundred answers described for the remote attack.

Still, the changelog says:

net_hash_mix() and hash_32() are kept, to separate namespaces and to reduce the result to the table size.

With this construction the namespaces don't get independent bucket maps.

Could the namespace be part of the keyed hash input instead? For IPv4 that could be siphash_2u32(addr, net_hash_mix(net), &tcpm_hash_key), and IPv6 could add the mix to its input the same way. inet_ehashfn() does something similar: it feeds net_hash_mix(net) into the hash seed instead of XORing it into the output.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117041029.80543-1-juanagusnicco%40gmail.com
#3 lore raw

The issue Sashiko flagged looks like a quirk to me.

On the collision route Sashiko describes, the attacker has to be local and needs on the order of 2^32 connections per target address. I couldn't find another route, and the worst case is still a local leak of peer IP addresses that only applies in specific configurations.

I'll look into whether it can be addressed at no cost on every axis (backporting, clarity, etc.).

I will send v3 today including Eric's requested changes and answers to his questions. I confirmed the remote leak is exploitable even on high traffic hosts.

Best,
Agustin

Quoted 118 lines · On Thu, Nov 19, 2026 at 11:12 AM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In net/ipv4/tcp_metrics.c, tcpm_addr_hash() hashes only the peer address, with one global key (tcpm_hash_key) shared by every…

--

tcp_metrics: hash the destination address with SipHash

This commit changes how a tcp_metrics bucket is picked. It used the ipv4_addr_hash()/ipv6_addr_hash() fold of the peer address and now uses SipHash of the address with a random key. The goal is to stop attackers from computing colliding addresses and recovering net_hash_mix(), which is still XORed in afterwards to separate namespaces.

Quoted 4 lines
net/ipv4/tcp_metrics.c +0 -0
index ae551546422fe..1d6c88bc35cc8 100644

[ ... ]

Quoted 20 lines
net/ipv4/tcp_metrics.c +16 -0
@@ -95,6 +96,22 @@ static unsigned int                tcp_metrics_hash_log __read_mostly;
 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);
+}
+

[ ... ]

net/ipv4/tcp_metrics.c static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, · line 347

Quoted 7 lines
net/ipv4/tcp_metrics.c +1 -0
@@ -329,6 +342,7 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
              return NULL;
 
      net = sock_net(sk);
+     hash = tcpm_addr_hash(&daddr);
      hash ^= net_hash_mix(net);
      hash = hash_32(hash, tcp_metrics_hash_log);

[Severity: Medium]

Is net_hash_mix() still enough to keep the namespaces apart here?

tcpm_addr_hash() takes no netns input and uses one global tcpm_hash_key. So S(addr) = siphash(addr, tcpm_hash_key) is the same in every netns. The namespace only comes in after that, in tcp_get_metrics(), __tcp_get_metrics_req() and the netlink paths through __parse_nl_addr().

For two namespaces A and B, the bucket maps then differ only by the constant mix_A ^ mix_B. That constant is applied before the invertible multiply in hash_32(). This is the XOR-then-multiply structure the changelog calls not a PRF.

tcp_metrics_hash is global. A local user who owns a netns (a container, or unshare -Urn where unprivileged user namespaces are allowed) seems to have both oracles the attack needs:

- tcpm_new() reclaim reuses the oldest entry in the bucket no matter which netns owns it. So another netns, such as init_net, can evict the user's own entries.

- TCP_METRICS_CMD_GET has no GENL_ADMIN_PERM and the family is netnsok. tcp_metrics_nl_dump() returns the caller's own entries in bucket order.

Because S(X) is shared, take an address X that the attacker controls. If X collides with a victim address V in the attacker's own namespaces, it also collides in the victim's netns.

Another route is to solve for mix_A ^ mix_B from cross-netns evictions. Either way, the attacker could watch V's bucket in the victim netns and tell whether V connected.

It isn't clear how cheap this is in practice. The S-collision route needs on the order of 2^32 own-netns tests. The other route needs more than the few hundred answers described for the remote attack.

Still, the changelog says:

net_hash_mix() and hash_32() are kept, to separate namespaces and to reduce the result to the table size.

With this construction the namespaces don't get independent bucket maps.

Could the namespace be part of the keyed hash input instead? For IPv4 that could be siphash_2u32(addr, net_hash_mix(net), &tcpm_hash_key), and IPv6 could add the mix to its input the same way. inet_ehashfn() does something similar: it feeds net_hash_mix(net) into the hash seed instead of XORing it into the output.

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117041029.80543-1-juanagusnicco%40gmail.com