From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFyUQ-0007eR-2P for qemu-devel@nongnu.org; Fri, 26 Oct 2018 05:33:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFyUM-0004dE-TP for qemu-devel@nongnu.org; Fri, 26 Oct 2018 05:33:09 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42157) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFyUM-0004cs-MN for qemu-devel@nongnu.org; Fri, 26 Oct 2018 05:33:06 -0400 Received: by mail-wr1-f65.google.com with SMTP id y15-v6so605323wru.9 for ; Fri, 26 Oct 2018 02:33:06 -0700 (PDT) References: <20181022120908.13285-1-ppandit@redhat.com> From: Paolo Bonzini Message-ID: Date: Fri, 26 Oct 2018 11:33:03 +0200 MIME-Version: 1.0 In-Reply-To: <20181022120908.13285-1-ppandit@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/3] arm: check bit index before use List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: P J P , Qemu Developers Cc: Peter Maydell , Moguofang , Prasad J Pandit On 22/10/2018 14:09, P J P wrote: > From: Prasad J Pandit > > While performing gpio write via strongarm_gpio_handler_update > routine, the 'bit' index could access beyond s->handler[28] array. > Add check to avoid OOB access. > > Reported-by: Moguofang > Signed-off-by: Prasad J Pandit > --- > hw/arm/strongarm.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/hw/arm/strongarm.c b/hw/arm/strongarm.c > index ec2627374d..3dda75feaf 100644 > --- a/hw/arm/strongarm.c > +++ b/hw/arm/strongarm.c > @@ -532,7 +532,9 @@ static void strongarm_gpio_handler_update(StrongARMGPIOInfo *s) > > for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) { > bit = ctz32(diff); > - qemu_set_irq(s->handler[bit], (level >> bit) & 1); > + if (bit < sizeof(s->handler) / sizeof(s->handler[0])) { > + qemu_set_irq(s->handler[bit], (level >> bit) & 1); > + } > } > > s->prev_level = level; > This is correct, but please use ARRAY_SIZE(s->handler). Paolo