Skip to content

Commit 63970f3

Browse files
chleroympe
authored andcommitted
powerpc/legacy_serial: Fix UBSAN: array-index-out-of-bounds
UBSAN complains when a pointer is calculated with invalid 'legacy_serial_console' index, allthough the index is verified before dereferencing the pointer. Fix it by checking 'legacy_serial_console' validity before calculating pointers. Fixes: 0bd3f9e ("powerpc/legacy_serial: Use early_ioremap()") Reported-by: Paul Menzel <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bc581db commit 63970f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/powerpc/kernel/legacy_serial.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,16 @@ static void __init setup_legacy_serial_console(int console)
356356

357357
static int __init ioremap_legacy_serial_console(void)
358358
{
359-
struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
360-
struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
359+
struct plat_serial8250_port *port;
360+
struct legacy_serial_info *info;
361361
void __iomem *vaddr;
362362

363363
if (legacy_serial_console < 0)
364364
return 0;
365365

366+
info = &legacy_serial_infos[legacy_serial_console];
367+
port = &legacy_serial_ports[legacy_serial_console];
368+
366369
if (!info->early_addr)
367370
return 0;
368371

0 commit comments

Comments
 (0)