From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FD6DBA44 for ; Tue, 7 Mar 2023 17:50:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1048EC433EF; Tue, 7 Mar 2023 17:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678211439; bh=bBjjq0SmBxSSIZUiQzFJmaeYDdxmF6vncQeJHdCxfyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s6ay9Z87c9L7f5z+6JrYcuhepQGluaKeGhTsR5X79zO2F+JOJFhbTUztTeYPRuImu b6vE93b55vTA5cO3jqvdGMFV7iHb0WZzGM3VR6vjb7siwrrbqU159shkSEcNX2lGsL MVjEXYZaxPc1oQLJolc7+4pNfWIMmABOAU65Ysoo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marc Orr , Ben Gardon , Venkatesh Srinivas , Maxim Levitsky , Sean Christopherson Subject: [PATCH 6.2 0831/1001] KVM: x86: Inject #GP if WRMSR sets reserved bits in APIC Self-IPI Date: Tue, 7 Mar 2023 18:00:03 +0100 Message-Id: <20230307170057.842196084@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170022.094103862@linuxfoundation.org> References: <20230307170022.094103862@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Sean Christopherson commit ba5838abb05334e4abfdff1490585c7f365e0424 upstream. Inject a #GP if the guest attempts to set reserved bits in the x2APIC-only Self-IPI register. Bits 7:0 hold the vector, all other bits are reserved. Reported-by: Marc Orr Cc: Ben Gardon Cc: Venkatesh Srinivas Cc: stable@vger.kernel.org Reviewed-by: Maxim Levitsky Link: https://lore.kernel.org/r/20230107011025.565472-2-seanjc@google.com Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/lapic.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2227,10 +2227,14 @@ static int kvm_lapic_reg_write(struct kv break; case APIC_SELF_IPI: - if (apic_x2apic_mode(apic)) - kvm_apic_send_ipi(apic, APIC_DEST_SELF | (val & APIC_VECTOR_MASK), 0); - else + /* + * Self-IPI exists only when x2APIC is enabled. Bits 7:0 hold + * the vector, everything else is reserved. + */ + if (!apic_x2apic_mode(apic) || (val & ~APIC_VECTOR_MASK)) ret = 1; + else + kvm_apic_send_ipi(apic, APIC_DEST_SELF | val, 0); break; default: ret = 1;