Re: [PATCH] regulator: max77802: Bounds check regulator id against opmode

From: Javier Martinez Canillas
Date: Sat Jan 28 2023 - 02:22:42 EST


Hello Kees,

On Fri, Jan 27, 2023 at 11:52 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> Explicitly bounds-check the id before accessing the opmode array. Seen
> with GCC 13:
>
> ../drivers/regulator/max77802-regulator.c: In function 'max77802_enable':
> ../drivers/regulator/max77802-regulator.c:217:29: warning: array subscript [0, 41] is outside array bounds of 'unsigned int[42]' [-Warray-bounds=]
> 217 | if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
> | ~~~~~~~~~~~~~~~~^~~~
> ../drivers/regulator/max77802-regulator.c:62:22: note: while referencing 'opmode'
> 62 | unsigned int opmode[MAX77802_REG_MAX];
> | ^~~~~~
>
> Cc: Javier Martinez Canillas <javier@xxxxxxxxxxxx>
> Cc: Liam Girdwood <lgirdwood@xxxxxxxxx>
> Cc: Mark Brown <broonie@xxxxxxxxxx>
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
> ---
> drivers/regulator/max77802-regulator.c | 34 ++++++++++++++++++--------

The patch looks good to me.

Acked-by: Javier Martinez Canillas <javierm@xxxxxxxxxx>

Best regards,
Javier