From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02B39352C34 for ; Mon, 20 Jul 2026 19:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784577384; cv=none; b=clSpiw6dgleuuvb6t6BKK3Jj/IMsj3yHu3QS2SLFL9J5D5JYoEjMfLyua7eW0Os7FQVKl8HOgFr8fVtaiI51ye5tcPcCTsaBtz85NngMnepb8jJTDLEPzB9BENHzLMUxevUV6BwfvVCYAZsfPkJ/88XgnF/wsyJi4TSbI6KyHu8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784577384; c=relaxed/simple; bh=NY1+sD89K/uh7RsVoBvAvpHWsUsZ7JQU0+n/sHhNxeI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YVFioTPIevtchNKOfVb5FpV9r/X+Bf1jJyVfRXkLwpFzfveScxlgbkDMMYnnlxaEkkVyIbqFvrYvMOU3b8ioP5z6dio3/aPKQ8C+9a3SqkI4Xu8LSqPdENedxl5Umavg9KWQxV/v7lYlz++nLxiCZIL8an4jilFDzGteWGWHaQQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ek5ZqWzf; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ek5ZqWzf" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784577379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OqNCrtg6TfhwScHFoGccejhO7qmhUjGXW09y0HJTu/o=; b=ek5ZqWzfcKSzuEPv6VEbHKTn3SwxGcmUmQxMCplgDJOzhkEWnqzVieA/sCkkS3xI8lqB7V KvRNuqhFufpmJxDv1MjB1sdFzgLdf8mlrjbyhhUzO+ci5rMg62/NawB1hOleG2ui1sxs+0 5WtGtpRjg8EX4i8R77iTXVye5l3+FlE= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: Thorsten Blum , linux-kernel@vger.kernel.org Subject: [PATCH RESEND] x86/fpu: Use vmemdup_user() in xstateregs_set() Date: Mon, 20 Jul 2026 21:55:35 +0200 Message-ID: <20260720195534.70111-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1583; i=thorsten.blum@linux.dev; h=from:subject; bh=NY1+sD89K/uh7RsVoBvAvpHWsUsZ7JQU0+n/sHhNxeI=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFlxtWYCTj763+4sNvTjaN8dfM32V7W3eq5JBCt3RX9PO sPpcxUdpSwMYlwMsmKKLA9m/ZjhW1pTuckkYifMHFYmkCEMXJwCMJFvZgz/ox62vNKv6eJefmcO z8J3th4FnWsjzjaET7jJ8N2NkcNBgJHhx+H0CvW1d49XfVM2uH7CyEo7x+9Sq/0UXo3P08XvXWH iAQA= X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 --- 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 -#include +#include +#include #include #include @@ -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; }