Received: by 10.213.65.68 with SMTP id h4csp1660945imn; Thu, 29 Mar 2018 08:41:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/QIn0l1w8Th02ptRhNWYd59BWzv487kLjsWLCrwv+miXQ7oR5lJzisX7I9LkSchfgZ7J4r X-Received: by 10.101.75.12 with SMTP id r12mr5848941pgq.36.1522338067779; Thu, 29 Mar 2018 08:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522338067; cv=none; d=google.com; s=arc-20160816; b=YSFJHhHL+J6dTgFwP/Zhy5AH5kMduxEsG32tuj7fwgvRftzfoWudO5hmj2H9kE9qrl PvlsJrbwQQjdFZRLr36LeOiTtIy0vDK8qqpROCU4GQP5gLzM/JTFf5mexuOPWeOyY8Xe AT4r44svLsLbKP6/4FNvhCkLSqnsrTd3RTnjFQRyU4K6B85QE9RXoIVM0KWQbBE0w4lu HE3QwNQSp024Jw0ltfz1Xy0RL3bUBkrPK9DNooUJbkA4kfboWGta8Mexv/lnItMW+FvG AG6QoM3wRmT7ByFWMqWa2xU9hK0dJt6/Qt8dXHtLQct2tHFlssq90gvuWJuvAE30qZ1c gbVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:arc-authentication-results; bh=MjJCfZfGYrFKOoV5iNoReUU8AcHumu4pD3JHuSJQZ3w=; b=xAG8+2RXpu1gYnBmZD/gkzFk0hKdYh4PaLnlnKyCwRr2WfCpeH/7/vqqSB4Hlwqa0N Ts+VugcssN9qTZXrGSyOZjQqXYPnDqWBK6SmWrSwZrXlBcm0XjBtZvmX70/9P/eLG+lP a25S/jFq+0XSnjb/+VMVkcwaxgRnOHc8mbyagnQfrdE1CALvyo+6cwzsJX6oCMM66alD GTXEhCHcu79QqrTg7xaecdDN9TXY6mA1g5y+jHXvv9CVRFlY01cI6k/ajvEU9eZ5RiaF tCVHLNa8vUTa8t0V+sBfblNGKbliyBxsaOuIfVsuUFHpV7MwfBm7GgctE7TSjbuzz5kD +RdQ== 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 135si4631424pfc.21.2018.03.29.08.40.53; Thu, 29 Mar 2018 08:41:07 -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 S1752246AbeC2PjE (ORCPT + 99 others); Thu, 29 Mar 2018 11:39:04 -0400 Received: from mail.efficios.com ([167.114.142.138]:43006 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751209AbeC2PjC (ORCPT ); Thu, 29 Mar 2018 11:39:02 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 02DBD1A94CC; Thu, 29 Mar 2018 11:39:02 -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 1EjNzYdsqmXV; Thu, 29 Mar 2018 11:39:01 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 4CF081A94BE; Thu, 29 Mar 2018 11:39:01 -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 0cc-BsWIuoqt; Thu, 29 Mar 2018 11:39:01 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 19A241A94B6; Thu, 29 Mar 2018 11:39:01 -0400 (EDT) Date: Thu, 29 Mar 2018 11:39:00 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: Thomas Gleixner , "Paul E. McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H. Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Alexander Viro Message-ID: <544124089.623.1522337940950.JavaMail.zimbra@efficios.com> In-Reply-To: <20180329142338.GD4043@hirez.programming.kicks-ass.net> References: <20180327160542.28457-1-mathieu.desnoyers@efficios.com> <20180328152814.GI4082@hirez.programming.kicks-ass.net> <533214853.56.1522251426819.JavaMail.zimbra@efficios.com> <20180328174935.GK4082@hirez.programming.kicks-ass.net> <181076499.279.1522268382303.JavaMail.zimbra@efficios.com> <87410797.545.1522331641598.JavaMail.zimbra@efficios.com> <20180329142338.GD4043@hirez.programming.kicks-ass.net> Subject: Re: [RFC PATCH for 4.17 02/21] rseq: Introduce restartable sequences system call (v12) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.7_GA_1964 (ZimbraWebClient - FF52 (Linux)/8.8.7_GA_1964) Thread-Topic: rseq: Introduce restartable sequences system call (v12) Thread-Index: qC/xnCwBJOliD3esxkq63c7Ywg8nxg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Mar 29, 2018, at 10:23 AM, Peter Zijlstra peterz@infradead.org wrote: > On Thu, Mar 29, 2018 at 09:54:01AM -0400, Mathieu Desnoyers wrote: >> Let's say we disallow system calls from rseq critical sections. A few points >> arise: >> >> - We still need to allow traps (page faults, breakpoints, ...) within rseq c.s., >> >> - We still need to allow interrupts within rseq c.s., > > Sure, but all those are different entry points, so that shouldn't be a > problem. Yes, indeed. > >> - We need to decide whether we just document that syscalls within rseq c.s. >> are not supported, or we enforce a behavior if this happens (e.g. SIGSEGV). >> If we enforce a SIGSEGV, we'd have to figure out whether it's worth it to >> add extra branches to the system call fast path to validate this. > > Without enforcement someone will eventually do this :/ We might (maybe) > get away with it being a debug option somewhere, but even that sounds > like trouble. I find it unlikely that someone will issue a syscall from a rseq critical section without really intending it. The system call would need to be crafted within the rseq assembly block. Enforcing SIGSEGV on syscall entry when nested in a rseq critical section will not be free both in terms of syscall overhead, and in terms of code maintenance: we'd need to add those checks into entry.S for each architecture supported, which pretty much doubles the amount of architecture-specific code we need to implement for rseq. Currently, all we need is to hook in signal delivery and wire up the system call numbers. If there is some clever arch-agnostic way to enforce SIGSEGV in those situations, I'm all ears. But I don't think it's worthwhile to enforce this if it costs in terms of system call speed and adds extra arch-specific code to maintain. We could simply document that issuing a system call within a rseq critical section will cause the restart behavior (whether the critical section is restarted or not) to be undefined. > >> - We need to carefully consider the case of system calls issued within signal >> handlers nested on top of rseq. When RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL is >> _not_ set, neither in the rseq c.s. descriptor nor in the TLS @flags, >> it's pretty much straightforward: upon signal delivery, the kernel moves the >> ip to abort, and clears the tls @rseq_cs pointer. This means that any system >> call issued within the signal handler is not actually within the rseq c.s. >> upon which the signal is nested. >> >> The case I worry about is if a thread sets the RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL >> flag in its TLS @flags field (useful in a debugging scenario where we want a >> debugger to single-step through the rseq c.s. and observe registers at each >> step). >> Arguably, this is only ever used in development. However, it does allow a >> situation >> where a system call executed within a signal handler can nest over a rseq c.s.. >> So if we choose to be very strict and SIGSEGV any syscall nested over rseq >> c.s., we may very well end up killing the process for no good reason in this >> scenario. > > Yes, that needs a little thought; but when we run the signal handler, > the IP would no longer be inside the active RSEQ, right? Good point, I missed that. So yes, even with the RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL flag set, the instruction pointer comparison would detect that we're not actually running in the rseq critical section if a syscall is issued from the signal handler. > >> - We need to decide whether all syscalls are disallowed, or if we want to pick >> specific ones (e.g. fork()). > > All. I'm fine with that. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com