Skip to contentSkip to conversation

arm: check bit index before use

PATCH In review P J P 3 participants 4 messages Oct 22, 2018 – Oct 26, 2018

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/3 arm: check bit index before use

From: Prasad J Pandit <[email protected]>

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.

---
 hw/arm/strongarm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/strongarm.c +3 -1
index ec2627374d..3dda75feaf 100644
@@ -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;
Signature · 1 line
2.17.2
#1 lore raw

2018-10-22

liqsub1

发件人:P J P <[email protected]>
发送时间:2018-10-23 01:39
主题:[Qemu-devel] [PATCH 1/3] arm: check bit index before use
收件人:"Qemu Developers"<[email protected]>
抄送:"Peter Maydell"<[email protected]>,"Moguofang"<[email protected]>,"Prasad J Pandit"<[email protected]>

From: Prasad J Pandit <[email protected]>

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.

---

 hw/arm/strongarm.c | 4 +++- 
 1 file changed, 3 insertions(+), 1 deletion(-) 
hw/arm/strongarm.c +1 -1
index ec2627374d..3dda75feaf 100644 
@@ -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; 
Signature · 1 line
2.17.2 
author
#2 lore raw
+-- 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

#3 lore raw
In reply to P J P
Quoted 18 lines · P J P

From: Prasad J Pandit <[email protected]>

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.

---
 hw/arm/strongarm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/arm/strongarm.c +0 -0
index ec2627374d..3dda75feaf 100644

hw/arm/strongarm.c static void strongarm_gpio_handler_update(StrongARMGPIOInfo *s) · line 540

Quoted 10 lines
hw/arm/strongarm.c +3 -1
@@ -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