From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27345263F5E for ; Tue, 13 Jan 2026 16:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768321047; cv=none; b=b7m1J/BHShO83q+RUygMjq51nJeDjUXLqFxVDRGZPyiavXoMR4NvpgU/J2Z2iXj2GCM4J+ldqf4wlroZ+LJZlJo5VWT2wml47MNw6NrvnJt+dJnVCxdsy8Oi1exh7EYrpK/M0WN1OPnTcJW+EOb8RG/QRe4mb4FVRwKQNEyh/UE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768321047; c=relaxed/simple; bh=WqJx9aUJA973Qr0mYXLofGYRCx1soCizR0tr6w6S8ss=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mte4YMRdyY1cP4CPILQJaRcyoxQLqdMaEzFHUCr+29PmQAXM0CrSFL/FsSEdDlK2VxPBmIfp9XVsn+nhmSVgaUATJ9nEBeT6qxWlDbG5FVQcQFaHn7aJy9/u6tQWAFYvrXB6csBC02H1g+fT9hn93VL3KjHeAqFC+ibN6+CprWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SIb24Ph5; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SIb24Ph5" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c52d37d346dso2927709a12.3 for ; Tue, 13 Jan 2026 08:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768321045; x=1768925845; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Hwcp4SES0NRzlCGplTTYOSpklg10HHGrYKPdipMVc2I=; b=SIb24Ph5ijYZXveVKjpSOI6yNiV1UwACqGOZfZGnCGTGrr1JsRXHMpeAQYx7u8sYii 6YhSH/8uW8v2nEfdjzZxSJEyySq09cQ2d9nZbYXW4UX8sJ4yf4kM+lrsLV7MzMDVXDq5 k3Gnnfp8AHcY7QoCPeuC8FQmimPclphT/QGKuLesfFGMeQltYgDC9BCqat9OLx/50VbZ zqV37dMudnO/nqnFWL0CsurY/XPuQeyb0prBfktPN4qAig+KjpEC37TLkW1fyqIa7VKF mnHFZlCQQMZ4lXzPmvovfgERccOS19QbuwJ2dJCK+0d4E7uPVsOHd3iCnow/ILIOML4T xo4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768321045; x=1768925845; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hwcp4SES0NRzlCGplTTYOSpklg10HHGrYKPdipMVc2I=; b=I+V+tWf4IFBAoDorKiO1tkfVliWyq5iAeq2xXEn7Gw7acgFUGjYrkJU7tttgLgyqnD OgOF5F207ref36PYLB/wbqOnjDkST60Irj6cd1EwVtXQHeZ+XMnMhPVS3V0g36R5bIRa t2oaNl06SdtdJgX03HAL6u5+ui7+A2AmFIyfV2Wo8/JoIfI5d0amXyBdjHtFWQ+xkWxm sfI2CpY5tkA+bec4eG1E+mteMPig14X5rxWGkeZsU0d/n7FXdN/0eXPmq61TYT2YE7RE iN7rOkCB/qsMz+L5f7GTjN3ll6iX/UfopS2WyLIPs4SACefMsZjfBzcylnvQGgVuvCZ+ n9sw== X-Forwarded-Encrypted: i=1; AJvYcCVz494EYVc2u0L+9H+Ka2hZ3b1tVhQvkOecGzUdcDYtzOV/YAqKCsbkWPDcvjkYN8DAL+vlkWQauWY16N0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2AM9lbiG9KioUT5nBgvy1PQfi9yyIsCqxOOuJEqLnXUTGPc8t 1Sz3+6rBRlXXQZj+RVFmhbwFSz9n5g13iS4Aj+yCWO/keizvebaSSjlZJwwjYyhPWfZBB91PDM8 LLwz80w== X-Google-Smtp-Source: AGHT+IHHuf1dzkNquieV5NtMYk+yqTT4fKxwLlyt3w/6c3AuKQwgEafeAo9wRWbz75FBhqCTPUulPdWJdj8= X-Received: from pgdk10.prod.google.com ([2002:a05:6a02:546a:b0:c1d:e051:4d17]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3387:b0:35f:5fc4:d886 with SMTP id adf61e73a8af0-3898f9cf3d7mr20016358637.43.1768321045360; Tue, 13 Jan 2026 08:17:25 -0800 (PST) Date: Tue, 13 Jan 2026 08:17:23 -0800 In-Reply-To: <0ac6908b608cf80eab7437004334fedd0f5f5317.1768304590.git.houwenlong.hwl@antgroup.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <0ac6908b608cf80eab7437004334fedd0f5f5317.1768304590.git.houwenlong.hwl@antgroup.com> Message-ID: Subject: Re: [PATCH] KVM: VMX: Don't register posted interrupt wakeup handler if alloc_kvm_area() fails From: Sean Christopherson To: Hou Wenlong Cc: kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" 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 > --- > 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; }