All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] arm64: dynamic shadow call stack support
@ 2022-06-13 13:40 Ard Biesheuvel
  2022-06-13 13:40 ` [PATCH v3 1/3] arm64: unwind: add asynchronous unwind tables to kernel and modules Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Ard Biesheuvel @ 2022-06-13 13:40 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: catalin.marinas, will, mark.rutland, maz, Ard Biesheuvel,
	Kees Cook, Sami Tolvanen, Fangrui Song, Nick Desaulniers, Dan Li

Generic kernel images such as Android's GKI usually enable all available
security features, which are typically implemented in such a way that
they only take effect if the underlying hardware can support it, but
don't interfere with correct and efficient operation otherwise.

For shadow call stack support, which is always supported by the
hardware, it means it will be enabled even if pointer authentication is
also supported, and enabled for signing return addresses stored on the
stack. The additional security provided by shadow call stack is only
marginal in this case, whereas the performance overhead is not.

Given that return address signing is based on PACIASP/AUTIASP
instructions that implicitly operate on the return address register
(X30) and are not idempotent (i.e., each needs to be emitted exactly
once before the return address is stored on the ordinary stack and after
it has been retrieved from it), we can convert these instruction 1:1
into shadow call stack pushes and pops involving the register X30.
As this is something that can be done at runtime rather than build time,
we can do this conditionally based on whether or not return address
signing is supported on the underlying hardware.

In order to be able to unwind call stacks that involve return address
signing, whether or not the return address is currently signed is
tracked by DWARF CFI directives in the unwinding metadata. This means we
can use this information to locate all PACIASP/AUTIASP instructions in
the binary, instead of having to use brute force and go over all
instructions in the entire program.

This series implements this approach for Clang, which has recently been
fixed to emit all these CFI directives correctly. This series is based
on an older PoC sent out last year [0] that targeted GCC only (due to
this issue). This v3 targets Clang only, as GCC has its own issues with
CFI accuracy.

Changes since v2 [1]:
- don't enable unwind table generation for nVHE code - it cannot be
  patched anyway so it has no use for it;
- drop checks for ID reg overrides
- fix some remaining TODOs regarding augmentation data and the code
  alignment factor
- disable PAC for leaf functions when dynamic SCS is configured, so that
  we don't end up with SCS pushes and pops in all leaf functions too;
- add I-cache maintenance after code patching
- add Rb's from Nick and Kees.

Changes since RFC v1:
- implement boot time check for PAC/BTI support, and only enable dynamic
  SCS if neither are supported;
- implement module patching as well;
- switch to Clang, and drop workaround for GCC bug;

[0] https://lore.kernel.org/linux-arm-kernel/20211013152243.2216899-1-ardb@kernel.org/
[1] https://lore.kernel.org/linux-arm-kernel/20220505161011.1801596-1-ardb@kernel.org/

Cc: Kees Cook <keescook@google.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Dan Li <ashimida@linux.alibaba.com>

Ard Biesheuvel (3):
  arm64: unwind: add asynchronous unwind tables to kernel and modules
  scs: add support for dynamic shadow call stacks
  arm64: implement dynamic shadow call stack for Clang

 Makefile                              |   2 +
 arch/Kconfig                          |   7 +
 arch/arm64/Kconfig                    |  12 +
 arch/arm64/Makefile                   |  15 +-
 arch/arm64/include/asm/module.lds.h   |   8 +
 arch/arm64/include/asm/scs.h          |  45 ++++
 arch/arm64/kernel/Makefile            |   2 +
 arch/arm64/kernel/head.S              |   3 +
 arch/arm64/kernel/irq.c               |   2 +-
 arch/arm64/kernel/module.c            |   8 +
 arch/arm64/kernel/patch-scs.c         | 257 ++++++++++++++++++++
 arch/arm64/kernel/sdei.c              |   2 +-
 arch/arm64/kernel/setup.c             |   4 +
 arch/arm64/kernel/vmlinux.lds.S       |  13 +
 arch/arm64/kvm/hyp/nvhe/Makefile      |   1 +
 drivers/firmware/efi/libstub/Makefile |   1 +
 include/linux/scs.h                   |  16 ++
 kernel/scs.c                          |  14 +-
 18 files changed, 406 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm64/kernel/patch-scs.c

-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-06-16 10:52 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13 13:40 [PATCH v3 0/3] arm64: dynamic shadow call stack support Ard Biesheuvel
2022-06-13 13:40 ` [PATCH v3 1/3] arm64: unwind: add asynchronous unwind tables to kernel and modules Ard Biesheuvel
2022-06-15 16:50   ` Sami Tolvanen
2022-06-15 16:53     ` Ard Biesheuvel
2022-06-15 21:29       ` Kees Cook
2022-06-15 21:52         ` Fangrui Song
2022-06-16  7:14           ` Ard Biesheuvel
2022-06-16  7:24             ` Fangrui Song
2022-06-13 13:40 ` [PATCH v3 2/3] scs: add support for dynamic shadow call stacks Ard Biesheuvel
2022-06-14  6:20   ` Ard Biesheuvel
2022-06-15 17:12     ` Sami Tolvanen
2022-06-16  7:14       ` Ard Biesheuvel
2022-06-13 13:40 ` [PATCH v3 3/3] arm64: implement dynamic shadow call stack for Clang Ard Biesheuvel
2022-06-13 16:30   ` Kees Cook
2022-06-13 16:50     ` Ard Biesheuvel
2022-06-15 21:32   ` Sami Tolvanen
2022-06-16 10:51     ` Ard Biesheuvel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.