linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Stellard <tstellar@redhat.com>
To: Sami Tolvanen <samitolvanen@google.com>, x86@kernel.org
Cc: Kees Cook <keescook@chromium.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com
Subject: Re: [PATCH v2 00/14] x86: Add support for Clang CFI
Date: Mon, 23 Aug 2021 10:16:09 -0700	[thread overview]
Message-ID: <1706ee8e-c21c-f867-c0be-24814a92b853@redhat.com> (raw)
In-Reply-To: <20210823171318.2801096-1-samitolvanen@google.com>

On 8/23/21 10:13 AM, 'Sami Tolvanen' via Clang Built Linux wrote:
> This series adds support for Clang's Control-Flow Integrity (CFI)
> checking to x86_64. With CFI, the compiler injects a runtime
> check before each indirect function call to ensure the target is
> a valid function with the correct static type. This restricts
> possible call targets and makes it more difficult for an attacker
> to exploit bugs that allow the modification of stored function
> pointers. For more details, see:
> 
>    https://clang.llvm.org/docs/ControlFlowIntegrity.html
> 
> Version 2 depends on Clang >=14, where we fixed the issue with
> referencing static functions from inline assembly. Based on the
> feedback for v1, this version also changes the declaration of
> functions that are not callable from C to use an opaque type,
> which stops the compiler from replacing references to them. This
> avoids the need to sprinkle function_nocfi() macros in the kernel
> code.

How invasive are the changes in clang 14 necessary to make CFI work?
Would it be possible to backport them to LLVM 13?

-Tom

