inet: use siphash in exception handling
Subsystems (3)
cover inet: use siphash in exception handling
From: Eric Dumazet <[email protected]>
A group of security researchers brought to our attention the weakness of hash functions used in rt6_exception_hash() and fnhe_hashfun()
I made two distinct patches to help backports, since IPv6 part was added in 4.15
Eric Dumazet (2):
ipv6: use siphash in rt6_exception_hash()
ipv4: use siphash instead of Jenkins in fnhe_hashfun()
net/ipv4/route.c | 12 ++++++------ net/ipv6/route.c | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-)
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog
PATCH 1/2 ipv6: use siphash in rt6_exception_hash()
From: Eric Dumazet <[email protected]>
A group of security researchers brought to our attention the weakness of hash function used in rt6_exception_hash()
Lets use siphash instead of Jenkins Hash, to considerably reduce security risks.
Following patch deals with IPv4.
--- net/ipv6/route.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
net/ipv6/route.c +14 -6
@@ -41,6 +41,7 @@#include <linux/nsproxy.h> #include <linux/slab.h> #include <linux/jhash.h> +#include <linux/siphash.h> #include <net/net_namespace.h> #include <net/snmp.h> #include <net/ipv6.h>
@@ -1484,17 +1485,24 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket)static u32 rt6_exception_hash (const struct in6_addr *dst,const struct in6_addr *src) { -static u32 seed__read_mostly ; -u32 val; +static siphash_key_t rt6_exception_key__read_mostly ; +struct { +struct in6_addr dst; +struct in6_addr src; + }__aligned(SIPHASH_ALIGNMENT) combined = { + .dst = *dst, + }; +u64 val; -net_get_random_once (&seed,sizeof (seed)); - val =jhash2 ((const u32 *)dst,sizeof (*dst)/sizeof (u32), seed); +net_get_random_once (&rt6_exception_key,sizeof (rt6_exception_key));#ifdef CONFIG_IPV6_SUBTREES if (src) - val =jhash2 ((const u32 *)src,sizeof (*src)/sizeof (u32), val); + combined.src = *src;#endif -return hash_32 (val,FIB6_EXCEPTION_BUCKET_SIZE_SHIFT ); + val =siphash (&combined,sizeof (combined), &rt6_exception_key); + +return hash_64 (val,FIB6_EXCEPTION_BUCKET_SIZE_SHIFT ); }/* Helper function to find the cached rt in the hash table
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog
Re: [PATCH net 1/2] ipv6: use siphash in rt6_exception_hash()
Quoted 9 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
A group of security researchers brought to our attention the weakness of hash function used in
rt6_exception_hash()Lets use siphash instead of Jenkins Hash, to considerably reduce security risks.
Quoted 7 lines
Following patch deals with IPv4.
Fixes 35732d01fe31 ("ipv6: introduce a hash table to store dst cache")Signed-off-by Eric Dumazet <[email protected]>Reported-by Keyu Man <[email protected]>Cc Wei Wang <[email protected]>Cc Martin KaFai Lau <[email protected]>
Thanks Eric!
Quoted 53 lines
---
net/ipv6/route.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)net/ipv6/route.c +14
-7@@ -41,6 +41,7 @@#include <linux/nsproxy.h> #include <linux/slab.h> #include <linux/jhash.h> +#include <linux/siphash.h> #include <net/net_namespace.h> #include <net/snmp.h> #include <net/ipv6.h> @@ -1484,17 +1485,24 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket)static u32 rt6_exception_hash (const struct in6_addr *dst,const struct in6_addr *src) { -static u32 seed__read_mostly ; -u32 val; +static siphash_key_t rt6_exception_key__read_mostly ; +struct { +struct in6_addr dst; +struct in6_addr src; + }__aligned(SIPHASH_ALIGNMENT) combined = { + .dst = *dst, + }; +u64 val; -net_get_random_once (&seed,sizeof (seed)); - val =jhash2 ((const u32 *)dst,sizeof (*dst)/sizeof (u32), seed); +net_get_random_once (&rt6_exception_key,sizeof (rt6_exception_key));#ifdef CONFIG_IPV6_SUBTREES if (src) - val =jhash2 ((const u32 *)src,sizeof (*src)/sizeof (u32), val); + combined.src = *src;#endif -return hash_32 (val,FIB6_EXCEPTION_BUCKET_SIZE_SHIFT ); + val =siphash (&combined,sizeof (combined), &rt6_exception_key); + +return hash_64 (val,FIB6_EXCEPTION_BUCKET_SIZE_SHIFT ); }/* Helper function to find the cached rt in the hash table -- 2.33.0.rc2.250.ged5fa647cd-goog
PATCH 2/2 ipv4: use siphash instead of Jenkins in fnhe_hashfun()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
A group of security researchers brought to our attention the weakness of hash function used in fnhe_hashfun().
Lets use siphash instead of Jenkins Hash, to considerably reduce security risks.
Also remove the inline keyword, this really is distracting.
--- net/ipv4/route.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/ipv4/route.c +6 -6
@@ -600,14 +600,14 @@ static struct fib_nh_exception *fnhe_oldest(struct fnhe_hash_bucket *hash)return oldest; } -static inline u32 fnhe_hashfun (__be32 daddr) +static u32 fnhe_hashfun (__be32 daddr) { -static u32 fnhe_hashrnd__read_mostly ; -u32 hval; +static siphash_key_t fnhe_hash_key__read_mostly ; +u64 hval; -net_get_random_once (&fnhe_hashrnd,sizeof (fnhe_hashrnd)); - hval =jhash_1word ((__force u32 )daddr, fnhe_hashrnd); -return hash_32 (hval,FNHE_HASH_SHIFT ); +net_get_random_once (&fnhe_hash_key,sizeof (fnhe_hash_key)); + hval =siphash_1u32 ((__force u32 )daddr, &fnhe_hash_key); +return hash_64 (hval,FNHE_HASH_SHIFT ); }static void fill_route_from_fnhe (struct rtable *rt,struct fib_nh_exception *fnhe)
Signature · 1 line
2.33.0.rc2.250.ged5fa647cd-goog
This series was applied to netdev/net.git (refs/heads/master):
Hello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 10 lines · On Wed, 25 Aug 2021 16:17:27 -0700 you wrote:
From: Eric Dumazet <[email protected]>
A group of security researchers brought to our attention the weakness of hash functions used in
rt6_exception_hash()andfnhe_hashfun()I made two distinct patches to help backports, since IPv6 part was added in 4.15
[...]
Here is the summary with links:
- [net,1/2] ipv6: use siphash in rt6_exception_hash()
https://git.kernel.org/netdev/net/c/4785305c05b2 - [net,2/2] ipv4: use siphash instead of Jenkins in fnhe_hashfun() https://git.kernel.org/netdev/net/c/6457378fe796
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html