aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasily Khoruzhick <vasilykh@arista.com>2018-10-25 15:15:43 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2018-11-03 09:16:28 -0400
commitf393808dc64149ccd0e5a8427505ba2974a59854 (patch)
tree023e5b21bd9552c5f15764d0f8ed50e7a5c574ce
parente4844c9c62a0fe47980d6c3d4b7a096a5d755925 (diff)
netfilter: conntrack: fix calculation of next bucket number in early_drop
If there's no entry to drop in bucket that corresponds to the hash, early_drop() should look for it in other buckets. But since it increments hash instead of bucket number, it actually looks in the same bucket 8 times: hsize is 16k by default (14 bits) and hash is 32-bit value, so reciprocal_scale(hash, hsize) returns the same value for hash..hash+7 in most cases. Fix it by increasing bucket number instead of hash and rename _hash to bucket to avoid future confusion. Fixes: 3e86638e9a0b ("netfilter: conntrack: consider ct netns in early_drop logic") Cc: <stable@vger.kernel.org> # v4.7+ Signed-off-by: Vasily Khoruzhick <vasilykh@arista.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--net/netfilter/nf_conntrack_core.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index ca1168d67fac..e92e749aff53 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1073,19 +1073,22 @@ static unsigned int early_drop_list(struct net *net,
1073 return drops; 1073 return drops;
1074} 1074}
1075 1075
1076static noinline int early_drop(struct net *net, unsigned int _hash) 1076static noinline int early_drop(struct net *net, unsigned int hash)
1077{ 1077{
1078 unsigned int i; 1078 unsigned int i, bucket;
1079 1079
1080 for (i = 0; i < NF_CT_EVICTION_RANGE; i++) { 1080 for (i = 0; i < NF_CT_EVICTION_RANGE; i++) {
1081 struct hlist_nulls_head *ct_hash; 1081 struct hlist_nulls_head *ct_hash;
1082 unsigned int hash, hsize, drops; 1082 unsigned int hsize, drops;
1083 1083
1084 rcu_read_lock(); 1084 rcu_read_lock();
1085 nf_conntrack_get_ht(&ct_hash, &hsize); 1085 nf_conntrack_get_ht(&ct_hash, &hsize);
1086 hash = reciprocal_scale(_hash++, hsize); 1086 if (!i)
1087 bucket = reciprocal_scale(hash, hsize);
1088 else
1089 bucket = (bucket + 1) % hsize;
1087 1090
1088 drops = early_drop_list(net, &ct_hash[hash]); 1091 drops = early_drop_list(net, &ct_hash[bucket]);
1089 rcu_read_unlock(); 1092 rcu_read_unlock();
1090 1093
1091 if (drops) { 1094 if (drops) {