Re: [PATCH] xen/blkback: do not leak mode property

From: Jan Beulich
Date: Tue Dec 04 2012 - 05:30:13 EST


>>> On 03.12.12 at 20:32, Olaf Hering <olaf@xxxxxxxxx> wrote:
> be->mode is obtained from xenbus_read, which does a kmalloc for the
> message body. The short string is never released, so do it on blkbk
> remove.
>
> Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
> ---
>
> !! Not compile tested !!
>
> drivers/block/xen-blkback/xenbus.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/block/xen-blkback/xenbus.c
> b/drivers/block/xen-blkback/xenbus.c
> index f58434c..a6585a4 100644
> --- a/drivers/block/xen-blkback/xenbus.c
> +++ b/drivers/block/xen-blkback/xenbus.c
> @@ -366,6 +366,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
> be->blkif = NULL;
> }
>
> + kfree(be->mode);

This looks necessary but insufficient - there's nothing really
preventing backend_changed() from being called more than once
for a given device (is simply the handler of xenbus watch). Hence
I think either that function needs to be guarded against multiple
execution (e.g. by removing the watch from that function itself,
if that's permitted by xenbus), or to properly deal with the
effects this has (including but probably not limited to the leaking
of be->mode).

Jan

> kfree(be);
> dev_set_drvdata(&dev->dev, NULL);
> return 0;
> --
> 1.8.0.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/