Re: KASAN: use-after-free Read in ib_uverbs_remove_one
From: Jason Gunthorpe
Date: Fri May 29 2020 - 09:29:25 EST
On Fri, May 29, 2020 at 04:31:26PM +0800, Hillf Danton wrote:
> Hold another grab to dev to prevent it from going home before work gets
> done with it.
>
> +++ b/drivers/infiniband/core/uverbs_main.c
> @@ -1152,6 +1152,8 @@ static int ib_uverbs_add_one(struct ib_d
> device->ops.mmap ? &uverbs_mmap_fops : &uverbs_fops);
> uverbs_dev->cdev.owner = THIS_MODULE;
>
> + /* pair with put_device() in ib_uverbs_remove_one() */
> + get_device(&uverbs_dev->dev);
> ret = cdev_device_add(&uverbs_dev->cdev, &uverbs_dev->dev);
> if (ret)
> goto err_uapi;
Doesn't look right, the put_device() in uverbs_remove_one() pairs with
the device_initialize() in this function.
The only thing I can think of is we called remove_once twice
somehow or had an extra put on some error path. But I couldn't find
any flow that would do either of those things
Jason