[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aWZwE1QukfjYDB_Q@google.com>
Date: Tue, 13 Jan 2026 08:17:23 -0800
From: Sean Christopherson <seanjc@...gle.com>
To: Hou Wenlong <houwenlong.hwl@...group.com>
Cc: kvm@...r.kernel.org, Paolo Bonzini <pbonzini@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] KVM: VMX: Don't register posted interrupt wakeup handler
if alloc_kvm_area() fails
On Tue, Jan 13, 2026, Hou Wenlong wrote:
> Unregistering the posted interrupt wakeup handler only happens during
> hardware unsetup. Therefore, if alloc_kvm_area() fails and continue to
> register the posted interrupt wakeup handler, this will leave the global
> posted interrupt wakeup handler pointer in an incorrect state. Although
> it should not be an issue, it's still better to change it.
Ouch, yeah, that's ugly. It's not entirely benign, as a failed allocation followed
by a spurious notification vector IRQ would trigger UAF. So it's probably worth
adding:
Fixes: ec5a4919fa7b ("KVM: VMX: Unregister posted interrupt wakeup handler on hardware unsetup")
Cc: stable@...r.kernel.org
even though I agree it's extremely unlikely to be an issue in practice.
> Signed-off-by: Hou Wenlong <houwenlong.hwl@...group.com>
> ---
> arch/x86/kvm/vmx/vmx.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 9b92f672ccfe..676f32aa72bb 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -8829,8 +8829,11 @@ __init int vmx_hardware_setup(void)
> }
>
> r = alloc_kvm_area();
> - if (r && nested)
> - nested_vmx_hardware_unsetup();
> + if (r) {
> + if (nested)
> + nested_vmx_hardware_unsetup();
> + return r;
> + }
I'm leaning towards using a goto with an explicit "return 0" in the happy case,
to make it less likely that a similar bug is introduced in the future. Any
preference on your end?
E.g. (untested)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 9b92f672ccfe..cecaaeb3f82a 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -8829,8 +8829,8 @@ __init int vmx_hardware_setup(void)
}
r = alloc_kvm_area();
- if (r && nested)
- nested_vmx_hardware_unsetup();
+ if (r)
+ goto err_kvm_area;
kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler);
@@ -8857,6 +8857,11 @@ __init int vmx_hardware_setup(void)
kvm_caps.inapplicable_quirks &= ~KVM_X86_QUIRK_IGNORE_GUEST_PAT;
+ return 0;
+
+err_kvm_area:
+ if (nested)
+ nested_vmx_hardware_unsetup();
return r;
}
Powered by blists - more mailing lists