Skip to content

Commit d546c62

Browse files
edumazetdavem330
authored andcommitted
ipv4: harden fnhe_hashfun()
Lets make this hash function a bit secure, as ICMP attacks are still in the wild. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 18a47e6 commit d546c62

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

include/net/ip_fib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ struct fnhe_hash_bucket {
6565
struct fib_nh_exception __rcu *chain;
6666
};
6767

68-
#define FNHE_HASH_SIZE 2048
68+
#define FNHE_HASH_SHIFT 11
69+
#define FNHE_HASH_SIZE (1 << FNHE_HASH_SHIFT)
6970
#define FNHE_RECLAIM_DEPTH 5
7071

7172
struct fib_nh {

net/ipv4/route.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,12 @@ static struct fib_nh_exception *fnhe_oldest(struct fnhe_hash_bucket *hash)
596596

597597
static inline u32 fnhe_hashfun(__be32 daddr)
598598
{
599+
static u32 fnhe_hashrnd __read_mostly;
599600
u32 hval;
600601

601-
hval = (__force u32) daddr;
602-
hval ^= (hval >> 11) ^ (hval >> 22);
603-
604-
return hval & (FNHE_HASH_SIZE - 1);
602+
net_get_random_once(&fnhe_hashrnd, sizeof(fnhe_hashrnd));
603+
hval = jhash_1word((__force u32) daddr, fnhe_hashrnd);
604+
return hash_32(hval, FNHE_HASH_SHIFT);
605605
}
606606

607607
static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnhe)

0 commit comments

Comments
 (0)