Skip to contentSkip to conversation

raw/cnxk_gpio: fix out of bound access for negative gpio

PATCH Applied Akhil Goyal 2 participants 2 messages Aug 7 – Sep 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 raw/cnxk_gpio: fix out of bound access for negative gpio

cnxk_gpio_valid(struct cnxk_gpiochip *gpiochip, int gpio) validates the GPIO number with only an upper bound while gpio can be wrongly configured as negative value from application. Added a check to reject negative values.

Fixes ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/cnxk_gpio/cnxk_gpio.c +1 -1
index 0549e326f9..e22fb7cf7b 100644
@@ -795,7 +795,7 @@ cnxk_gpio_process_buf(struct cnxk_gpio *gpio, struct rte_rawdev_buf *rbuf)
 static bool
 cnxk_gpio_valid(struct cnxk_gpiochip *gpiochip, int gpio)
 {
-	return gpio < gpiochip->num_gpios && gpiochip->gpios[gpio];
+	return (gpio >= 0) && (gpio < gpiochip->num_gpios) && gpiochip->gpios[gpio];
 }
 
 static int
Signature · 1 line
2.43.0
Applied
#1 lore raw
Quoted 10 lines · Akhil Goyal

cnxk_gpio_valid(struct cnxk_gpiochip *gpiochip, int gpio) validates the GPIO number with only an upper bound while gpio can be wrongly configured as negative value from application. Added a check to reject negative values.

Fixes ecc0dd455e9a ("raw/cnxk_gpio: add option to select subset of GPIOs")

Applied to dpdk-next-net-mrvl/for-main. Thanks

Quoted 20 lines
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/cnxk_gpio/cnxk_gpio.c +1 -2
index 0549e326f9..e22fb7cf7b 100644
@@ -795,7 +795,7 @@ cnxk_gpio_process_buf(struct cnxk_gpio *gpio, struct rte_rawdev_buf *rbuf)
 static bool
 cnxk_gpio_valid(struct cnxk_gpiochip *gpiochip, int gpio)
 {
-       return gpio < gpiochip->num_gpios && gpiochip->gpios[gpio];
+       return (gpio >= 0) && (gpio < gpiochip->num_gpios) && gpiochip->gpios[gpio];
 }
 
 static int
--

2.43.0