From: Christian Borntraeger Subject: [PATCH] kvm-s390: fix potential array overrun in intercept handling Date: Thu, 21 Jan 2010 11:56:03 +0100 Message-ID: <201001211156.03669.borntraeger@de.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Martin Schwidefsky , Heiko Carstens , cotte@de.ibm.com To: Marcelo Tosatti , Avi Kivity Return-path: Received: from mtagate1.uk.ibm.com ([194.196.100.161]:35226 "EHLO mtagate1.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751492Ab0AUK4I (ORCPT ); Thu, 21 Jan 2010 05:56:08 -0500 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o0LAu6ON000811 for ; Thu, 21 Jan 2010 10:56:06 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o0LAu6Kq1134776 for ; Thu, 21 Jan 2010 10:56:06 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o0LAu56Y012653 for ; Thu, 21 Jan 2010 10:56:05 GMT Sender: kvm-owner@vger.kernel.org List-ID: Avi, Marcelo, kvm_handle_sie_intercept uses a jump table to get the intercept handler for a SIE intercept. Static code analysis revealed a potential problem: the intercept_funcs jump table was defined to contain (0x48 >> 2) entries, but we only checked for code > 0x48 which would cause an off-by-one array overflow if code == 0x48. Since the table is only populated up to (0x28 >> 2), we can reduce the jump table size while fixing the off-by-one. Signed-off-by: Christian Borntraeger --- (patch was refreshed with -U8 to see the full jump table.) arch/s390/kvm/intercept.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Index: linux-2.6/arch/s390/kvm/intercept.c =================================================================== --- linux-2.6.orig/arch/s390/kvm/intercept.c +++ linux-2.6/arch/s390/kvm/intercept.c @@ -208,32 +208,32 @@ static int handle_instruction_and_prog(s if (rc == -ENOTSUPP) vcpu->arch.sie_block->icptcode = 0x04; if (rc) return rc; return rc2; } -static const intercept_handler_t intercept_funcs[0x48 >> 2] = { +static const intercept_handler_t intercept_funcs[(0x28 >> 2) + 1] = { [0x00 >> 2] = handle_noop, [0x04 >> 2] = handle_instruction, [0x08 >> 2] = handle_prog, [0x0C >> 2] = handle_instruction_and_prog, [0x10 >> 2] = handle_noop, [0x14 >> 2] = handle_noop, [0x1C >> 2] = kvm_s390_handle_wait, [0x20 >> 2] = handle_validity, [0x28 >> 2] = handle_stop, }; int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu) { intercept_handler_t func; u8 code = vcpu->arch.sie_block->icptcode; - if (code & 3 || code > 0x48) + if (code & 3 || code > 0x28) return -ENOTSUPP; func = intercept_funcs[code >> 2]; if (func) return func(vcpu); return -ENOTSUPP; }