From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D2F4C352BE for ; Fri, 17 Apr 2020 14:46:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 497532076A for ; Fri, 17 Apr 2020 14:46:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fvRRL6Ua" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 497532076A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uzqbuQ0GFqIYpYobrkKedRlKyUMgEzPR6j6tP7HJ2/Y=; b=fvRRL6UaGr+vRV TAtEbDA6aFv5qXYt+okEWjvRFEjx3KudHbWLuhT8lFlsMgqQNYESTKpPFa30mlErqaVwfqRnEBhCz 4Kye2ZI7w3FcGY3aY92nUtx4Op5CrHbsVBrxix2Al7BwFg3bxYKwzdZ139pv7EMwdmAcsTcsBONB3 9Jb/KgQ8vF9auMl3UWEhp1oReE67rfo+nbojDbloXORFQTW1ttBCcMyGwWWbEjZkHnhcoym6UOXiG l4THQimCquyQylQ4swASM+2Ko6L+s68t0LRSJuJbN3buTjkXI/Mt1SrmlUi4uPaXr7rZCZ6qJZaBS EK8gLesC39Iv7+ru7vsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPSGL-00010X-9w; Fri, 17 Apr 2020 14:46:37 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPSGJ-0000zP-3i for linux-arm-kernel@lists.infradead.org; Fri, 17 Apr 2020 14:46:36 +0000 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 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-Disposition: inline In-Reply-To: <20200417100039.GS20730@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200417_074635_240610_220992E3 X-CRM114-Status: GOOD ( 30.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , kernel-hardening@lists.openwall.com, Catalin Marinas , Will Deacon , Marc Zyngier , Masahiro Yamada , clang-built-linux@googlegroups.com, Ingo Molnar , Sami Tolvanen , Laura Abbott , Dave Martin , Kees Cook , Jann Horn , Steven Rostedt , linux-arm-kernel@lists.infradead.org, Michal Marek , Ard Biesheuvel , Nick Desaulniers , linux-kernel@vger.kernel.org, Miguel Ojeda , James Morse , Masami Hiramatsu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel