pinctrl: stm32: fix array read out of bound
Subsystems (4)
Antonio Borneo
maintainerPATCH 1/1 pinctrl: stm32: fix array read out of bound
The existing code does not verify if the "tentative" index exceeds the size of the array, causing out of bound read.
Issue identified with kasan.
Check the index before using it.
Signed-off-by Antonio Borneo <[email protected]>
Fixes 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +5 -3
@@ -1283,9 +1283,11 @@ static struct stm32_desc_pin *stm32_pctrl_get_desc_pin_from_gpio(struct stm32_piint i;/* With few exceptions (e.g. bank 'Z'), pin number matches with pin index in array */ - pin_desc = pctl->pins + stm32_pin_nb; -if (pin_desc->pin.number == stm32_pin_nb) -return pin_desc; +if (stm32_pin_nb < pctl->npins) { + pin_desc = pctl->pins + stm32_pin_nb; +if (pin_desc->pin.number == stm32_pin_nb) +return pin_desc; + }/* Otherwise, loop all array to find the pin with the right number */ for (i =0 ; i < pctl->npins; i++) {
base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa
Signature · 1 line
2.42.0
Quoted 8 lines · Antonio Borneo
The existing code does not verify if the "tentative" index exceeds the size of the array, causing out of bound read.
Issue identified with kasan.Check the index before using it.
Signed-off-by Antonio Borneo <[email protected]>Fixes 32c170ff15b0 ("pinctrl: stm32: set default gpio line names using pin names")
Patch applied for fixes.
And now I feel better about that I spent so much time porting Kasan to ARM32.
Yours,
Linus Walleij