Skip to content

Commit 13be929

Browse files
committed
target/i386: do not crash if microvm guest uses SGX CPUID leaves
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: 1dec2e1 ("i386: Update SGX CPUID info according to hardware/KVM/user input", 2021-09-30) Cc: [email protected] Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2142 Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a7ddb48 commit 13be929

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

hw/i386/sgx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict)
268268

269269
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
270270
{
271-
PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
271+
PCMachineState *pcms =
272+
(PCMachineState *)object_dynamic_cast(qdev_get_machine(),
273+
TYPE_PC_MACHINE);
272274
SGXEPCDevice *epc;
273275

274-
if (pcms->sgx_epc.size == 0 || pcms->sgx_epc.nr_sections <= section_nr) {
276+
if (!pcms || pcms->sgx_epc.size == 0 || pcms->sgx_epc.nr_sections <= section_nr) {
275277
return true;
276278
}
277279

0 commit comments

Comments
 (0)