Received: by 10.192.165.148 with SMTP id m20csp4293451imm; Mon, 30 Apr 2018 15:45:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrpBINQHw2tJeiCX35eleLyjOJ/UN/r9CzT0ZV5JbG8193hON3QQI2ScCEo7DRDcieTf08D X-Received: by 10.98.227.15 with SMTP id g15mr13626430pfh.68.1525128327988; Mon, 30 Apr 2018 15:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525128327; cv=none; d=google.com; s=arc-20160816; b=y7ejvBwcADOHXvVt74wOYtD+cVhooQjBPnmfFckEYsS4dl05eaUUkfsZcN6nAXdH12 GquuKp8GdWjUJEEG3aFjfs1/gXhTvtKz/y/3+4vGLgK7ACad0D6DzCQEwKI8f++HZ9Ph ctgKC+HrPS1eAIm2Wep7ls9DSsAhOb742mToH/+EGSBZZS8HAsEsgXavPGoXSMz/yZpp hi8B0Pe95a/diUMPUVKDaiDeDirgANktwVYHLFpeAz0yV2P7RtWdIBuHEjIjYr01u5mA yQDrCj0S05gZmA79MQ3FbGc4Enfg3LtE3OOHrqGTo0DV51qwStzd5XZtEZVHS/sYCDte GS8g== 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=YkFbF2OM8WXZNDSEu91KK5MMAGPpHVIbGWzr28eZMOs=; b=UsfDWU9LLd099pItnupnwEKLqvLDsK731jlNcC4tyi+IZQ6kES5x1TSe9mxjkGHwlo ECwpMw4uBDn+s+Azx2Ui6BvaGO0oYI86n0XPzXuFB5AD8cTuUUHclXiH+H1kVOSnNowO Qd3X+P5gdg3sfn3TLZ+Wbz7ALGke3O5SS8Q36rf8wowUzB9yB3zzIl2ijfZKnCe4HjVe a4dmghke+TTQT1yoyOiwri01NFL5Se+VLwyT1nRPVTRcMdaBb7kzqYsfnhO/+cr6WDMl hDQtlvX4AZ05ePj6kfoAjB/njjr4OhDtE3zFznxQywCFjb5f6yG8mgydadoPyIMocDSI ejiQ== 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 y4-v6si3838387pgc.588.2018.04.30.15.45.13; Mon, 30 Apr 2018 15:45:27 -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 S1755557AbeD3Wox (ORCPT + 99 others); Mon, 30 Apr 2018 18:44:53 -0400 Received: from mail.efficios.com ([167.114.142.138]:52980 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755379AbeD3Wop (ORCPT ); Mon, 30 Apr 2018 18:44:45 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C946D1A62CB; Mon, 30 Apr 2018 18:44:44 -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 wlHTdBjDLPso; Mon, 30 Apr 2018 18:44:44 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 67B7D1A62BA; Mon, 30 Apr 2018 18:44:44 -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 wTrdT5fsAHOb; Mon, 30 Apr 2018 18:44:44 -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 099811A6286; Mon, 30 Apr 2018 18:44:44 -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 , Joel Fernandes , Mathieu Desnoyers Subject: [PATCH 05/14] x86: Add support for restartable sequences (v2) Date: Mon, 30 Apr 2018 18:44:24 -0400 Message-Id: <20180430224433.17407-6-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> References: <20180430224433.17407-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 c07f492b871a..62e00a1a7cf7 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -180,6 +180,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 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) 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 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) 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