* [PATCH] KVM: x86: Zero-initialize temporary fxregs_state buffers in FXSAVE emulation
@ 2026-02-12 21:24 Uros Bizjak
2026-03-05 17:07 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2026-02-12 21:24 UTC (permalink / raw)
To: kvm, x86, linux-kernel
Cc: Uros Bizjak, Sean Christopherson, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin
Explicitly zero-initialize stack-allocated struct fxregs_state
variables in em_fxsave() and fxregs_fixup() to ensure all padding and
unused fields are cleared before use.
Both functions declare temporary fxregs_state buffers that may be
partially written by fxsave. Although the emulator copies only the
architecturally defined portion of the state to userspace, any padding
or otherwise untouched bytes in the structure can remain uninitialized.
This can lead to the use of uninitialized stack data and may trigger
KMSAN reports. In the worst case, it could result in leaking stack
contents if such bytes are ever exposed.
No functional change intended.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/kvm/emulate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c8e292e9a24d..20ed588015f1 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3708,7 +3708,7 @@ static inline size_t fxstate_size(struct x86_emulate_ctxt *ctxt)
*/
static int em_fxsave(struct x86_emulate_ctxt *ctxt)
{
- struct fxregs_state fx_state;
+ struct fxregs_state fx_state = {};
int rc;
rc = check_fxsr(ctxt);
@@ -3738,7 +3738,7 @@ static int em_fxsave(struct x86_emulate_ctxt *ctxt)
static noinline int fxregs_fixup(struct fxregs_state *fx_state,
const size_t used_size)
{
- struct fxregs_state fx_tmp;
+ struct fxregs_state fx_tmp = {};
int rc;
rc = asm_safe("fxsave %[fx]", , [fx] "+m"(fx_tmp));
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] KVM: x86: Zero-initialize temporary fxregs_state buffers in FXSAVE emulation
2026-02-12 21:24 [PATCH] KVM: x86: Zero-initialize temporary fxregs_state buffers in FXSAVE emulation Uros Bizjak
@ 2026-03-05 17:07 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-03-05 17:07 UTC (permalink / raw)
To: Sean Christopherson, kvm, x86, linux-kernel, Uros Bizjak
Cc: Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
On Thu, 12 Feb 2026 22:24:04 +0100, Uros Bizjak wrote:
> Explicitly zero-initialize stack-allocated struct fxregs_state
> variables in em_fxsave() and fxregs_fixup() to ensure all padding and
> unused fields are cleared before use.
>
> Both functions declare temporary fxregs_state buffers that may be
> partially written by fxsave. Although the emulator copies only the
> architecturally defined portion of the state to userspace, any padding
> or otherwise untouched bytes in the structure can remain uninitialized.
> This can lead to the use of uninitialized stack data and may trigger
> KMSAN reports. In the worst case, it could result in leaking stack
> contents if such bytes are ever exposed.
>
> [...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: Zero-initialize temporary fxregs_state buffers in FXSAVE emulation
https://github.com/kvm-x86/linux/commit/e1df128dc00b
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-05 17:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-12 21:24 [PATCH] KVM: x86: Zero-initialize temporary fxregs_state buffers in FXSAVE emulation Uros Bizjak
2026-03-05 17:07 ` Sean Christopherson
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®