diff mbox series

netfilter:get_next_corpse():No need to double check the *bucket

Message ID 20191001082441.7140-1-wh_bin@126.com
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series netfilter:get_next_corpse():No need to double check the *bucket | expand

Commit Message

wh_bin@126.com Oct. 1, 2019, 8:24 a.m. UTC
From: Hongbin Wang <wh_bin@126.com>

The *bucket is in for loops,it has been checked.

Signed-off-by: Hongbin Wang <wh_bin@126.com>
---
 net/netfilter/nf_conntrack_core.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Florian Westphal Oct. 1, 2019, 9:37 a.m. UTC | #1
wh_bin@126.com <wh_bin@126.com> wrote:
> From: Hongbin Wang <wh_bin@126.com>
> 
> The *bucket is in for loops,it has been checked.
> 
> Signed-off-by: Hongbin Wang <wh_bin@126.com>
> ---
>  net/netfilter/nf_conntrack_core.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
> index 0c63120b2db2..8d48babe6561 100644
> --- a/net/netfilter/nf_conntrack_core.c
> +++ b/net/netfilter/nf_conntrack_core.c
> @@ -2000,14 +2000,12 @@ get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
>  		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
>  		local_bh_disable();
>  		nf_conntrack_lock(lockp);
> -		if (*bucket < nf_conntrack_htable_size) {
> -			hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[*bucket], hnnode) {
> -				if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
> -					continue;
> -				ct = nf_ct_tuplehash_to_ctrack(h);
> -				if (iter(ct, data))
> -					goto found;
> -			}
> +		hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[*bucket], hnnode) {

I don't think this is correct.
unless we hold nf_conntrack_lock() nf_conntrack_hash[] could be
reallocated, no?
diff mbox series

Patch

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 0c63120b2db2..8d48babe6561 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2000,14 +2000,12 @@  get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
 		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
 		local_bh_disable();
 		nf_conntrack_lock(lockp);
-		if (*bucket < nf_conntrack_htable_size) {
-			hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[*bucket], hnnode) {
-				if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-					continue;
-				ct = nf_ct_tuplehash_to_ctrack(h);
-				if (iter(ct, data))
-					goto found;
-			}
+		hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[*bucket], hnnode) {
+			if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
+				continue;
+			ct = nf_ct_tuplehash_to_ctrack(h);
+			if (iter(ct, data))
+				goto found;
 		}
 		spin_unlock(lockp);
 		local_bh_enable();