Skip to content

Commit 4bb0bd8

Browse files
Al Virogeertu
authored andcommitted
m68k: Handle arrivals of multiple signals correctly
When we have several pending signals, have entered with the kernel with large exception frame *and* have already built at least one sigframe, regs->stkadj is going to be non-zero and regs->format/sr/pc are going to be junk - the real values are in shifted exception stack frame we'd built when putting together the first sigframe. If that happens, subsequent sigframes are going to be garbage. Not hard to fix - just need to find the "adjusted" frame first and look for format/vector/sr/pc in it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Tested-by: Michael Schmitz <schmitzmic@gmail.com> Reviewed-by: Michael Schmitz <schmitzmic@gmail.com> Tested-by: Finn Thain <fthain@linux-m68k.org> Link: https://lore.kernel.org/r/YP2dBIAPTaVvHiZ6@zeniv-ca.linux.org.uk Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
1 parent a7b68ed commit 4bb0bd8

1 file changed

Lines changed: 42 additions & 46 deletions

File tree

‎arch/m68k/kernel/signal.c‎

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static inline void save_fpu_state(struct sigcontext *sc, struct pt_regs *regs)
447447

448448
if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) {
449449
fpu_version = sc->sc_fpstate[0];
450-
if (CPU_IS_020_OR_030 &&
450+
if (CPU_IS_020_OR_030 && !regs->stkadj &&
451451
regs->vector >= (VEC_FPBRUC * 4) &&
452452
regs->vector <= (VEC_FPNAN * 4)) {
453453
/* Clear pending exception in 68882 idle frame */
@@ -510,7 +510,7 @@ static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs *
510510
if (!(CPU_IS_060 || CPU_IS_COLDFIRE))
511511
context_size = fpstate[1];
512512
fpu_version = fpstate[0];
513-
if (CPU_IS_020_OR_030 &&
513+
if (CPU_IS_020_OR_030 && !regs->stkadj &&
514514
regs->vector >= (VEC_FPBRUC * 4) &&
515515
regs->vector <= (VEC_FPNAN * 4)) {
516516
/* Clear pending exception in 68882 idle frame */
@@ -832,25 +832,32 @@ asmlinkage int do_rt_sigreturn(struct pt_regs *regs, struct switch_stack *sw)
832832
return 0;
833833
}
834834

835+
static inline struct pt_regs *rte_regs(struct pt_regs *regs)
836+
{
837+
return (void *)regs + regs->stkadj;
838+
}
839+
835840
static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs,
836841
unsigned long mask)
837842
{
843+
struct pt_regs *tregs = rte_regs(regs);
838844
sc->sc_mask = mask;
839845
sc->sc_usp = rdusp();
840846
sc->sc_d0 = regs->d0;
841847
sc->sc_d1 = regs->d1;
842848
sc->sc_a0 = regs->a0;
843849
sc->sc_a1 = regs->a1;
844-
sc->sc_sr = regs->sr;
845-
sc->sc_pc = regs->pc;
846-
sc->sc_formatvec = regs->format << 12 | regs->vector;
850+
sc->sc_sr = tregs->sr;
851+
sc->sc_pc = tregs->pc;
852+
sc->sc_formatvec = tregs->format << 12 | tregs->vector;
847853
save_a5_state(sc, regs);
848854
save_fpu_state(sc, regs);
849855
}
850856

851857
static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *regs)
852858
{
853859
struct switch_stack *sw = (struct switch_stack *)regs - 1;
860+
struct pt_regs *tregs = rte_regs(regs);
854861
greg_t __user *gregs = uc->uc_mcontext.gregs;
855862
int err = 0;
856863

@@ -871,9 +878,9 @@ static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *
871878
err |= __put_user(sw->a5, &gregs[13]);
872879
err |= __put_user(sw->a6, &gregs[14]);
873880
err |= __put_user(rdusp(), &gregs[15]);
874-
err |= __put_user(regs->pc, &gregs[16]);
875-
err |= __put_user(regs->sr, &gregs[17]);
876-
err |= __put_user((regs->format << 12) | regs->vector, &uc->uc_formatvec);
881+
err |= __put_user(tregs->pc, &gregs[16]);
882+
err |= __put_user(tregs->sr, &gregs[17]);
883+
err |= __put_user((tregs->format << 12) | tregs->vector, &uc->uc_formatvec);
877884
err |= rt_save_fpu_state(uc, regs);
878885
return err;
879886
}
@@ -890,13 +897,14 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set,
890897
struct pt_regs *regs)
891898
{
892899
struct sigframe __user *frame;
893-
int fsize = frame_extra_sizes(regs->format);
900+
struct pt_regs *tregs = rte_regs(regs);
901+
int fsize = frame_extra_sizes(tregs->format);
894902
struct sigcontext context;
895903
int err = 0, sig = ksig->sig;
896904

897905
if (fsize < 0) {
898906
pr_debug("setup_frame: Unknown frame format %#x\n",
899-
regs->format);
907+
tregs->format);
900908
return -EFAULT;
901909
}
902910

@@ -907,7 +915,7 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set,
907915

908916
err |= __put_user(sig, &frame->sig);
909917

910-
err |= __put_user(regs->vector, &frame->code);
918+
err |= __put_user(tregs->vector, &frame->code);
911919
err |= __put_user(&frame->sc, &frame->psc);
912920

913921
if (_NSIG_WORDS > 1)
@@ -933,42 +941,37 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set,
933941

934942
push_cache ((unsigned long) &frame->retcode);
935943

936-
/*
937-
* Set up registers for signal handler. All the state we are about
938-
* to destroy is successfully copied to sigframe.
939-
*/
940-
wrusp ((unsigned long) frame);
941-
regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
942-
adjustformat(regs);
943-
944944
/*
945945
* This is subtle; if we build more than one sigframe, all but the
946946
* first one will see frame format 0 and have fsize == 0, so we won't
947947
* screw stkadj.
948948
*/
949-
if (fsize)
949+
if (fsize) {
950950
regs->stkadj = fsize;
951-
952-
/* Prepare to skip over the extra stuff in the exception frame. */
953-
if (regs->stkadj) {
954-
struct pt_regs *tregs =
955-
(struct pt_regs *)((ulong)regs + regs->stkadj);
951+
tregs = rte_regs(regs);
956952
pr_debug("Performing stackadjust=%04lx\n", regs->stkadj);
957-
/* This must be copied with decreasing addresses to
958-
handle overlaps. */
959953
tregs->vector = 0;
960954
tregs->format = 0;
961-
tregs->pc = regs->pc;
962955
tregs->sr = regs->sr;
963956
}
957+
958+
/*
959+
* Set up registers for signal handler. All the state we are about
960+
* to destroy is successfully copied to sigframe.
961+
*/
962+
wrusp ((unsigned long) frame);
963+
tregs->pc = (unsigned long) ksig->ka.sa.sa_handler;
964+
adjustformat(regs);
965+
964966
return 0;
965967
}
966968

967969
static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
968970
struct pt_regs *regs)
969971
{
970972
struct rt_sigframe __user *frame;
971-
int fsize = frame_extra_sizes(regs->format);
973+
struct pt_regs *tregs = rte_regs(regs);
974+
int fsize = frame_extra_sizes(tregs->format);
972975
int err = 0, sig = ksig->sig;
973976

974977
if (fsize < 0) {
@@ -1018,34 +1021,27 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
10181021

10191022
push_cache ((unsigned long) &frame->retcode);
10201023

1021-
/*
1022-
* Set up registers for signal handler. All the state we are about
1023-
* to destroy is successfully copied to sigframe.
1024-
*/
1025-
wrusp ((unsigned long) frame);
1026-
regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
1027-
adjustformat(regs);
1028-
10291024
/*
10301025
* This is subtle; if we build more than one sigframe, all but the
10311026
* first one will see frame format 0 and have fsize == 0, so we won't
10321027
* screw stkadj.
10331028
*/
1034-
if (fsize)
1029+
if (fsize) {
10351030
regs->stkadj = fsize;
1036-
1037-
/* Prepare to skip over the extra stuff in the exception frame. */
1038-
if (regs->stkadj) {
1039-
struct pt_regs *tregs =
1040-
(struct pt_regs *)((ulong)regs + regs->stkadj);
1031+
tregs = rte_regs(regs);
10411032
pr_debug("Performing stackadjust=%04lx\n", regs->stkadj);
1042-
/* This must be copied with decreasing addresses to
1043-
handle overlaps. */
10441033
tregs->vector = 0;
10451034
tregs->format = 0;
1046-
tregs->pc = regs->pc;
10471035
tregs->sr = regs->sr;
10481036
}
1037+
1038+
/*
1039+
* Set up registers for signal handler. All the state we are about
1040+
* to destroy is successfully copied to sigframe.
1041+
*/
1042+
wrusp ((unsigned long) frame);
1043+
tregs->pc = (unsigned long) ksig->ka.sa.sa_handler;
1044+
adjustformat(regs);
10491045
return 0;
10501046
}
10511047

0 commit comments

Comments
 (0)