public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86/amd/pmf: Fix memory leak in amd_pmf_get_pb_data()
@ 2024-01-23  1:11 Cong Liu
  2024-01-23 14:37 ` Shyam Sundar S K
  0 siblings, 1 reply; 7+ messages in thread
From: Cong Liu @ 2024-01-23  1:11 UTC (permalink / raw)
  To: Shyam Sundar S K, Hans de Goede, Ilpo Järvinen
  Cc: Cong Liu, platform-driver-x86, linux-kernel

amd_pmf_get_pb_data() will allocate memory for the policy buffer,
but does not free it if copy_from_user() fails. This leads to a memory
leak.

Signed-off-by: Cong Liu <liucong2@kylinos.cn>
---
 drivers/platform/x86/amd/pmf/tee-if.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index 502ce93d5cdd..f8c0177afb0d 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -298,8 +298,10 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf,
 	if (!new_policy_buf)
 		return -ENOMEM;
 
-	if (copy_from_user(new_policy_buf, buf, length))
+	if (copy_from_user(new_policy_buf, buf, length)) {
+		kfree(new_policy_buf);
 		return -EFAULT;
+	}
 
 	kfree(dev->policy_buf);
 	dev->policy_buf = new_policy_buf;
-- 
2.34.1


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

end of thread, other threads:[~2024-01-29  9:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23  1:11 [PATCH] platform/x86/amd/pmf: Fix memory leak in amd_pmf_get_pb_data() Cong Liu
2024-01-23 14:37 ` Shyam Sundar S K
2024-01-24  1:29   ` [PATCH v2] " Cong Liu
2024-01-26 19:16     ` Hans de Goede
2024-01-28 10:45       ` [v2] " Markus Elfring
2024-01-29  8:59         ` Hans de Goede
2024-01-29  9:52           ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox