lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1521067427.2750.40.camel@redhat.com>
Date:   Wed, 14 Mar 2018 23:43:47 +0100
From:   Davide Caratti <dcaratti@...hat.com>
To:     Cong Wang <xiyou.wangcong@...il.com>
Cc:     Jamal Hadi Salim <jhs@...atatu.com>, Jiri Pirko <jiri@...nulli.us>,
        "David S. Miller" <davem@...emloft.net>,
        Linux Kernel Network Developers <netdev@...r.kernel.org>
Subject: Re: [PATCH net] net/sched: act_simple: don't leak 'index' in the
 error path

hello Cong, thank you for reviewing this.

On Wed, 2018-03-14 at 11:41 -0700, Cong Wang wrote:
> On Tue, Mar 13, 2018 at 7:13 PM, Davide Caratti <dcaratti@...hat.com> wrote:
> 
> Looks like we just need to replace the tcf_idr_cleanup() with
> tcf_idr_release()? Which is also simpler.

I just tried it on act_simple, and I can confirm: 'index' does not leak
anymore if alloc_defdata() fails to kzalloc(), and then tcf_idr_release()
is called in place of of tcf_idr_cleanup().

> Looks like all other callers of tcf_idr_cleanup() need to be replaced too,
> but I don't audit all of them...

no problem, I can try to do that, it's not going to be a big series
anyway.

while at it, I will also fix other spots where the same bug can be
reproduced, even if tcf_idr_cleanup() is not there: for example, when
tcf_vlan_init() fails allocating struct tcf_vlan_params *p,

ASSERT_RTNL();
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) {
	if (ovr)
		tcf_idr_release(*a, bind);
	return -ENOMEM;
}

the followinng behavior can be observed:

# tc actions flush action vlan                                  
# tc actions add action vlan pop index 5                        
RTNETLINK answers: Cannot allocate memory  
We have an error talking to the kernel     
# tc actions add action vlan pop index 5                        
RTNETLINK answers: No space left on device 
We have an error talking to the kernel     
# tc actions add action vlan pop index 5                        
RTNETLINK answers: No space left on device 
We have an error talking to the kernel     

Probably testing the value of 'ovr' here is wrong, or maybe it's 
not enough: I will also verify what happens using 'replace'
keyword instead of 'add'. 

> 
> [...]
> 
> >         if (!exists) {
> > +               defdata = nla_strdup(tb[TCA_DEF_DATA], GFP_KERNEL);
> > +               if (unlikely(!defdata))
> > +                       return -ENOMEM;
> > +
> >                 ret = tcf_idr_create(tn, parm->index, est, a,
> >                                      &act_simp_ops, bind, false);
> >                 if (ret)
> >                         return ret;
> 
> You leak memory here on failure, BTW.

Ouch, you are right. I was wrongly convinced that act_simp_ops.cleanup()
was called also in case of failure of tcf_idr_create(), but it's not true.
 
Indeed, a call to act_simp_ops.cleanup() happens if we call
tcf_idr_release() after tcf_idr_create() returned 0.

regards,
-- 
davide

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