aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>2018-06-02 08:43:58 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-06-06 05:58:32 -0400
commitd6761b8fd96967f7ff4b16c6875e94929a897916 (patch)
tree7ddebb20825b5e855623a652acb7d2873169efcd
parent338035edc9b96cd63f4bc823db5f36c617c560bf (diff)
x86: Add support for restartable sequences
Call the rseq_handle_notify_resume() function on return to userspace if TIF_NOTIFY_RESUME thread flag is set. Perform fixup on the pre-signal frame when a signal is delivered on top of a restartable sequence critical section. Check that system calls are not invoked from within rseq critical sections by invoking rseq_signal() from syscall_return_slowpath(). With CONFIG_DEBUG_RSEQ, such behavior results in termination of the process with SIGSEGV. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Joel Fernandes <joelaf@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Dave Watson <davejwatson@fb.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: "H . Peter Anvin" <hpa@zytor.com> Cc: Chris Lameter <cl@linux.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Andrew Hunter <ahh@google.com> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com> Cc: Paul Turner <pjt@google.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Ben Maurer <bmaurer@fb.com> Cc: linux-api@vger.kernel.org Cc: Andy Lutomirski <luto@amacapital.net> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lkml.kernel.org/r/20180602124408.8430-7-mathieu.desnoyers@efficios.com
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/entry/common.c3
-rw-r--r--arch/x86/kernel/signal.c6
3 files changed, 10 insertions, 0 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1fe24b624d44..c320ce005b02 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -182,6 +182,7 @@ config X86
182 select HAVE_REGS_AND_STACK_ACCESS_API 182 select HAVE_REGS_AND_STACK_ACCESS_API
183 select HAVE_RELIABLE_STACKTRACE if X86_64 && UNWINDER_FRAME_POINTER && STACK_VALIDATION 183 select HAVE_RELIABLE_STACKTRACE if X86_64 && UNWINDER_FRAME_POINTER && STACK_VALIDATION
184 select HAVE_STACK_VALIDATION if X86_64 184 select HAVE_STACK_VALIDATION if X86_64
185 select HAVE_RSEQ
185 select HAVE_SYSCALL_TRACEPOINTS 186 select HAVE_SYSCALL_TRACEPOINTS
186 select HAVE_UNSTABLE_SCHED_CLOCK 187 select HAVE_UNSTABLE_SCHED_CLOCK
187 select HAVE_USER_RETURN_NOTIFIER 188 select HAVE_USER_RETURN_NOTIFIER
diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index fbf6a6c3fd2d..92190879b228 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -164,6 +164,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
164 if (cached_flags & _TIF_NOTIFY_RESUME) { 164 if (cached_flags & _TIF_NOTIFY_RESUME) {
165 clear_thread_flag(TIF_NOTIFY_RESUME); 165 clear_thread_flag(TIF_NOTIFY_RESUME);
166 tracehook_notify_resume(regs); 166 tracehook_notify_resume(regs);
167 rseq_handle_notify_resume(regs);
167 } 168 }
168 169
169 if (cached_flags & _TIF_USER_RETURN_NOTIFY) 170 if (cached_flags & _TIF_USER_RETURN_NOTIFY)
@@ -254,6 +255,8 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs)
254 WARN(irqs_disabled(), "syscall %ld left IRQs disabled", regs->orig_ax)) 255 WARN(irqs_disabled(), "syscall %ld left IRQs disabled", regs->orig_ax))
255 local_irq_enable(); 256 local_irq_enable();
256 257
258 rseq_syscall(regs);
259
257 /* 260 /*
258 * First do one-time work. If these work items are enabled, we 261 * First do one-time work. If these work items are enabled, we
259 * want to run them exactly once per syscall exit with IRQs on. 262 * want to run them exactly once per syscall exit with IRQs on.
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index da270b95fe4d..445ca11ff863 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -688,6 +688,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
688 sigset_t *set = sigmask_to_save(); 688 sigset_t *set = sigmask_to_save();
689 compat_sigset_t *cset = (compat_sigset_t *) set; 689 compat_sigset_t *cset = (compat_sigset_t *) set;
690 690
691 /*
692 * Increment event counter and perform fixup for the pre-signal
693 * frame.
694 */
695 rseq_signal_deliver(regs);
696
691 /* Set up the stack frame */ 697 /* Set up the stack frame */
692 if (is_ia32_frame(ksig)) { 698 if (is_ia32_frame(ksig)) {
693 if (ksig->ka.sa.sa_flags & SA_SIGINFO) 699 if (ksig->ka.sa.sa_flags & SA_SIGINFO)