Skip to content

Commit c972c1c

Browse files
q2venPaolo Abeni
authored andcommitted
ipv4: Switch inet_addr_hash() to less predictable hash.
Recently, commit 4a0ec2a ("ipv6: switch inet6_addr_hash() to less predictable hash") and commit 4daf4dc ("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 <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 7213a1c commit c972c1c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/net/ip.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ static inline unsigned int ipv4_addr_hash(__be32 ip)
690690
return (__force unsigned int) ip;
691691
}
692692

693+
static inline u32 __ipv4_addr_hash(const __be32 ip, const u32 initval)
694+
{
695+
return jhash_1word((__force u32)ip, initval);
696+
}
697+
693698
static inline u32 ipv4_portaddr_hash(const struct net *net,
694699
__be32 saddr,
695700
unsigned int port)

net/ipv4/devinet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct inet_fill_args {
121121

122122
static u32 inet_addr_hash(const struct net *net, __be32 addr)
123123
{
124-
u32 val = (__force u32) addr ^ net_hash_mix(net);
124+
u32 val = __ipv4_addr_hash(addr, net_hash_mix(net));
125125

126126
return hash_32(val, IN4_ADDR_HSIZE_SHIFT);
127127
}

0 commit comments

Comments
 (0)