Re: [PATCH net v2] tcp_metrics: hash the destination address with SipHash

From: Juan Agustín Nicco

Date: Thu Nov 19 2026 - 12:21:33 EST


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


On Thu, Nov 19, 2026 at 11:12 AM <netdev-bot+sashiko@xxxxxxxxxx> 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.
>
> > diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
> > index ae551546422fe..1d6c88bc35cc8 100644
> > --- a/net/ipv4/tcp_metrics.c
> > +++ b/net/ipv4/tcp_metrics.c
>
> [ ... ]
>
> > @@ -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);
> > +}
> > +
>
> [ ... ]
>
> > @@ -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