[PATCH] powerpc/legacy_serial: Fix UBSAN: array-index-out-of-bounds

Segher Boessenkool segher at kernel.crashing.org
Tue May 11 07:14:44 AEST 2021


On Sat, May 08, 2021 at 06:36:21AM +0000, Christophe Leroy wrote:
> UBSAN complains when a pointer is calculated with invalid
> 'legacy_serial_console' index, allthough the index is verified
> before dereferencing the pointer.

Addressing like this is UB already.

You could just move this:

> -	if (legacy_serial_console < 0)
> -		return 0;

to before

> -	struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
> -	struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];

and no other change is necessary.


Segher


More information about the Linuxppc-dev mailing list