* [PATCH nf v3] netfilter: xt_CT: fix refcnt leak on error path
@ 2017-04-14 2:00 gfree.wind
2017-04-25 9:05 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: gfree.wind @ 2017-04-14 2:00 UTC (permalink / raw)
To: pablo, netfilter-devel; +Cc: Gao Feng, Liping Zhang
From: Gao Feng <fgao@ikuai8.com>
There are two cases which causes refcnt leak.
1. 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.
2. When the time policy is not found, we should call module_put.
Otherwise, the related cthelper module cannot be removed anymore.
It is easy to reproduce by typing the following command:
# iptables -t raw -A OUTPUT -p tcp -j CT --helper ftp --timeout xxx
Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
---
v3: Merge the patch of Liping together
v2: enhance the patch
v1: initial version
net/netfilter/xt_CT.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index b008db0..81fdcdc 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -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;
@@ -200,6 +202,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
struct xt_ct_target_info_v1 *info)
{
struct nf_conntrack_zone zone;
+ struct nf_conn_help *help;
struct nf_conn *ct;
int ret = -EOPNOTSUPP;
@@ -248,7 +251,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
if (info->timeout[0]) {
ret = xt_ct_set_timeout(ct, par, info->timeout);
if (ret < 0)
- goto err3;
+ goto err4;
}
__set_bit(IPS_CONFIRMED_BIT, &ct->status);
nf_conntrack_get(&ct->ct_general);
@@ -256,6 +259,10 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
info->ct = ct;
return 0;
+err4:
+ help = nfct_help(ct);
+ if (help)
+ module_put(help->helper->me);
err3:
nf_ct_tmpl_free(ct);
err2:
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH nf v3] netfilter: xt_CT: fix refcnt leak on error path
2017-04-14 2:00 [PATCH nf v3] netfilter: xt_CT: fix refcnt leak on error path gfree.wind
@ 2017-04-25 9:05 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2017-04-25 9:05 UTC (permalink / raw)
To: gfree.wind; +Cc: netfilter-devel, Gao Feng, Liping Zhang
On Fri, Apr 14, 2017 at 10:00:08AM +0800, gfree.wind@foxmail.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
>
> There are two cases which causes refcnt leak.
>
> 1. 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.
>
> 2. When the time policy is not found, we should call module_put.
> Otherwise, the related cthelper module cannot be removed anymore.
> It is easy to reproduce by typing the following command:
> # iptables -t raw -A OUTPUT -p tcp -j CT --helper ftp --timeout xxx
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-04-25 9:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-14 2:00 [PATCH nf v3] netfilter: xt_CT: fix refcnt leak on error path gfree.wind
2017-04-25 9:05 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).