Commit 4785305c authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

ipv6: use siphash in rt6_exception_hash()

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.

Fixes: 35732d01 ("ipv6: introduce a hash table to store dst cache")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reported-by: default avatarKeyu Man <kman001@ucr.edu>
Cc: Wei Wang <weiwan@google.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Acked-by: default avatarWei Wang <weiwan@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 92ea47fe
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/nsproxy.h> #include <linux/nsproxy.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/jhash.h> #include <linux/jhash.h>
#include <linux/siphash.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/snmp.h> #include <net/snmp.h>
#include <net/ipv6.h> #include <net/ipv6.h>
...@@ -1484,17 +1485,24 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket) ...@@ -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, static u32 rt6_exception_hash(const struct in6_addr *dst,
const struct in6_addr *src) const struct in6_addr *src)
{ {
static u32 seed __read_mostly; static siphash_key_t rt6_exception_key __read_mostly;
u32 val; struct {
struct in6_addr dst;
struct in6_addr src;
} __aligned(SIPHASH_ALIGNMENT) combined = {
.dst = *dst,
};
u64 val;
net_get_random_once(&seed, sizeof(seed)); net_get_random_once(&rt6_exception_key, sizeof(rt6_exception_key));
val = jhash2((const u32 *)dst, sizeof(*dst)/sizeof(u32), seed);
#ifdef CONFIG_IPV6_SUBTREES #ifdef CONFIG_IPV6_SUBTREES
if (src) if (src)
val = jhash2((const u32 *)src, sizeof(*src)/sizeof(u32), val); combined.src = *src;
#endif #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 /* Helper function to find the cached rt in the hash table
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment