linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 00/15] x86: Add support for Clang CFI
@ 2021-10-13 18:16 Sami Tolvanen
  2021-10-13 18:16 ` [PATCH v5 01/15] objtool: Add CONFIG_CFI_CLANG support Sami Tolvanen
                   ` (18 more replies)
  0 siblings, 19 replies; 117+ messages in thread
From: Sami Tolvanen @ 2021-10-13 18:16 UTC (permalink / raw)
  To: x86
  Cc: Kees Cook, Josh Poimboeuf, Peter Zijlstra, Nathan Chancellor,
	Nick Desaulniers, Sedat Dilek, Steven Rostedt, linux-hardening,
	linux-kernel, llvm, Sami Tolvanen

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

Note that v5 is based on tip/master. 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-v5

---
Changes in v5:
- Renamed DECLARE_ASM_FUNC_SYMBOL() to DECLARE_NOT_CALLED_FROM_C()
  after some discussion about naming.

- Added an explicit include for <linux/cfi.h> to tracepoint.c.

- Updated commit messages based on feedback.

Changes in v4:
- Dropped the extable patch after the code was refactored in -tip.

- Switched to __section() instead of open-coding the attribute.

- Added an explicit ifdef for filtering out CC_FLAGS_CFI in
  purgatory for readability.

- Added a comment to arch_cfi_jump_reloc_offset() in objtool.

Changes in v3:
- Dropped Clang requirement to >= 13 after the missing compiler
  fix was backported there.

- Added DEFINE_CFI_IMMEDIATE_RETURN_STUB to address the issue
  with tp_stub_func in kernel/tracepoint.c.

- Renamed asm_func_t to asm_func_ptr.

- Changed extable handlers to use __cficanonical instead of
  disabling CFI for fixup_exception.

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 (1):
  x86, relocs: Ignore __typeid__ relocations

Sami Tolvanen (14):
  objtool: Add CONFIG_CFI_CLANG support
  objtool: Add ASM_STACK_FRAME_NON_STANDARD
  linkage: Add DECLARE_NOT_CALLED_FROM_C
  cfi: Add DEFINE_CFI_IMMEDIATE_RETURN_STUB
  tracepoint: Exclude tp_stub_func from CFI checking
  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/power/Makefile               |  2 ++
 arch/x86/purgatory/Makefile           |  4 +++
 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/asm-generic/vmlinux.lds.h     | 11 ++++++
 include/linux/cfi.h                   | 13 +++++++
 include/linux/ftrace.h                |  7 ++--
 include/linux/linkage.h               | 13 +++++++
 include/linux/objtool.h               |  6 ++++
 kernel/cfi.c                          | 24 ++++++++++++-
 kernel/tracepoint.c                   |  6 ++--
 tools/include/linux/objtool.h         |  6 ++++
 tools/objtool/arch/x86/decode.c       | 17 +++++++++
 tools/objtool/elf.c                   | 51 +++++++++++++++++++++++++++
 tools/objtool/include/objtool/arch.h  |  3 ++
 tools/objtool/include/objtool/elf.h   |  2 +-
 36 files changed, 218 insertions(+), 66 deletions(-)


base-commit: 880e2b8e3151574b9e3419d1fbb06726ddee8b03
-- 
2.33.0.1079.g6e70778dc9-goog


^ permalink raw reply	[flat|nested] 117+ messages in thread

end of thread, other threads:[~2021-11-15 13:09 UTC | newest]

