Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp390096ybz; Fri, 17 Apr 2020 03:04:54 -0700 (PDT) X-Google-Smtp-Source: APiQypIpIaEc28azN+ArQqk02r2hgQi2OYJ8gmya6gHSBtg3Y2Z2kFTWLgMsElSe7zMSBs1GQwPT X-Received: by 2002:a17:907:11de:: with SMTP id va30mr2225961ejb.121.1587117894795; Fri, 17 Apr 2020 03:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587117894; cv=none; d=google.com; s=arc-20160816; b=dHAIXgd4Av1mykwpHCvEcvrFSC3xFeHQrWW4sQOfl0Eg/I1rXdeTsjvsEu/We2pAd0 DH/87amwkNvYC9u0sIOAN+oypr8BAOfP+JSyJbqHwHocfl7DwfI0KBw2046pDIGl0JNY xzOO5xfoNYodQSwyiX3TRUPkB5WyjD8uVGYlwLKHtMay/HWVKNy78Y8rUd9YDqkjPCz2 UT42jNpy51sKA5sI7hMAiqAzIhdjYPqP9fzNhk+/uSnmCiXsrycpwsz5tpJXdLF+IquF eA3GlULykGlfTMrgVLwvQDuIfJ5/JCLsJlECR4Db6txfAIl27pFXjHRREaxiXh0Kkl5T /AxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=/sCrLJsk9M0RFgQwNkauJ/Dtc5/K6rCJg0npReZJ/ZM=; b=LGmRkAR6bsHD1O0O7E67hQrZ6TpoaRrFnBB+rz09MgydRux5VTuTFcxVjIMhSdCxJg CEkXJx2glrvyBH/8tViETjoJZM4MUQirna6BkXAD0FstFzpRCtEg/4r6rHV/YM9JnHQu UFyQwD4I59zcEqgN7mdIj3KIK4WopV09qBPEOoWtJVN+qiUSyG0LB4povNTIjFv1LUhl 0aF5m4gs81U3+mXjgKTsdSf2SSDwKDEgObQ3Z3JADvFPDc6csYS/QRrurJ2HJnwVFVGJ 7hGc8nplCtljG0PuGKOWVrgeP1NHlkVEdEmkpcNCQQ4roaxhybV/TGwAwGYZ71RaRL6n rOmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=G25zyJyL; 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 i13si16577263edt.174.2020.04.17.03.04.30; Fri, 17 Apr 2020 03:04:54 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=G25zyJyL; 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 S1727840AbgDQKBW (ORCPT + 99 others); Fri, 17 Apr 2020 06:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726207AbgDQKBV (ORCPT ); Fri, 17 Apr 2020 06:01:21 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6E52C061A0C for ; Fri, 17 Apr 2020 03:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/sCrLJsk9M0RFgQwNkauJ/Dtc5/K6rCJg0npReZJ/ZM=; b=G25zyJyLZs4ijof9NKQ93s/RtD tp1CABmZSWsvURGWx1WS3YUul4JFfkwKfPlMdOUMLdf0WJVJTQmYH7kEnhXsJQOx0kyS3h3w+4g5E s+xd6331OtUvGqwz0rttWZMMrZR+P8JR5WVKgcxW9SWh1X+w7ZXxIONjudPt4TumeaAQPaOiHvfJf hqJFmA4o3d/ICe7K81YdhfKX/Cu65J5gdmf91MuW2YmlJLqzGWkPWtZYiYRHVPbv0K/7xLORS8GtG SAJt6bXYa7kxdX69qaFDx4rwpwhNl0i+c4WbpER2GL+jX2fzS/+iDQNUr+t6P36U7llVMhvrYMKxh yu548iOQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPNne-000501-Rg; Fri, 17 Apr 2020 10:00:43 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 816003010BC; Fri, 17 Apr 2020 12:00:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6AB682B120750; Fri, 17 Apr 2020 12:00:39 +0200 (CEST) Date: Fri, 17 Apr 2020 12:00:39 +0200 From: Peter Zijlstra To: Sami Tolvanen Cc: Will Deacon , Catalin Marinas , James Morse , Steven Rostedt , Ard Biesheuvel , Mark Rutland , 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: <20200417100039.GS20730@hirez.programming.kicks-ass.net> References: <20191018161033.261971-1-samitolvanen@google.com> <20200416161245.148813-1-samitolvanen@google.com> <20200416161245.148813-5-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200416161245.148813-5-samitolvanen@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. And doesn't BPF also do stuff like this?