[PATCH] drivers: visorbus: fix use-after free bugs

From: Qinglang Miao
Date: Fri Nov 20 2020 - 02:44:50 EST


kfree(dev) is called in put_device(&dev->device) so that following
use would cause use-after-free bug.

There are two inappropriate use of put_device:

1. In create_visor_device, put dev_err before put_device to fix this.

2. In remove_visor_device, the former put_device is redundant because
device_unregister contains put_device already.

Fixes: 93d3ad90c2d4 ("drivers: visorbus: move driver out of staging")
Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Signed-off-by: Qinglang Miao <miaoqinglang@xxxxxxxxxx>
---
drivers/visorbus/visorbus_main.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/visorbus/visorbus_main.c b/drivers/visorbus/visorbus_main.c
index 152fd29f0..031349baf 100644
--- a/drivers/visorbus/visorbus_main.c
+++ b/drivers/visorbus/visorbus_main.c
@@ -695,15 +695,14 @@ int create_visor_device(struct visor_device *dev)
return 0;

err_put:
- put_device(&dev->device);
dev_err(&dev->device, "Creating visor device failed. %d\n", err);
+ put_device(&dev->device);
return err;
}

void remove_visor_device(struct visor_device *dev)
{
list_del(&dev->list_all);
- put_device(&dev->device);
if (dev->pending_msg_hdr)
visorbus_response(dev, 0, CONTROLVM_DEVICE_DESTROY);
device_unregister(&dev->device);
--
2.23.0