diff mbox series

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

Message ID 20241008120101.734521-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 4a0ec2aa0704c8271fde33a0f7bb92d09c066c17
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ipv6: switch inet6_addr_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, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
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:01 p.m. UTC
In commit 3f27fb23219e ("ipv6: addrconf: add per netns perturbation
in inet6_addr_hash()"), I added net_hash_mix() in inet6_addr_hash()
to get better hash dispersion, at a time all netns were sharing the
hash table.

Since then, commit 21a216a8fc63 ("ipv6/addrconf: allocate a per
netns hash table") made the hash table per netns.

We could remove the net_hash_mix() from inet6_addr_hash(), but
there is still an issue with ipv6_addr_hash().

It is highly predictable and a malicious user can easily create
thousands of IPv6 addresses all stored in the same 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/addrconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern Oct. 8, 2024, 2:40 p.m. UTC | #1
On 10/8/24 6:01 AM, Eric Dumazet wrote:
> In commit 3f27fb23219e ("ipv6: addrconf: add per netns perturbation
> in inet6_addr_hash()"), I added net_hash_mix() in inet6_addr_hash()
> to get better hash dispersion, at a time all netns were sharing the
> hash table.
> 
> Since then, commit 21a216a8fc63 ("ipv6/addrconf: allocate a per
> netns hash table") made the hash table per netns.
> 
> We could remove the net_hash_mix() from inet6_addr_hash(), but
> there is still an issue with ipv6_addr_hash().
> 
> It is highly predictable and a malicious user can easily create
> thousands of IPv6 addresses all stored in the same 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/addrconf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
Kuniyuki Iwashima Oct. 8, 2024, 4:21 p.m. UTC | #2
From: Eric Dumazet <edumazet@google.com>
Date: Tue,  8 Oct 2024 12:01:01 +0000
> In commit 3f27fb23219e ("ipv6: addrconf: add per netns perturbation
> in inet6_addr_hash()"), I added net_hash_mix() in inet6_addr_hash()
> to get better hash dispersion, at a time all netns were sharing the
> hash table.
> 
> Since then, commit 21a216a8fc63 ("ipv6/addrconf: allocate a per
> netns hash table") made the hash table per netns.
> 
> We could remove the net_hash_mix() from inet6_addr_hash(), but
> there is still an issue with ipv6_addr_hash().
> 
> It is highly predictable and a malicious user can easily create
> thousands of IPv6 addresses all stored in the same 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:01:01 +0000 you wrote:
> In commit 3f27fb23219e ("ipv6: addrconf: add per netns perturbation
> in inet6_addr_hash()"), I added net_hash_mix() in inet6_addr_hash()
> to get better hash dispersion, at a time all netns were sharing the
> hash table.
> 
> Since then, commit 21a216a8fc63 ("ipv6/addrconf: allocate a per
> netns hash table") made the hash table per netns.
> 
> [...]

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

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 94dceac528842c47c18e71ad75e9d16ae373b4f2..f31528d4f694e42032276ddd6230b23911c480b5 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1016,7 +1016,7 @@  ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
 
 static u32 inet6_addr_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);
 }