mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86/amd/pmf: Use memdup_user()
@ 2024-05-08  9:46 Thorsten Blum
  2024-05-10 11:12 ` Markus Elfring
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Blum @ 2024-05-08  9:46 UTC (permalink / raw)
  To: Shyam Sundar S K, Hans de Goede, Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, Thorsten Blum

Switching to memdup_user() overwrites the allocated memory only once,
whereas kzalloc() followed by copy_from_user() initializes the allocated
memory to zero and then immediately overwrites it.

Fixes the following Coccinelle/coccicheck warning reported by
memdup_user.cocci:

	WARNING opportunity for memdup_user

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 drivers/platform/x86/amd/pmf/tee-if.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c
index b438de4d6bfc..1b53cabc9aa2 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -301,14 +301,9 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf,
 		return -EINVAL;
 
 	/* re-alloc to the new buffer length of the policy binary */
-	new_policy_buf = kzalloc(length, GFP_KERNEL);
-	if (!new_policy_buf)
-		return -ENOMEM;
-
-	if (copy_from_user(new_policy_buf, buf, length)) {
-		kfree(new_policy_buf);
-		return -EFAULT;
-	}
+	new_policy_buf = memdup_user(buf, length);
+	if (IS_ERR(new_policy_buf))
+		return PTR_ERR(new_policy_buf);
 
 	kfree(dev->policy_buf);
 	dev->policy_buf = new_policy_buf;
-- 
2.45.0


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

end of thread, other threads:[~2024-05-30 19:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08  9:46 [PATCH] platform/x86/amd/pmf: Use memdup_user() Thorsten Blum
2024-05-10 11:12 ` Markus Elfring
2024-05-27  8:36   ` [PATCH v2] " Thorsten Blum
2024-05-27 10:15     ` Ilpo Järvinen
2024-05-27 10:38     ` Dan Carpenter
2024-05-30 14:15       ` Thorsten Blum
2024-05-30 19:28         ` Dan Carpenter

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

all inboxes | Powered by JetHome®