124e6dc35SBrian Gerst // SPDX-License-Identifier: GPL-2.0
224e6dc35SBrian Gerst /*
324e6dc35SBrian Gerst * Copyright (C) 1991, 1992 Linus Torvalds
424e6dc35SBrian Gerst *
524e6dc35SBrian Gerst * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
624e6dc35SBrian Gerst * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
724e6dc35SBrian Gerst * 2000-12-* x86-64 compatibility mode signal handling by Andi Kleen
824e6dc35SBrian Gerst */
924e6dc35SBrian Gerst
1024e6dc35SBrian Gerst #include <linux/sched.h>
1124e6dc35SBrian Gerst #include <linux/sched/task_stack.h>
1224e6dc35SBrian Gerst #include <linux/mm.h>
1324e6dc35SBrian Gerst #include <linux/smp.h>
1424e6dc35SBrian Gerst #include <linux/kernel.h>
1524e6dc35SBrian Gerst #include <linux/errno.h>
1624e6dc35SBrian Gerst #include <linux/wait.h>
1724e6dc35SBrian Gerst #include <linux/unistd.h>
1824e6dc35SBrian Gerst #include <linux/stddef.h>
1924e6dc35SBrian Gerst #include <linux/personality.h>
2024e6dc35SBrian Gerst #include <linux/compat.h>
2124e6dc35SBrian Gerst #include <linux/binfmts.h>
2224e6dc35SBrian Gerst #include <linux/syscalls.h>
2324e6dc35SBrian Gerst #include <asm/ucontext.h>
2424e6dc35SBrian Gerst #include <linux/uaccess.h>
2524e6dc35SBrian Gerst #include <asm/fpu/signal.h>
2624e6dc35SBrian Gerst #include <asm/ptrace.h>
2724e6dc35SBrian Gerst #include <asm/user32.h>
2824e6dc35SBrian Gerst #include <uapi/asm/sigcontext.h>
2924e6dc35SBrian Gerst #include <asm/proto.h>
3024e6dc35SBrian Gerst #include <asm/vdso.h>
3124e6dc35SBrian Gerst #include <asm/sigframe.h>
3224e6dc35SBrian Gerst #include <asm/sighandling.h>
3324e6dc35SBrian Gerst #include <asm/smap.h>
34ae53fa18SH. Peter Anvin (Intel) #include <asm/gsseg.h>
3524e6dc35SBrian Gerst
3624e6dc35SBrian Gerst #ifdef CONFIG_IA32_EMULATION
3724e6dc35SBrian Gerst #include <asm/ia32_unistd.h>
3824e6dc35SBrian Gerst
reload_segments(struct sigcontext_32 * sc)3924e6dc35SBrian Gerst static inline void reload_segments(struct sigcontext_32 *sc)
4024e6dc35SBrian Gerst {
4124e6dc35SBrian Gerst unsigned int cur;
4224e6dc35SBrian Gerst
4324e6dc35SBrian Gerst savesegment(gs, cur);
4424e6dc35SBrian Gerst if ((sc->gs | 0x03) != cur)
4524e6dc35SBrian Gerst load_gs_index(sc->gs | 0x03);
4624e6dc35SBrian Gerst savesegment(fs, cur);
4724e6dc35SBrian Gerst if ((sc->fs | 0x03) != cur)
4824e6dc35SBrian Gerst loadsegment(fs, sc->fs | 0x03);
4924e6dc35SBrian Gerst savesegment(ds, cur);
5024e6dc35SBrian Gerst if ((sc->ds | 0x03) != cur)
5124e6dc35SBrian Gerst loadsegment(ds, sc->ds | 0x03);
5224e6dc35SBrian Gerst savesegment(es, cur);
5324e6dc35SBrian Gerst if ((sc->es | 0x03) != cur)
5424e6dc35SBrian Gerst loadsegment(es, sc->es | 0x03);
5524e6dc35SBrian Gerst }
5624e6dc35SBrian Gerst
5724e6dc35SBrian Gerst #define sigset32_t compat_sigset_t
58f6e2a56cSBrian Gerst #define siginfo32_t compat_siginfo_t
5924e6dc35SBrian Gerst #define restore_altstack32 compat_restore_altstack
6024e6dc35SBrian Gerst #define unsafe_save_altstack32 unsafe_compat_save_altstack
6124e6dc35SBrian Gerst
6224e6dc35SBrian Gerst #else
6324e6dc35SBrian Gerst
6424e6dc35SBrian Gerst #define sigset32_t sigset_t
65f6e2a56cSBrian Gerst #define siginfo32_t siginfo_t
6624e6dc35SBrian Gerst #define __NR_ia32_sigreturn __NR_sigreturn
6724e6dc35SBrian Gerst #define __NR_ia32_rt_sigreturn __NR_rt_sigreturn
6824e6dc35SBrian Gerst #define restore_altstack32 restore_altstack
6924e6dc35SBrian Gerst #define unsafe_save_altstack32 unsafe_save_altstack
7024e6dc35SBrian Gerst #define __copy_siginfo_to_user32 copy_siginfo_to_user
7124e6dc35SBrian Gerst
7224e6dc35SBrian Gerst #endif
7324e6dc35SBrian Gerst
7424e6dc35SBrian Gerst /*
7524e6dc35SBrian Gerst * Do a signal return; undo the signal stack.
7624e6dc35SBrian Gerst */
ia32_restore_sigcontext(struct pt_regs * regs,struct sigcontext_32 __user * usc)7724e6dc35SBrian Gerst static bool ia32_restore_sigcontext(struct pt_regs *regs,
7824e6dc35SBrian Gerst struct sigcontext_32 __user *usc)
7924e6dc35SBrian Gerst {
8024e6dc35SBrian Gerst struct sigcontext_32 sc;
8124e6dc35SBrian Gerst
8224e6dc35SBrian Gerst /* Always make any pending restarted system calls return -EINTR */
8324e6dc35SBrian Gerst current->restart_block.fn = do_no_restart_syscall;
8424e6dc35SBrian Gerst
8524e6dc35SBrian Gerst if (unlikely(copy_from_user(&sc, usc, sizeof(sc))))
8624e6dc35SBrian Gerst return false;
8724e6dc35SBrian Gerst
8824e6dc35SBrian Gerst /* Get only the ia32 registers. */
8924e6dc35SBrian Gerst regs->bx = sc.bx;
9024e6dc35SBrian Gerst regs->cx = sc.cx;
9124e6dc35SBrian Gerst regs->dx = sc.dx;
9224e6dc35SBrian Gerst regs->si = sc.si;
9324e6dc35SBrian Gerst regs->di = sc.di;
9424e6dc35SBrian Gerst regs->bp = sc.bp;
9524e6dc35SBrian Gerst regs->ax = sc.ax;
9624e6dc35SBrian Gerst regs->sp = sc.sp;
9724e6dc35SBrian Gerst regs->ip = sc.ip;
9824e6dc35SBrian Gerst
9924e6dc35SBrian Gerst /* Get CS/SS and force CPL3 */
10024e6dc35SBrian Gerst regs->cs = sc.cs | 0x03;
10124e6dc35SBrian Gerst regs->ss = sc.ss | 0x03;
10224e6dc35SBrian Gerst
10324e6dc35SBrian Gerst regs->flags = (regs->flags & ~FIX_EFLAGS) | (sc.flags & FIX_EFLAGS);
10424e6dc35SBrian Gerst /* disable syscall checks */
10524e6dc35SBrian Gerst regs->orig_ax = -1;
10624e6dc35SBrian Gerst
10724e6dc35SBrian Gerst #ifdef CONFIG_IA32_EMULATION
10824e6dc35SBrian Gerst /*
10924e6dc35SBrian Gerst * Reload fs and gs if they have changed in the signal
11024e6dc35SBrian Gerst * handler. This does not handle long fs/gs base changes in
11124e6dc35SBrian Gerst * the handler, but does not clobber them at least in the
11224e6dc35SBrian Gerst * normal case.
11324e6dc35SBrian Gerst */
11424e6dc35SBrian Gerst reload_segments(&sc);
11524e6dc35SBrian Gerst #else
11624e6dc35SBrian Gerst loadsegment(gs, sc.gs);
11724e6dc35SBrian Gerst regs->fs = sc.fs;
11824e6dc35SBrian Gerst regs->es = sc.es;
11924e6dc35SBrian Gerst regs->ds = sc.ds;
12024e6dc35SBrian Gerst #endif
12124e6dc35SBrian Gerst
12224e6dc35SBrian Gerst return fpu__restore_sig(compat_ptr(sc.fpstate), 1);
12324e6dc35SBrian Gerst }
12424e6dc35SBrian Gerst
SYSCALL32_DEFINE0(sigreturn)12524e6dc35SBrian Gerst SYSCALL32_DEFINE0(sigreturn)
12624e6dc35SBrian Gerst {
12724e6dc35SBrian Gerst struct pt_regs *regs = current_pt_regs();
12824e6dc35SBrian Gerst struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8);
12924e6dc35SBrian Gerst sigset_t set;
13024e6dc35SBrian Gerst
13124e6dc35SBrian Gerst if (!access_ok(frame, sizeof(*frame)))
13224e6dc35SBrian Gerst goto badframe;
13324e6dc35SBrian Gerst if (__get_user(set.sig[0], &frame->sc.oldmask)
13424e6dc35SBrian Gerst || __get_user(((__u32 *)&set)[1], &frame->extramask[0]))
13524e6dc35SBrian Gerst goto badframe;
13624e6dc35SBrian Gerst
13724e6dc35SBrian Gerst set_current_blocked(&set);
13824e6dc35SBrian Gerst
13924e6dc35SBrian Gerst if (!ia32_restore_sigcontext(regs, &frame->sc))
14024e6dc35SBrian Gerst goto badframe;
14124e6dc35SBrian Gerst return regs->ax;
14224e6dc35SBrian Gerst
14324e6dc35SBrian Gerst badframe:
14424e6dc35SBrian Gerst signal_fault(regs, frame, "32bit sigreturn");
14524e6dc35SBrian Gerst return 0;
14624e6dc35SBrian Gerst }
14724e6dc35SBrian Gerst
SYSCALL32_DEFINE0(rt_sigreturn)14824e6dc35SBrian Gerst SYSCALL32_DEFINE0(rt_sigreturn)
14924e6dc35SBrian Gerst {
15024e6dc35SBrian Gerst struct pt_regs *regs = current_pt_regs();
15124e6dc35SBrian Gerst struct rt_sigframe_ia32 __user *frame;
15224e6dc35SBrian Gerst sigset_t set;
15324e6dc35SBrian Gerst
15424e6dc35SBrian Gerst frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4);
15524e6dc35SBrian Gerst
15624e6dc35SBrian Gerst if (!access_ok(frame, sizeof(*frame)))
15724e6dc35SBrian Gerst goto badframe;
15824e6dc35SBrian Gerst if (__get_user(*(__u64 *)&set, (__u64 __user *)&frame->uc.uc_sigmask))
15924e6dc35SBrian Gerst goto badframe;
16024e6dc35SBrian Gerst
16124e6dc35SBrian Gerst set_current_blocked(&set);
16224e6dc35SBrian Gerst
16324e6dc35SBrian Gerst if (!ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext))
16424e6dc35SBrian Gerst goto badframe;
16524e6dc35SBrian Gerst
16624e6dc35SBrian Gerst if (restore_altstack32(&frame->uc.uc_stack))
16724e6dc35SBrian Gerst goto badframe;
16824e6dc35SBrian Gerst
16924e6dc35SBrian Gerst return regs->ax;
17024e6dc35SBrian Gerst
17124e6dc35SBrian Gerst badframe:
17224e6dc35SBrian Gerst signal_fault(regs, frame, "32bit rt sigreturn");
17324e6dc35SBrian Gerst return 0;
17424e6dc35SBrian Gerst }
17524e6dc35SBrian Gerst
17624e6dc35SBrian Gerst /*
17724e6dc35SBrian Gerst * Set up a signal frame.
17824e6dc35SBrian Gerst */
17924e6dc35SBrian Gerst
18024e6dc35SBrian Gerst #define get_user_seg(seg) ({ unsigned int v; savesegment(seg, v); v; })
18124e6dc35SBrian Gerst
18224e6dc35SBrian Gerst static __always_inline int
__unsafe_setup_sigcontext32(struct sigcontext_32 __user * sc,void __user * fpstate,struct pt_regs * regs,unsigned int mask)18324e6dc35SBrian Gerst __unsafe_setup_sigcontext32(struct sigcontext_32 __user *sc,
18424e6dc35SBrian Gerst void __user *fpstate,
18524e6dc35SBrian Gerst struct pt_regs *regs, unsigned int mask)
18624e6dc35SBrian Gerst {
18724e6dc35SBrian Gerst unsafe_put_user(get_user_seg(gs), (unsigned int __user *)&sc->gs, Efault);
18824e6dc35SBrian Gerst #ifdef CONFIG_IA32_EMULATION
18924e6dc35SBrian Gerst unsafe_put_user(get_user_seg(fs), (unsigned int __user *)&sc->fs, Efault);
19024e6dc35SBrian Gerst unsafe_put_user(get_user_seg(ds), (unsigned int __user *)&sc->ds, Efault);
19124e6dc35SBrian Gerst unsafe_put_user(get_user_seg(es), (unsigned int __user *)&sc->es, Efault);
19224e6dc35SBrian Gerst #else
19324e6dc35SBrian Gerst unsafe_put_user(regs->fs, (unsigned int __user *)&sc->fs, Efault);
19424e6dc35SBrian Gerst unsafe_put_user(regs->es, (unsigned int __user *)&sc->es, Efault);
19524e6dc35SBrian Gerst unsafe_put_user(regs->ds, (unsigned int __user *)&sc->ds, Efault);
19624e6dc35SBrian Gerst #endif
19724e6dc35SBrian Gerst
19824e6dc35SBrian Gerst unsafe_put_user(regs->di, &sc->di, Efault);
19924e6dc35SBrian Gerst unsafe_put_user(regs->si, &sc->si, Efault);
20024e6dc35SBrian Gerst unsafe_put_user(regs->bp, &sc->bp, Efault);
20124e6dc35SBrian Gerst unsafe_put_user(regs->sp, &sc->sp, Efault);
20224e6dc35SBrian Gerst unsafe_put_user(regs->bx, &sc->bx, Efault);
20324e6dc35SBrian Gerst unsafe_put_user(regs->dx, &sc->dx, Efault);
20424e6dc35SBrian Gerst unsafe_put_user(regs->cx, &sc->cx, Efault);
20524e6dc35SBrian Gerst unsafe_put_user(regs->ax, &sc->ax, Efault);
20624e6dc35SBrian Gerst unsafe_put_user(current->thread.trap_nr, &sc->trapno, Efault);
20724e6dc35SBrian Gerst unsafe_put_user(current->thread.error_code, &sc->err, Efault);
20824e6dc35SBrian Gerst unsafe_put_user(regs->ip, &sc->ip, Efault);
20924e6dc35SBrian Gerst unsafe_put_user(regs->cs, (unsigned int __user *)&sc->cs, Efault);
21024e6dc35SBrian Gerst unsafe_put_user(regs->flags, &sc->flags, Efault);
21124e6dc35SBrian Gerst unsafe_put_user(regs->sp, &sc->sp_at_signal, Efault);
21224e6dc35SBrian Gerst unsafe_put_user(regs->ss, (unsigned int __user *)&sc->ss, Efault);
21324e6dc35SBrian Gerst
21424e6dc35SBrian Gerst unsafe_put_user(ptr_to_compat(fpstate), &sc->fpstate, Efault);
21524e6dc35SBrian Gerst
21624e6dc35SBrian Gerst /* non-iBCS2 extensions.. */
21724e6dc35SBrian Gerst unsafe_put_user(mask, &sc->oldmask, Efault);
21824e6dc35SBrian Gerst unsafe_put_user(current->thread.cr2, &sc->cr2, Efault);
21924e6dc35SBrian Gerst return 0;
22024e6dc35SBrian Gerst
22124e6dc35SBrian Gerst Efault:
22224e6dc35SBrian Gerst return -EFAULT;
22324e6dc35SBrian Gerst }
22424e6dc35SBrian Gerst
22524e6dc35SBrian Gerst #define unsafe_put_sigcontext32(sc, fp, regs, set, label) \
22624e6dc35SBrian Gerst do { \
22724e6dc35SBrian Gerst if (__unsafe_setup_sigcontext32(sc, fp, regs, set->sig[0])) \
22824e6dc35SBrian Gerst goto label; \
22924e6dc35SBrian Gerst } while(0)
23024e6dc35SBrian Gerst
ia32_setup_frame(struct ksignal * ksig,struct pt_regs * regs)23124e6dc35SBrian Gerst int ia32_setup_frame(struct ksignal *ksig, struct pt_regs *regs)
23224e6dc35SBrian Gerst {
23324e6dc35SBrian Gerst sigset32_t *set = (sigset32_t *) sigmask_to_save();
23424e6dc35SBrian Gerst struct sigframe_ia32 __user *frame;
23524e6dc35SBrian Gerst void __user *restorer;
23624e6dc35SBrian Gerst void __user *fp = NULL;
23724e6dc35SBrian Gerst
23824e6dc35SBrian Gerst /* copy_to_user optimizes that into a single 8 byte store */
23924e6dc35SBrian Gerst static const struct {
24024e6dc35SBrian Gerst u16 poplmovl;
24124e6dc35SBrian Gerst u32 val;
24224e6dc35SBrian Gerst u16 int80;
24324e6dc35SBrian Gerst } __attribute__((packed)) code = {
24424e6dc35SBrian Gerst 0xb858, /* popl %eax ; movl $...,%eax */
24524e6dc35SBrian Gerst __NR_ia32_sigreturn,
24624e6dc35SBrian Gerst 0x80cd, /* int $0x80 */
24724e6dc35SBrian Gerst };
24824e6dc35SBrian Gerst
24924e6dc35SBrian Gerst frame = get_sigframe(ksig, regs, sizeof(*frame), &fp);
25024e6dc35SBrian Gerst
25124e6dc35SBrian Gerst if (ksig->ka.sa.sa_flags & SA_RESTORER) {
25224e6dc35SBrian Gerst restorer = ksig->ka.sa.sa_restorer;
25324e6dc35SBrian Gerst } else {
25424e6dc35SBrian Gerst /* Return stub is in 32bit vsyscall page */
25524e6dc35SBrian Gerst if (current->mm->context.vdso)
25624e6dc35SBrian Gerst restorer = current->mm->context.vdso +
25724e6dc35SBrian Gerst vdso_image_32.sym___kernel_sigreturn;
25824e6dc35SBrian Gerst else
25924e6dc35SBrian Gerst restorer = &frame->retcode;
26024e6dc35SBrian Gerst }
26124e6dc35SBrian Gerst
26224e6dc35SBrian Gerst if (!user_access_begin(frame, sizeof(*frame)))
26324e6dc35SBrian Gerst return -EFAULT;
26424e6dc35SBrian Gerst
26524e6dc35SBrian Gerst unsafe_put_user(ksig->sig, &frame->sig, Efault);
26624e6dc35SBrian Gerst unsafe_put_sigcontext32(&frame->sc, fp, regs, set, Efault);
26724e6dc35SBrian Gerst unsafe_put_user(set->sig[1], &frame->extramask[0], Efault);
26824e6dc35SBrian Gerst unsafe_put_user(ptr_to_compat(restorer), &frame->pretcode, Efault);
26924e6dc35SBrian Gerst /*
27024e6dc35SBrian Gerst * These are actually not used anymore, but left because some
27124e6dc35SBrian Gerst * gdb versions depend on them as a marker.
27224e6dc35SBrian Gerst */
27324e6dc35SBrian Gerst unsafe_put_user(*((u64 *)&code), (u64 __user *)frame->retcode, Efault);
27424e6dc35SBrian Gerst user_access_end();
27524e6dc35SBrian Gerst
27624e6dc35SBrian Gerst /* Set up registers for signal handler */
27724e6dc35SBrian Gerst regs->sp = (unsigned long) frame;
27824e6dc35SBrian Gerst regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
27924e6dc35SBrian Gerst
28024e6dc35SBrian Gerst /* Make -mregparm=3 work */
28124e6dc35SBrian Gerst regs->ax = ksig->sig;
28224e6dc35SBrian Gerst regs->dx = 0;
28324e6dc35SBrian Gerst regs->cx = 0;
28424e6dc35SBrian Gerst
28524e6dc35SBrian Gerst #ifdef CONFIG_IA32_EMULATION
28624e6dc35SBrian Gerst loadsegment(ds, __USER_DS);
28724e6dc35SBrian Gerst loadsegment(es, __USER_DS);
28824e6dc35SBrian Gerst #else
28924e6dc35SBrian Gerst regs->ds = __USER_DS;
29024e6dc35SBrian Gerst regs->es = __USER_DS;
29124e6dc35SBrian Gerst #endif
29224e6dc35SBrian Gerst
29324e6dc35SBrian Gerst regs->cs = __USER32_CS;
29424e6dc35SBrian Gerst regs->ss = __USER_DS;
29524e6dc35SBrian Gerst
29624e6dc35SBrian Gerst return 0;
29724e6dc35SBrian Gerst Efault:
29824e6dc35SBrian Gerst user_access_end();
29924e6dc35SBrian Gerst return -EFAULT;
30024e6dc35SBrian Gerst }
30124e6dc35SBrian Gerst
ia32_setup_rt_frame(struct ksignal * ksig,struct pt_regs * regs)30224e6dc35SBrian Gerst int ia32_setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
30324e6dc35SBrian Gerst {
30424e6dc35SBrian Gerst sigset32_t *set = (sigset32_t *) sigmask_to_save();
30524e6dc35SBrian Gerst struct rt_sigframe_ia32 __user *frame;
30624e6dc35SBrian Gerst void __user *restorer;
30724e6dc35SBrian Gerst void __user *fp = NULL;
30824e6dc35SBrian Gerst
30924e6dc35SBrian Gerst /* unsafe_put_user optimizes that into a single 8 byte store */
31024e6dc35SBrian Gerst static const struct {
31124e6dc35SBrian Gerst u8 movl;
31224e6dc35SBrian Gerst u32 val;
31324e6dc35SBrian Gerst u16 int80;
31424e6dc35SBrian Gerst u8 pad;
31524e6dc35SBrian Gerst } __attribute__((packed)) code = {
31624e6dc35SBrian Gerst 0xb8,
31724e6dc35SBrian Gerst __NR_ia32_rt_sigreturn,
31824e6dc35SBrian Gerst 0x80cd,
31924e6dc35SBrian Gerst 0,
32024e6dc35SBrian Gerst };
32124e6dc35SBrian Gerst
32224e6dc35SBrian Gerst frame = get_sigframe(ksig, regs, sizeof(*frame), &fp);
32324e6dc35SBrian Gerst
32424e6dc35SBrian Gerst if (!user_access_begin(frame, sizeof(*frame)))
32524e6dc35SBrian Gerst return -EFAULT;
32624e6dc35SBrian Gerst
32724e6dc35SBrian Gerst unsafe_put_user(ksig->sig, &frame->sig, Efault);
32824e6dc35SBrian Gerst unsafe_put_user(ptr_to_compat(&frame->info), &frame->pinfo, Efault);
32924e6dc35SBrian Gerst unsafe_put_user(ptr_to_compat(&frame->uc), &frame->puc, Efault);
33024e6dc35SBrian Gerst
33124e6dc35SBrian Gerst /* Create the ucontext. */
33224e6dc35SBrian Gerst if (static_cpu_has(X86_FEATURE_XSAVE))
33324e6dc35SBrian Gerst unsafe_put_user(UC_FP_XSTATE, &frame->uc.uc_flags, Efault);
33424e6dc35SBrian Gerst else
33524e6dc35SBrian Gerst unsafe_put_user(0, &frame->uc.uc_flags, Efault);
33624e6dc35SBrian Gerst unsafe_put_user(0, &frame->uc.uc_link, Efault);
33724e6dc35SBrian Gerst unsafe_save_altstack32(&frame->uc.uc_stack, regs->sp, Efault);
33824e6dc35SBrian Gerst
33924e6dc35SBrian Gerst if (ksig->ka.sa.sa_flags & SA_RESTORER)
34024e6dc35SBrian Gerst restorer = ksig->ka.sa.sa_restorer;
34124e6dc35SBrian Gerst else
34224e6dc35SBrian Gerst restorer = current->mm->context.vdso +
34324e6dc35SBrian Gerst vdso_image_32.sym___kernel_rt_sigreturn;
34424e6dc35SBrian Gerst unsafe_put_user(ptr_to_compat(restorer), &frame->pretcode, Efault);
34524e6dc35SBrian Gerst
34624e6dc35SBrian Gerst /*
34724e6dc35SBrian Gerst * Not actually used anymore, but left because some gdb
34824e6dc35SBrian Gerst * versions need it.
34924e6dc35SBrian Gerst */
35024e6dc35SBrian Gerst unsafe_put_user(*((u64 *)&code), (u64 __user *)frame->retcode, Efault);
35124e6dc35SBrian Gerst unsafe_put_sigcontext32(&frame->uc.uc_mcontext, fp, regs, set, Efault);
35224e6dc35SBrian Gerst unsafe_put_user(*(__u64 *)set, (__u64 __user *)&frame->uc.uc_sigmask, Efault);
35324e6dc35SBrian Gerst user_access_end();
35424e6dc35SBrian Gerst
35524e6dc35SBrian Gerst if (__copy_siginfo_to_user32(&frame->info, &ksig->info))
35624e6dc35SBrian Gerst return -EFAULT;
35724e6dc35SBrian Gerst
35824e6dc35SBrian Gerst /* Set up registers for signal handler */
35924e6dc35SBrian Gerst regs->sp = (unsigned long) frame;
36024e6dc35SBrian Gerst regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
36124e6dc35SBrian Gerst
36224e6dc35SBrian Gerst /* Make -mregparm=3 work */
36324e6dc35SBrian Gerst regs->ax = ksig->sig;
36424e6dc35SBrian Gerst regs->dx = (unsigned long) &frame->info;
36524e6dc35SBrian Gerst regs->cx = (unsigned long) &frame->uc;
36624e6dc35SBrian Gerst
36724e6dc35SBrian Gerst #ifdef CONFIG_IA32_EMULATION
36824e6dc35SBrian Gerst loadsegment(ds, __USER_DS);
36924e6dc35SBrian Gerst loadsegment(es, __USER_DS);
37024e6dc35SBrian Gerst #else
37124e6dc35SBrian Gerst regs->ds = __USER_DS;
37224e6dc35SBrian Gerst regs->es = __USER_DS;
37324e6dc35SBrian Gerst #endif
37424e6dc35SBrian Gerst
37524e6dc35SBrian Gerst regs->cs = __USER32_CS;
37624e6dc35SBrian Gerst regs->ss = __USER_DS;
37724e6dc35SBrian Gerst
37824e6dc35SBrian Gerst return 0;
37924e6dc35SBrian Gerst Efault:
38024e6dc35SBrian Gerst user_access_end();
38124e6dc35SBrian Gerst return -EFAULT;
38224e6dc35SBrian Gerst }
383f6e2a56cSBrian Gerst
384f6e2a56cSBrian Gerst /*
385f6e2a56cSBrian Gerst * The siginfo_t structure and handing code is very easy
386f6e2a56cSBrian Gerst * to break in several ways. It must always be updated when new
387f6e2a56cSBrian Gerst * updates are made to the main siginfo_t, and
388f6e2a56cSBrian Gerst * copy_siginfo_to_user32() must be updated when the
389f6e2a56cSBrian Gerst * (arch-independent) copy_siginfo_to_user() is updated.
390f6e2a56cSBrian Gerst *
391f6e2a56cSBrian Gerst * It is also easy to put a new member in the siginfo_t
392f6e2a56cSBrian Gerst * which has implicit alignment which can move internal structure
393f6e2a56cSBrian Gerst * alignment around breaking the ABI. This can happen if you,
394f6e2a56cSBrian Gerst * for instance, put a plain 64-bit value in there.
395f6e2a56cSBrian Gerst */
396f6e2a56cSBrian Gerst
397f6e2a56cSBrian Gerst /*
398f6e2a56cSBrian Gerst * If adding a new si_code, there is probably new data in
399f6e2a56cSBrian Gerst * the siginfo. Make sure folks bumping the si_code
400f6e2a56cSBrian Gerst * limits also have to look at this code. Make sure any
401f6e2a56cSBrian Gerst * new fields are handled in copy_siginfo_to_user32()!
402f6e2a56cSBrian Gerst */
403f6e2a56cSBrian Gerst static_assert(NSIGILL == 11);
404f6e2a56cSBrian Gerst static_assert(NSIGFPE == 15);
405*a5f6c2acSRick Edgecombe static_assert(NSIGSEGV == 10);
406f6e2a56cSBrian Gerst static_assert(NSIGBUS == 5);
407f6e2a56cSBrian Gerst static_assert(NSIGTRAP == 6);
408f6e2a56cSBrian Gerst static_assert(NSIGCHLD == 6);
409f6e2a56cSBrian Gerst static_assert(NSIGSYS == 2);
410f6e2a56cSBrian Gerst
411f6e2a56cSBrian Gerst /* This is part of the ABI and can never change in size: */
412f6e2a56cSBrian Gerst static_assert(sizeof(siginfo32_t) == 128);
413f6e2a56cSBrian Gerst
414f6e2a56cSBrian Gerst /* This is a part of the ABI and can never change in alignment */
415f6e2a56cSBrian Gerst static_assert(__alignof__(siginfo32_t) == 4);
416f6e2a56cSBrian Gerst
417f6e2a56cSBrian Gerst /*
418f6e2a56cSBrian Gerst * The offsets of all the (unioned) si_fields are fixed
419f6e2a56cSBrian Gerst * in the ABI, of course. Make sure none of them ever
420f6e2a56cSBrian Gerst * move and are always at the beginning:
421f6e2a56cSBrian Gerst */
422f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, _sifields) == 3 * sizeof(int));
423f6e2a56cSBrian Gerst
424f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_signo) == 0);
425f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_errno) == 4);
426f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_code) == 8);
427f6e2a56cSBrian Gerst
428f6e2a56cSBrian Gerst /*
429f6e2a56cSBrian Gerst * Ensure that the size of each si_field never changes.
430f6e2a56cSBrian Gerst * If it does, it is a sign that the
431f6e2a56cSBrian Gerst * copy_siginfo_to_user32() code below needs to updated
432f6e2a56cSBrian Gerst * along with the size in the CHECK_SI_SIZE().
433f6e2a56cSBrian Gerst *
434f6e2a56cSBrian Gerst * We repeat this check for both the generic and compat
435f6e2a56cSBrian Gerst * siginfos.
436f6e2a56cSBrian Gerst *
437f6e2a56cSBrian Gerst * Note: it is OK for these to grow as long as the whole
438f6e2a56cSBrian Gerst * structure stays within the padding size (checked
439f6e2a56cSBrian Gerst * above).
440f6e2a56cSBrian Gerst */
441f6e2a56cSBrian Gerst
442f6e2a56cSBrian Gerst #define CHECK_SI_OFFSET(name) \
443f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, _sifields) == \
444f6e2a56cSBrian Gerst offsetof(siginfo32_t, _sifields.name))
445f6e2a56cSBrian Gerst
446f6e2a56cSBrian Gerst #define CHECK_SI_SIZE(name, size) \
447f6e2a56cSBrian Gerst static_assert(sizeof_field(siginfo32_t, _sifields.name) == size)
448f6e2a56cSBrian Gerst
449f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_kill);
450f6e2a56cSBrian Gerst CHECK_SI_SIZE (_kill, 2*sizeof(int));
451f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_pid) == 0xC);
452f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_uid) == 0x10);
453f6e2a56cSBrian Gerst
454f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_timer);
455f6e2a56cSBrian Gerst #ifdef CONFIG_COMPAT
456f6e2a56cSBrian Gerst /* compat_siginfo_t doesn't have si_sys_private */
457f6e2a56cSBrian Gerst CHECK_SI_SIZE (_timer, 3*sizeof(int));
458f6e2a56cSBrian Gerst #else
459f6e2a56cSBrian Gerst CHECK_SI_SIZE (_timer, 4*sizeof(int));
460f6e2a56cSBrian Gerst #endif
461f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_tid) == 0x0C);
462f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_overrun) == 0x10);
463f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_value) == 0x14);
464f6e2a56cSBrian Gerst
465f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_rt);
466f6e2a56cSBrian Gerst CHECK_SI_SIZE (_rt, 3*sizeof(int));
467f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_pid) == 0x0C);
468f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_uid) == 0x10);
469f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_value) == 0x14);
470f6e2a56cSBrian Gerst
471f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_sigchld);
472f6e2a56cSBrian Gerst CHECK_SI_SIZE (_sigchld, 5*sizeof(int));
473f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_pid) == 0x0C);
474f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_uid) == 0x10);
475f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_status) == 0x14);
476f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_utime) == 0x18);
477f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_stime) == 0x1C);
478f6e2a56cSBrian Gerst
479f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_sigfault);
480f6e2a56cSBrian Gerst CHECK_SI_SIZE (_sigfault, 4*sizeof(int));
481f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_addr) == 0x0C);
482f6e2a56cSBrian Gerst
483f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_trapno) == 0x10);
484f6e2a56cSBrian Gerst
485f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_addr_lsb) == 0x10);
486f6e2a56cSBrian Gerst
487f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_lower) == 0x14);
488f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_upper) == 0x18);
489f6e2a56cSBrian Gerst
490f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_pkey) == 0x14);
491f6e2a56cSBrian Gerst
492f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_perf_data) == 0x10);
493f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_perf_type) == 0x14);
494f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_perf_flags) == 0x18);
495f6e2a56cSBrian Gerst
496f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_sigpoll);
497f6e2a56cSBrian Gerst CHECK_SI_SIZE (_sigpoll, 2*sizeof(int));
498f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_band) == 0x0C);
499f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_fd) == 0x10);
500f6e2a56cSBrian Gerst
501f6e2a56cSBrian Gerst CHECK_SI_OFFSET(_sigsys);
502f6e2a56cSBrian Gerst CHECK_SI_SIZE (_sigsys, 3*sizeof(int));
503f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_call_addr) == 0x0C);
504f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_syscall) == 0x10);
505f6e2a56cSBrian Gerst static_assert(offsetof(siginfo32_t, si_arch) == 0x14);
506f6e2a56cSBrian Gerst
507f6e2a56cSBrian Gerst /* any new si_fields should be added here */
508