netfilter: nf_nat: use hash random for bysource hash
authorPatrick McHardy <kaber@trash.net>
Fri, 23 Dec 2011 13:00:13 +0000 (14:00 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 23 Dec 2011 13:36:44 +0000 (14:36 +0100)
Use nf_conntrack_hash_rnd in NAT bysource hash to avoid hash chain attacks.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/ipv4/netfilter/nf_nat_core.c
net/netfilter/nf_conntrack_core.c

index 58ab7a4611dd1b84ccacdac4abdf85801634ff87..76600f8d434b31351964a6fcdb9a6f84eaec4de9 100644 (file)
@@ -57,7 +57,7 @@ hash_by_src(const struct net *net, u16 zone,
        /* Original src, to ensure we map it consistently if poss. */
        hash = jhash_3words((__force u32)tuple->src.u3.ip,
                            (__force u32)tuple->src.u.all ^ zone,
-                           tuple->dst.protonum, 0);
+                           tuple->dst.protonum, nf_conntrack_hash_rnd);
        return ((u64)hash * net->ipv4.nat_htable_size) >> 32;
 }
 
index 8b2842e321fb9e77ce51f385cb3d543a9b4554c3..b76090fd92c14d0503ff43886bf1bc73631fe763 100644 (file)
@@ -67,6 +67,7 @@ DEFINE_PER_CPU(struct nf_conn, nf_conntrack_untracked);
 EXPORT_PER_CPU_SYMBOL(nf_conntrack_untracked);
 
 unsigned int nf_conntrack_hash_rnd __read_mostly;
+EXPORT_SYMBOL_GPL(nf_conntrack_hash_rnd);
 
 static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple, u16 zone)
 {