Re: [PATCH] KVM: VMX: Don't register posted interrupt wakeup handler if alloc_kvm_area() fails
From: Sean Christopherson
Date: Tue Jan 13 2026 - 11:17:25 EST
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@xxxxxxxxxxxxxxx
even though I agree it's extremely unlikely to be an issue in practice.
> Signed-off-by: Hou Wenlong <houwenlong.hwl@xxxxxxxxxxxx>
> ---
> 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;
}