raw/cnxk_gpio: fix out of bound access for negative gpio
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")
Signed-off-by Akhil Goyal <[email protected]>
--- drivers/raw/cnxk_gpio/cnxk_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/raw/cnxk_gpio/cnxk_gpio.c +1 -1
@@ -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
Jerin Jacob
AppliedQuoted 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")Signed-off-by Akhil Goyal <[email protected]>
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@@ -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