Skip to contentSkip to conversation

netfilter: xt_CT: Fix one possible memleak of timeout

PATCH In review [email protected] 2 participants 2 messages Apr 6, 2017 – Apr 13, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: xt_CT: Fix one possible memleak of timeout

From: Gao Feng <[email protected]>

When nf_ct_timeout_ext_add failed in xt_ct_set_timeout, it should free the timeout refcnt.

Now goto the err_put_timeout error handler instead of going ahead.

---
v2: Keep the ret = -ENOMEM, per Gao Feng
v1: initial version

 net/netfilter/xt_CT.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/xt_CT.c +3 -1
index b008db0..a1783b6 100644
@@ -167,8 +167,10 @@ static void __xt_ct_tg_timeout_put(struct ctnl_timeout *timeout)
 		goto err_put_timeout;
 	}
 	timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
-	if (timeout_ext == NULL)
+	if (!timeout_ext) {
 		ret = -ENOMEM;
+		goto err_put_timeout;
+	}
 
 	rcu_read_unlock();
 	return ret;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 20 lines · On Thu, Apr 06, 2017 at 07:19:34PM +0800, [email protected] wrote:

From: Gao Feng <[email protected]>

When nf_ct_timeout_ext_add failed in xt_ct_set_timeout, it should free the timeout refcnt.

Now goto the err_put_timeout error handler instead of going ahead.

---
v2: Keep the ret = -ENOMEM, per Gao Feng
v1: initial version

 net/netfilter/xt_CT.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/xt_CT.c +0 -0
index b008db0..a1783b6 100644

net/netfilter/xt_CT.c static void __xt_ct_tg_timeout_put(struct ctnl_timeout *timeout) · line 173

Quoted 8 lines
net/netfilter/xt_CT.c +3 -1
@@ -167,8 +167,10 @@ static void __xt_ct_tg_timeout_put(struct ctnl_timeout *timeout)
 		goto err_put_timeout;
 	}
 	timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
-	if (timeout_ext == NULL)
+	if (!timeout_ext) {
 		ret = -ENOMEM;
+		goto err_put_timeout;
+	}

This also needs to be fixed, just a few line after this:

        timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
        if (timeout_ext == NULL)
                ret = -ENOMEM;