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=-11.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=no 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 855D4CA9ECF for ; Fri, 1 Nov 2019 22:11:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BA352085B for ; Fri, 1 Nov 2019 22:11:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pA7VrUMF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727462AbfKAWL4 (ORCPT ); Fri, 1 Nov 2019 18:11:56 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:38835 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725989AbfKAWLz (ORCPT ); Fri, 1 Nov 2019 18:11:55 -0400 Received: by mail-pf1-f201.google.com with SMTP id d126so8451988pfd.5 for ; Fri, 01 Nov 2019 15:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QMYlUo6go1QaBsrZ04QyWd4mPltUOCdHxfrp1U4piPI=; b=pA7VrUMFgvackUgMe/piXoHPkTAs+b/FFKd8gPmFfcrm/KLP7Y+qoLxKMb3126U4e4 sdc0PRcooZZRR7RfeEW8vSmh8Z+iN5SpQ3vrACcpfafjhRMOxaG4DcNMaMQ/jH+YMFTQ r/J7E7luA3G1eVcRLIosgkLfpTwkGRI4H5MiJjQGC5qknsQF0D95Ifddmh7yZgfVY06Y lGysSOFEA2svnEQDD4F+BF17NRGzU1zUsLAcHo3QsdOsLgpA4MzE8Wua0beo2OciXAbj hH7VxVMfFSL3zwxFfUv0LvZAmYLX9knJ/S/TZ4mdE2y8p/EH4Vk5EufFFRO6LzQQem00 RNeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QMYlUo6go1QaBsrZ04QyWd4mPltUOCdHxfrp1U4piPI=; b=my3HOxUaRa7ClvbDLQZTZLgWg7sGPrKPSjLFqFhg9OCA/dmcOZKh6Xd5RzggxEo6Rd OSseH00StJRkb42JYBeMU/l6tdHuXMJlM0OkHj0DGDK6B46Pxynx9nM8wNKVSCSS5UdN HJrsEcV097vPEx+JV6tfgsyRukIG3JvZBiYg+AW2IjD9ev3aJ8oT7E28Co7UFZ1Zxi3i 1+HMscM86yEENI2/tq33z6btNQ3YZ/dfaaOfuUJgORtYHq6L4xgudbWto0Nm02whBhlO ApGwUnrNrh96thPdDIKsAEHBmMHCGx77QrEBJAlTGIYOMRzQ5M9PBtXeboJ4zsXfvG/e /ECA== X-Gm-Message-State: APjAAAU0fnifStKIByLXfd9iGcyNBUnC9Wuw3jX2WLTtofhwikMeT6F4 hgc4v1ziC+R5/SNnVmcaHQEdxhq5DHnGQ9aBdaY= X-Google-Smtp-Source: APXvYqzTngnWtjbqEG3gQE3K9LX8wVZzWKEGtYb0s66XOiVH27Hv4t/hwOe2zbXaGKcIrGCYHg0Cwu16o68haAeZgf4= X-Received: by 2002:a65:64d4:: with SMTP id t20mr15535375pgv.181.1572646314485; Fri, 01 Nov 2019 15:11:54 -0700 (PDT) Date: Fri, 1 Nov 2019 15:11:33 -0700 In-Reply-To: <20191018161033.261971-1-samitolvanen@google.com> Message-Id: <20191101221150.116536-1-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v4 00/17] add support for Clang's Shadow Call Stack From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel Cc: Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , 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, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series adds support for Clang's Shadow Call Stack (SCS) mitigation, which uses a separately allocated shadow stack to protect against return address overwrites. More information can be found here: https://clang.llvm.org/docs/ShadowCallStack.html SCS provides better protection against traditional buffer overflows than CONFIG_STACKPROTECTOR_*, but it should be noted that SCS 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. SCS is currently supported only on arm64, where the compiler requires the x18 register to be reserved for holding the current task's shadow stack pointer. Because of this, the series includes patches from Ard to remove x18 usage from assembly code. With -fsanitize=shadow-call-stack, the compiler injects instructions to all non-leaf C functions to store the return address to the shadow stack, and unconditionally load it again before returning. As a result, SCS is currently incompatible with features that rely on modifying function return addresses to alter control flow, such as function graph tracing and kretprobes, although it may be possible to later change these features to modify the shadow stack instead. A copy of the return address is still kept in the kernel stack for compatibility with stack unwinding, for example. SCS has a minimal performance overhead, but allocating shadow stacks increases kernel memory usage. The feature is therefore mostly useful on hardware that lacks support for PAC instructions. Changes in v4: - Fixed authorship for Ard's patches - Added missing commit messages - Commented code that clears SCS from thread_info - Added a comment about SCS_END_MAGIC being non-canonical Changes in v3: - Switched to filter-out for removing SCS flags in Makefiles - Changed the __noscs attribute to use __no_sanitize__("...") instead of no_sanitize("...") - Cleaned up inline function definitions and moved task_scs() into a macro - Cleaned up scs_free() and scs_magic() - Moved SCS initialization into dup_task_struct() and removed the now unused scs_task_init() - Added comments to __scs_base() and scs_task_reset() to better document design choices - Changed copy_page to make the offset and bias explicit Changes in v2: - Changed Ard's KVM patch to use x29 instead of x18 for the guest context, which makes restore_callee_saved_regs cleaner - Updated help text (and commit messages) to point out differences in security properties compared to user space SCS - Cleaned up config options: removed the ROP protection choice, replaced the CC_IS_CLANG dependency with an arch-specific cc-option test, and moved disabling of incompatible config options to an arch-specific Kconfig - Added CC_FLAGS_SCS, which are filtered out where needed instead of using DISABLE_SCS - Added a __has_feature guard around __noscs for older clang versions Ard Biesheuvel (3): arm64/lib: copy_page: avoid x18 register in assembler code arm64: kvm: stop treating register x18 as caller save arm64: kernel: avoid x18 __cpu_soft_restart Sami Tolvanen (14): arm64: mm: avoid x18 in idmap_kpti_install_ng_mappings add support for Clang's Shadow Call Stack (SCS) scs: add accounting scs: add support for stack usage debugging kprobes: fix compilation without CONFIG_KRETPROBES arm64: kprobes: fix kprobes without CONFIG_KRETPROBES arm64: disable kretprobes with SCS arm64: disable function graph tracing with SCS arm64: reserve x18 from general allocation with SCS arm64: preserve x18 when CPU is suspended arm64: efi: restore x18 if it was corrupted arm64: vdso: disable Shadow Call Stack arm64: disable SCS for hypervisor code arm64: implement Shadow Call Stack Makefile | 6 + arch/Kconfig | 33 ++++ arch/arm64/Kconfig | 9 +- arch/arm64/Makefile | 4 + arch/arm64/include/asm/scs.h | 37 +++++ arch/arm64/include/asm/stacktrace.h | 4 + arch/arm64/include/asm/suspend.h | 2 +- arch/arm64/include/asm/thread_info.h | 3 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/cpu-reset.S | 4 +- arch/arm64/kernel/efi-rt-wrapper.S | 7 +- arch/arm64/kernel/entry.S | 28 ++++ arch/arm64/kernel/head.S | 9 ++ arch/arm64/kernel/irq.c | 2 + arch/arm64/kernel/probes/kprobes.c | 2 + arch/arm64/kernel/process.c | 2 + arch/arm64/kernel/scs.c | 39 +++++ arch/arm64/kernel/smp.c | 4 + arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kvm/hyp/Makefile | 3 + arch/arm64/kvm/hyp/entry.S | 41 +++-- arch/arm64/lib/copy_page.S | 38 ++--- arch/arm64/mm/proc.S | 73 +++++---- drivers/base/node.c | 6 + fs/proc/meminfo.c | 4 + include/linux/compiler-clang.h | 6 + include/linux/compiler_types.h | 4 + include/linux/mmzone.h | 3 + include/linux/scs.h | 57 +++++++ init/init_task.c | 8 + kernel/Makefile | 1 + kernel/fork.c | 9 ++ kernel/kprobes.c | 38 ++--- kernel/sched/core.c | 2 + kernel/sched/sched.h | 1 + kernel/scs.c | 227 +++++++++++++++++++++++++++ mm/page_alloc.c | 6 + mm/vmstat.c | 3 + 39 files changed, 634 insertions(+), 97 deletions(-) create mode 100644 arch/arm64/include/asm/scs.h create mode 100644 arch/arm64/kernel/scs.c create mode 100644 include/linux/scs.h create mode 100644 kernel/scs.c base-commit: 0dbe6cb8f7e05bc9611602ef45980a6c57b245a3 -- 2.24.0.rc1.363.gb1bccd3e3d-goog 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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=no 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 AF9ACCA9ED0 for ; Fri, 1 Nov 2019 22:12:17 +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 81946217D9 for ; Fri, 1 Nov 2019 22:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NL12S0JT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pA7VrUMF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 81946217D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TUL23OCmX9xLZu768m1CVoA0IDSdVVCpEAj+398M85o=; b=NL12S0JT11VJNa f4RoQmW1FfcCOVHX6wtkOyFoVtxnnRRjRIcyQdGfS0aNbbHrnLoO0Nle1zJVY8fJwCXCY+113bXjG gmS5nnhIArjkljQGSjXDVQElrJzuWe8BhcQSBpDd8AfdyHfH3TU/FC0AO2LnFGP2Gh/NEJJ/jU/OS +x7Lk/3sHrjkWiXZX02blNZ1mb1kcYynBtyKeyHG5LiUBXtBjlk8L5QCoB1QVpvlYnY7HZ30osTEQ 7aagrdGsqQp68wZTJPHVpbfusWZpYiiRESubzbvOAYtlR2PBrwWJVSK2Bi8Z5GN98njL5Y/x6bsgC NV6ncnPfDjwTYtRcO9Rg==; 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 1iQf9O-0007oj-Of; Fri, 01 Nov 2019 22:12:10 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iQf9C-0007dh-VE for linux-arm-kernel@lists.infradead.org; Fri, 01 Nov 2019 22:12:00 +0000 Received: by mail-pf1-x449.google.com with SMTP id r187so8428175pfc.16 for ; Fri, 01 Nov 2019 15:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QMYlUo6go1QaBsrZ04QyWd4mPltUOCdHxfrp1U4piPI=; b=pA7VrUMFgvackUgMe/piXoHPkTAs+b/FFKd8gPmFfcrm/KLP7Y+qoLxKMb3126U4e4 sdc0PRcooZZRR7RfeEW8vSmh8Z+iN5SpQ3vrACcpfafjhRMOxaG4DcNMaMQ/jH+YMFTQ r/J7E7luA3G1eVcRLIosgkLfpTwkGRI4H5MiJjQGC5qknsQF0D95Ifddmh7yZgfVY06Y lGysSOFEA2svnEQDD4F+BF17NRGzU1zUsLAcHo3QsdOsLgpA4MzE8Wua0beo2OciXAbj hH7VxVMfFSL3zwxFfUv0LvZAmYLX9knJ/S/TZ4mdE2y8p/EH4Vk5EufFFRO6LzQQem00 RNeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QMYlUo6go1QaBsrZ04QyWd4mPltUOCdHxfrp1U4piPI=; b=q07iKgD4z7EdYPdWVVQSlbsKlc/gdQCPZt3Iei2dfEMeLWZ90sMXZyEUeilBbGEKzP 8rX+1EbZT26g5J40XQxAEl0LQKnLEOBPA+RCFwrnZktVqcaAoVVO9aSLl6/YVD0gjQc/ 4IYv6z7BH2rDHrx1WVMi9GfYGCXZZT/qqL7V4UWJPI+YPlZlN/oUW5Qgq2sA1dMceh0P prsNCx0T+qaQSpyJkyZllQT3tBzhtWlgmPkdGw5BUsJ6K8Fpl2brtQytjc66ReD2+cSQ 7LokvYN6QjIVOGQPRKn6eRYyfhv+tKBAsGaD/KdFpei9NadC07gdz1mIWlHVEDvnCFjC 3/Zg== X-Gm-Message-State: APjAAAWS/rPT6coGwTpDs64tDKlQYGObGJSTAHEXVEDVQxL/xGikAqei 7tVxnt9sEWOnyo9r7sii8Zqwy77gA3EzAeSIYd8= X-Google-Smtp-Source: APXvYqzTngnWtjbqEG3gQE3K9LX8wVZzWKEGtYb0s66XOiVH27Hv4t/hwOe2zbXaGKcIrGCYHg0Cwu16o68haAeZgf4= X-Received: by 2002:a65:64d4:: with SMTP id t20mr15535375pgv.181.1572646314485; Fri, 01 Nov 2019 15:11:54 -0700 (PDT) Date: Fri, 1 Nov 2019 15:11:33 -0700 In-Reply-To: <20191018161033.261971-1-samitolvanen@google.com> Message-Id: <20191101221150.116536-1-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v4 00/17] add support for Clang's Shadow Call Stack From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191101_151159_017003_BD59F78B X-CRM114-Status: GOOD ( 20.20 ) 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: Mark Rutland , Kees Cook , Jann Horn , Masahiro Yamada , Marc Zyngier , kernel-hardening@lists.openwall.com, Nick Desaulniers , linux-kernel@vger.kernel.org, Miguel Ojeda , clang-built-linux@googlegroups.com, Sami Tolvanen , Laura Abbott , Dave Martin , linux-arm-kernel@lists.infradead.org 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 This patch series adds support for Clang's Shadow Call Stack (SCS) mitigation, which uses a separately allocated shadow stack to protect against return address overwrites. More information can be found here: https://clang.llvm.org/docs/ShadowCallStack.html SCS provides better protection against traditional buffer overflows than CONFIG_STACKPROTECTOR_*, but it should be noted that SCS 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. SCS is currently supported only on arm64, where the compiler requires the x18 register to be reserved for holding the current task's shadow stack pointer. Because of this, the series includes patches from Ard to remove x18 usage from assembly code. With -fsanitize=shadow-call-stack, the compiler injects instructions to all non-leaf C functions to store the return address to the shadow stack, and unconditionally load it again before returning. As a result, SCS is currently incompatible with features that rely on modifying function return addresses to alter control flow, such as function graph tracing and kretprobes, although it may be possible to later change these features to modify the shadow stack instead. A copy of the return address is still kept in the kernel stack for compatibility with stack unwinding, for example. SCS has a minimal performance overhead, but allocating shadow stacks increases kernel memory usage. The feature is therefore mostly useful on hardware that lacks support for PAC instructions. Changes in v4: - Fixed authorship for Ard's patches - Added missing commit messages - Commented code that clears SCS from thread_info - Added a comment about SCS_END_MAGIC being non-canonical Changes in v3: - Switched to filter-out for removing SCS flags in Makefiles - Changed the __noscs attribute to use __no_sanitize__("...") instead of no_sanitize("...") - Cleaned up inline function definitions and moved task_scs() into a macro - Cleaned up scs_free() and scs_magic() - Moved SCS initialization into dup_task_struct() and removed the now unused scs_task_init() - Added comments to __scs_base() and scs_task_reset() to better document design choices - Changed copy_page to make the offset and bias explicit Changes in v2: - Changed Ard's KVM patch to use x29 instead of x18 for the guest context, which makes restore_callee_saved_regs cleaner - Updated help text (and commit messages) to point out differences in security properties compared to user space SCS - Cleaned up config options: removed the ROP protection choice, replaced the CC_IS_CLANG dependency with an arch-specific cc-option test, and moved disabling of incompatible config options to an arch-specific Kconfig - Added CC_FLAGS_SCS, which are filtered out where needed instead of using DISABLE_SCS - Added a __has_feature guard around __noscs for older clang versions Ard Biesheuvel (3): arm64/lib: copy_page: avoid x18 register in assembler code arm64: kvm: stop treating register x18 as caller save arm64: kernel: avoid x18 __cpu_soft_restart Sami Tolvanen (14): arm64: mm: avoid x18 in idmap_kpti_install_ng_mappings add support for Clang's Shadow Call Stack (SCS) scs: add accounting scs: add support for stack usage debugging kprobes: fix compilation without CONFIG_KRETPROBES arm64: kprobes: fix kprobes without CONFIG_KRETPROBES arm64: disable kretprobes with SCS arm64: disable function graph tracing with SCS arm64: reserve x18 from general allocation with SCS arm64: preserve x18 when CPU is suspended arm64: efi: restore x18 if it was corrupted arm64: vdso: disable Shadow Call Stack arm64: disable SCS for hypervisor code arm64: implement Shadow Call Stack Makefile | 6 + arch/Kconfig | 33 ++++ arch/arm64/Kconfig | 9 +- arch/arm64/Makefile | 4 + arch/arm64/include/asm/scs.h | 37 +++++ arch/arm64/include/asm/stacktrace.h | 4 + arch/arm64/include/asm/suspend.h | 2 +- arch/arm64/include/asm/thread_info.h | 3 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/cpu-reset.S | 4 +- arch/arm64/kernel/efi-rt-wrapper.S | 7 +- arch/arm64/kernel/entry.S | 28 ++++ arch/arm64/kernel/head.S | 9 ++ arch/arm64/kernel/irq.c | 2 + arch/arm64/kernel/probes/kprobes.c | 2 + arch/arm64/kernel/process.c | 2 + arch/arm64/kernel/scs.c | 39 +++++ arch/arm64/kernel/smp.c | 4 + arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kvm/hyp/Makefile | 3 + arch/arm64/kvm/hyp/entry.S | 41 +++-- arch/arm64/lib/copy_page.S | 38 ++--- arch/arm64/mm/proc.S | 73 +++++---- drivers/base/node.c | 6 + fs/proc/meminfo.c | 4 + include/linux/compiler-clang.h | 6 + include/linux/compiler_types.h | 4 + include/linux/mmzone.h | 3 + include/linux/scs.h | 57 +++++++ init/init_task.c | 8 + kernel/Makefile | 1 + kernel/fork.c | 9 ++ kernel/kprobes.c | 38 ++--- kernel/sched/core.c | 2 + kernel/sched/sched.h | 1 + kernel/scs.c | 227 +++++++++++++++++++++++++++ mm/page_alloc.c | 6 + mm/vmstat.c | 3 + 39 files changed, 634 insertions(+), 97 deletions(-) create mode 100644 arch/arm64/include/asm/scs.h create mode 100644 arch/arm64/kernel/scs.c create mode 100644 include/linux/scs.h create mode 100644 kernel/scs.c base-commit: 0dbe6cb8f7e05bc9611602ef45980a6c57b245a3 -- 2.24.0.rc1.363.gb1bccd3e3d-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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=-11.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=no 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 33AB1CA9ED1 for ; Fri, 1 Nov 2019 22:12:17 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 4AF2621897 for ; Fri, 1 Nov 2019 22:12:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pA7VrUMF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4AF2621897 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-17231-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 28137 invoked by uid 550); 1 Nov 2019 22:12:08 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Received: (qmail 28113 invoked from network); 1 Nov 2019 22:12:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QMYlUo6go1QaBsrZ04QyWd4mPltUOCdHxfrp1U4piPI=; b=pA7VrUMFgvackUgMe/piXoHPkTAs+b/FFKd8gPmFfcrm/KLP7Y+qoLxKMb3126U4e4 sdc0PRcooZZRR7RfeEW8vSmh8Z+iN5SpQ3vrACcpfafjhRMOxaG4DcNMaMQ/jH+YMFTQ r/J7E7luA3G1eVcRLIosgkLfpTwkGRI4H5MiJjQGC5qknsQF0D95Ifddmh7yZgfVY06Y lGysSOFEA2svnEQDD4F+BF17NRGzU1zUsLAcHo3QsdOsLgpA4MzE8Wua0beo2OciXAbj hH7VxVMfFSL3zwxFfUv0LvZAmYLX9knJ/S/TZ4mdE2y8p/EH4Vk5EufFFRO6LzQQem00 RNeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QMYlUo6go1QaBsrZ04QyWd4mPltUOCdHxfrp1U4piPI=; b=DK2SsoRVprTqM8eaFDoiD/B0Xi9I9470Mv6caZpArSbXZ/MmJ8KGFRe/uq5EPAVRhx uD4BDR+2GAAbu0a3vHGhhQ/kSTp6sCPxOp1605/3CoogZObw7G57XMW0xm1u9BuZeMFh w0lv3F+uYIftlcErvECOdsDPIp9wQW0EQpzVsg1RHhbFvQGKYDnjbNpwB1tHi53ZylUJ esnQDajPMogX5ndTwpI9ETrkSodfh5yVVuti0tHWEpUL8eh5B3E3BY1uciAAV3+gQfvw Xcvabd7y1dTYzJkTMiI5cC5r5hmZtKFa16c6dGq6qJvjDi8y70I/p7XGo8FX1dVDBBop HVdg== X-Gm-Message-State: APjAAAXTbEUN5FLvaRZwElu9m9MXGqdkO5F7/7R+woq7ajrX7Os+YlS+ F15DDjen299B3s3RUlTd3THSz9DHwbt6XhQE0aM= X-Google-Smtp-Source: APXvYqzTngnWtjbqEG3gQE3K9LX8wVZzWKEGtYb0s66XOiVH27Hv4t/hwOe2zbXaGKcIrGCYHg0Cwu16o68haAeZgf4= X-Received: by 2002:a65:64d4:: with SMTP id t20mr15535375pgv.181.1572646314485; Fri, 01 Nov 2019 15:11:54 -0700 (PDT) Date: Fri, 1 Nov 2019 15:11:33 -0700 In-Reply-To: <20191018161033.261971-1-samitolvanen@google.com> Message-Id: <20191101221150.116536-1-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog Subject: [PATCH v4 00/17] add support for Clang's Shadow Call Stack From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel Cc: Dave Martin , Kees Cook , Laura Abbott , Mark Rutland , 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, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" This patch series adds support for Clang's Shadow Call Stack (SCS) mitigation, which uses a separately allocated shadow stack to protect against return address overwrites. More information can be found here: https://clang.llvm.org/docs/ShadowCallStack.html SCS provides better protection against traditional buffer overflows than CONFIG_STACKPROTECTOR_*, but it should be noted that SCS 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. SCS is currently supported only on arm64, where the compiler requires the x18 register to be reserved for holding the current task's shadow stack pointer. Because of this, the series includes patches from Ard to remove x18 usage from assembly code. With -fsanitize=shadow-call-stack, the compiler injects instructions to all non-leaf C functions to store the return address to the shadow stack, and unconditionally load it again before returning. As a result, SCS is currently incompatible with features that rely on modifying function return addresses to alter control flow, such as function graph tracing and kretprobes, although it may be possible to later change these features to modify the shadow stack instead. A copy of the return address is still kept in the kernel stack for compatibility with stack unwinding, for example. SCS has a minimal performance overhead, but allocating shadow stacks increases kernel memory usage. The feature is therefore mostly useful on hardware that lacks support for PAC instructions. Changes in v4: - Fixed authorship for Ard's patches - Added missing commit messages - Commented code that clears SCS from thread_info - Added a comment about SCS_END_MAGIC being non-canonical Changes in v3: - Switched to filter-out for removing SCS flags in Makefiles - Changed the __noscs attribute to use __no_sanitize__("...") instead of no_sanitize("...") - Cleaned up inline function definitions and moved task_scs() into a macro - Cleaned up scs_free() and scs_magic() - Moved SCS initialization into dup_task_struct() and removed the now unused scs_task_init() - Added comments to __scs_base() and scs_task_reset() to better document design choices - Changed copy_page to make the offset and bias explicit Changes in v2: - Changed Ard's KVM patch to use x29 instead of x18 for the guest context, which makes restore_callee_saved_regs cleaner - Updated help text (and commit messages) to point out differences in security properties compared to user space SCS - Cleaned up config options: removed the ROP protection choice, replaced the CC_IS_CLANG dependency with an arch-specific cc-option test, and moved disabling of incompatible config options to an arch-specific Kconfig - Added CC_FLAGS_SCS, which are filtered out where needed instead of using DISABLE_SCS - Added a __has_feature guard around __noscs for older clang versions Ard Biesheuvel (3): arm64/lib: copy_page: avoid x18 register in assembler code arm64: kvm: stop treating register x18 as caller save arm64: kernel: avoid x18 __cpu_soft_restart Sami Tolvanen (14): arm64: mm: avoid x18 in idmap_kpti_install_ng_mappings add support for Clang's Shadow Call Stack (SCS) scs: add accounting scs: add support for stack usage debugging kprobes: fix compilation without CONFIG_KRETPROBES arm64: kprobes: fix kprobes without CONFIG_KRETPROBES arm64: disable kretprobes with SCS arm64: disable function graph tracing with SCS arm64: reserve x18 from general allocation with SCS arm64: preserve x18 when CPU is suspended arm64: efi: restore x18 if it was corrupted arm64: vdso: disable Shadow Call Stack arm64: disable SCS for hypervisor code arm64: implement Shadow Call Stack Makefile | 6 + arch/Kconfig | 33 ++++ arch/arm64/Kconfig | 9 +- arch/arm64/Makefile | 4 + arch/arm64/include/asm/scs.h | 37 +++++ arch/arm64/include/asm/stacktrace.h | 4 + arch/arm64/include/asm/suspend.h | 2 +- arch/arm64/include/asm/thread_info.h | 3 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/asm-offsets.c | 3 + arch/arm64/kernel/cpu-reset.S | 4 +- arch/arm64/kernel/efi-rt-wrapper.S | 7 +- arch/arm64/kernel/entry.S | 28 ++++ arch/arm64/kernel/head.S | 9 ++ arch/arm64/kernel/irq.c | 2 + arch/arm64/kernel/probes/kprobes.c | 2 + arch/arm64/kernel/process.c | 2 + arch/arm64/kernel/scs.c | 39 +++++ arch/arm64/kernel/smp.c | 4 + arch/arm64/kernel/vdso/Makefile | 2 +- arch/arm64/kvm/hyp/Makefile | 3 + arch/arm64/kvm/hyp/entry.S | 41 +++-- arch/arm64/lib/copy_page.S | 38 ++--- arch/arm64/mm/proc.S | 73 +++++---- drivers/base/node.c | 6 + fs/proc/meminfo.c | 4 + include/linux/compiler-clang.h | 6 + include/linux/compiler_types.h | 4 + include/linux/mmzone.h | 3 + include/linux/scs.h | 57 +++++++ init/init_task.c | 8 + kernel/Makefile | 1 + kernel/fork.c | 9 ++ kernel/kprobes.c | 38 ++--- kernel/sched/core.c | 2 + kernel/sched/sched.h | 1 + kernel/scs.c | 227 +++++++++++++++++++++++++++ mm/page_alloc.c | 6 + mm/vmstat.c | 3 + 39 files changed, 634 insertions(+), 97 deletions(-) create mode 100644 arch/arm64/include/asm/scs.h create mode 100644 arch/arm64/kernel/scs.c create mode 100644 include/linux/scs.h create mode 100644 kernel/scs.c base-commit: 0dbe6cb8f7e05bc9611602ef45980a6c57b245a3 -- 2.24.0.rc1.363.gb1bccd3e3d-goog