> 
> The first two patches contain objtool support for CFI, the
> remaining patches change function declarations to use opaque
> types, fix type mismatch issues that confuse the compiler, and
> disable CFI where it can't be used.
> 
> You can also pull this series from
> 
>    https://github.com/samitolvanen/linux.git x86-cfi-v2
> 
> ---
> Changes in v2:
> - Dropped the first objtool patch as the warnings were fixed in
>    separate patches.
> 
> - Changed fix_cfi_relocs() in objtool to not rely on jump table
>    symbols, and to return an error if it can't find a relocation.
> 
> - Fixed a build issue with ASM_STACK_FRAME_NON_STANDARD().
> 
> - Dropped workarounds for inline assembly references to
>    address-taken static functions with CFI as this was fixed in
>    the compiler.
> 
> - Changed the C declarations of non-callable functions to use
>    opaque types and dropped the function_nocfi() patches.
> 
> - Changed ARCH_SUPPORTS_CFI_CLANG to depend on Clang >=14 for
>    the compiler fixes.
> 
> Kees Cook (2):
>    x86/extable: Do not mark exception callback as CFI
>    x86, relocs: Ignore __typeid__ relocations
> 
> Sami Tolvanen (12):
>    objtool: Add CONFIG_CFI_CLANG support
>    objtool: Add ASM_STACK_FRAME_NON_STANDARD
>    linkage: Add DECLARE_ASM_FUNC_SYMBOL
>    ftrace: Use an opaque type for functions not callable from C
>    lkdtm: Disable UNSET_SMEP with CFI
>    lkdtm: Use an opaque type for lkdtm_rodata_do_nothing
>    x86: Use an opaque type for functions not callable from C
>    x86/purgatory: Disable CFI
>    x86, module: Ignore __typeid__ relocations
>    x86, cpu: Use LTO for cpu.c with CFI
>    x86, kprobes: Fix optprobe_template_func type mismatch
>    x86, build: Allow CONFIG_CFI_CLANG to be selected
> 
>   arch/x86/Kconfig                      |  1 +
>   arch/x86/include/asm/ftrace.h         |  2 +-
>   arch/x86/include/asm/idtentry.h       | 10 +++---
>   arch/x86/include/asm/page_64.h        |  7 ++--
>   arch/x86/include/asm/paravirt_types.h |  3 +-
>   arch/x86/include/asm/processor.h      |  2 +-
>   arch/x86/include/asm/proto.h          | 25 ++++++-------
>   arch/x86/include/asm/uaccess_64.h     |  9 ++---
>   arch/x86/kernel/alternative.c         |  2 +-
>   arch/x86/kernel/ftrace.c              |  2 +-
>   arch/x86/kernel/kprobes/opt.c         |  4 +--
>   arch/x86/kernel/module.c              |  4 +++
>   arch/x86/kernel/paravirt.c            |  4 +--
>   arch/x86/kvm/emulate.c                |  4 +--
>   arch/x86/kvm/kvm_emulate.h            |  9 ++---
>   arch/x86/mm/extable.c                 |  1 +
>   arch/x86/power/Makefile               |  2 ++
>   arch/x86/purgatory/Makefile           |  2 +-
>   arch/x86/tools/relocs.c               |  7 ++++
>   arch/x86/xen/enlighten_pv.c           |  6 ++--
>   arch/x86/xen/xen-ops.h                | 10 +++---
>   drivers/misc/lkdtm/bugs.c             |  2 +-
>   drivers/misc/lkdtm/lkdtm.h            |  2 +-
>   drivers/misc/lkdtm/perms.c            |  2 +-
>   drivers/misc/lkdtm/rodata.c           |  2 +-
>   include/linux/ftrace.h                |  7 ++--
>   include/linux/linkage.h               | 13 +++++++
>   include/linux/objtool.h               |  6 ++++
>   tools/include/linux/objtool.h         |  6 ++++
>   tools/objtool/arch/x86/decode.c       | 16 +++++++++
>   tools/objtool/elf.c                   | 51 +++++++++++++++++++++++++++
>   tools/objtool/include/objtool/arch.h  |  3 ++
>   tools/objtool/include/objtool/elf.h   |  2 +-
>   33 files changed, 166 insertions(+), 62 deletions(-)
> 
> 
> base-commit: d5ae8d7f85b7f6f6e60f1af8ff4be52b0926fde1
> 


  parent reply	other threads:[~2021-08-23 17:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-23 17:13 [PATCH v2 00/14] x86: Add support for Clang CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 01/14] objtool: Add CONFIG_CFI_CLANG support Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 02/14] objtool: Add ASM_STACK_FRAME_NON_STANDARD Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 03/14] linkage: Add DECLARE_ASM_FUNC_SYMBOL Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 04/14] ftrace: Use an opaque type for functions not callable from C Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 05/14] lkdtm: Disable UNSET_SMEP with CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 06/14] lkdtm: Use an opaque type for lkdtm_rodata_do_nothing Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 07/14] x86: Use an opaque type for functions not callable from C Sami Tolvanen
2021-08-26 16:54   ` Andy Lutomirski
2021-08-26 22:11     ` Sami Tolvanen
2021-08-26 23:23       ` Andy Lutomirski
2021-08-26 23:45         ` Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 08/14] x86/extable: Do not mark exception callback as CFI Sami Tolvanen
2021-08-26 16:56   ` Andy Lutomirski
2021-08-30 19:57     ` Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 09/14] x86/purgatory: Disable CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 10/14] x86, relocs: Ignore __typeid__ relocations Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 11/14] x86, module: " Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 12/14] x86, cpu: Use LTO for cpu.c with CFI Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 13/14] x86, kprobes: Fix optprobe_template_func type mismatch Sami Tolvanen
2021-08-23 17:13 ` [PATCH v2 14/14] x86, build: Allow CONFIG_CFI_CLANG to be selected Sami Tolvanen
2021-08-23 17:16 ` Tom Stellard [this message]
2021-08-23 17:20   ` [PATCH v2 00/14] x86: Add support for Clang CFI Sami Tolvanen
2021-08-24 17:26     ` Tom Stellard
2021-08-24 17:30       ` Sami Tolvanen
2021-08-24 19:46 ` Peter Zijlstra
2021-08-25 15:49   ` Sami Tolvanen
2021-08-26 11:43     ` Peter Zijlstra
2021-08-26 21:52       ` Sami Tolvanen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1706ee8e-c21c-f867-c0be-24814a92b853@redhat.com \
    --to=tstellar@redhat.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=samitolvanen@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).