Skip to content

Commit f393808

Browse files
vasilykh-aristaummakynes
authored andcommitted
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: 3e86638 ("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>
1 parent e4844c9 commit f393808

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,19 +1073,22 @@ static unsigned int early_drop_list(struct net *net,
10731073
return drops;
10741074
}
10751075

1076-
static noinline int early_drop(struct net *net, unsigned int _hash)
1076+
static noinline int early_drop(struct net *net, unsigned int hash)
10771077
{
1078-
unsigned int i;
1078+
unsigned int i, bucket;
10791079

10801080
for (i = 0; i < NF_CT_EVICTION_RANGE; i++) {
10811081
struct hlist_nulls_head *ct_hash;
1082-
unsigned int hash, hsize, drops;
1082+
unsigned int hsize, drops;
10831083

10841084
rcu_read_lock();
10851085
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;
10871090

1088-
drops = early_drop_list(net, &ct_hash[hash]);
1091+
drops = early_drop_list(net, &ct_hash[bucket]);
10891092
rcu_read_unlock();
10901093

10911094
if (drops) {

0 commit comments

Comments
 (0)