Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4633729ybc; Fri, 15 Nov 2019 07:41:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxUUTqr2V5Pwdej+/gRLvervPMHjL3/MCwlFMyxRpjFS5n0LmdRixyI5CZ73SCZH3aDr4WQ X-Received: by 2002:a1c:7e91:: with SMTP id z139mr15464645wmc.15.1573832499335; Fri, 15 Nov 2019 07:41:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573832499; cv=none; d=google.com; s=arc-20160816; b=m1daY6GJfp/n5COrQi4K302XBvivjAKy1+bW91kvUSWTJcqytQKd5vmTpOfAVPcoNh Nfd/o8fTTeHFdVvRsB3QKSY7J1ENwN11yjmyq2SUdOMjTjcyrGmPtYxeyLu8eV+4Lbfz kIL+o2tAkspNhZpnNx2AvWkdVj49FXjkgKon7qGz03jlj63tOrC4kAixhxIEPSzUy2y/ rCeReIegvelzHfm6rOrVOgTX2qBZ4ONv6teIrynmxD/wL9xf6BtA0i5L3r1OEhSGjY1a A5O3tLN7SIuMzjJFIgd72+lLGyJan6wHU2KQyQ5PYxg7TQ7BY2WoeB0bnYbudo3eHcYY BaPg== 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=KBb2GGkXr6gwJrFH25//TGaFkCKCltS/vm5mDCZYYL0=; b=Vkeynz3u1Yit78ZR7jCYAr9GXbdv65DbJLlR0oSbrZu+reVacPdNkx/A0CV+P7W0rE SLfgJz5lIU4tBWPDCzklJQjrL4XPE4wZM8vhCfuVw+suMI+CWtBZQqdcOvhKNA5Ly1+a AGiSbCQEa91gyPTRJiE1UEHPROps5KLfFgDu/spD42ikBxxVYCWjZMmdbhlJX+pYENU5 f8bvKb5RefqGG5ZsKKs/78zVb8LmbXh7bZDfzSWmQl/kg9HQ6h7Z5RsXtmW19nKqNRwA yrUPfBC2j49Lkx0DayzY+W7YvKvoFe9NVmZGSxcmI0Z293k1/KhP/OmYufRpZeunKmq+ 1udQ== 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 a11si8257803edj.143.2019.11.15.07.41.13; Fri, 15 Nov 2019 07:41:39 -0800 (PST) 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 S1727671AbfKOPhL (ORCPT + 99 others); Fri, 15 Nov 2019 10:37:11 -0500 Received: from foss.arm.com ([217.140.110.172]:32918 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfKOPhL (ORCPT ); Fri, 15 Nov 2019 10:37:11 -0500 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 A421530E; Fri, 15 Nov 2019 07:37:10 -0800 (PST) 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 6B1103F534; Fri, 15 Nov 2019 07:37:08 -0800 (PST) Date: Fri, 15 Nov 2019 15:37:06 +0000 From: Mark Rutland To: Sami Tolvanen Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 05/14] add support for Clang's Shadow Call Stack (SCS) Message-ID: <20191115153705.GJ41572@lakrids.cambridge.arm.com> References: <20191018161033.261971-1-samitolvanen@google.com> <20191105235608.107702-1-samitolvanen@google.com> <20191105235608.107702-6-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191105235608.107702-6-samitolvanen@google.com> 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 On Tue, Nov 05, 2019 at 03:55:59PM -0800, Sami Tolvanen wrote: > This change adds generic support for Clang's Shadow Call Stack, > which uses a shadow stack to protect return addresses from being > overwritten by an attacker. Details are available here: > > https://clang.llvm.org/docs/ShadowCallStack.html > > Note that security guarantees in the kernel differ from the > ones documented for user space. The kernel must store addresses > of shadow stacks used by other tasks and interrupt handlers in > memory, which means an attacker capable reading and writing > arbitrary memory may be able to locate them and hijack control > flow by modifying shadow stacks that are not currently in use. > > Signed-off-by: Sami Tolvanen > Reviewed-by: Kees Cook > Reviewed-by: Miguel Ojeda > --- > Makefile | 6 ++ > arch/Kconfig | 33 ++++++ > include/linux/compiler-clang.h | 6 ++ > include/linux/compiler_types.h | 4 + > include/linux/scs.h | 57 ++++++++++ > init/init_task.c | 8 ++ > kernel/Makefile | 1 + > kernel/fork.c | 9 ++ > kernel/sched/core.c | 2 + > kernel/scs.c | 187 +++++++++++++++++++++++++++++++++ > 10 files changed, 313 insertions(+) > create mode 100644 include/linux/scs.h > create mode 100644 kernel/scs.c > > diff --git a/Makefile b/Makefile > index b37d0e8fc61d..7f3a4c5c7dcc 100644 > --- a/Makefile > +++ b/Makefile > @@ -846,6 +846,12 @@ ifdef CONFIG_LIVEPATCH > KBUILD_CFLAGS += $(call cc-option, -flive-patching=inline-clone) > endif > > +ifdef CONFIG_SHADOW_CALL_STACK > +CC_FLAGS_SCS := -fsanitize=shadow-call-stack > +KBUILD_CFLAGS += $(CC_FLAGS_SCS) > +export CC_FLAGS_SCS > +endif > + > # arch Makefile may override CC so keep this after arch Makefile is included > NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) > > diff --git a/arch/Kconfig b/arch/Kconfig > index 5f8a5d84dbbe..5e34cbcd8d6a 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -521,6 +521,39 @@ config STACKPROTECTOR_STRONG > about 20% of all kernel functions, which increases the kernel code > size by about 2%. > > +config ARCH_SUPPORTS_SHADOW_CALL_STACK > + bool > + help > + An architecture should select this if it supports Clang's Shadow > + Call Stack, has asm/scs.h, and implements runtime support for shadow > + stack switching. > + > +config SHADOW_CALL_STACK_VMAP > + bool > + depends on SHADOW_CALL_STACK > + help > + Use virtually mapped shadow call stacks. Selecting this option > + provides better stack exhaustion protection, but increases per-thread > + memory consumption as a full page is allocated for each shadow stack. The bool needs some display text to make it selectable. This should probably be below SHADOW_CALL_STACK so that when it shows up in menuconfig it's where you'd expect it to be. I locally hacked that in, but when building defconfig + SHADOW_CALL_STACK + SHADOW_CALL_STACK_VMAP, the build explodes as below: | [mark@lakrids:~/src/linux]% usellvm 9.0.0 usekorg 8.1.0 make ARCH=arm64 CROSS_COMPILE=aarch64-linux- CC=clang -j56 -s | arch/arm64/kernel/scs.c:28:7: error: use of undeclared identifier 'VMALLOC_START' | VMALLOC_START, VMALLOC_END, | ^ | arch/arm64/kernel/scs.c:28:22: error: use of undeclared identifier 'VMALLOC_END' | VMALLOC_START, VMALLOC_END, | ^ | arch/arm64/kernel/scs.c:29:7: error: use of undeclared identifier 'SCS_GFP' | SCS_GFP, PAGE_KERNEL, | ^ | arch/arm64/kernel/scs.c:29:16: error: use of undeclared identifier 'PAGE_KERNEL' | SCS_GFP, PAGE_KERNEL, | ^ | 4 errors generated. | scripts/Makefile.build:265: recipe for target 'arch/arm64/kernel/scs.o' failed | make[2]: *** [arch/arm64/kernel/scs.o] Error 1 | scripts/Makefile.build:509: recipe for target 'arch/arm64/kernel' failed | make[1]: *** [arch/arm64/kernel] Error 2 | Makefile:1655: recipe for target 'arch/arm64' failed | make: *** [arch/arm64] Error 2 | make: *** Waiting for unfinished jobs.... Other than that, this largely looks good to me! Thanks, Mark.