Skip to contentSkip to conversation

hw/vmcoreinfo: make guest format endian safe

PATCH In review Ani Sinha 2 participants 2 messages Jul 12, 2024

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH 1/1 hw/vmcoreinfo: make guest format endian safe

Guest and host formats in struct FWCfgVMCoreInfo are written in little endian format. However, the hypervisor host might be big endian. We need to do appropriate conversions between the formats before comparing the values. Fix it.

---
 hw/misc/vmcoreinfo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/misc/vmcoreinfo.c +2 -1
index 833773ade5..e00df95e29 100644
@@ -21,9 +21,10 @@
 static void fw_cfg_vmci_write(void *dev, off_t offset, size_t len)
 {
     VMCoreInfoState *s = VMCOREINFO(dev);
+    uint16_t guest_format = le16_to_cpu(s->vmcoreinfo.guest_format);
 
     s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo)
-        && s->vmcoreinfo.guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
+        && guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
 }
 
 static void vmcoreinfo_reset(void *dev)
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 5 lines · Ani Sinha

Guest and host formats in struct FWCfgVMCoreInfo are written in little endian format. However, the hypervisor host might be big endian. We need to do appropriate conversions between the formats before comparing the values. Fix it.

Looks right, but that shouldn't matter since the comparison is with 0.

Quoted 24 lines
---
 hw/misc/vmcoreinfo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/misc/vmcoreinfo.c +2 -2
index 833773ade5..e00df95e29 100644
@@ -21,9 +21,10 @@
 static void fw_cfg_vmci_write(void *dev, off_t offset, size_t len)
 {
     VMCoreInfoState *s = VMCOREINFO(dev);
+    uint16_t guest_format = le16_to_cpu(s->vmcoreinfo.guest_format);
 
     s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo)
-        && s->vmcoreinfo.guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
+        && guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
 }
 
 static void vmcoreinfo_reset(void *dev)
--

2.42.0