The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH RESEND] x86/fpu: Use vmemdup_user() in xstateregs_set()
@ 2026-07-20 19:55 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-07-20 19:55 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin
  Cc: Thorsten Blum, linux-kernel

Replace the open-coded vmalloc() and copy_from_user() with
vmemdup_user() to simplify xstateregs_set().

vmemdup_user() returns an ERR_PTR() on failure, preserving the existing
-ENOMEM and -EFAULT error codes. Since vmemdup_user() is backed by
kvmalloc(), use kvfree() to free the buffer instead.

Return early on error and drop the obsolete out label.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/kernel/fpu/regset.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c
index 0986c2200adc..8dc9de732c78 100644
--- a/arch/x86/kernel/fpu/regset.c
+++ b/arch/x86/kernel/fpu/regset.c
@@ -3,7 +3,8 @@
  * FPU register's regset abstraction, for ptrace, core dumps, etc.
  */
 #include <linux/sched/task_stack.h>
-#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/string.h>
 
 #include <asm/fpu/api.h>
 #include <asm/fpu/signal.h>
@@ -157,21 +158,15 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
 		return -EFAULT;
 
 	if (!kbuf) {
-		tmpbuf = vmalloc(count);
-		if (!tmpbuf)
-			return -ENOMEM;
-
-		if (copy_from_user(tmpbuf, ubuf, count)) {
-			ret = -EFAULT;
-			goto out;
-		}
+		tmpbuf = vmemdup_user(ubuf, count);
+		if (IS_ERR(tmpbuf))
+			return PTR_ERR(tmpbuf);
 	}
 
 	fpu_force_restore(fpu);
 	ret = copy_uabi_from_kernel_to_xstate(fpu->fpstate, kbuf ?: tmpbuf, &target->thread.pkru);
 
-out:
-	vfree(tmpbuf);
+	kvfree(tmpbuf);
 	return ret;
 }
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-20 19:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 19:55 [PATCH RESEND] x86/fpu: Use vmemdup_user() in xstateregs_set() Thorsten Blum

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