Thread overview: 117+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 18:16 [PATCH v5 00/15] x86: Add support for Clang CFI Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 01/15] objtool: Add CONFIG_CFI_CLANG support Sami Tolvanen
2021-10-13 18:59   ` Kees Cook
2021-10-14  0:44   ` Josh Poimboeuf
2021-10-14 10:22   ` Peter Zijlstra
2021-10-14 19:20     ` Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 02/15] objtool: Add ASM_STACK_FRAME_NON_STANDARD Sami Tolvanen
2021-10-13 18:59   ` Kees Cook
2021-10-13 18:16 ` [PATCH v5 03/15] linkage: Add DECLARE_NOT_CALLED_FROM_C Sami Tolvanen
2021-10-13 19:00   ` Kees Cook
2021-10-15  2:51   ` Andy Lutomirski
2021-10-15 15:35     ` Sami Tolvanen
2021-10-15 15:55     ` Thomas Gleixner
2021-10-15 16:22       ` Andy Lutomirski
2021-10-15 16:47         ` Sami Tolvanen
2021-10-15 17:34           ` Andy Lutomirski
2021-10-15 17:57       ` Thomas Gleixner
2021-10-15 18:42         ` Sami Tolvanen
2021-10-15 19:35           ` Andy Lutomirski
2021-10-15 20:37             ` Sami Tolvanen
2021-10-16 21:12               ` Josh Poimboeuf
2021-10-18 17:08                 ` Sami Tolvanen
2021-10-15 22:17           ` Thomas Gleixner
2021-10-16 21:16             ` Josh Poimboeuf
2021-10-13 18:16 ` [PATCH v5 04/15] cfi: Add DEFINE_CFI_IMMEDIATE_RETURN_STUB Sami Tolvanen
2021-10-13 19:02   ` Kees Cook
2021-10-13 18:16 ` [PATCH v5 05/15] tracepoint: Exclude tp_stub_func from CFI checking Sami Tolvanen
2021-10-13 19:03   ` Kees Cook
2021-10-13 19:20   ` Steven Rostedt
2021-10-13 18:16 ` [PATCH v5 06/15] ftrace: Use an opaque type for functions not callable from C Sami Tolvanen
2021-10-13 19:04   ` Kees Cook
2021-10-13 19:20   ` Steven Rostedt
2021-10-13 18:16 ` [PATCH v5 07/15] lkdtm: Disable UNSET_SMEP with CFI Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 08/15] lkdtm: Use an opaque type for lkdtm_rodata_do_nothing Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 09/15] x86: Use an opaque type for functions not callable from C Sami Tolvanen
2021-10-14 11:21   ` Borislav Petkov
2021-10-14 16:07     ` Kees Cook
2021-10-14 17:31       ` Borislav Petkov
2021-10-14 18:24         ` Sami Tolvanen
2021-10-14 19:00           ` Nick Desaulniers
2021-10-14 18:47         ` Kees Cook
2021-10-14 18:52           ` Steven Rostedt
2021-10-14 19:06             ` Josh Poimboeuf
2021-10-13 18:16 ` [PATCH v5 10/15] x86/purgatory: Disable CFI Sami Tolvanen
2021-10-13 19:05   ` Kees Cook
2021-10-13 18:16 ` [PATCH v5 11/15] x86, relocs: Ignore __typeid__ relocations Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 12/15] x86, module: " Sami Tolvanen
2021-10-13 18:55   ` Kees Cook
2021-10-13 18:16 ` [PATCH v5 13/15] x86, cpu: Use LTO for cpu.c with CFI Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 14/15] x86, kprobes: Fix optprobe_template_func type mismatch Sami Tolvanen
2021-10-13 18:16 ` [PATCH v5 15/15] x86, build: Allow CONFIG_CFI_CLANG to be selected Sami Tolvanen
2021-10-13 18:56   ` Kees Cook
2021-10-13 19:07 ` [PATCH v5 00/15] x86: Add support for Clang CFI Kees Cook
2021-10-19 10:06 ` Alexander Lobakin
2021-10-19 15:40   ` Sami Tolvanen
2021-10-21 10:27 ` Alexander Lobakin
2021-10-26 20:16 ` Peter Zijlstra
2021-10-27 10:02   ` David Laight
2021-10-27 10:17     ` Peter Zijlstra
2021-10-27 12:05   ` Mark Rutland
2021-10-27 12:22     ` Ard Biesheuvel
2021-10-27 12:48       ` Peter Zijlstra
2021-10-27 13:04         ` Peter Zijlstra
2021-10-27 13:30           ` Ard Biesheuvel
2021-10-27 14:03             ` Peter Zijlstra
2021-10-27 14:18               ` Ard Biesheuvel
2021-10-27 14:36                 ` Peter Zijlstra
2021-10-27 15:50                 ` Sami Tolvanen
2021-10-27 15:55                   ` Ard Biesheuvel
2021-10-29 20:03                   ` Peter Zijlstra
2021-10-30  7:47                     ` [PATCH] static_call,x86: Robustify trampoline patching Peter Zijlstra
2021-10-30  8:16                       ` Peter Zijlstra
2021-11-02 17:35                         ` Kees Cook
2021-11-02 18:15                           ` Peter Zijlstra
2021-11-15 13:09                         ` Rasmus Villemoes
2021-10-30 17:19                       ` Ard Biesheuvel
2021-10-30 18:02                         ` Peter Zijlstra
2021-10-30 18:55                           ` Ard Biesheuvel
2021-10-31 16:24                             ` Ard Biesheuvel
2021-10-31 16:39                               ` Peter Zijlstra
2021-10-31 16:44                                 ` Ard Biesheuvel
2021-10-31 20:09                                   ` Peter Zijlstra
2021-10-31 20:21                                     ` Ard Biesheuvel
2021-10-31 20:44                                       ` Peter Zijlstra
2021-10-31 23:36                                         ` Ard Biesheuvel
2021-11-01  9:01                                           ` Peter Zijlstra
2021-11-01  9:36                                             ` David Laight
2021-11-01 14:14                                             ` Ard Biesheuvel
2021-11-02 12:57                                               ` Peter Zijlstra
2021-11-02 15:15                                                 ` Peter Zijlstra
2021-11-02 17:44                                                   ` Ard Biesheuvel
2021-11-02 18:14                                                     ` Peter Zijlstra
2021-11-02 18:17                                                       ` Peter Zijlstra
2021-11-02 18:18                                                       ` Ard Biesheuvel
2021-11-02 21:48                                                         ` Peter Zijlstra
2021-11-02 18:10                                                 ` Kees Cook
2021-11-02 21:02                                                   ` Andy Lutomirski
2021-11-02 23:13                                                     ` Kees Cook
2021-11-03  0:20                                                       ` Andy Lutomirski
2021-11-03  8:35                                                         ` Peter Zijlstra
2021-11-03 10:01                                                           ` David Laight
2021-11-03 19:32                                                           ` Andy Lutomirski
2021-11-02 21:19                                                   ` Peter Zijlstra
2021-11-11 12:15                       ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
2021-10-30 19:07                     ` [PATCH v5 00/15] x86: Add support for Clang CFI Sami Tolvanen
2021-10-27 17:11           ` Kees Cook
2021-10-27 21:21             ` Peter Zijlstra
2021-10-27 22:27               ` Kees Cook
2021-10-28 11:09                 ` Peter Zijlstra
2021-10-28 17:12                   ` Kees Cook
2021-10-28 20:29                     ` Peter Zijlstra
2021-11-02 17:26                       ` Kees Cook
2021-11-01  4:13                 ` Andy Lutomirski
2021-10-27 12:46     ` Peter Zijlstra
2021-10-27 12:55     ` David Laight
2021-10-27 13:17       ` Mark Rutland
2021-10-27 21:31         ` David Laight

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).