From: netdev-bot+sashiko@kernel.org
To: juanagusnicco@gmail.com
Cc: edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] tcp_metrics: hash the destination address with SipHash
Date: Thu, 19 Nov 2026 16:12:44 +0000 [thread overview]
Message-ID: <179510476492.3136.15185317023274420078@kernel.org> (raw)
In-Reply-To: <20261117041029.80543-1-juanagusnicco@gmail.com>
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
prev parent reply other threads:[~2026-11-19 16:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 4:10 [PATCH net v2] tcp_metrics: hash the destination address with SipHash Juan Agustin Niccolini
2026-11-17 9:20 ` Eric Dumazet
2026-11-19 16:12 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179510476492.3136.15185317023274420078@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=juanagusnicco@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox