Re: [PATCH 3.2 42/70] net: possible use after free in dst_release

Ben Hutchings
2016-01-18T11:50:37Z

[-- Attachment #1: Type: text/plain, Size: 2251 bytes --]

On Sun, 2016-01-17 at 19:49 -0800, Francesco Ruggeri wrote:
> On Sun, Jan 17, 2016 at 7:18 PM, Ben Hutchings <ben@decadent.org.uk> wrote:
> > 3.2.76-rc1 review patch.  If anyone has any objections, please let me know.
> >
> > ------------------
> >
> > From: Francesco Ruggeri <fruggeri@aristanetworks.com>
> >
> > commit 07a5d38453599052aff0877b16bb9c1585f08609 upstream.
> >
> > dst_release should not access dst->flags after decrementing
> > __refcnt to 0. The dst_entry may be in dst_busy_list and
> > dst_gc_task may dst_destroy it before dst_release gets a chance
> > to access dst->flags.
> >
> > Fixes: d69bbf88c8d0 ("net: fix a race in dst_release()")
> > Fixes: 27b75c95f10d ("net: avoid RCU for NOCACHE dst")
> > Signed-off-by: Francesco Ruggeri <fruggeri@arista.com>
> > Acked-by: Eric Dumazet <edumazet@google.com>
> > Signed-off-by: David S. Miller <davem@davemloft.net>
> > [bwh: Backported to 3.2: adjust context]
> > Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> > ---
> >  net/core/dst.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > --- a/net/core/dst.c
> > +++ b/net/core/dst.c
> > @@ -269,10 +269,11 @@ void dst_release(struct dst_entry *dst)
> >  {
> >         if (dst) {
> >                 int newrefcnt;
> > +               unsigned short nocache = dst->flags & DST_NOCACHE;
>
> Only one minor thing. Before 3.6 dst->flags was an int.

I noticed that - but no flags outside the 16-bit range are assigned, so
I think this is OK.

Ben.

> Thanks,
> Francesco
>
> >
> >                 newrefcnt = atomic_dec_return(&dst->__refcnt);
> >                 WARN_ON(newrefcnt < 0);
> > -               if (!newrefcnt && unlikely(dst->flags & DST_NOCACHE)) {
> > +               if (!newrefcnt && unlikely(nocache)) {
> >                         dst = dst_destroy(dst);
> >                         if (dst)
> >                                 __dst_free(dst);
> >
--
Ben Hutchings
A free society is one where it is safe to be unpopular. - Adlai Stevenson

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]