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] [day] [month] [year] [list]
Date:   Sun, 2 Feb 2020 20:39:06 -0800
From:   Cong Wang <xiyou.wangcong@...il.com>
To:     Jakub Kicinski <kuba@...nel.org>
Cc:     Linux Kernel Network Developers <netdev@...r.kernel.org>,
        syzbot <syzbot+35d4dea36c387813ed31@...kaller.appspotmail.com>,
        Eric Dumazet <eric.dumazet@...il.com>,
        John Fastabend <john.fastabend@...il.com>,
        Jamal Hadi Salim <jhs@...atatu.com>,
        Jiri Pirko <jiri@...nulli.us>
Subject: Re: [Patch net] net_sched: fix an OOB access in cls_tcindex

On Sun, Feb 2, 2020 at 1:30 PM Jakub Kicinski <kuba@...nel.org> wrote:
>
> On Sun,  2 Feb 2020 10:19:50 -0800, Cong Wang wrote:
> > As Eric noticed, tcindex_alloc_perfect_hash() uses cp->hash
> > to compute the size of memory allocation, but cp->hash is
> > set again after the allocation, this caused an out-of-bound
> > access.
> >
> > So we have to move all cp->hash initialization and computation
> > before the memory allocation. Move cp->mask and cp->shift together
> > as cp->hash may need them for computation.
> >
> > Reported-and-tested-by: syzbot+35d4dea36c387813ed31@...kaller.appspotmail.com
> > Fixes: 331b72922c5f ("net: sched: RCU cls_tcindex")
> > Cc: Eric Dumazet <eric.dumazet@...il.com>
> > Cc: John Fastabend <john.fastabend@...il.com>
> > Cc: Jamal Hadi Salim <jhs@...atatu.com>
> > Cc: Jiri Pirko <jiri@...nulli.us>
> > Signed-off-by: Cong Wang <xiyou.wangcong@...il.com>
> > ---
> >  net/sched/cls_tcindex.c | 38 +++++++++++++++++++-------------------
> >  1 file changed, 19 insertions(+), 19 deletions(-)
> >
> > diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
> > index 3d4a1280352f..2ba8c034fce8 100644
> > --- a/net/sched/cls_tcindex.c
> > +++ b/net/sched/cls_tcindex.c
> > @@ -333,6 +333,25 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
> >       cp->fall_through = p->fall_through;
> >       cp->tp = tp;
> >
> > +     if (tb[TCA_TCINDEX_HASH])
> > +             cp->hash = nla_get_u32(tb[TCA_TCINDEX_HASH]);
> > +
> > +     if (tb[TCA_TCINDEX_MASK])
> > +             cp->mask = nla_get_u16(tb[TCA_TCINDEX_MASK]);
> > +
> > +     if (tb[TCA_TCINDEX_SHIFT])
> > +             cp->shift = nla_get_u32(tb[TCA_TCINDEX_SHIFT]);
> > +
> > +     if (!cp->hash) {
> > +             /* Hash not specified, use perfect hash if the upper limit
> > +              * of the hashing index is below the threshold.
> > +              */
> > +             if ((cp->mask >> cp->shift) < PERFECT_HASH_THRESHOLD)
> > +                     cp->hash = (cp->mask >> cp->shift) + 1;
> > +             else
> > +                     cp->hash = DEFAULT_HASH_SIZE;
> > +     }
> > +
> >       if (p->perfect) {
> >               int i;
> >
>                 if (tcindex_alloc_perfect_hash(net, cp) < 0)
>                         goto errout;
>                 for (i = 0; i < cp->hash; i++)
>                         cp->perfect[i].res = p->perfect[i].res;
>                 balloc = 1;
>         }
>
> Wouldn't the loop be a problem now? cp->hash defaulted to previous
> value - s/cp->hash/min(cp->hash, p->hash)/ ?

Yes, good catch!

>
> Also, unrelated, I think the jump to errout1 leaks cp->perfect and exts?

Yes, we should call tcindex_free_perfect_hash(). I will make
a separated patch for this.

Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