Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757224AbcJ3Ryj (ORCPT ); Sun, 30 Oct 2016 13:54:39 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34737 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753015AbcJ3Ryi (ORCPT ); Sun, 30 Oct 2016 13:54:38 -0400 Message-ID: <581633D3.3080502@gmail.com> Date: Sun, 30 Oct 2016 23:24:27 +0530 From: Sudip Mukherjee User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Jann Horn , Arnd Bergmann , Greg Kroah-Hartman CC: linux-kernel@vger.kernel.org, linux-parport@lists.infradead.org, Andy Lutomirski Subject: Re: [PATCH] ppdev: fix double-free of pp->pdev->name References: <1477842248-2234-1-git-send-email-jann@thejh.net> In-Reply-To: <1477842248-2234-1-git-send-email-jann@thejh.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2116 Lines: 57 On Sunday 30 October 2016 09:14 PM, Jann Horn 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. I think the above should not be a part of the commit message. It looks like a valid bug. As we have now started using the device model from this release, so device_unregister() will finally call free_pardevice() and that will free the name. > > Signed-off-by: Jann Horn > --- Acked-by: Sudip Mukherjee > drivers/char/ppdev.c | 3 --- > 1 file changed, 3 deletions(-) > > diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c > index d23368874710..6af1ce04b3da 100644 > --- a/drivers/char/ppdev.c > +++ b/drivers/char/ppdev.c > @@ -748,10 +748,7 @@ static int pp_release(struct inode *inode, struct file *file) > } > > if (pp->pdev) { > - const char *name = pp->pdev->name; > - > parport_unregister_device(pp->pdev); > - kfree(name); > pp->pdev = NULL; > pr_debug(CHRDEV "%x: unregistered pardevice\n", minor); > } >