Merge branch 'exit-cleanups-for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / kernel / signal.c
index 52b6abe..cf7e250 100644 (file)
@@ -54,6 +54,7 @@
 #include <asm/unistd.h>
 #include <asm/siginfo.h>
 #include <asm/cacheflush.h>
+#include <asm/syscall.h>       /* for syscall_get_* */
 
 /*
  * SLAB caches for signal bits.
@@ -1213,7 +1214,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)
        case SIL_FAULT_MCEERR:
        case SIL_FAULT_BNDERR:
        case SIL_FAULT_PKUERR:
-       case SIL_PERF_EVENT:
+       case SIL_FAULT_PERF_EVENT:
        case SIL_SYS:
                ret = false;
                break;
@@ -1322,7 +1323,7 @@ int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p
  * that is why we also clear SIGNAL_UNKILLABLE.
  */
 static int
-force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t)
+force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t, bool sigdfl)
 {
        unsigned long int flags;
        int ret, blocked, ignored;
@@ -1333,7 +1334,7 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t)
        action = &t->sighand->action[sig-1];
        ignored = action->sa.sa_handler == SIG_IGN;
        blocked = sigismember(&t->blocked, sig);
-       if (blocked || ignored) {
+       if (blocked || ignored || sigdfl) {
                action->sa.sa_handler = SIG_DFL;
                if (blocked) {
                        sigdelset(&t->blocked, sig);
@@ -1354,7 +1355,7 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t)
 
 int force_sig_info(struct kernel_siginfo *info)
 {
-       return force_sig_info_to_task(info, current);
+       return force_sig_info_to_task(info, current, false);
 }
 
 /*
@@ -1681,7 +1682,6 @@ void force_sigsegv(int sig)
 }
 
 int force_sig_fault_to_task(int sig, int code, void __user *addr
-       ___ARCH_SI_TRAPNO(int trapno)
        ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
        , struct task_struct *t)
 {
@@ -1692,28 +1692,22 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr
        info.si_errno = 0;
        info.si_code  = code;
        info.si_addr  = addr;
-#ifdef __ARCH_SI_TRAPNO
-       info.si_trapno = trapno;
-#endif
 #ifdef __ia64__
        info.si_imm = imm;
        info.si_flags = flags;
        info.si_isr = isr;
 #endif
-       return force_sig_info_to_task(&info, t);
+       return force_sig_info_to_task(&info, t, false);
 }
 
 int force_sig_fault(int sig, int code, void __user *addr
-       ___ARCH_SI_TRAPNO(int trapno)
        ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr))
 {
        return force_sig_fault_to_task(sig, code, addr
-                                      ___ARCH_SI_TRAPNO(trapno)
                                       ___ARCH_SI_IA64(imm, flags, isr), current);
 }
 
 int send_sig_fault(int sig, int code, void __user *addr
-       ___ARCH_SI_TRAPNO(int trapno)
        ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
        , struct task_struct *t)
 {
@@ -1724,9 +1718,6 @@ int send_sig_fault(int sig, int code, void __user *addr
        info.si_errno = 0;
        info.si_code  = code;
        info.si_addr  = addr;
-#ifdef __ARCH_SI_TRAPNO
-       info.si_trapno = trapno;
-#endif
 #ifdef __ia64__
        info.si_imm = imm;
        info.si_flags = flags;
@@ -1808,6 +1799,27 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)
        return force_sig_info(&info);
 }
 
+/**
+ * force_sig_seccomp - signals the task to allow in-process syscall emulation
+ * @syscall: syscall number to send to userland
+ * @reason: filter-supplied reason code to send to userland (via si_errno)
+ *
+ * Forces a SIGSYS with a code of SYS_SECCOMP and related sigsys info.
+ */
+int force_sig_seccomp(int syscall, int reason, bool force_coredump)
+{
+       struct kernel_siginfo info;
+
+       clear_siginfo(&info);
+       info.si_signo = SIGSYS;
+       info.si_code = SYS_SECCOMP;
+       info.si_call_addr = (void __user *)KSTK_EIP(current);
+       info.si_errno = reason;
+       info.si_arch = syscall_get_arch(current);
+       info.si_syscall = syscall;
+       return force_sig_info_to_task(&info, current, force_coredump);
+}
+
 /* For the crazy architectures that include trap information in
  * the errno field, instead of an actual errno value.
  */
@@ -1823,6 +1835,39 @@ int force_sig_ptrace_errno_trap(int errno, void __user *addr)
        return force_sig_info(&info);
 }
 
+/* For the rare architectures that include trap information using
+ * si_trapno.
+ */
+int force_sig_fault_trapno(int sig, int code, void __user *addr, int trapno)
+{
+       struct kernel_siginfo info;
+
+       clear_siginfo(&info);
+       info.si_signo = sig;
+       info.si_errno = 0;
+       info.si_code  = code;
+       info.si_addr  = addr;
+       info.si_trapno = trapno;
+       return force_sig_info(&info);
+}
+
+/* For the rare architectures that include trap information using
+ * si_trapno.
+ */
+int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
+                         struct task_struct *t)
+{
+       struct kernel_siginfo info;
+
+       clear_siginfo(&info);
+       info.si_signo = sig;
+       info.si_errno = 0;
+       info.si_code  = code;
+       info.si_addr  = addr;
+       info.si_trapno = trapno;
+       return send_sig_info(info.si_signo, &info, t);
+}
+
 int kill_pgrp(struct pid *pid, int sig, int priv)
 {
        int ret;
@@ -2572,7 +2617,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)
        case SIL_FAULT_MCEERR:
        case SIL_FAULT_BNDERR:
        case SIL_FAULT_PKUERR:
