linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmem: core: Fix a potential use after free
@ 2019-12-27  9:20 Xu Wang
  2019-12-28 11:30 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Xu Wang @ 2019-12-27  9:20 UTC (permalink / raw)
  To: srinivas.kandagatla; +Cc: linux-kernel

Free the nvmem structure only after we are done using it.
This patch just moves the put_device() down a bit to avoid the
use after free.

Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 9f1ee9c..7051d34 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -535,8 +535,8 @@ static struct nvmem_device *__nvmem_device_get(void *data,
 
 static void __nvmem_device_put(struct nvmem_device *nvmem)
 {
-	put_device(&nvmem->dev);
 	module_put(nvmem->owner);
+	put_device(&nvmem->dev);
 	kref_put(&nvmem->refcnt, nvmem_device_release);
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-06 12:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-27  9:20 [PATCH] nvmem: core: Fix a potential use after free Xu Wang
2019-12-28 11:30 ` Markus Elfring
2019-12-28 12:25 ` nvmem: core: Checking the decrementing of reference counters Markus Elfring
2020-01-06 12:35 ` [PATCH] nvmem: core: Fix a potential use after free Srinivas Kandagatla

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).