gpio: aggregator: Fix off by one in gpiochip_fwd_desc_add()
Subsystems (3)
PATCH 1/1 gpio: aggregator: Fix off by one in gpiochip_fwd_desc_add()
The "> chip->ngpio" comparison here needs to be ">= chip->ngpio", otherwise it leads to an out of bounds access. The fwd->valid_mask bitmap only has chip->ngpio bits and the fwd->descs[] array has that same number of elements. These values are set in devm_gpiochip_fwd_alloc().
--- drivers/gpio/gpio-aggregator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-aggregator.c +1 -1
@@ -744,7 +744,7 @@ int gpiochip_fwd_desc_add(struct gpiochip_fwd *fwd, struct gpio_desc *desc, {struct gpio_chip *chip = &fwd->chip; -if (offset > chip->ngpio) +if (offset >= chip->ngpio)return -EINVAL ;if (test_and_set_bit (offset, fwd->valid_mask))
Signature · 1 line
2.47.2
Quoted 8 lines · Dan Carpenter
The ">
chip->ngpio" comparison here needs to be ">=chip->ngpio", otherwise it leads to an out of bounds access. Thefwd->valid_maskbitmap only haschip->ngpiobits and the fwd->descs[] array has that same number of elements. These values are set indevm_gpiochip_fwd_alloc().Fixes c44ce91b8ada ("gpio: aggregator: refactor the code to add GPIO desc in the forwarder")Signed-off-by Dan Carpenter <[email protected]>
drivers/gpio/gpio-aggregator.c int gpiochip_fwd_desc_add(struct gpiochip_fwd *fwd, struct gpio_desc *desc, · line 750
Quoted 11 lines
drivers/gpio/gpio-aggregator.c +1
-1@@ -744,7 +744,7 @@ int gpiochip_fwd_desc_add(struct gpiochip_fwd *fwd, struct gpio_desc *desc, {struct gpio_chip *chip = &fwd->chip; -if (offset > chip->ngpio) +if (offset >= chip->ngpio)return -EINVAL ;if (test_and_set_bit (offset, fwd->valid_mask))
Looks like my similar comment in
https://lore.kernel.org/all/CAMuHMdVLo2w609eFOKRkYAfEMb8XOTNB-XzzZn_89VM-YV_-kA@mail.gmail.com/
was lost in the noise. I'll try to remember to make ">=" stand out more among all quoted code.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 8 lines · Dan Carpenter
The ">
chip->ngpio" comparison here needs to be ">=chip->ngpio", otherwise it leads to an out of bounds access. Thefwd->valid_maskbitmap only haschip->ngpiobits and the fwd->descs[] array has that same number of elements. These values are set indevm_gpiochip_fwd_alloc().[...]
Applied, thanks!
[1/1] gpio: aggregator: Fix off by one in gpiochip_fwd_desc_add()
https://git.kernel.org/brgl/linux/c/148547000cfc1ba8cec02857268333d08724b9cc
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Quoted 10 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Quoted 7 lines · Dan Carpenter
The ">
chip->ngpio" comparison here needs to be ">=chip->ngpio", otherwise it leads to an out of bounds access. Thefwd->valid_maskbitmap only haschip->ngpiobits and the fwd->descs[] array has that same number of elements. These values are set indevm_gpiochip_fwd_alloc().
Quoted 6 lines
Quoted 1 line
[...]
Applied, thanks!
[1/1] gpio: aggregator: Fix off by one in
gpiochip_fwd_desc_add()https://git.kernel.org/brgl/linux/c/148547000cfc1ba8cec02857268333d08724b9cc
Do I need this for the aggregator immutable branch I merged yesterday?
I have only merged that branch to my new development series, if you need me to pull in a new version just send a new pull request and I will use that instead.
Yours,
Linus Walleij
Quoted 20 lines · Linus Walleij
Quoted 10 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Quoted 7 lines · Dan Carpenter
The ">
chip->ngpio" comparison here needs to be ">=chip->ngpio", otherwise it leads to an out of bounds access. Thefwd->valid_maskbitmap only haschip->ngpiobits and the fwd->descs[] array has that same number of elements. These values are set indevm_gpiochip_fwd_alloc().Quoted 6 lines
Quoted 1 line
[...]
Applied, thanks!
[1/1] gpio: aggregator: Fix off by one in
gpiochip_fwd_desc_add()https://git.kernel.org/brgl/linux/c/148547000cfc1ba8cec02857268333d08724b9cc
Quoted 8 lines
Do I need this for the aggregator immutable branch I merged yesterday?
I have only merged that branch to my new development series, if you need me to pull in a new version just send a new pull request and I will use that instead.
Yours,
Linus Walleij
No, it's not a build-time dependency and it will end up in next anyway from my tree.
Bart