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, christina.joos@intel.com,
stephan.rohr@intel.com, chang.seok.bae@intel.com,
stable@vger.kernel.org
Subject: [PATCH] x86/fpu: Fix PKRU state saving for coredump
Date: Thu, 15 Oct 2026 21:05:44 +0000 [thread overview]
Message-ID: <20261015210545.48208-1-chang.seok.bae@intel.com> (raw)
Christina reported mismatched PKRU values from GDB coredump tests [1].
PKRU is stored in thread.pkru rather than in fpstate. Then the coredump
path currently syncs fpstate only and hands thread.pkru to
copy_xstate_to_uabi_buf(), so a task that still owns the register state
can end up dumping a stale PKRU value.
Save PKRU from the register when the target is the current task.
Fixes: e84ba47e313d ("x86/fpu: Hook up PKRU into ptrace()")
Closes: https://sourceware.org/bugzilla/show_bug.cgi?id=34646 # [1]
Reported-by: Christina Joos <christina.joos@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Tested-by: Christina Joos <christina.joos@intel.com>
Cc: stable@vger.kernel.org
---
Testing:
Christina verified the fix through the GDB tests that originally exposed
the issue. Also a simple test that sets PKRU and triggers a coredump by
dereferencing a NULL pointer can verify the saved PKRU from the corefile
read.
The existing ptrace selftests cover most of this path but not completely,
e.g. not checking back from a corefile. So it may worth adding coredump
tests for XSTATEs in general. I'd follow up on this separately.
Code changes:
The PKRU saving could be folded into sync_fpstate() similar to
restore_fpregs_from_init_fpstate(). Instead, since this is on the saving
path and PKRU storage is separate, sync_pkru() makes that dinstinction
more explicit along with the fix.
---
arch/x86/kernel/fpu/regset.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c
index 0986c2200adc..213a06fd72f3 100644
--- a/arch/x86/kernel/fpu/regset.c
+++ b/arch/x86/kernel/fpu/regset.c
@@ -49,6 +49,13 @@ static void sync_fpstate(struct fpu *fpu)
fpu_sync_fpstate(fpu);
}
+/* Keep the same invocation context with sync_fpstate() */
+static void sync_pkru(struct task_struct *target)
+{
+ if (target == current)
+ target->thread.pkru = read_pkru();
+}
+
/*
* Invalidate cached FPU registers before modifying the stopped target
* task's fpstate.
@@ -135,6 +142,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
sync_fpstate(x86_task_fpu(target));
+ /* copy_xstate_to_uabi_buf() takes PKRU from thread.pkru */
+ sync_pkru(target);
+
copy_xstate_to_uabi_buf(to, target, XSTATE_COPY_XSAVE);
return 0;
}
--
2.53.0
reply other threads:[~2026-10-15 21:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261015210545.48208-1-chang.seok.bae@intel.com \
--to=chang.seok.bae@intel.com \
--cc=bp@alien8.de \
--cc=christina.joos@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=stable@vger.kernel.org \
--cc=stephan.rohr@intel.com \
--cc=tglx@kernel.org \
--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®