qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] arm: check bit index before use
@ 2018-10-22 12:09 P J P
  2018-10-22 12:15 ` liqsub1
  2018-10-26  9:33 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: P J P @ 2018-10-22 12:09 UTC (permalink / raw)
  To: Qemu Developers; +Cc: Peter Maydell, Moguofang, Prasad J Pandit

From: Prasad J Pandit <pjp@fedoraproject.org>

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 <moguofang@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 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;
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] arm: check bit index before use
  2018-10-22 12:09 [Qemu-devel] [PATCH 1/3] arm: check bit index before use P J P
@ 2018-10-22 12:15 ` liqsub1
  2018-10-22 18:14   ` P J P
  2018-10-26  9:33 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: liqsub1 @ 2018-10-22 12:15 UTC (permalink / raw)
  To: P J P, Qemu Developers; +Cc: Peter Maydell, Moguofang, Prasad J Pandit



2018-10-22 

liqsub1 



发件人:P J P <ppandit@redhat.com>
发送时间:2018-10-23 01:39
主题:[Qemu-devel] [PATCH 1/3] arm: check bit index before use
收件人:"Qemu Developers"<qemu-devel@nongnu.org>
抄送:"Peter Maydell"<peter.maydell@linaro.org>,"Moguofang"<moguofang@huawei.com>,"Prasad J Pandit"<pjp@fedoraproject.org>

From: Prasad J Pandit <pjp@fedoraproject.org> 

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 <moguofang@huawei.com> 
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> 
--- 
 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])) { 

Hello Prasad,
Maybe you can use ARRAY_SIZE here.

Thanks,
Li Qiang

+            qemu_set_irq(s->handler[bit], (level >> bit) & 1); 
+        } 
     } 



  
     s->prev_level = level; 
--  
2.17.2 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] arm: check bit index before use
  2018-10-22 12:15 ` liqsub1
@ 2018-10-22 18:14   ` P J P
  0 siblings, 0 replies; 4+ messages in thread
From: P J P @ 2018-10-22 18:14 UTC (permalink / raw)
  To: liqsub1; +Cc: Qemu Developers, Peter Maydell, Moguofang

+-- On Mon, 22 Oct 2018, liqsub1 wrote --+
| +        if (bit < sizeof(s->handler) / sizeof(s->handler[0])) { 
| 
| Maybe you can use ARRAY_SIZE here.

Yes, sent patch v1.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] arm: check bit index before use
  2018-10-22 12:09 [Qemu-devel] [PATCH 1/3] arm: check bit index before use P J P
  2018-10-22 12:15 ` liqsub1
@ 2018-10-26  9:33 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2018-10-26  9:33 UTC (permalink / raw)
  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 <pjp@fedoraproject.org>
> 
> 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 <moguofang@huawei.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
>  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-26  9:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-22 12:09 [Qemu-devel] [PATCH 1/3] arm: check bit index before use P J P
2018-10-22 12:15 ` liqsub1
2018-10-22 18:14   ` P J P
2018-10-26  9:33 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).