All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/platform/x86/amd: pmf: Fix a double free on module unload
@ 2025-05-06 13:11 Mario Limonciello
  2025-05-06 15:53 ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Mario Limonciello @ 2025-05-06 13:11 UTC (permalink / raw)
  To: mario.limonciello, Shyam-sundar.S-k, hdegoede, ilpo.jarvinen,
	dan.carpenter
  Cc: platform-driver-x86

From: Mario Limonciello <mario.limonciello@amd.com>

If setting up smart PC fails for any reason then this can lead to
a double free when unloading amd-pmf.  This is because dev->buf was
freed but never set to NULL and is again freed in
amd_pmf_deinit_smart_pc().

Explicitly set pointers to NULL after freeing them to avoid the
double free.

Fixes: 5b1122fc4995f ("platform/x86/amd/pmf: fix cleanup in amd_pmf_init_smart_pc()")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/platform/x86/amd/pmf/tee-if.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index a1e43873a07b0..48902f1c767c6 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -579,10 +579,13 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)
 	amd_pmf_tee_deinit(dev);
 err_free_prev_data:
 	kfree(dev->prev_data);
+	dev->prev_data = NULL;
 err_free_policy:
 	kfree(dev->policy_buf);
+	dev->policy_buf = NULL;
 err_free_dram_buf:
 	kfree(dev->buf);
+	dev->buf = NULL;
 err_cancel_work:
 	cancel_delayed_work_sync(&dev->pb_work);
 
-- 
2.43.0


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

end of thread, other threads:[~2025-05-07  7:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 13:11 [PATCH] drivers/platform/x86/amd: pmf: Fix a double free on module unload Mario Limonciello
2025-05-06 15:53 ` Dan Carpenter
2025-05-06 16:11   ` Mario Limonciello
2025-05-07  1:41     ` Mario Limonciello
2025-05-07  1:49     ` Mario Limonciello
2025-05-07  7:22       ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.