netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash
@ 2024-10-08 12:13 Eric Dumazet
  2024-10-08 14:40 ` David Ahern
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2024-10-08 12:13 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: David Ahern, Kuniyuki Iwashima, netdev, eric.dumazet,
	Eric Dumazet

commit 2384d02520ff ("net/ipv6: Add anycast addresses to a global hashtable")
added inet6_acaddr_hash(), using ipv6_addr_hash() and net_hash_mix()
to get hash spreading for typical users.

However ipv6_addr_hash() is highly predictable and a malicious user
could abuse a specific hash bucket.

Switch to __ipv6_addr_jhash(). We could use a dedicated
secret, or reuse net_hash_mix() as I did in this patch.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv6/anycast.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 0627c4c18d1a5067a668da778ad444855194cbeb..562cace50ca9ae635dd0762e147b452be44c729c 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -49,9 +49,10 @@ static DEFINE_SPINLOCK(acaddr_hash_lock);
 
 static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr);
 
-static u32 inet6_acaddr_hash(struct net *net, const struct in6_addr *addr)
+static u32 inet6_acaddr_hash(const struct net *net,
+			     const struct in6_addr *addr)
 {
-	u32 val = ipv6_addr_hash(addr) ^ net_hash_mix(net);
+	u32 val = __ipv6_addr_jhash(addr, net_hash_mix(net));
 
 	return hash_32(val, IN6_ADDR_HSIZE_SHIFT);
 }
-- 
2.47.0.rc0.187.ge670bccf7e-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash
  2024-10-08 12:13 [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash Eric Dumazet
@ 2024-10-08 14:40 ` David Ahern
  2024-10-08 16:23 ` Kuniyuki Iwashima
  2024-10-10  2:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2024-10-08 14:40 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Kuniyuki Iwashima, netdev, eric.dumazet

On 10/8/24 6:13 AM, Eric Dumazet wrote:
> commit 2384d02520ff ("net/ipv6: Add anycast addresses to a global hashtable")
> added inet6_acaddr_hash(), using ipv6_addr_hash() and net_hash_mix()
> to get hash spreading for typical users.
> 
> However ipv6_addr_hash() is highly predictable and a malicious user
> could abuse a specific hash bucket.
> 
> Switch to __ipv6_addr_jhash(). We could use a dedicated
> secret, or reuse net_hash_mix() as I did in this patch.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  net/ipv6/anycast.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash
  2024-10-08 12:13 [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash Eric Dumazet
  2024-10-08 14:40 ` David Ahern
@ 2024-10-08 16:23 ` Kuniyuki Iwashima
  2024-10-10  2:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-08 16:23 UTC (permalink / raw)
  To: edumazet; +Cc: davem, dsahern, eric.dumazet, kuba, kuniyu, netdev, pabeni

From: Eric Dumazet <edumazet@google.com>
Date: Tue,  8 Oct 2024 12:13:07 +0000
> commit 2384d02520ff ("net/ipv6: Add anycast addresses to a global hashtable")
> added inet6_acaddr_hash(), using ipv6_addr_hash() and net_hash_mix()
> to get hash spreading for typical users.
> 
> However ipv6_addr_hash() is highly predictable and a malicious user
> could abuse a specific hash bucket.
> 
> Switch to __ipv6_addr_jhash(). We could use a dedicated
> secret, or reuse net_hash_mix() as I did in this patch.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash
  2024-10-08 12:13 [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash Eric Dumazet
  2024-10-08 14:40 ` David Ahern
  2024-10-08 16:23 ` Kuniyuki Iwashima
@ 2024-10-10  2:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-10  2:50 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, dsahern, kuniyu, netdev, eric.dumazet

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  8 Oct 2024 12:13:07 +0000 you wrote:
> commit 2384d02520ff ("net/ipv6: Add anycast addresses to a global hashtable")
> added inet6_acaddr_hash(), using ipv6_addr_hash() and net_hash_mix()
> to get hash spreading for typical users.
> 
> However ipv6_addr_hash() is highly predictable and a malicious user
> could abuse a specific hash bucket.
> 
> [...]

Here is the summary with links:
  - [net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash
    https://git.kernel.org/netdev/net-next/c/4daf4dc275f1

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-10  2:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08 12:13 [PATCH net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash Eric Dumazet
2024-10-08 14:40 ` David Ahern
2024-10-08 16:23 ` Kuniyuki Iwashima
2024-10-10  2:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).