[NETFILTER]: conntrack: fix refcount leak when finding expectation
authorYasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
Mon, 27 Nov 2006 18:26:46 +0000 (10:26 -0800)
committerDavid S. Miller <davem@sunset.davemloft.net>
Wed, 29 Nov 2006 04:59:37 +0000 (20:59 -0800)
All users of __{ip,nf}_conntrack_expect_find() don't expect that
it increments the reference count of expectation.

Signed-off-by: Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/netfilter/ip_conntrack_core.c
net/netfilter/nf_conntrack_core.c

index 143c4668538b40203063e2c6c741b395a0bf3fef..8b848aa77bfc39000ae75f9bb5969bd111280553 100644 (file)
@@ -225,10 +225,8 @@ __ip_conntrack_expect_find(const struct ip_conntrack_tuple *tuple)
        struct ip_conntrack_expect *i;
        
        list_for_each_entry(i, &ip_conntrack_expect_list, list) {
-               if (ip_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask)) {
-                       atomic_inc(&i->use);
+               if (ip_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask))
                        return i;
-               }
        }
        return NULL;
 }
@@ -241,6 +239,8 @@ ip_conntrack_expect_find(const struct ip_conntrack_tuple *tuple)
        
        read_lock_bh(&ip_conntrack_lock);
        i = __ip_conntrack_expect_find(tuple);
+       if (i)
+               atomic_inc(&i->use);
        read_unlock_bh(&ip_conntrack_lock);
 
        return i;
index 0f5830779b444c2b73102c5531a9b0aa6bd4c83a..de0567b1f4223a898f9004a2c436c9cf7110ac9d 100644 (file)
@@ -469,10 +469,8 @@ __nf_conntrack_expect_find(const struct nf_conntrack_tuple *tuple)
        struct nf_conntrack_expect *i;
        
        list_for_each_entry(i, &nf_conntrack_expect_list, list) {
-               if (nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask)) {
-                       atomic_inc(&i->use);
+               if (nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask))
                        return i;
-               }
        }
        return NULL;
 }
@@ -485,6 +483,8 @@ nf_conntrack_expect_find(const struct nf_conntrack_tuple *tuple)
        
        read_lock_bh(&nf_conntrack_lock);
        i = __nf_conntrack_expect_find(tuple);
+       if (i)
+               atomic_inc(&i->use);
        read_unlock_bh(&nf_conntrack_lock);
 
        return i;