Skip to contentSkip to conversation

drivers: visorbus: fix use-after free bugs

PATCH New Qinglang Miao 1 participant 1 message Nov 20, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: visorbus: fix use-after free bugs

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")
---
 drivers/visorbus/visorbus_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/visorbus/visorbus_main.c +1 -2
index 152fd29f0..031349baf 100644
@@ -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);
Signature · 1 line
2.23.0