powerpc/crash: Rearrange loop condition to avoid out of bounds array access
PATCH 1/1 powerpc/crash: Rearrange loop condition to avoid out of bounds array access
The array crash_shutdown_handles[] has size CRASH_HANDLER_MAX, thus when we loop over the elements of the list we check crash_shutdown_handles[i] && i < CRASH_HANDLER_MAX. However this means that when we increment i to CRASH_HANDLER_MAX we will perform an out of bound array access checking the first condition before exiting on the second condition.
To avoid the out of bounds access, simply reorder the loop conditions.
Fixes Coverity bug #128232
--- arch/powerpc/kernel/crash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/crash.c +1 -1
@@ -351,7 +351,7 @@ void default_machine_crash_shutdown(struct pt_regs *regs) old_handler = __debugger_fault_handler; __debugger_fault_handler = handle_fault; crash_shutdown_cpu =smp_processor_id (); -for (i =0 ; crash_shutdown_handles[i] && i <CRASH_HANDLER_MAX ; i++) { +for (i =0 ; i <CRASH_HANDLER_MAX && crash_shutdown_handles[i]; i++) {if (setjmp (crash_shutdown_buf) ==0 ) {/* * Insert syncs and delay to ensure
Signature · 1 line
2.5.5
Quoted 11 lines · Suraj Jitindar Singh
The array crash_shutdown_handles[] has size
CRASH_HANDLER_MAX, thus when we loop over the elements of the list we check crash_shutdown_handles[i] && i <CRASH_HANDLER_MAX. However this means that when we increment i toCRASH_HANDLER_MAXwe will perform an out of bound array access checking the first condition before exiting on the second condition.To avoid the out of bounds access, simply reorder the loop conditions.
Fixes Coverity bug #128232
Signed-off-by Suraj Jitindar Singh <[email protected]>
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Quoted 10 lines · Suraj Jitindar Singh
The array crash_shutdown_handles[] has size
CRASH_HANDLER_MAX, thus when we loop over the elements of the list we check crash_shutdown_handles[i] && i <CRASH_HANDLER_MAX. However this means that when we increment i toCRASH_HANDLER_MAXwe will perform an out of bound array access checking the first condition before exiting on the second condition.To avoid the out of bounds access, simply reorder the loop conditions.
Signed-off-by Suraj Jitindar Singh <[email protected]>Reviewed-by Andrew Donnellan <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a7d6392866e9777cb287ad194c
cheers