Re: [PATCH 4.4 38/97] netfilter: xt_CT: fix refcnt leak on error path

From: Ben Hutchings
Date: Tue Apr 10 2018 - 11:14:17 EST


On Tue, 2018-04-03 at 18:46 +0100, Ben Hutchings wrote:
> On Fri, 2018-03-23 at 10:54 +0100, Greg Kroah-Hartman wrote:
> > 4.4-stable review patch.ÂÂIf anyone has any objections, please let me know.
> >
> > ------------------
> >
> > From: Gao Feng <fgao@xxxxxxxxxx>
> >
> >
> > [ Upstream commit 470acf55a021713869b9bcc967268ac90c8a0fac ]
[...]Â
> > @@ -249,7 +252,7 @@ static int xt_ct_tg_check(const struct x
> > Â 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);
> > @@ -257,6 +260,10 @@ out:
> > Â info->ct = ct;
> > Â return 0;
> > Â
> > +err4:
> > + help = nfct_help(ct);
> > + if (help)
> > + module_put(help->helper->me);
> > Âerr3:
> > Â nf_ct_tmpl_free(ct);
> > Âerr2:
>
> This does not.ÂÂnf_ct_tmpl_free() calls nf_ct_ext_destroy() which I
> think will call back into xt_ct_tg_destroy().ÂÂSo I think the module
> reference is already dropped here and we mustn't do it twice.ÂÂAm I
> missing something?

I still don't understand this code, but I have verified that the
module_put() is needed on this error path to balance the module
reference count. I.e. this fix is good.

Ben.

--
Ben Hutchings
Software Developer, Codethink Ltd.