Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp657480ybz; Fri, 17 Apr 2020 07:48:17 -0700 (PDT) X-Google-Smtp-Source: APiQypKM6Cle9AQ9RkYaKVwVijfxxJhyYv1EcpVHJE3thYf4g1iqax9CjDR/UgJXj0dIOyltZ03N X-Received: by 2002:aa7:ca55:: with SMTP id j21mr3179504edt.86.1587134897059; Fri, 17 Apr 2020 07:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587134897; cv=none; d=google.com; s=arc-20160816; b=ZJmd0KkGpXXGZBewyjx7Hbrs4XLBQqAmO9eDxXUxMyQD44wCNgnLPvDm7cDrAjvpAX Abi1LzMBnwsgd1el/sZwPEaAvsCTpJJt5Urj3fW7kF+gJg104LtiGj+B7vpXsv6Lg3B0 1O5wiQHZ68MUG5ONRG39IhkbRaQNzYSNFfMR6Qy13XKETzjbn+lOZz4oOA62T0sFgrQY tc/1WW2+bFkK1fqUn80zrQ9BlPsEHWuPWwtXRgf5xwZYxmttZcMnUcgmuvrCfYLcmKij l+6Ds0PCD5DzL2XJhyzJwFho25GB8X67Ot7B6NNVde6joWvImHwYMYSdVW7kS6xbXOHW tQ5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=YGMj6dKGSxT1U2ErpaPB7YOtpxfEhby8o9pUafCfEIg=; b=HavN1amFlHTRk39PSfIEeUQN/8BbqVs3dH9qEbhnU5ZYh6yBX1DaCDf7lryHldB37O 0iE3BMLjziqs0AZNK3wIX9wFba8I9eLmqsyOTkXRw/2aITopwc7eTlU26C2Mnm1e66CP z4h3U8U6+iiXC/Ja/Tsl/D5x7Gr027JNBDXXwX70vgVrBPxUaUurQVij2helN7sN0CZL mLIffvKZ5HRE7nX+y4ic/U/Oguv4U46jAbCIYJui8k4C77eDOxz4PpeqLa0Gdi/oQkWI DyQwwQHZJ/N5+03K0Sw87LAq2bLxBix5pjA5AidWh7EfOx9wt0v0bPdQsr/Q3GQwGQvv MG2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q14si14364985edi.65.2020.04.17.07.47.53; Fri, 17 Apr 2020 07:48:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728104AbgDQOqf (ORCPT + 99 others); Fri, 17 Apr 2020 10:46:35 -0400 Received: from foss.arm.com ([217.140.110.172]:52198 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726707AbgDQOqe (ORCPT ); Fri, 17 Apr 2020 10:46:34 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D964330E; Fri, 17 Apr 2020 07:46:33 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 061A33F73D; Fri, 17 Apr 2020 07:46:30 -0700 (PDT) Date: Fri, 17 Apr 2020 15:46:21 +0100 From: Mark Rutland To: Peter Zijlstra Cc: Sami Tolvanen , Will Deacon , Catalin Marinas , James Morse , Steven Rostedt , Ard Biesheuvel , Masahiro Yamada , Michal Marek , Ingo Molnar , Juri Lelli , Vincent Guittot , Dave Martin , Kees Cook , Laura Abbott , Marc Zyngier , Masami Hiramatsu , Nick Desaulniers , Jann Horn , Miguel Ojeda , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v11 04/12] scs: disable when function graph tracing is enabled Message-ID: <20200417144620.GA9529@lakrids.cambridge.arm.com> References: <20191018161033.261971-1-samitolvanen@google.com> <20200416161245.148813-1-samitolvanen@google.com> <20200416161245.148813-5-samitolvanen@google.com> <20200417100039.GS20730@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200417100039.GS20730@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On Fri, Apr 17, 2020 at 12:00:39PM +0200, Peter Zijlstra wrote: > On Thu, Apr 16, 2020 at 09:12:37AM -0700, Sami Tolvanen wrote: > > The graph tracer hooks returns by modifying frame records on the > > (regular) stack, but with SCS the return address is taken from the > > shadow stack, and the value in the frame record has no effect. As we > > don't currently have a mechanism to determine the corresponding slot > > on the shadow stack (and to pass this through the ftrace > > infrastructure), for now let's disable SCS when the graph tracer is > > enabled. > > > > With SCS the return address is taken from the shadow stack and the > > value in the frame record has no effect. The mcount based graph tracer > > hooks returns by modifying frame records on the (regular) stack, and > > thus is not compatible. The patchable-function-entry graph tracer > > used for DYNAMIC_FTRACE_WITH_REGS modifies the LR before it is saved > > to the shadow stack, and is compatible. > > > > Modifying the mcount based graph tracer to work with SCS would require > > a mechanism to determine the corresponding slot on the shadow stack > > (and to pass this through the ftrace infrastructure), and we expect > > that everyone will eventually move to the patchable-function-entry > > based graph tracer anyway, so for now let's disable SCS when the > > mcount-based graph tracer is enabled. > > > > SCS and patchable-function-entry are both supported from LLVM 10.x. > > SCS would actually provide another way to do return hooking. An arguably > much saner model at that. > > The 'normal' way is to (temporary) replace the on-stack return value, > and then replace it back in the return handler. This is because we can't > simply push a fake return on the stack, because that would wreck the > expected stack layout of the regular function. > > But there is nothing that would stop us from pushing an extra entry on > the SCS. It would in fact be a much cleaner solution. The entry hook > sticks an extra entry on the SCS, the function ignores what's on the > normal stack and pops from the SCS, we return to the exit handler, which > in turn pops from the SCS stack at which point we're back to regular. For background: on arm64 we wanted to use DYNAMIC_FTRACE_WITH_REGS since we already have to use that to handle pointer authentication, and didn't want to gain more ways of implementing ftrace. Arguably we should move the dependency into the arm64 Kconfig for ARCH_SUPPORTS_SHADOW_CALL_STACK. > The only 'funny' is that the exit handler itself should not push to the > SCS, or we should frob the return-to-exit-handler such that it lands > after the push. > > > Signed-off-by: Sami Tolvanen > > Reviewed-by: Kees Cook > > Reviewed-by: Mark Rutland > > --- > > arch/Kconfig | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/Kconfig b/arch/Kconfig > > index 691a552c2cc3..c53cb9025ad2 100644 > > --- a/arch/Kconfig > > +++ b/arch/Kconfig > > @@ -542,6 +542,7 @@ config ARCH_SUPPORTS_SHADOW_CALL_STACK > > > > config SHADOW_CALL_STACK > > bool "Clang Shadow Call Stack" > > + depends on DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER > > depends on ARCH_SUPPORTS_SHADOW_CALL_STACK > > help > > This option enables Clang's Shadow Call Stack, which uses a > AFAICT you also need to kill KRETPROBES, which plays similar games. Hmm... how does KREPROBES work? If you can only mess with the return address when probing the first instruction in the function, it'll just work for SCS or pointer authentication, as the LR is used at that instant. If KRETPROBES tries to mess with the return address elsewhere it'd be broken today... > And doesn't BPF also do stuff like this? Can BPF mess with return addresses now!? Thanks, Mark.