diff mbox series

[net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash

Message ID 20241008121307.800040-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 4daf4dc275f1aa3b9629334c4185d62b7bdff1c4
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ipv6: switch inet6_acaddr_hash() to less predictable hash | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-09--18-00 (tests: 772)

Commit Message

Eric Dumazet Oct. 8, 2024, 12:13 p.m. UTC
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(-)

Comments

David Ahern Oct. 8, 2024, 2:40 p.m. UTC | #1
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>
Kuniyuki Iwashima Oct. 8, 2024, 4:23 p.m. UTC | #2
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>
patchwork-bot+netdevbpf@kernel.org Oct. 10, 2024, 2:50 a.m. UTC | #3
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!
diff mbox series

Patch

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);
 }