[PATCH 2/4] powerpc: fix initjmp storing function pointer at wrong offset

Ahmad Fatoum a.fatoum at barebox.org
Mon Mar 2 05:47:34 PST 2026


initjmp was storing the function pointer at offset 88, which is the CR
(condition register) slot in the jmp_buf, instead of offset 84, which is
the LR (link register) slot. When longjmp later restored the buffer, it
would load uninitialized data into LR and jump to it, causing a crash.

This was caught by the setjmp selftest, which triggered a reboot loop on
qemu-ppce500.

Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 arch/powerpc/lib/setjmp.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/lib/setjmp.S b/arch/powerpc/lib/setjmp.S
index 021a57eebc3c..7f4d041ce213 100644
--- a/arch/powerpc/lib/setjmp.S
+++ b/arch/powerpc/lib/setjmp.S
@@ -79,8 +79,8 @@ END(longjmp)
 ENTRY(initjmp)
 	addi	r3,r3,7		# align to 8 byte boundary
 	rlwinm	r3,r3,0,0,28
-	stw	r5,0(r3)	# offset 0
-	stwu	r4,88(r3)	# offset 88
+	stw	r5,0(r3)	# offset 0 - stack pointer
+	stw	r4,84(r3)	# offset 84 - link register
 	li	r3,0
 	blr
 END(initjmp)
-- 
2.47.3




More information about the barebox mailing list