Skip to contentSkip to conversation

iio: dac: fix off-by-one comparison and out-of-bounds write

PATCH In review Colin King 3 participants 3 messages Jun 2, 2016 – Jun 3, 2016

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 iio: dac: fix off-by-one comparison and out-of-bounds write

From: Colin Ian King <[email protected]>

The check on reg is off-by-one, it should be >= rather than >. Fix this to stop an out-of-bounds write to st->channel_modes[reg].

---
 drivers/iio/dac/ad5592r-base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5592r-base.c +1 -1
index 948f600..69bde59 100644
@@ -525,7 +525,7 @@ static int ad5592r_alloc_channels(struct ad5592r_state *st)
 
 	device_for_each_child_node(st->dev, child) {
 		ret = fwnode_property_read_u32(child, "reg", &reg);
-		if (ret || reg > ARRAY_SIZE(st->channel_modes))
+		if (ret || reg >= ARRAY_SIZE(st->channel_modes))
 			continue;
 
 		ret = fwnode_property_read_u32(child, "adi,mode", &tmp);
Signature · 1 line
2.8.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

The check on reg is off-by-one, it should be >= rather than >. Fix this to stop an out-of-bounds write to st->channel_modes[reg].

Quoted 18 lines
---
  drivers/iio/dac/ad5592r-base.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5592r-base.c +1 -1
index 948f600..69bde59 100644
@@ -525,7 +525,7 @@ static int ad5592r_alloc_channels(struct ad5592r_state *st)
 
  	device_for_each_child_node(st->dev, child) {
  		ret = fwnode_property_read_u32(child, "reg", &reg);
-		if (ret || reg > ARRAY_SIZE(st->channel_modes))
+		if (ret || reg >= ARRAY_SIZE(st->channel_modes))
  			continue;
 
  		ret = fwnode_property_read_u32(child, "adi,mode", &tmp);
Signature · 7 lines
Greetings,
Michael

--
Analog Devices GmbH      Otl-Aicher Strasse 60-64      80807 München
Sitz der Gesellschaft München, Registergericht München HRB 40368,
Geschäftsführer: Peter Kolberg, Ali Raza Husain, Eileen Wynne
maintainer
#2 lore raw
Quoted 9 lines · Michael Hennerich
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

The check on reg is off-by-one, it should be >= rather than >. Fix this to stop an out-of-bounds write to st->channel_modes[reg].

Already have a fix queued from the 29th of April - will push out in the next few days. It just managed to miss going out in the last cycle by a few days.

Thanks,

Jonathan

Quoted 21 lines
Quoted 19 lines
---
  drivers/iio/dac/ad5592r-base.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad5592r-base.c +1 -1
index 948f600..69bde59 100644
@@ -525,7 +525,7 @@ static int ad5592r_alloc_channels(struct ad5592r_state *st)
 
      device_for_each_child_node(st->dev, child) {
          ret = fwnode_property_read_u32(child, "reg", &reg);
-        if (ret || reg > ARRAY_SIZE(st->channel_modes))
+        if (ret || reg >= ARRAY_SIZE(st->channel_modes))
              continue;
 
          ret = fwnode_property_read_u32(child, "adi,mode", &tmp);