netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ipv4: harden fnhe_hashfun()
@ 2014-09-04 15:21 Eric Dumazet
  2014-09-06  0:40 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2014-09-04 15:21 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Neal Cardwell

From: Eric Dumazet <edumazet@google.com>

Lets make this hash function a bit secure, as ICMP attacks are still
in the wild.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/ip_fib.h |    3 ++-
 net/ipv4/route.c     |    8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 9922093f575e..6c8f00236a47 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -65,7 +65,8 @@ struct fnhe_hash_bucket {
 	struct fib_nh_exception __rcu	*chain;
 };
 
-#define FNHE_HASH_SIZE		2048
+#define FNHE_HASH_SHIFT		11
+#define FNHE_HASH_SIZE		(1 << FNHE_HASH_SHIFT)
 #define FNHE_RECLAIM_DEPTH	5
 
 struct fib_nh {
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index eaa4b000c7b4..deb7a2ec3669 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -596,12 +596,12 @@ static struct fib_nh_exception *fnhe_oldest(struct fnhe_hash_bucket *hash)
 
 static inline u32 fnhe_hashfun(__be32 daddr)
 {
+	static u32 fnhe_hashrnd __read_mostly;
 	u32 hval;
 
-	hval = (__force u32) daddr;
-	hval ^= (hval >> 11) ^ (hval >> 22);
-
-	return hval & (FNHE_HASH_SIZE - 1);
+	net_get_random_once(&fnhe_hashrnd, sizeof(fnhe_hashrnd));
+	hval = jhash_1word((__force u32) daddr, fnhe_hashrnd);
+	return hash_32(hval, FNHE_HASH_SHIFT);
 }
 
 static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnhe)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] ipv4: harden fnhe_hashfun()
  2014-09-04 15:21 [PATCH net-next] ipv4: harden fnhe_hashfun() Eric Dumazet
@ 2014-09-06  0:40 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-09-06  0:40 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, ncardwell

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 04 Sep 2014 08:21:31 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> Lets make this hash function a bit secure, as ICMP attacks are still
> in the wild.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied, thanks Eric.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-06  0:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-04 15:21 [PATCH net-next] ipv4: harden fnhe_hashfun() Eric Dumazet
2014-09-06  0:40 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).