public inbox for linux-sgx@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/sgx: Replace kmalloc() + copy_from_user() with memdup_user()
@ 2025-09-08 20:12 Thorsten Blum
  2025-09-10 17:12 ` Jarkko Sakkinen
  2025-09-21  9:59 ` kernel test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2025-09-08 20:12 UTC (permalink / raw)
  To: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, x86, H. Peter Anvin
  Cc: Thorsten Blum, linux-sgx, linux-kernel

Replace kmalloc() followed by copy_from_user() with memdup_user() to
improve and simplify sgx_ioc_enclave_create().

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
index 66f1efa16fbb..e99fc38f1273 100644
--- a/arch/x86/kernel/cpu/sgx/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/ioctl.c
@@ -164,15 +164,11 @@ static long sgx_ioc_enclave_create(struct sgx_encl *encl, void __user *arg)
 	if (copy_from_user(&create_arg, arg, sizeof(create_arg)))
 		return -EFAULT;
 
-	secs = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!secs)
-		return -ENOMEM;
-
-	if (copy_from_user(secs, (void __user *)create_arg.src, PAGE_SIZE))
-		ret = -EFAULT;
-	else
-		ret = sgx_encl_create(encl, secs);
+	secs = memdup_user((void __user *)create_arg.src, PAGE_SIZE);
+	if (IS_ERR(secs))
+		return PTR_ERR(secs);
 
+	ret = sgx_encl_create(encl, secs);
 	kfree(secs);
 	return ret;
 }
-- 
2.51.0


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

end of thread, other threads:[~2025-09-25 15:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 20:12 [PATCH] x86/sgx: Replace kmalloc() + copy_from_user() with memdup_user() Thorsten Blum
2025-09-10 17:12 ` Jarkko Sakkinen
2025-09-21  9:59 ` kernel test robot
2025-09-22 13:18   ` Thorsten Blum
2025-09-25 15:37     ` Dave Hansen

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