Re: [PATCH] mips: cdmm: fix use-after-free in mips_cdmm_bus_discover

From: Serge Semin
Date: Fri Nov 20 2020 - 09:07:09 EST


Hello Qinglang

Thanks for the patch. Good catch. Please see a tiny nitpick below.

On Fri, Nov 20, 2020 at 03:48:47PM +0800, Qinglang Miao wrote:
> kfree(dev) has been called inside put_device so anther
> kfree would cause a use-after-free bug/
>
> Fixes: 8286ae03308c ("MIPS: Add CDMM bus support")
> Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
> Signed-off-by: Qinglang Miao <miaoqinglang@xxxxxxxxxx>
> ---
> drivers/bus/mips_cdmm.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/bus/mips_cdmm.c b/drivers/bus/mips_cdmm.c
> index 9f7ed1fcd..e43786c67 100644
> --- a/drivers/bus/mips_cdmm.c
> +++ b/drivers/bus/mips_cdmm.c
> @@ -561,7 +561,6 @@ static void mips_cdmm_bus_discover(struct mips_cdmm_bus *bus)
> ret = device_register(&dev->dev);

> if (ret) {
> put_device(&dev->dev);
> - kfree(dev);
> }

After removing kfree() from here the braces around the if clause
are no more needed in accordance with the kernel coding style.
Please remove them too. Then feel free to add the tag
Acked-by: Serge Semin <fancer.lancer@xxxxxxxxx>

-Sergey

> }
> }
> --
> 2.23.0
>