Skip to contentSkip to conversation

powerpc/crash: Rearrange loop condition to avoid out of bounds array access

PATCH Applied Suraj Jitindar Singh 3 participants 3 messages Jul 11, 2016 – Jul 15, 2016 PowerPC

lore
Share & tools
lore
#0 lore raw

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
index 888bdf1..47b63de 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 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

Fixes 1d1451655bad ("powerpc: Add array bounds checking to crash_shutdown_handlers")
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]  IBM Australia Limited
reviewer Applied
#2 lore raw
In reply to Suraj Jitindar Singh
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 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.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/a7d6392866e9777cb287ad194c

cheers