From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, weiguixiong@bytedance.com,
omermetekaya0@gmail.com, chang.seok.bae@intel.com,
stable@vger.kernel.org
Subject: [PATCH 5/6] x86/fpu: Fix memory leak with dynamic fpstate and exec()
Date: Mon, 30 Nov 2026 20:51:41 +0000 [thread overview]
Message-ID: <20261130205143.1258369-6-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20261130205143.1258369-1-chang.seok.bae@intel.com>
Using an XFD-controlled xfeature can allocate a larger fpstate. On
exec(), fpstate_reset() replaces fpu->fpstate with the embedded buffer
without freeing the dynamic allocation. Once the pointer is overwritten,
the allocation cannot be freed on task exit.
Free vmalloc'ed area from fpu_reset_fpstate().
Fixes: 500afbf645a0 ("x86/fpu/xstate: Add fpstate_realloc()/free()")
Closes: https://lore.kernel.org/20260929151013.81562-2-weiguixiong@bytedance.com
Reported-by: Guixiong Wei <weiguixiong@bytedance.com>
Originally-by: Guixiong Wei <weiguixiong@bytedance.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: stable@vger.kernel.org
---
arch/x86/kernel/fpu/core.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index de746eedfe397..f088b1f8518ea 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -680,16 +680,28 @@ static int update_fpu_shstk(struct task_struct *dst, unsigned long ssp)
* Reset fpstate metadata and register storage to the init values from:
* - fpu_clone() for new task's FPU state
* - fpu_flush_thread() for current
+ *
+ * Also, free up the expanded storage.
*/
static void fpu_reset_fpstate(struct task_struct *tsk, struct fpu *fpu, bool reset_regs)
{
+ struct fpstate *oldfps = NULL;
+
/* Current must get its register storage reset. */
WARN_ON_ONCE(tsk == current && !reset_regs);
- if (tsk == current)
+ /* New tasks must have a null pointer from arch_dup_task_struct() */
+ WARN_ON_ONCE(tsk != current && fpu->fpstate != NULL);
+
+ if (tsk == current) {
+ oldfps = fpu->fpstate;
fpregs_lock();
+ }
- /* Reset the fpstate metadata: */
+ /*
+ * Reset the fpstate metadata, including fpu->fpstate being
+ * reset to __fpstate.
+ */
fpstate_reset(fpu);
/*
@@ -719,8 +731,10 @@ static void fpu_reset_fpstate(struct task_struct *tsk, struct fpu *fpu, bool res
*/
set_tsk_thread_flag(tsk, TIF_NEED_FPU_LOAD);
- if (tsk == current)
+ if (tsk == current) {
fpregs_unlock();
+ fpstate_free(oldfps);
+ }
}
/* Clone current's FPU state on fork */
--
2.53.0
next prev parent reply other threads:[~2026-11-30 21:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 20:51 [PATCH 0/6] x86/fpu: Fix issues around resetting fpstate Chang S. Bae
2026-11-30 20:51 ` [PATCH 1/6] x86/fpu: Remove remaining fpstate reset for init_task Chang S. Bae
2026-11-30 20:51 ` [PATCH 2/6] x86/fpu: Refactor fpstate storage reset sequence Chang S. Bae
2026-11-30 20:51 ` [PATCH 3/6] x86/fpu: Reset the fpstate on exec() under fpregs_lock() Chang S. Bae
2026-11-30 20:51 ` [PATCH 4/6] x86/fpu: Refactor fpstate memory free helpers Chang S. Bae
2026-11-30 20:51 ` Chang S. Bae [this message]
2026-11-30 20:51 ` [PATCH 6/6] selftests/x86/amx: Test fpstate memory cleanup on exec() Chang S. Bae
2026-11-30 21:33 ` Chang S. Bae
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130205143.1258369-6-chang.seok.bae@intel.com \
--to=chang.seok.bae@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=omermetekaya0@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=weiguixiong@bytedance.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®