Skip to contentSkip to conversation

spapr_vty: lookup should only return valid VTY objects

PATCH Superseded David Gibson 1 participant 2 messages Jul 1, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr_vty: lookup should only return valid VTY objects

From: Greg Kurz <[email protected]>

If a guest passes the reg property of a valid VIO object that is not a VTY to either H_GET_TERM_CHAR or H_PUT_TERM_CHAR, QEMU hits a dynamic cast assertion and aborts.

PAPR+ says "Hypervisor checks the termno parameter for validity against the Vterm IOA unit addresses assigned to the partition, else return H_Parameter."

This patch adds a type check to ensure vty_lookup() either returns a pointer to a valid VTY object or NULL. H_GET_TERM_CHAR and H_PUT_TERM_CHAR will now return H_PARAMETER to the guest instead of crashing.

The patch has no effect on the reg == 0 hack used to implement the RTAS call display-character.

---
 hw/char/spapr_vty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I've already merged this into spapr-next and it will be in the next batch I send if not merged before that.

But I think this is an important enough fix (it allows the guest to crash qemu) that it should probably be fastracked into mainline and stable.

hw/char/spapr_vty.c +1 -1
index 1d53035..f407cd0 100644
@@ -228,7 +228,7 @@ VIOsPAPRDevice *vty_lookup(sPAPRMachineState *spapr, target_ulong reg)
         return spapr_vty_get_default(spapr->vio_bus);
     }
 
-    return sdev;
+    return object_dynamic_cast(sdev, TYPE_VIO_SPAPR_VTY_DEVICE);
 }
 
 static void spapr_vty_register_types(void)
Signature · 1 line
2.4.3
#1 lore raw

Ugh, sorry, this version is buggy, I'll resend.

Quoted 42 lines · David Gibson

From: Greg Kurz <[email protected]>

If a guest passes the reg property of a valid VIO object that is not a VTY to either H_GET_TERM_CHAR or H_PUT_TERM_CHAR, QEMU hits a dynamic cast assertion and aborts.

PAPR+ says "Hypervisor checks the termno parameter for validity against the Vterm IOA unit addresses assigned to the partition, else return H_Parameter."

This patch adds a type check to ensure vty_lookup() either returns a pointer to a valid VTY object or NULL. H_GET_TERM_CHAR and H_PUT_TERM_CHAR will now return H_PARAMETER to the guest instead of crashing.

The patch has no effect on the reg == 0 hack used to implement the RTAS call display-character.

---
 hw/char/spapr_vty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I've already merged this into spapr-next and it will be in the next batch I send if not merged before that.

But I think this is an important enough fix (it allows the guest to crash qemu) that it should probably be fastracked into mainline and stable.

hw/char/spapr_vty.c +1 -1
index 1d53035..f407cd0 100644
@@ -228,7 +228,7 @@ VIOsPAPRDevice *vty_lookup(sPAPRMachineState *spapr, target_ulong reg)
         return spapr_vty_get_default(spapr->vio_bus);
     }
 
-    return sdev;
+    return object_dynamic_cast(sdev, TYPE_VIO_SPAPR_VTY_DEVICE);
 }
 
 static void spapr_vty_register_types(void)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson