git: 8103f9ccbc22 - stable/15 - powerpc64: don't reserve the red zone on the alternate signal stack

From: Piotr Kubaj <pkubaj_at_FreeBSD.org>
Date: Sun, 22 Nov 2026 19:28:58 UTC
The branch stable/15 has been updated by pkubaj:

URL: https://cgit.FreeBSD.org/src/commit/?id=8103f9ccbc227043fc5a3630a0450bacfd2c797b

commit 8103f9ccbc227043fc5a3630a0450bacfd2c797b
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2026-10-18 10:41:37 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2026-11-22 19:28:39 +0000

    powerpc64: don't reserve the red zone on the alternate signal stack
    
    A 64-bit signal frame is 1552 bytes; rounded up and with the 512 byte
    red zone added it needs 2096 bytes, more than MINSIGSTKSZ (2048), so a
    handler on a minimum size alternate stack had its frame start 48 bytes
    below the stack. The red zone only exists below the interrupted code's
    stack pointer, so skip it only when the frame goes on that stack.
    
    A handler on a MINSIGSTKSZ alternate stack overwrote the 48 bytes below
    it; the frame stays within the stack now.
    
    Reviewed by:    jhibbits
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D61519
    
    (cherry picked from commit 34005cb7d5caeee3f3073cbc2adc3b2841ef54d7)
---
 sys/powerpc/powerpc/exec_machdep.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c
index 8b02d5cf19be..23b7acb483d6 100644
--- a/sys/powerpc/powerpc/exec_machdep.c
+++ b/sys/powerpc/powerpc/exec_machdep.c
@@ -213,11 +213,7 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 		sfp = (caddr_t)&sf;
 		sfpsize = sizeof(sf);
 		#ifdef __powerpc64__
-		/*
-		 * 64-bit PPC defines a 512 byte red zone below
-		 * the existing stack (ELF ABI v2 §2.2.2.4)
-		 */
-		rndfsize = 512 + roundup(sizeof(sf), 48);
+		rndfsize = roundup(sizeof(sf), 48);
 		#else
 		rndfsize = roundup(sizeof(sf), 16);
 		#endif
@@ -252,6 +248,14 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 		usfp = (void *)(((uintptr_t)td->td_sigstk.ss_sp +
 		   td->td_sigstk.ss_size - rndfsize) & ~0xFul);
 	} else {
+		#ifdef __powerpc64__
+		/*
+		 * 64-bit PPC defines a 512 byte red zone below
+		 * the existing stack (ELF ABI v2 §2.2.2.4)
+		 */
+		if (!SV_PROC_FLAG(p, SV_ILP32))
+			sp -= 512;
+		#endif
 		usfp = (void *)((sp - rndfsize) & ~0xFul);
 	}