From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIEtK-0007re-AL for qemu-devel@nongnu.org; Tue, 25 Feb 2014 05:05:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WIEtB-0005Fa-TY for qemu-devel@nongnu.org; Tue, 25 Feb 2014 05:05:33 -0500 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:46792) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WIEtB-0005FP-Fe for qemu-devel@nongnu.org; Tue, 25 Feb 2014 05:05:25 -0500 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Feb 2014 10:05:24 -0000 From: Christian Borntraeger Date: Tue, 25 Feb 2014 11:05:23 +0100 Message-Id: <1393322735-31277-6-git-send-email-borntraeger@de.ibm.com> In-Reply-To: <1393322735-31277-1-git-send-email-borntraeger@de.ibm.com> References: <1393322735-31277-1-git-send-email-borntraeger@de.ibm.com> Subject: [Qemu-devel] [PATCH 05/17] s390x/virtio-hcall: Add range check for hypervisor call List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori , Peter Maydell Cc: Thomas Huth , qemu-stable@nongnu.org, qemu-devel , Alexander Graf , Christian Borntraeger , Jens Freimann , Cornelia Huck , 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 CC: qemu-stable@nongnu.org --- 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