lkml.org 
[lkml]   [2016]   [Nov]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2] ppdev: fix double-free of pp->pdev->name
Date
On Sunday, October 30, 2016 11:19:24 PM CET Jann Horn wrote:
> 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);
> }
>

I took a closer look at this and found that we also leak the name
that is passed in register_device() in the same file:

name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
...
pdev = parport_register_dev_model(port, name, &ppdev_cb, minor);

parport_register_dev_model() copies the name using kstrdup() and
we should really free it after parport_register_dev_model().

It's not a huge problem, just leaking a few bytes of memory, but
the extra kfree() probably came from this confusion.

Arnd

\
 
 \ /
  Last update: 2016-11-10 14:19    [W:1.376 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site