0d1fb0a47c09b arch/um/kernel/signal.c (Alex Dewar 2019-08-25 10:49:17 +0100 1) // SPDX-License-Identifier: GPL-2.0
1d3468a6643a6 arch/um/kernel/signal.c (Jeff Dike 2006-07-10 04:45:13 -0700 2) /*
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 3) * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 4) */
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 5)
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 6) #include <linux/module.h>
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 7) #include <linux/ptrace.h>
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 8) #include <linux/sched.h>
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 9) #include <linux/ftrace.h>
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 10) #include <asm/siginfo.h>
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 11) #include <asm/signal.h>
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 12) #include <asm/unistd.h>
37185b3324087 arch/um/kernel/signal.c (Al Viro 2012-10-08 03:27:32 +0100 13) #include <frame_kern.h>
37185b3324087 arch/um/kernel/signal.c (Al Viro 2012-10-08 03:27:32 +0100 14) #include <kern_util.h>
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 15) #include <os.h>
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 16)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 17) EXPORT_SYMBOL(block_signals);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 18) EXPORT_SYMBOL(unblock_signals);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 19)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 20) void block_signals_trace(void)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 21) {
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 22) block_signals();
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 23) if (current_thread_info())
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 24) trace_hardirqs_off();
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 25) }
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 26)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 27) void unblock_signals_trace(void)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 28) {
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 29) if (current_thread_info())
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 30) trace_hardirqs_on();
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 31) unblock_signals();
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 32) }
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 33)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 34) void um_trace_signals_on(void)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 35) {
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 36) if (current_thread_info())
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 37) trace_hardirqs_on();
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 38) }
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 39)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 40) void um_trace_signals_off(void)
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 41) {
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 42) if (current_thread_info())
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 43) trace_hardirqs_off();
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 44) }
0dafcbe128d2a arch/um/kernel/signal.c (Johannes Berg 2019-08-23 13:16:23 +0200 45)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 46) /*
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 47) * OK, we're invoking a handler
1d3468a6643a6 arch/um/kernel/signal.c (Jeff Dike 2006-07-10 04:45:13 -0700 48) */
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 49) static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 50) {
b7f9a11a6cf1e arch/um/kernel/signal.c (Al Viro 2012-05-02 09:59:21 -0400 51) sigset_t *oldset = sigmask_to_save();
f9a38eace4498 arch/um/kernel/signal.c (Al Viro 2012-09-06 13:39:47 -0400 52) int singlestep = 0;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 53) unsigned long sp;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 54) int err;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 55)
f9a38eace4498 arch/um/kernel/signal.c (Al Viro 2012-09-06 13:39:47 -0400 56) if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED))
f9a38eace4498 arch/um/kernel/signal.c (Al Viro 2012-09-06 13:39:47 -0400 57) singlestep = 1;
f9a38eace4498 arch/um/kernel/signal.c (Al Viro 2012-09-06 13:39:47 -0400 58)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 59) /* Did we come from a system call? */
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 60) if (PT_REGS_SYSCALL_NR(regs) >= 0) {
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 61) /* If so, check system call restarting.. */
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 62) switch (PT_REGS_SYSCALL_RET(regs)) {
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 63) case -ERESTART_RESTARTBLOCK:
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 64) case -ERESTARTNOHAND:
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 65) PT_REGS_SYSCALL_RET(regs) = -EINTR;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 66) break;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 67)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 68) case -ERESTARTSYS:
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 69) if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 70) PT_REGS_SYSCALL_RET(regs) = -EINTR;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 71) break;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 72) }
df561f6688fef arch/um/kernel/signal.c (Gustavo A. R. Silva 2020-08-23 17:36:59 -0500 73) fallthrough;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 74) case -ERESTARTNOINTR:
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 75) PT_REGS_RESTART_SYSCALL(regs);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 76) PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 77) break;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 78) }
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 79) }
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 80)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 81) sp = PT_REGS_SP(regs);
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 82) if ((ksig->ka.sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0))
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 83) sp = current->sas_ss_sp + current->sas_ss_size;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 84)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 85) #ifdef CONFIG_ARCH_HAS_SC_SIGNALS
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 86) if (!(ksig->ka.sa.sa_flags & SA_SIGINFO))
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 87) err = setup_signal_stack_sc(sp, ksig, regs, oldset);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 88) else
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 89) #endif
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 90) err = setup_signal_stack_si(sp, ksig, regs, oldset);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 91)
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 92) signal_setup_done(err, ksig, singlestep);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 93) }
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 94)
ccaee5f851470 arch/um/kernel/signal.c (Ingo Molnar 2015-07-03 12:44:20 -0700 95) void do_signal(struct pt_regs *regs)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 96) {
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 97) struct ksignal ksig;
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 98) int handled_sig = 0;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 99)
322740efbb7ca arch/um/kernel/signal.c (Richard Weinberger 2016-01-25 23:33:30 +0100 100) while (get_signal(&ksig)) {
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 101) handled_sig = 1;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 102) /* Whee! Actually deliver the signal. */
307627eebbb0b arch/um/kernel/signal.c (Richard Weinberger 2013-10-06 21:57:10 +0200 103) handle_signal(&ksig, regs);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 104) }
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 105)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 106) /* Did we come from a system call? */
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 107) if (!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)) {
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 108) /* Restart the system call - no handlers present */
c5d4bb171cab1 arch/um/kernel/signal.c (Jeff Dike 2008-02-04 22:31:14 -0800 109) switch (PT_REGS_SYSCALL_RET(regs)) {
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 110) case -ERESTARTNOHAND:
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 111) case -ERESTARTSYS:
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 112) case -ERESTARTNOINTR:
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 113) PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 114) PT_REGS_RESTART_SYSCALL(regs);
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 115) break;
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 116) case -ERESTART_RESTARTBLOCK:
1d3468a6643a6 arch/um/kernel/signal.c (Jeff Dike 2006-07-10 04:45:13 -0700 117) PT_REGS_ORIG_SYSCALL(regs) = __NR_restart_syscall;
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 118) PT_REGS_RESTART_SYSCALL(regs);
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 119) break;
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 120) }
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 121) }
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 122)
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 123) /*
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 124) * This closes a way to execute a system call on the host. If
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 125) * you set a breakpoint on a system call instruction and singlestep
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 126) * from it, the tracing thread used to PTRACE_SINGLESTEP the process
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 127) * rather than PTRACE_SYSCALL it, allowing the system call to execute
1d3468a6643a6 arch/um/kernel/signal.c (Jeff Dike 2006-07-10 04:45:13 -0700 128) * on the host. The tracing thread will check this flag and
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 129) * PTRACE_SYSCALL if necessary.
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 130) */
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 131) if (current->ptrace & PT_DTRACE)
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 132) current->thread.singlestep_syscall =
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 133) is_syscall(PT_REGS_IP(¤t->thread.regs));
2fc10620e7411 arch/um/kernel/signal_kern.c (Jeff Dike 2006-01-18 17:44:02 -0800 134)
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 135) /*
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 136) * if there's no signal to deliver, we just put the saved sigmask
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 137) * back
ba180fd437156 arch/um/kernel/signal.c (Jeff Dike 2007-10-16 01:27:00 -0700 138) */
51a7b448d4134 arch/um/kernel/signal.c (Al Viro 2012-05-21 23:33:55 -0400 139) if (!handled_sig)
51a7b448d4134 arch/um/kernel/signal.c (Al Viro 2012-05-21 23:33:55 -0400 140) restore_saved_sigmask();
^1da177e4c3f4 arch/um/kernel/signal_kern.c (Linus Torvalds 2005-04-16 15:20:36 -0700 141) }