[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20161030164735.GA2558@pc.thejh.net>
Date: Sun, 30 Oct 2016 17:47:35 +0100
From: Jann Horn <jann@...jh.net>
To: Andy Lutomirski <luto@...capital.net>
Cc: Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Sudip Mukherjee <sudipm.mukherjee@...il.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
linux-parport@...ts.infradead.org
Subject: Re: [PATCH] ppdev: fix double-free of pp->pdev->name
On Sun, Oct 30, 2016 at 09:29:10AM -0700, Andy Lutomirski wrote:
> On Sun, Oct 30, 2016 at 8:44 AM, Jann Horn <jann@...jh.net> wrote:
> > free_pardevice() is called by parport_unregister_device() and already frees
> > pp->pdev->name, don't try to do it again.
> >
> > This bug causes kernel crashes.
> >
> > I found and verified this with KASAN and some added pr_emerg()s:
> >
> > [ 60.316568] pp_release: pp->pdev->name == ffff88039cb264c0
> > [ 60.316692] free_pardevice: freeing par_dev->name at ffff88039cb264c0
> > [ 60.316706] pp_release: kfree(ffff88039cb264c0)
> > [ 60.316714] ==========================================================
> > [ 60.316722] BUG: Double free or freeing an invalid pointer
> > [ 60.316731] Unexpected shadow byte: 0xFB
> > [ 60.316801] Object at ffff88039cb264c0, in cache kmalloc-32 size: 32
> > [ 60.316813] Allocated:
> > [ 60.316824] PID = 1695
> > [ 60.316869] Freed:
> > [ 60.316880] PID = 1695
> > [ 60.316935] ==========================================================
> >
> > CCing Andy Lutomirski because I think this is what broke vmapped stacks
> > for me - after applying this patch, vmapped stacks worked for me.
> > Previously, I got oopses (and lockups) caused by area->pages[0] being
> > 0x400000000 in __vunmap(), with area->pages being allocated in the kmalloc
> > area.
>
> That's an odd symptom. I assume that what's happening is that the
> pages array is being freed early by the extra kfree in here and then
> getting corrupted.
Well, as far as I can tell, there are two ways to reach that.
Obvious first way, but a pretty tight race:
Task A: free(name)
Task B: allocate area->pages in same place
Task A: second free(name), releasing area->pages
Second way (if the SLAB allocator, which I'm using, is used):
Task A: free(name), appends the object to ac->entry in ___cache_free()
Task A: second free(name), appends the object to ac->entry again
Task B: ____cache_alloc() returns object from array cache
Task C: ____cache_alloc() returns same object again
So then the same memory would be used by two separate objects?
Download attachment "signature.asc" of type "application/pgp-signature" (820 bytes)
Powered by blists - more mailing lists