Skip to content

Commit 4785305

Browse files
edumazetdavem330
authored andcommitted
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: 35732d0 ("ipv6: introduce a hash table to store dst cache") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Keyu Man <kman001@ucr.edu> Cc: Wei Wang <weiwan@google.com> Cc: Martin KaFai Lau <kafai@fb.com> Acked-by: Wei Wang <weiwan@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 92ea47f commit 4785305

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

net/ipv6/route.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/nsproxy.h>
4242
#include <linux/slab.h>
4343
#include <linux/jhash.h>
44+
#include <linux/siphash.h>
4445
#include <net/net_namespace.h>
4546
#include <net/snmp.h>
4647
#include <net/ipv6.h>
@@ -1484,17 +1485,24 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket)
14841485
static u32 rt6_exception_hash(const struct in6_addr *dst,
14851486
const struct in6_addr *src)
14861487
{
1487-
static u32 seed __read_mostly;
1488-
u32 val;
1488+
static siphash_key_t rt6_exception_key __read_mostly;
1489+
struct {
1490+
struct in6_addr dst;
1491+
struct in6_addr src;
1492+
} __aligned(SIPHASH_ALIGNMENT) combined = {
1493+
.dst = *dst,
1494+
};
1495+
u64 val;
14891496

1490-
net_get_random_once(&seed, sizeof(seed));
1491-
val = jhash2((const u32 *)dst, sizeof(*dst)/sizeof(u32), seed);
1497+
net_get_random_once(&rt6_exception_key, sizeof(rt6_exception_key));
14921498

14931499
#ifdef CONFIG_IPV6_SUBTREES
14941500
if (src)
1495-
val = jhash2((const u32 *)src, sizeof(*src)/sizeof(u32), val);
1501+
combined.src = *src;
14961502
#endif
1497-
return hash_32(val, FIB6_EXCEPTION_BUCKET_SIZE_SHIFT);
1503+
val = siphash(&combined, sizeof(combined), &rt6_exception_key);
1504+
1505+
return hash_64(val, FIB6_EXCEPTION_BUCKET_SIZE_SHIFT);
14981506
}
14991507

15001508
/* Helper function to find the cached rt in the hash table

0 commit comments

Comments
 (0)