From patchwork Wed Jul 1 03:51:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 489850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5761C140A9A for ; Wed, 1 Jul 2015 13:51:32 +1000 (AEST) Received: from localhost ([::1]:49522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA93a-0003cJ-IW for incoming@patchwork.ozlabs.org; Tue, 30 Jun 2015 23:51:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA93G-000337-2P for qemu-devel@nongnu.org; Tue, 30 Jun 2015 23:51:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZA93C-0007cE-Rj for qemu-devel@nongnu.org; Tue, 30 Jun 2015 23:51:10 -0400 Received: from ozlabs.org ([103.22.144.67]:47919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZA93C-0007Z8-GM; Tue, 30 Jun 2015 23:51:06 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 46E58140B00; Wed, 1 Jul 2015 13:51:01 +1000 (AEST) From: David Gibson To: agraf@suse.de, peter.myadell@linaro.org, qemu-stable@nongnu.org Date: Wed, 1 Jul 2015 13:51:43 +1000 Message-Id: <1435722703-12515-1-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.4.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 103.22.144.67 Cc: aik@ozlabs.ru, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, David Gibson , Greg Kurz Subject: [Qemu-devel] [PATCH] spapr_vty: lookup should only return valid VTY objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Greg Kurz 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 --- 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. diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index 1d53035..f407cd0 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -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)