Skip to contentSkip to conversation

hw/gpio/pca9552: fix off-by-one in QOM led index validation

PATCH Applied yujun 5 participants 5 messages Jun 29

lore
Share & tools
lore

yujun

author
#0 lore raw

PATCH 1/1 hw/gpio/pca9552: fix off-by-one in QOM led index validation

pca955x_get_led() and pca955x_set_led() accept led indices equal to pin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register past max_reg.

Use the same >= pin_count bounds check as pca9554_set_pin() and the gpio input handler assert in this file.

Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")
---
 hw/gpio/pca9552.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/gpio/pca9552.c +4 -4
index 472d8ad957..b13ac9fd9c 100644
@@ -311,8 +311,8 @@ static void pca955x_get_led(Object *obj, Visitor *v, const char *name,
         error_setg(errp, "%s: error reading %s", __func__, name);
         return;
     }
-    if (led < 0 || led > k->pin_count) {
-        error_setg(errp, "%s invalid led %s", __func__, name);
+    if (led < 0 || led >= k->pin_count) {
+        error_setg(errp, "%s: invalid led %s", __func__, name);
         return;
     }
     /*
@@ -352,8 +352,8 @@ static void pca955x_set_led(Object *obj, Visitor *v, const char *name,
         error_setg(errp, "%s: error reading %s", __func__, name);
         return;
     }
-    if (led < 0 || led > k->pin_count) {
-        error_setg(errp, "%s invalid led %s", __func__, name);
+    if (led < 0 || led >= k->pin_count) {
+        error_setg(errp, "%s: invalid led %s", __func__, name);
         return;
     }
 
Signature · 1 line
2.25.1
#1 lore raw

Glenn,

Cc me if you ack this change. I can take it through the aspeed queue.

Thanks,

C.

Quoted 40 lines · yujun

pca955x_get_led() and pca955x_set_led() accept led indices equal to pin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register past max_reg.

Use the same >= pin_count bounds check as pca9554_set_pin() and the gpio input handler assert in this file.

Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")
---
  hw/gpio/pca9552.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
hw/gpio/pca9552.c +4 -4
index 472d8ad957..b13ac9fd9c 100644
@@ -311,8 +311,8 @@ static void pca955x_get_led(Object *obj, Visitor *v, const char *name,
          error_setg(errp, "%s: error reading %s", __func__, name);
          return;
      }
-    if (led < 0 || led > k->pin_count) {
-        error_setg(errp, "%s invalid led %s", __func__, name);
+    if (led < 0 || led >= k->pin_count) {
+        error_setg(errp, "%s: invalid led %s", __func__, name);
          return;
      }
      /*
@@ -352,8 +352,8 @@ static void pca955x_set_led(Object *obj, Visitor *v, const char *name,
          error_setg(errp, "%s: error reading %s", __func__, name);
          return;
      }
-    if (led < 0 || led > k->pin_count) {
-        error_setg(errp, "%s invalid led %s", __func__, name);
+    if (led < 0 || led >= k->pin_count) {
+        error_setg(errp, "%s: invalid led %s", __func__, name);
          return;
      }
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to yujun
Quoted 11 lines · yujun

pca955x_get_led() and pca955x_set_led() accept led indices equal to pin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register past max_reg.

Use the same >= pin_count bounds check as pca9554_set_pin() and the gpio input handler assert in this file.

Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")

thanks
-- PMM

Reviewed-by on v1 1/1
#3 lore raw
In reply to yujun

Thanks,

Glenn

Quoted 40 lines · yujun

pca955x_get_led() and pca955x_set_led() accept led indices equal to pin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register past max_reg.

Use the same >= pin_count bounds check as pca9554_set_pin() and the gpio input handler assert in this file.

Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")
---
 hw/gpio/pca9552.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/gpio/pca9552.c +4 -4
index 472d8ad957..b13ac9fd9c 100644
@@ -311,8 +311,8 @@ static void pca955x_get_led(Object *obj, Visitor *v, const char *name,
         error_setg(errp, "%s: error reading %s", __func__, name);
         return;
     }
-    if (led < 0 || led > k->pin_count) {
-        error_setg(errp, "%s invalid led %s", __func__, name);
+    if (led < 0 || led >= k->pin_count) {
+        error_setg(errp, "%s: invalid led %s", __func__, name);
         return;
     }
     /*
@@ -352,8 +352,8 @@ static void pca955x_set_led(Object *obj, Visitor *v, const char *name,
         error_setg(errp, "%s: error reading %s", __func__, name);
         return;
     }
-    if (led < 0 || led > k->pin_count) {
-        error_setg(errp, "%s invalid led %s", __func__, name);
+    if (led < 0 || led >= k->pin_count) {
+        error_setg(errp, "%s: invalid led %s", __func__, name);
         return;
     }
 
#4 lore raw
In reply to yujun
Quoted 5 lines · yujun

pca955x_get_led() and pca955x_set_led() accept led indices equal to pin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register past max_reg.

Quoted 8 lines

Use the same >= pin_count bounds check as pca9554_set_pin() and the gpio input handler assert in this file.

Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")
---
  hw/gpio/pca9552.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

Queued via hw-misc, thanks!

Phil.