Skip to content

Commit b3dc6b9

Browse files
riastradhriastradh
authored andcommitted
alpha: Align signal pointer on entry to signal handler.
PR kern/59327: user stack pointer is not aligned properly
1 parent 535ca24 commit b3dc6b9

4 files changed

Lines changed: 24 additions & 29 deletions

File tree

sys/arch/alpha/alpha/compat_16_machdep.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: compat_16_machdep.c,v 1.23 2021/10/27 04:14:59 thorpej Exp $ */
1+
/* $NetBSD: compat_16_machdep.c,v 1.24 2025/04/25 00:59:26 riastradh Exp $ */
22

33
/*-
44
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
8585
#include <machine/cpu.h>
8686
#include <machine/reg.h>
8787

88-
__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.23 2021/10/27 04:14:59 thorpej Exp $");
88+
__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.24 2025/04/25 00:59:26 riastradh Exp $");
8989

9090

9191
#ifdef DEBUG
@@ -112,8 +112,9 @@ sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
112112
sig_t catcher = SIGACTION(p, sig).sa_handler;
113113

114114
tf = l->l_md.md_tf;
115-
fp = getframe(l, sig, &onstack);
116-
fp--;
115+
116+
/* Allocate space for the signal handler context. */
117+
fp = getframe(l, sig, &onstack, sizeof(*fp), _Alignof(*fp));
117118

118119
#ifdef DEBUG
119120
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)

sys/arch/alpha/alpha/machdep.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: machdep.c,v 1.382 2025/03/16 19:27:30 thorpej Exp $ */
1+
/* $NetBSD: machdep.c,v 1.383 2025/04/25 00:59:26 riastradh Exp $ */
22

33
/*-
44
* Copyright (c) 1998, 1999, 2000, 2019, 2020 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
6969

7070
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
7171

72-
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.382 2025/03/16 19:27:30 thorpej Exp $");
72+
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.383 2025/04/25 00:59:26 riastradh Exp $");
7373

7474
#include <sys/param.h>
7575
#include <sys/systm.h>
@@ -1477,21 +1477,24 @@ regdump(struct trapframe *framep)
14771477

14781478

14791479
void *
1480-
getframe(const struct lwp *l, int sig, int *onstack)
1480+
getframe(const struct lwp *l, int sig, int *onstack, size_t size, size_t align)
14811481
{
1482-
void *frame;
1482+
uintptr_t frame;
1483+
1484+
KASSERT((align & (align - 1)) == 0);
14831485

14841486
/* Do we need to jump onto the signal stack? */
14851487
*onstack =
14861488
(l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
14871489
(SIGACTION(l->l_proc, sig).sa_flags & SA_ONSTACK) != 0;
14881490

14891491
if (*onstack)
1490-
frame = (void *)((char *)l->l_sigstk.ss_sp +
1491-
l->l_sigstk.ss_size);
1492+
frame = (uintptr_t)l->l_sigstk.ss_sp + l->l_sigstk.ss_size;
14921493
else
1493-
frame = (void *)(alpha_pal_rdusp());
1494-
return (frame);
1494+
frame = (uintptr_t)alpha_pal_rdusp();
1495+
frame -= size;
1496+
frame &= ~(STACK_ALIGNBYTES | (align - 1));
1497+
return (void *)frame;
14951498
}
14961499

14971500
void
@@ -1520,11 +1523,10 @@ sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
15201523
struct trapframe *tf;
15211524
sig_t catcher = SIGACTION(p, ksi->ksi_signo).sa_handler;
15221525

1523-
fp = (struct sigframe_siginfo *)getframe(l,ksi->ksi_signo,&onstack);
15241526
tf = l->l_md.md_tf;
15251527

15261528
/* Allocate space for the signal handler context. */
1527-
fp--;
1529+
fp = getframe(l, ksi->ksi_signo, &onstack, sizeof(*fp), _Alignof(*fp));
15281530

15291531
#ifdef DEBUG
15301532
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)

sys/arch/alpha/include/frame.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: frame.h,v 1.10 2019/03/25 19:24:30 maxv Exp $ */
1+
/* $NetBSD: frame.h,v 1.11 2025/04/25 00:59:27 riastradh Exp $ */
22

33
/*
44
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -112,12 +112,15 @@ struct sigframe_siginfo {
112112
};
113113

114114
#ifdef _KERNEL
115-
void *getframe(const struct lwp *, int, int *);
115+
116+
#include <sys/stddef.h>
117+
void *getframe(const struct lwp *, int, int *, size_t, size_t);
116118
void buildcontext(struct lwp *, const void *, const void *, const void *);
117119
void sendsig_siginfo(const ksiginfo_t *, const sigset_t *);
118120
#if defined(COMPAT_16)
119121
void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *);
120122
#endif
123+
121124
#endif
122125

123126
#endif /* _ALPHA_FRAME_H_ */

tests/kernel/t_signal_and_sp.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: t_signal_and_sp.c,v 1.15 2025/04/25 00:26:59 riastradh Exp $ */
1+
/* $NetBSD: t_signal_and_sp.c,v 1.16 2025/04/25 00:59:27 riastradh Exp $ */
22

33
/*
44
* Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
2727
*/
2828

2929
#include <sys/cdefs.h>
30-
__RCSID("$NetBSD: t_signal_and_sp.c,v 1.15 2025/04/25 00:26:59 riastradh Exp $");
30+
__RCSID("$NetBSD: t_signal_and_sp.c,v 1.16 2025/04/25 00:59:27 riastradh Exp $");
3131

3232
#include <sys/wait.h>
3333

@@ -426,11 +426,6 @@ ATF_TC_BODY(signalsp_sigaltstack, tc)
426426
fprintf(stderr, "stack @ [%p, %p)\n",
427427
stack, stack + SIGSTKSZ + STACK_ALIGNBYTES);
428428

429-
#if defined __alpha__
430-
atf_tc_expect_fail("PR kern/59327:"
431-
" user stack pointer is not aligned properly");
432-
#endif
433-
434429
/*
435430
* Try with all alignments of high addresses.
436431
*/
@@ -578,12 +573,6 @@ ATF_TC_BODY(misaligned_sp_and_signal, tc)
578573
sa.sa_handler = &signalsphandler;
579574
RL(sigaction(SIGALRM, &sa, NULL));
580575

581-
#if defined __alpha__
582-
atf_tc_expect_fail("PR kern/58149:"
583-
" Cannot return from a signal handler"
584-
" if SP was misaligned when the signal arrived");
585-
#endif
586-
587576
/*
588577
* Set up an interval timer so that we receive SIGALRM after 50 ms.
589578
*/

0 commit comments

Comments
 (0)