From: David Gibson Date: Thu, 2 Jul 2015 06:23:24 +0000 (+1000) Subject: spapr_vty: lookup should only return valid VTY objects X-Git-Tag: v2.3.1~26 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9b4420ad624905860deda56b5901276d695dad9c;p=users%2Fdwmw2%2Fqemu.git spapr_vty: lookup should only return valid VTY objects 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. Signed-off-by: Greg Kurz Signed-off-by: David Gibson Signed-off-by: Alexander Graf (cherry picked from commit 0f888bfaddfc5f55b0d82cde2e1164658a672375) Signed-off-by: Michael Roth --- diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index 4e464bd15a..c7f824ed13 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -228,6 +228,10 @@ VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg) return spapr_vty_get_default(spapr->vio_bus); } + if (!object_dynamic_cast(OBJECT(sdev), TYPE_VIO_SPAPR_VTY_DEVICE)) { + return NULL; + } + return sdev; }