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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C1AD0C433EF for ; Tue, 22 Feb 2022 16:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc: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=GSkj5ZkXjdJ9jIp/kraGcf2LEYBawCGiDaNO8byA0oI=; b=jlispOnm271Xe0 9eZxh9M0GRRJx0y+b9U/fveYf5gZXtacztYsB7S+FpmecD1OelowafzsVLj12vwec268gUOvV2qow zrnNzrSrG6mFD8lvG15/9tb3kEaPMOID+bxIW1EAFo3ldIzq08RJAvcOOAXuwAYP4CGXq27P0b9rZ ygl1jl1hyG/JmlmxzRr+9xY3CpSqxFQiC8h3+jO97QQCjgxLq0jNlMlRIcvqOGX4DICBBhU3LzDBk HP03dT+VVWdO2CDvuaV28vbXavcihF1Y5RB8ROObLX+yox5T6Y3ZPsbeKzNWGa9YzHGh9PiQSO2OG OTukoEDUGyFT4vxaICqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMXpt-00AaMm-GA; Tue, 22 Feb 2022 16:16:21 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMXpn-00AaKm-Es for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 16:16:19 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 21DD8B81B77; Tue, 22 Feb 2022 16:16:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4680EC340E8; Tue, 22 Feb 2022 16:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645546572; bh=cw0B3xLAFu8eNbwEcUhRaoqQRgX+dp6zyPu8ZZdGJEk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qj86MVS/KFRmoD+RX0XD9c17t6PhYBpAVK2L0e5Q9rEYYmGvy3lPSYVHbxwcCipPP HVYOBhnbW7+HWqQCFQZkCV9g3uLtuiH5ui5FHaf8E/FtjfyDPnHdqw9bHUOddo/n7e QrjcN4gNhqxsmIXws4gG9YN4zhuZJ50zuVJkj7ZPRccPHeJyZReHlXF6Vuy+yGiiI+ 4xKcSV2iHrUsDkzQehs9UCoZ+/ttImhKiJGLJgZPsl6BZWb+isFSFWKJu6+DzBYADd pGceMxRln8XU6aDGRzJLfXkXnaX5UYpkRgZdycqMmQeoi9zdGGLMvN0xm+aJ+/A60G vaN3NGqhSrlwQ== Date: Tue, 22 Feb 2022 09:16:06 -0700 From: Nathan Chancellor To: Dan Li Cc: catalin.marinas@arm.com, will@kernel.org, ndesaulniers@google.com, keescook@chromium.org, masahiroy@kernel.org, tglx@linutronix.de, akpm@linux-foundation.org, mark.rutland@arm.com, samitolvanen@google.com, npiggin@gmail.com, linux@roeck-us.net, mhiramat@kernel.org, ojeda@kernel.org, luc.vanoostenryck@gmail.com, elver@google.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH] [PATCH] AARCH64: Add gcc Shadow Call Stack support Message-ID: References: <20220222095736.24898-1-ashimida@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220222095736.24898-1-ashimida@linux.alibaba.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220222_081615_819291_2F1A1A92 X-CRM114-Status: GOOD ( 27.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Feb 22, 2022 at 01:57:36AM -0800, Dan Li wrote: > Shadow call stack is available in GCC > 11.2.0, this patch makes > the corresponding kernel configuration available when compiling > the kernel with gcc. > > Note that the implementation in GCC is slightly different from Clang. > With SCS enabled, functions will only pop x30 once in the epilogue, > like: > > str x30, [x18], #8 > stp x29, x30, [sp, #-16]! > ...... > - ldp x29, x30, [sp], #16 //clang > + ldr x29, [sp], #16 //GCC > ldr x30, [x18, #-8]! > > Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ce09ab17ddd21f73ff2caf6eec3b0ee9b0e1a11e > > Signed-off-by: Dan Li Reviewed-by: Nathan Chancellor A few open-ended comments below. > --- > FYI: > This function can be used to test if the shadow call stack works: > //noinline void __noscs scs_test(void) > noinline void scs_test(void) > { > register unsigned long *sp asm("sp"); > unsigned long * lr = sp + 1; > > asm volatile("":::"x30"); > *lr = 0; > } > > ffff800008012704: d503233f paciasp > ffff800008012708: f800865e str x30, [x18], #8 > ffff80000801270c: a9bf7bfd stp x29, x30, [sp, #-16]! > ffff800008012710: 910003fd mov x29, sp > ffff800008012714: 910003e0 mov x0, sp > ffff800008012718: f900041f str xzr, [x0, #8] > ffff80000801271c: f85f8e5e ldr x30, [x18, #-8]! > ffff800008012720: f84107fd ldr x29, [sp], #16 > ffff800008012724: d50323bf autiasp > ffff800008012728: d65f03c0 ret > > If SCS protection is enabled, this function will return normally. > If the function has __noscs attribute (scs disabled), it will crash due to 0 > address access. > > arch/Kconfig | 6 +++--- > arch/arm64/Kconfig | 2 +- > include/linux/compiler-gcc.h | 4 ++++ > 3 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/Kconfig b/arch/Kconfig > index 678a80713b21..35db7b72bdb0 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -604,11 +604,11 @@ config ARCH_SUPPORTS_SHADOW_CALL_STACK > switching. > > config SHADOW_CALL_STACK > - bool "Clang Shadow Call Stack" > - depends on CC_IS_CLANG && ARCH_SUPPORTS_SHADOW_CALL_STACK > + bool "Shadow Call Stack" > + depends on ARCH_SUPPORTS_SHADOW_CALL_STACK > depends on DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER > help > - This option enables Clang's Shadow Call Stack, which uses a > + This option enables Clang/GCC's Shadow Call Stack, which uses a I wonder if we want to just ditch the mention of the compiler if both support it? > shadow stack to protect function return addresses from being > overwritten by an attacker. More information can be found in > Clang's documentation: > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 09b885cc4db5..a48a604301aa 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -1255,7 +1255,7 @@ config HW_PERF_EVENTS > config ARCH_HAS_FILTER_PGPROT > def_bool y > > -# Supported by clang >= 7.0 > +# Supported by clang >= 7.0 or GCC > 11.2.0 Same thing here, although eventually there may be a minimum GCC version bump to something newer than 11.2.0, which would allow us to just drop CONFIG_CC_HAVE_SHADOW_CALL_STACK altogether. No strong opinion. > config CC_HAVE_SHADOW_CALL_STACK > def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18) > > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h > index ccbbd31b3aae..deff5b308470 100644 > --- a/include/linux/compiler-gcc.h > +++ b/include/linux/compiler-gcc.h > @@ -97,6 +97,10 @@ > #define KASAN_ABI_VERSION 4 > #endif > > +#ifdef CONFIG_SHADOW_CALL_STACK > +#define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) > +#endif > + > #if __has_attribute(__no_sanitize_address__) > #define __no_sanitize_address __attribute__((no_sanitize_address)) > #else > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel