linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: visorbus: fix use-after free bugs
@ 2020-11-20  7:48 Qinglang Miao
  0 siblings, 0 replies; only message in thread
From: Qinglang Miao @ 2020-11-20  7:48 UTC (permalink / raw)
  To: David Kershner, sparmaintainer; +Cc: linux-kernel, Qinglang Miao

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@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-20  7:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20  7:48 [PATCH] drivers: visorbus: fix use-after free bugs Qinglang Miao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).