Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  1997-11-28  Modified for POSIX.1b signals by Richard Henderson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  2000-06-20  Pentium III FXSR, SSE support by Gareth Hughes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  2000-2002   x86-64 support by Andi Kleen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/user-return-notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/uprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/context_tracking.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/entry-common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/ucontext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/fpu/internal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/fpu/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/vdso.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/mce.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/sighandling.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/vm86.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/proto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/ia32_unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #endif /* CONFIG_X86_64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <asm/syscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <asm/sigframe.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <asm/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * If regs->ss will cause an IRET fault, change it.  Otherwise leave it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * alone.  Using this generally makes no sense unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * user_64bit_mode(regs) would return true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static void force_valid_ss(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u32 ar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	asm volatile ("lar %[old_ss], %[ar]\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		      "jz 1f\n\t"		/* If invalid: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		      "xorl %[ar], %[ar]\n\t"	/* set ar = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		      "1:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		      : [ar] "=r" (ar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		      : [old_ss] "rm" ((u16)regs->ss));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * For a valid 64-bit user context, we need DPL 3, type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * read-write data or read-write exp-down data, and S and P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * set.  We can't use VERW because VERW doesn't check the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * P bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	ar &= AR_DPL_MASK | AR_S | AR_P | AR_TYPE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (ar != (AR_DPL3 | AR_S | AR_P | AR_TYPE_RWDATA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	    ar != (AR_DPL3 | AR_S | AR_P | AR_TYPE_RWDATA_EXPDOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		regs->ss = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) # define CONTEXT_COPY_SIZE	offsetof(struct sigcontext, reserved1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) # define CONTEXT_COPY_SIZE	sizeof(struct sigcontext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int restore_sigcontext(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			      struct sigcontext __user *usc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			      unsigned long uc_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct sigcontext sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* Always make any pending restarted system calls return -EINTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	current->restart_block.fn = do_no_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (copy_from_user(&sc, usc, CONTEXT_COPY_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	set_user_gs(regs, sc.gs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	regs->fs = sc.fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	regs->es = sc.es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	regs->ds = sc.ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #endif /* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	regs->bx = sc.bx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	regs->cx = sc.cx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	regs->dx = sc.dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	regs->si = sc.si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	regs->di = sc.di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	regs->bp = sc.bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	regs->ax = sc.ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	regs->sp = sc.sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	regs->ip = sc.ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	regs->r8 = sc.r8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	regs->r9 = sc.r9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	regs->r10 = sc.r10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	regs->r11 = sc.r11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	regs->r12 = sc.r12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	regs->r13 = sc.r13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	regs->r14 = sc.r14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	regs->r15 = sc.r15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #endif /* CONFIG_X86_64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* Get CS/SS and force CPL3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	regs->cs = sc.cs | 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	regs->ss = sc.ss | 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	regs->flags = (regs->flags & ~FIX_EFLAGS) | (sc.flags & FIX_EFLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* disable syscall checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	regs->orig_ax = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * Fix up SS if needed for the benefit of old DOSEMU and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * CRIU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (unlikely(!(uc_flags & UC_STRICT_RESTORE_SS) && user_64bit_mode(regs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		force_valid_ss(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return fpu__restore_sig((void __user *)sc.fpstate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			       IS_ENABLED(CONFIG_X86_32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static __always_inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) __unsafe_setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		     struct pt_regs *regs, unsigned long mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	unsafe_put_user(get_user_gs(regs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				  (unsigned int __user *)&sc->gs, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	unsafe_put_user(regs->fs, (unsigned int __user *)&sc->fs, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	unsafe_put_user(regs->es, (unsigned int __user *)&sc->es, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unsafe_put_user(regs->ds, (unsigned int __user *)&sc->ds, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #endif /* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	unsafe_put_user(regs->di, &sc->di, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsafe_put_user(regs->si, &sc->si, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	unsafe_put_user(regs->bp, &sc->bp, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	unsafe_put_user(regs->sp, &sc->sp, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsafe_put_user(regs->bx, &sc->bx, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	unsafe_put_user(regs->dx, &sc->dx, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	unsafe_put_user(regs->cx, &sc->cx, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	unsafe_put_user(regs->ax, &sc->ax, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	unsafe_put_user(regs->r8, &sc->r8, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	unsafe_put_user(regs->r9, &sc->r9, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	unsafe_put_user(regs->r10, &sc->r10, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	unsafe_put_user(regs->r11, &sc->r11, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsafe_put_user(regs->r12, &sc->r12, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	unsafe_put_user(regs->r13, &sc->r13, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	unsafe_put_user(regs->r14, &sc->r14, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	unsafe_put_user(regs->r15, &sc->r15, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #endif /* CONFIG_X86_64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	unsafe_put_user(current->thread.trap_nr, &sc->trapno, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	unsafe_put_user(current->thread.error_code, &sc->err, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	unsafe_put_user(regs->ip, &sc->ip, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	unsafe_put_user(regs->cs, (unsigned int __user *)&sc->cs, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	unsafe_put_user(regs->flags, &sc->flags, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	unsafe_put_user(regs->sp, &sc->sp_at_signal, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	unsafe_put_user(regs->ss, (unsigned int __user *)&sc->ss, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #else /* !CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	unsafe_put_user(regs->flags, &sc->flags, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	unsafe_put_user(regs->cs, &sc->cs, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	unsafe_put_user(0, &sc->gs, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsafe_put_user(0, &sc->fs, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	unsafe_put_user(regs->ss, &sc->ss, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #endif /* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	unsafe_put_user(fpstate, (unsigned long __user *)&sc->fpstate, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	/* non-iBCS2 extensions.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	unsafe_put_user(mask, &sc->oldmask, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	unsafe_put_user(current->thread.cr2, &sc->cr2, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define unsafe_put_sigcontext(sc, fp, regs, set, label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (__unsafe_setup_sigcontext(sc, fp, regs, set->sig[0]))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		goto label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) } while(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define unsafe_put_sigmask(set, frame, label) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	unsafe_put_user(*(__u64 *)(set), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			(__u64 __user *)&(frame)->uc.uc_sigmask, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * Set up a signal frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * Determine which stack to use..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static unsigned long align_sigframe(unsigned long sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * Align the stack pointer according to the i386 ABI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * i.e. so that on function entry ((sp + 4) & 15) == 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	sp = ((sp + 4) & -16ul) - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #else /* !CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	sp = round_down(sp, 16) - 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void __user *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	     void __user **fpstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* Default to using normal stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	bool nested_altstack = on_sig_stack(regs->sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	bool entering_altstack = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	unsigned long math_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	unsigned long sp = regs->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	unsigned long buf_fx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* redzone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (IS_ENABLED(CONFIG_X86_64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		sp -= 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/* This is the X/Open sanctioned signal stack switching.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (ka->sa.sa_flags & SA_ONSTACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		 * This checks nested_altstack via sas_ss_flags(). Sensible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 * programs use SS_AUTODISARM, which disables that check, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 * programs that don't use SS_AUTODISARM get compatible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		if (sas_ss_flags(sp) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			sp = current->sas_ss_sp + current->sas_ss_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			entering_altstack = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	} else if (IS_ENABLED(CONFIG_X86_32) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		   !nested_altstack &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		   regs->ss != __USER_DS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		   !(ka->sa.sa_flags & SA_RESTORER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		   ka->sa.sa_restorer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		/* This is the legacy signal stack switching. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		sp = (unsigned long) ka->sa.sa_restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		entering_altstack = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	sp = fpu__alloc_mathframe(sp, IS_ENABLED(CONFIG_X86_32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				  &buf_fx, &math_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	*fpstate = (void __user *)sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	sp = align_sigframe(sp - frame_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * If we are on the alternate signal stack and would overflow it, don't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * Return an always-bogus address instead so we will die with SIGSEGV.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (unlikely((nested_altstack || entering_altstack) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		     !__on_sig_stack(sp))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (show_unhandled_signals && printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			pr_info("%s[%d] overflowed sigaltstack\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return (void __user *)-1L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/* save i387 and extended state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	ret = copy_fpstate_to_sigframe(*fpstate, (void __user *)buf_fx, math_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return (void __user *)-1L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return (void __user *)sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	u16 poplmovl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	u16 int80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) } __attribute__((packed)) retcode = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	0xb858,		/* popl %eax; movl $..., %eax */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	__NR_sigreturn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	0x80cd,		/* int $0x80 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	u8  movl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	u16 int80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	u8  pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) } __attribute__((packed)) rt_retcode = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	0xb8,		/* movl $..., %eax */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	__NR_rt_sigreturn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	0x80cd,		/* int $0x80 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	      struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	void __user *restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	void __user *fp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (!user_access_begin(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	unsafe_put_user(sig, &frame->sig, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	unsafe_put_sigcontext(&frame->sc, fp, regs, set, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	unsafe_put_user(set->sig[1], &frame->extramask[0], Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (current->mm->context.vdso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		restorer = current->mm->context.vdso +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			vdso_image_32.sym___kernel_sigreturn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		restorer = &frame->retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (ksig->ka.sa.sa_flags & SA_RESTORER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		restorer = ksig->ka.sa.sa_restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/* Set up to return from userspace.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	unsafe_put_user(restorer, &frame->pretcode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 * WE DO NOT USE IT ANY MORE! It's only left here for historical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	 * reasons and because gdb uses it as a signature to notice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	 * signal handler stack frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	unsafe_put_user(*((u64 *)&retcode), (u64 *)frame->retcode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	/* Set up registers for signal handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	regs->sp = (unsigned long)frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	regs->ax = (unsigned long)sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	regs->dx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	regs->cx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	regs->ds = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	regs->es = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	regs->ss = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	regs->cs = __USER_CS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static int __setup_rt_frame(int sig, struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			    sigset_t *set, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	void __user *restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	void __user *fp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (!user_access_begin(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	unsafe_put_user(sig, &frame->sig, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	unsafe_put_user(&frame->info, &frame->pinfo, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	unsafe_put_user(&frame->uc, &frame->puc, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* Create the ucontext.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (static_cpu_has(X86_FEATURE_XSAVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		unsafe_put_user(UC_FP_XSTATE, &frame->uc.uc_flags, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		unsafe_put_user(0, &frame->uc.uc_flags, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	unsafe_put_user(0, &frame->uc.uc_link, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	unsafe_save_altstack(&frame->uc.uc_stack, regs->sp, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	/* Set up to return from userspace.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	restorer = current->mm->context.vdso +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		vdso_image_32.sym___kernel_rt_sigreturn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (ksig->ka.sa.sa_flags & SA_RESTORER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		restorer = ksig->ka.sa.sa_restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	unsafe_put_user(restorer, &frame->pretcode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 * WE DO NOT USE IT ANY MORE! It's only left here for historical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * reasons and because gdb uses it as a signature to notice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 * signal handler stack frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	unsafe_put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	unsafe_put_sigmask(set, frame, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (copy_siginfo_to_user(&frame->info, &ksig->info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	/* Set up registers for signal handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	regs->sp = (unsigned long)frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	regs->ax = (unsigned long)sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	regs->dx = (unsigned long)&frame->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	regs->cx = (unsigned long)&frame->uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	regs->ds = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	regs->es = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	regs->ss = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	regs->cs = __USER_CS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) #else /* !CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static unsigned long frame_uc_flags(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (boot_cpu_has(X86_FEATURE_XSAVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		flags = UC_FP_XSTATE | UC_SIGCONTEXT_SS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		flags = UC_SIGCONTEXT_SS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (likely(user_64bit_mode(regs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		flags |= UC_STRICT_RESTORE_SS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	return flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static int __setup_rt_frame(int sig, struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			    sigset_t *set, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	void __user *fp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	unsigned long uc_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/* x86-64 should always use SA_RESTORER. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (!(ksig->ka.sa.sa_flags & SA_RESTORER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	uc_flags = frame_uc_flags(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (!user_access_begin(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	/* Create the ucontext.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	unsafe_put_user(uc_flags, &frame->uc.uc_flags, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	unsafe_put_user(0, &frame->uc.uc_link, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	unsafe_save_altstack(&frame->uc.uc_stack, regs->sp, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	/* Set up to return from userspace.  If provided, use a stub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	   already in userspace.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	unsafe_put_user(ksig->ka.sa.sa_restorer, &frame->pretcode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	unsafe_put_sigmask(set, frame, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		if (copy_siginfo_to_user(&frame->info, &ksig->info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/* Set up registers for signal handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	regs->di = sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	/* In case the signal handler was declared without prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	regs->ax = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	/* This also works for non SA_SIGINFO handlers because they expect the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	   next argument after the signal number on the stack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	regs->si = (unsigned long)&frame->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	regs->dx = (unsigned long)&frame->uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	regs->sp = (unsigned long)frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	 * Set up the CS and SS registers to run signal handlers in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	 * 64-bit mode, even if the handler happens to be interrupting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	 * 32-bit or 16-bit code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	 * SS is subtle.  In 64-bit mode, we don't need any particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	 * SS descriptor, but we do need SS to be valid.  It's possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	 * that the old SS is entirely bogus -- this can happen if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	 * signal we're trying to deliver is #GP or #SS caused by a bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	 * SS value.  We also have a compatbility issue here: DOSEMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	 * relies on the contents of the SS register indicating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	 * SS value at the time of the signal, even though that code in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	 * DOSEMU predates sigreturn's ability to restore SS.  (DOSEMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	 * avoids relying on sigreturn to restore SS; instead it uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	 * a trampoline.)  So we do our best: if the old SS was valid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	 * we keep it.  Otherwise we replace it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	regs->cs = __USER_CS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (unlikely(regs->ss != __USER_DS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		force_valid_ss(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) #endif /* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static int x32_copy_siginfo_to_user(struct compat_siginfo __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		const struct kernel_siginfo *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	struct compat_siginfo new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	copy_siginfo_to_external32(&new, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (from->si_signo == SIGCHLD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		new._sifields._sigchld_x32._utime = from->si_utime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		new._sifields._sigchld_x32._stime = from->si_stime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (copy_to_user(to, &new, sizeof(struct compat_siginfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int copy_siginfo_to_user32(struct compat_siginfo __user *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			   const struct kernel_siginfo *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	if (in_x32_syscall())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		return x32_copy_siginfo_to_user(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	return __copy_siginfo_to_user32(to, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) #endif /* CONFIG_X86_X32_ABI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static int x32_setup_rt_frame(struct ksignal *ksig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 			      compat_sigset_t *set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			      struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	struct rt_sigframe_x32 __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	unsigned long uc_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	void __user *restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	void __user *fp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	if (!(ksig->ka.sa.sa_flags & SA_RESTORER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	uc_flags = frame_uc_flags(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	if (!user_access_begin(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	/* Create the ucontext.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	unsafe_put_user(uc_flags, &frame->uc.uc_flags, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	unsafe_put_user(0, &frame->uc.uc_link, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	unsafe_compat_save_altstack(&frame->uc.uc_stack, regs->sp, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	unsafe_put_user(0, &frame->uc.uc__pad0, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	restorer = ksig->ka.sa.sa_restorer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	unsafe_put_user(restorer, (unsigned long __user *)&frame->pretcode, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	unsafe_put_sigcontext(&frame->uc.uc_mcontext, fp, regs, set, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	unsafe_put_sigmask(set, frame, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		if (x32_copy_siginfo_to_user(&frame->info, &ksig->info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	/* Set up registers for signal handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	regs->sp = (unsigned long) frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	/* We use the x32 calling convention here... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	regs->di = ksig->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	regs->si = (unsigned long) &frame->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	regs->dx = (unsigned long) &frame->uc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	loadsegment(ds, __USER_DS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	loadsegment(es, __USER_DS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	regs->cs = __USER_CS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	regs->ss = __USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) #endif	/* CONFIG_X86_X32_ABI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	user_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)  * Do a signal return; undo the signal stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) SYSCALL_DEFINE0(sigreturn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	struct sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	frame = (struct sigframe __user *)(regs->sp - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	if (__get_user(set.sig[0], &frame->sc.oldmask) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	    __get_user(set.sig[1], &frame->extramask[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	 * x86_32 has no uc_flags bits relevant to restore_sigcontext.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	 * Save a few cycles by skipping the __get_user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	if (restore_sigcontext(regs, &frame->sc, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	return regs->ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	signal_fault(regs, frame, "sigreturn");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) #endif /* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) SYSCALL_DEFINE0(rt_sigreturn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	struct rt_sigframe __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	unsigned long uc_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	if (__get_user(*(__u64 *)&set, (__u64 __user *)&frame->uc.uc_sigmask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	if (__get_user(uc_flags, &frame->uc.uc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	if (restore_altstack(&frame->uc.uc_stack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	return regs->ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	signal_fault(regs, frame, "rt_sigreturn");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static inline int is_ia32_compat_frame(struct ksignal *ksig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return IS_ENABLED(CONFIG_IA32_EMULATION) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		ksig->ka.sa.sa_flags & SA_IA32_ABI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static inline int is_ia32_frame(struct ksignal *ksig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	return IS_ENABLED(CONFIG_X86_32) || is_ia32_compat_frame(ksig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static inline int is_x32_frame(struct ksignal *ksig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	return IS_ENABLED(CONFIG_X86_X32_ABI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		ksig->ka.sa.sa_flags & SA_X32_ABI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	int usig = ksig->sig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	sigset_t *set = sigmask_to_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	compat_sigset_t *cset = (compat_sigset_t *) set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	/* Perform fixup for the pre-signal frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	rseq_signal_deliver(ksig, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	/* Set up the stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	if (is_ia32_frame(ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		if (ksig->ka.sa.sa_flags & SA_SIGINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			return ia32_setup_rt_frame(usig, ksig, cset, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 			return ia32_setup_frame(usig, ksig, cset, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	} else if (is_x32_frame(ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		return x32_setup_rt_frame(ksig, cset, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		return __setup_rt_frame(ksig->sig, ksig, set, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) handle_signal(struct ksignal *ksig, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	bool stepping, failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	struct fpu *fpu = &current->thread.fpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	if (v8086_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	/* Are we from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	if (syscall_get_nr(current, regs) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		/* If so, check system call restarting.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		switch (syscall_get_error(current, regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 			regs->ax = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 				regs->ax = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 			regs->ax = regs->orig_ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 			regs->ip -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	 * If TF is set due to a debugger (TIF_FORCED_TF), clear TF now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	 * so that register information in the sigcontext is correct and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	 * then notify the tracer before entering the signal handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	stepping = test_thread_flag(TIF_SINGLESTEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	if (stepping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		user_disable_single_step(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	failed = (setup_rt_frame(ksig, regs) < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	if (!failed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		 * Clear the direction flag as per the ABI for function entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 		 * Clear RF when entering the signal handler, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		 * it might disable possible debug exception from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		 * signal handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		 * Clear TF for the case when it wasn't set by debugger to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		 * avoid the recursive send_sigtrap() in SIGTRAP handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 		regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 		 * Ensure the signal handler starts with the new fpu state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 		fpu__clear_user_states(fpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 	signal_setup_done(failed, ksig, stepping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) #ifdef CONFIG_IA32_EMULATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	if (current_thread_info()->status & TS_COMPAT_RESTART)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		return __NR_ia32_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	return __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	return __NR_restart_syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)  * Note that 'init' is a special process: it doesn't get signals it doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)  * want to handle. Thus you cannot kill init even with a SIGKILL even by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)  * mistake.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) void arch_do_signal(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	struct ksignal ksig;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	if (get_signal(&ksig)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 		/* Whee! Actually deliver the signal.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 		handle_signal(&ksig, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	/* Did we come from a system call? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	if (syscall_get_nr(current, regs) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 		/* Restart the system call - no handlers present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 		switch (syscall_get_error(current, regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		case -ERESTARTNOHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 		case -ERESTARTSYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 		case -ERESTARTNOINTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 			regs->ax = regs->orig_ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 			regs->ip -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		case -ERESTART_RESTARTBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 			regs->ax = get_nr_restart_syscall(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 			regs->ip -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	 * If there's no signal to deliver, we just put the saved sigmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	 * back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	restore_saved_sigmask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	struct task_struct *me = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 	if (show_unhandled_signals && printk_ratelimit()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 		printk("%s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		       "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 		       task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		       me->comm, me->pid, where, frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 		       regs->ip, regs->sp, regs->orig_ax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		print_vma_addr(KERN_CONT " in ", regs->ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) COMPAT_SYSCALL_DEFINE0(x32_rt_sigreturn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	struct rt_sigframe_x32 __user *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	sigset_t set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	unsigned long uc_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	if (!access_ok(frame, sizeof(*frame)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	if (__get_user(set.sig[0], (__u64 __user *)&frame->uc.uc_sigmask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 	if (__get_user(uc_flags, &frame->uc.uc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	set_current_blocked(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 	if (compat_restore_altstack(&frame->uc.uc_stack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 		goto badframe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	return regs->ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) badframe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	signal_fault(regs, frame, "x32 rt_sigreturn");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) #endif