netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 net-next] ipv4: Switch inet_addr_hash() to less predictable hash.
@ 2024-10-18  1:41 Kuniyuki Iwashima
  2024-10-18  5:15 ` Eric Dumazet
  2024-10-23 11:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-18  1:41 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	David Ahern
  Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev

Recently, commit 4a0ec2aa0704 ("ipv6: switch inet6_addr_hash()
to less predictable hash") and commit 4daf4dc275f1 ("ipv6: switch
inet6_acaddr_hash() to less predictable hash") hardened IPv6
address hash functions.

inet_addr_hash() is also highly predictable, and a malicious use
could abuse a specific bucket.

Let's follow the change on IPv4 by using jhash_1word().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/net/ip.h   | 5 +++++
 net/ipv4/devinet.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/net/ip.h b/include/net/ip.h
index 4be0a6a603b2..0e548c1f2a0e 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -690,6 +690,11 @@ static inline unsigned int ipv4_addr_hash(__be32 ip)
 	return (__force unsigned int) ip;
 }
 
+static inline u32 __ipv4_addr_hash(const __be32 ip, const u32 initval)
+{
+	return jhash_1word((__force u32)ip, initval);
+}
+
 static inline u32 ipv4_portaddr_hash(const struct net *net,
 				     __be32 saddr,
 				     unsigned int port)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index d81fff93d208..3e5e3b5e78c4 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -121,7 +121,7 @@ struct inet_fill_args {
 
 static u32 inet_addr_hash(const struct net *net, __be32 addr)
 {
-	u32 val = (__force u32) addr ^ net_hash_mix(net);
+	u32 val = __ipv4_addr_hash(addr, net_hash_mix(net));
 
 	return hash_32(val, IN4_ADDR_HSIZE_SHIFT);
 }
-- 
2.39.5 (Apple Git-154)


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

* Re: [PATCH v1 net-next] ipv4: Switch inet_addr_hash() to less predictable hash.
  2024-10-18  1:41 [PATCH v1 net-next] ipv4: Switch inet_addr_hash() to less predictable hash Kuniyuki Iwashima
@ 2024-10-18  5:15 ` Eric Dumazet
  2024-10-23 11:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2024-10-18  5:15 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, David Ahern,
	Kuniyuki Iwashima, netdev

On Fri, Oct 18, 2024 at 3:41 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> Recently, commit 4a0ec2aa0704 ("ipv6: switch inet6_addr_hash()
> to less predictable hash") and commit 4daf4dc275f1 ("ipv6: switch
> inet6_acaddr_hash() to less predictable hash") hardened IPv6
> address hash functions.
>
> inet_addr_hash() is also highly predictable, and a malicious use
> could abuse a specific bucket.
>
> Let's follow the change on IPv4 by using jhash_1word().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH v1 net-next] ipv4: Switch inet_addr_hash() to less predictable hash.
  2024-10-18  1:41 [PATCH v1 net-next] ipv4: Switch inet_addr_hash() to less predictable hash Kuniyuki Iwashima
  2024-10-18  5:15 ` Eric Dumazet
@ 2024-10-23 11:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-23 11:30 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: davem, edumazet, kuba, pabeni, dsahern, kuni1840, netdev

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Thu, 17 Oct 2024 18:41:00 -0700 you wrote:
> Recently, commit 4a0ec2aa0704 ("ipv6: switch inet6_addr_hash()
> to less predictable hash") and commit 4daf4dc275f1 ("ipv6: switch
> inet6_acaddr_hash() to less predictable hash") hardened IPv6
> address hash functions.
> 
> inet_addr_hash() is also highly predictable, and a malicious use
> could abuse a specific bucket.
> 
> [...]

Here is the summary with links:
  - [v1,net-next] ipv4: Switch inet_addr_hash() to less predictable hash.
    https://git.kernel.org/netdev/net-next/c/c972c1c41d9b

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] 3+ messages in thread

end of thread, other threads:[~2024-10-23 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-18  1:41 [PATCH v1 net-next] ipv4: Switch inet_addr_hash() to less predictable hash Kuniyuki Iwashima
2024-10-18  5:15 ` Eric Dumazet
2024-10-23 11:30 ` 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).