Received: from eggs.gnu.org ([2001:4830:134:3::10]:42501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WBp2N-00017y-6J for qemu-devel@nongnu.org; Fri, 07 Feb 2014 12:16:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WBp29-0005iG-2u for qemu-devel@nongnu.org; Fri, 07 Feb 2014 12:16:23 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:46986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WBp28-0005hb-Pf for qemu-devel@nongnu.org; Fri, 07 Feb 2014 12:16:09 -0500 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Feb 2014 17:16:08 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id BB39A1B08061 for ; Fri, 7 Feb 2014 17:15:38 +0000 (GMT) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s17HFrnB66519110 for ; Fri, 7 Feb 2014 17:15:53 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s17HG4hx029360 for ; Fri, 7 Feb 2014 10:16:05 -0700 From: Christian Borntraeger Date: Fri, 7 Feb 2014 18:16:16 +0100 Message-Id: <1391793385-46694-8-git-send-email-borntraeger@de.ibm.com> In-Reply-To: <1391793385-46694-1-git-send-email-borntraeger@de.ibm.com> References: <1391793385-46694-1-git-send-email-borntraeger@de.ibm.com> Subject: [Qemu-devel] [Patch/RFC 07/16] s390x/virtio-hcall: Add range check for hypervisor call List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel Cc: Heinz Graalfs , Thomas Huth , Alexander Graf , Dominik Dingel , Christian Borntraeger , Jens Freimann , Paolo Bonzini , Richard Henderson From: Thomas Huth The handler for diag 500 did not check whether the requested function was in the supported range, so illegal values could crash QEMU in the worst case. Signed-off-by: Thomas Huth Reviewed-by: Cornelia Huck Signed-off-by: Christian Borntraeger --- hw/s390x/s390-virtio-hcall.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/s390x/s390-virtio-hcall.c b/hw/s390x/s390-virtio-hcall.c index ee62649..0e328d8 100644 --- a/hw/s390x/s390-virtio-hcall.c +++ b/hw/s390x/s390-virtio-hcall.c @@ -26,11 +26,14 @@ void s390_register_virtio_hypercall(uint64_t code, s390_virtio_fn fn) int s390_virtio_hypercall(CPUS390XState *env) { - s390_virtio_fn fn = s390_diag500_table[env->regs[1]]; + s390_virtio_fn fn; - if (!fn) { - return -EINVAL; + if (env->regs[1] < MAX_DIAG_SUBCODES) { + fn = s390_diag500_table[env->regs[1]]; + if (fn) { + return fn(&env->regs[2]); + } } - return fn(&env->regs[2]); + return -EINVAL; } -- 1.8.4.2