From: Sean Christopherson <seanjc@google.com>
To: Hou Wenlong <houwenlong.hwl@antgroup.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: VMX: Don't register posted interrupt wakeup handler if alloc_kvm_area() fails
Date: Tue, 13 Jan 2026 08:17:23 -0800 [thread overview]
Message-ID: <aWZwE1QukfjYDB_Q@google.com> (raw)
In-Reply-To: <0ac6908b608cf80eab7437004334fedd0f5f5317.1768304590.git.houwenlong.hwl@antgroup.com>
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@vger.kernel.org
even though I agree it's extremely unlikely to be an issue in practice.
> Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.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;
}
next prev parent reply other threads:[~2026-01-13 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-13 11:56 [PATCH] KVM: VMX: Don't register posted interrupt wakeup handler if alloc_kvm_area() fails Hou Wenlong
2026-01-13 16:17 ` Sean Christopherson [this message]
2026-01-14 3:11 ` Hou Wenlong
2026-01-14 21:22 ` Sean Christopherson
2026-01-15 18:03 ` Sean Christopherson
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=aWZwE1QukfjYDB_Q@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=houwenlong.hwl@antgroup.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.