-       case SIL_PERF_EVENT:
+       case SIL_FAULT_PERF_EVENT:
                ksig->info.si_addr = arch_untagged_si_addr(
                        ksig->info.si_addr, ksig->sig, ksig->info.si_code);
                break;
@@ -3257,11 +3302,14 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)
                                layout = SIL_FAULT_PKUERR;
 #endif
                        else if ((sig == SIGTRAP) && (si_code == TRAP_PERF))
-                               layout = SIL_PERF_EVENT;
-#ifdef __ARCH_SI_TRAPNO
-                       else if (layout == SIL_FAULT)
+                               layout = SIL_FAULT_PERF_EVENT;
+                       else if (IS_ENABLED(CONFIG_SPARC) &&
+                                (sig == SIGILL) && (si_code == ILL_ILLTRP))
+                               layout = SIL_FAULT_TRAPNO;
+                       else if (IS_ENABLED(CONFIG_ALPHA) &&
+                                ((sig == SIGFPE) ||
+                                 ((sig == SIGTRAP) && (si_code == TRAP_UNK))))
                                layout = SIL_FAULT_TRAPNO;
-#endif
                }
                else if (si_code <= NSIGPOLL)
                        layout = SIL_POLL;
@@ -3383,7 +3431,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,
                to->si_addr = ptr_to_compat(from->si_addr);
                to->si_pkey = from->si_pkey;
                break;
-       case SIL_PERF_EVENT:
+       case SIL_FAULT_PERF_EVENT:
                to->si_addr = ptr_to_compat(from->si_addr);
                to->si_perf_data = from->si_perf_data;
                to->si_perf_type = from->si_perf_type;
@@ -3460,7 +3508,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,
                to->si_addr = compat_ptr(from->si_addr);
                to->si_pkey = from->si_pkey;
                break;
-       case SIL_PERF_EVENT:
+       case SIL_FAULT_PERF_EVENT:
                to->si_addr = compat_ptr(from->si_addr);
                to->si_perf_data = from->si_perf_data;
                to->si_perf_type = from->si_perf_type;