qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org
Subject: [PULL 01/11] target/i386: do not crash if microvm guest uses SGX CPUID leaves
Date: Tue, 23 Jul 2024 16:15:19 +0200	[thread overview]
Message-ID: <20240723141529.551737-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20240723141529.551737-1-pbonzini@redhat.com>

sgx_epc_get_section assumes a PC platform is in use:

bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
{
    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());

However, sgx_epc_get_section is called by CPUID regardless of whether
SGX state has been initialized or which platform is in use.  Check
whether the machine has the right QOM class and if not behave as if
there are no EPC sections.

Fixes: 1dec2e1f19f ("i386: Update SGX CPUID info according to hardware/KVM/user input", 2021-09-30)
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2142
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/i386/sgx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
index a14a84bc6f6..849472a1286 100644
--- a/hw/i386/sgx.c
+++ b/hw/i386/sgx.c
@@ -268,10 +268,12 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict)
 
 bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
 {
-    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PCMachineState *pcms =
+        (PCMachineState *)object_dynamic_cast(qdev_get_machine(),
+                                              TYPE_PC_MACHINE);
     SGXEPCDevice *epc;
 
-    if (pcms->sgx_epc.size == 0 || pcms->sgx_epc.nr_sections <= section_nr) {
+    if (!pcms || pcms->sgx_epc.size == 0 || pcms->sgx_epc.nr_sections <= section_nr) {
         return true;
     }
 
-- 
2.45.2



  reply	other threads:[~2024-07-23 14:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23 14:15 [PULL 00/11] target/i386, HPET changes for QEMU 9.1 soft freeze Paolo Bonzini
2024-07-23 14:15 ` Paolo Bonzini [this message]
2024-07-23 14:15 ` [PULL 02/11] qio: add support for SO_PEERCRED for socket channel Paolo Bonzini
2024-07-23 14:15 ` [PULL 03/11] tools: build qemu-vmsr-helper Paolo Bonzini
2024-07-25 10:28   ` Peter Maydell
2024-07-25 10:30     ` Paolo Bonzini
2024-07-23 14:15 ` [PULL 04/11] Add support for RAPL MSRs in KVM/Qemu Paolo Bonzini
2024-07-25 10:25   ` Peter Maydell
2024-07-23 14:15 ` [PULL 05/11] hpet: fix and cleanup persistence of interrupt status Paolo Bonzini
2025-03-19 15:28   ` Fiona Ebner
2025-03-19 15:30     ` Paolo Bonzini
2025-03-19 15:47       ` Fiona Ebner
2025-03-19 15:51         ` Paolo Bonzini
2025-03-19 15:56           ` Fiona Ebner
2024-07-23 14:15 ` [PULL 06/11] hpet: ignore high bits of comparator in 32-bit mode Paolo Bonzini
2024-07-23 14:15 ` [PULL 07/11] hpet: remove unnecessary variable "index" Paolo Bonzini
2024-07-23 14:15 ` [PULL 08/11] hpet: place read-only bits directly in "new_val" Paolo Bonzini
2024-07-23 14:15 ` [PULL 09/11] hpet: accept 64-bit reads and writes Paolo Bonzini
2024-07-23 14:15 ` [PULL 10/11] hpet: store full 64-bit target value of the counter Paolo Bonzini
2024-07-23 14:15 ` [PULL 11/11] hpet: avoid timer storms on periodic timers Paolo Bonzini
2024-07-24  2:58 ` [PULL 00/11] target/i386, HPET changes for QEMU 9.1 soft freeze Richard Henderson

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=20240723141529.551737-2-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).