Received: by 10.192.165.156 with SMTP id m28csp2339935imm; Thu, 12 Apr 2018 12:36:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+zlRJ38U9nX0EntgNFioy6m2ciMCyLgFaM2Er9CHSyUpSPJsbgK6ibGcxTOwxbBw/cOZKX X-Received: by 10.101.99.66 with SMTP id p2mr1682547pgv.286.1523561774413; Thu, 12 Apr 2018 12:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523561774; cv=none; d=google.com; s=arc-20160816; b=uTXcJKSsqrOe9Vt1aRJ/s8eYuAKBJ/Irya4IPMXfd3uZQEdrfv/EJYb0cQ9qlP3JKT vA9l39lyqiQZkD+xVD9fRNcA0MukKHenWIwGOEOpmf5t7IhlP+DmvbXIS/7Kh1HGMcTj +AOYRle18JDnQ6ZIMDthg1kbttkUYhcTgw/m7vNQM4AXaKzsg9g8C7cKLTIrvpgMFSHV FYdKgv9YIxyP2/DX0awvqvDsC7dKL1pzUUUt9usoG1DdZ4t3bhaUXS0Gm7RVZaP7j+6C DQY+Hnti4KHudIrEF9GnGhOd3+K5i1C1tmNasYvNYuk5E8UH6bpHQ3fwwQZPdP+WaTAg Li4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=4EX2kx7fJYaxkUVaZ26eSF5QEPwn4LstqCqXO13XhaQ=; b=s/JT3tROoHiBNJ40BLeposYtOgh4xjO01tlh2DuJazq3+Cc4RfohPYtRdgzrcE9Oav 0YNHFtzgeRIWRmFgYGdd/zqQYP8HD5kFwNmf93lvzFgyE4cVRVP3fCgFygF6tswtoeUU +jzZXUbJzxqcmQ9AdXdhwPXrUlWAnAbuOuslFaMAYK7iYVq/BEXnDx8ozbOoYbwY4wJD XtGUylTdWmGCm7Yqw7Vw+wGCf8Ky5OyS69sDRmm6RsNpDwh1pW4v6G7QHTSiaPIIhPTr 4UO/N8lK8uNbVHmWQGzcA6vg6djEDx7Ts1RfcWuHqXkOGxoAoq6o52W9E65ion9OuKJu 3v0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1-v6si3835715pld.255.2018.04.12.12.36.00; Thu, 12 Apr 2018 12:36:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754078AbeDLTdE (ORCPT + 99 others); Thu, 12 Apr 2018 15:33:04 -0400 Received: from mail.efficios.com ([167.114.142.138]:45580 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753058AbeDLT2W (ORCPT ); Thu, 12 Apr 2018 15:28:22 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C1E6B1B06B6; Thu, 12 Apr 2018 15:28:21 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id AUtSuqCr63SZ; Thu, 12 Apr 2018 15:28:21 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 5DEB91B06A9; Thu, 12 Apr 2018 15:28:21 -0400 (EDT) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ZasDDRgEltdK; Thu, 12 Apr 2018 15:28:21 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id F41241B0695; Thu, 12 Apr 2018 15:28:20 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra , "Paul E . McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Mathieu Desnoyers Subject: [RFC PATCH for 4.18 05/23] x86: Add support for restartable sequences (v2) Date: Thu, 12 Apr 2018 15:27:42 -0400 Message-Id: <20180412192800.15708-6-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180412192800.15708-1-mathieu.desnoyers@efficios.com> References: <20180412192800.15708-1-mathieu.desnoyers@efficios.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Thomas Gleixner CC: Russell King CC: Catalin Marinas CC: Will Deacon CC: Paul Turner CC: Andrew Hunter CC: Peter Zijlstra CC: Andy Lutomirski CC: Andi Kleen CC: Dave Watson CC: Chris Lameter CC: Ingo Molnar CC: "H. Peter Anvin" CC: Ben Maurer CC: Steven Rostedt CC: "Paul E. McKenney" CC: Josh Triplett CC: Linus Torvalds CC: Andrew Morton CC: Boqun Feng CC: linux-api@vger.kernel.org --- Changes since v1: - Call rseq_signal() when returning from a system call. --- arch/x86/Kconfig | 1 + arch/x86/entry/common.c | 3 +++ arch/x86/kernel/signal.c | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 0fa71a78ec99..47a2b14fcc7d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -178,6 +178,7 @@ config X86 select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if X86_64 && UNWINDER_FRAME_POINTER && STACK_VALIDATION select HAVE_STACK_VALIDATION if X86_64 + select HAVE_RSEQ select HAVE_SYSCALL_TRACEPOINTS select HAVE_UNSTABLE_SCHED_CLOCK select HAVE_USER_RETURN_NOTIFIER diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 74f6eee15179..5bc9c9fe49c4 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) if (cached_flags & _TIF_NOTIFY_RESUME) { clear_thread_flag(TIF_NOTIFY_RESUME); tracehook_notify_resume(regs); + rseq_handle_notify_resume(regs); } if (cached_flags & _TIF_USER_RETURN_NOTIFY) @@ -254,6 +255,8 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs) WARN(irqs_disabled(), "syscall %ld left IRQs disabled", regs->orig_ax)) local_irq_enable(); + rseq_syscall(regs); + /* * First do one-time work. If these work items are enabled, we * 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 4cdc0b27ec82..0f549cbd8b46 100644 --- a/arch/x86/kernel/signal.c +++ b/arch/x86/kernel/signal.c @@ -687,6 +687,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs) sigset_t *set = sigmask_to_save(); compat_sigset_t *cset = (compat_sigset_t *) set; + /* + * Increment event counter and perform fixup for the pre-signal + * frame. + */ + rseq_signal_deliver(regs); + /* Set up the stack frame */ if (is_ia32_frame(ksig)) { if (ksig->ka.sa.sa_flags & SA_SIGINFO) -- 2.11.0