linux-stable/arch/arm64/kvm/hyp/nvhe
Marco Elver aebc7b0d8d list: Introduce CONFIG_LIST_HARDENED
Numerous production kernel configs (see [1, 2]) are choosing to enable
CONFIG_DEBUG_LIST, which is also being recommended by KSPP for hardened
configs [3]. The motivation behind this is that the option can be used
as a security hardening feature (e.g. CVE-2019-2215 and CVE-2019-2025
are mitigated by the option [4]).

The feature has never been designed with performance in mind, yet common
list manipulation is happening across hot paths all over the kernel.

Introduce CONFIG_LIST_HARDENED, which performs list pointer checking
inline, and only upon list corruption calls the reporting slow path.

To generate optimal machine code with CONFIG_LIST_HARDENED:

  1. Elide checking for pointer values which upon dereference would
     result in an immediate access fault (i.e. minimal hardening
     checks).  The trade-off is lower-quality error reports.

  2. Use the __preserve_most function attribute (available with Clang,
     but not yet with GCC) to minimize the code footprint for calling
     the reporting slow path. As a result, function size of callers is
     reduced by avoiding saving registers before calling the rarely
     called reporting slow path.

     Note that all TUs in lib/Makefile already disable function tracing,
     including list_debug.c, and __preserve_most's implied notrace has
     no effect in this case.

  3. Because the inline checks are a subset of the full set of checks in
     __list_*_valid_or_report(), always return false if the inline
     checks failed.  This avoids redundant compare and conditional
     branch right after return from the slow path.

As a side-effect of the checks being inline, if the compiler can prove
some condition to always be true, it can completely elide some checks.

Since DEBUG_LIST is functionally a superset of LIST_HARDENED, the
Kconfig variables are changed to reflect that: DEBUG_LIST selects
LIST_HARDENED, whereas LIST_HARDENED itself has no dependency on
DEBUG_LIST.

Running netperf with CONFIG_LIST_HARDENED (using a Clang compiler with
"preserve_most") shows throughput improvements, in my case of ~7% on
average (up to 20-30% on some test cases).

Link: https://r.android.com/1266735 [1]
Link: https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/blob/main/config [2]
Link: https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project/Recommended_Settings [3]
Link: https://googleprojectzero.blogspot.com/2019/11/bad-binder-android-in-wild-exploit.html [4]
Signed-off-by: Marco Elver <elver@google.com>
Link: https://lore.kernel.org/r/20230811151847.1594958-3-elver@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>
2023-08-15 14:57:25 -07:00
..
.gitignore KVM: arm64: Generate hyp relocation data 2021-01-23 14:01:00 +00:00
Makefile list: Introduce CONFIG_LIST_HARDENED 2023-08-15 14:57:25 -07:00
cache.S KVM: arm64: Provide I-cache invalidation by virtual address at EL2 2022-11-11 17:16:25 +00:00
debug-sr.c arm64/sysreg: Rename TRBLIMITR_EL1 fields per auto-gen tools format 2023-06-14 14:37:32 +01:00
early_alloc.c KVM: arm64: Provide {get,put}_page() stubs for early hyp allocator 2021-12-16 12:58:55 +00:00
ffa.c KVM: arm64: pkvm: Add support for fragmented FF-A descriptors 2023-06-01 21:34:51 +00:00
gen-hyprel.c KVM: arm64: Support PREL/PLT relocs in EL2 code 2021-03-31 14:59:19 +01:00
host.S KVM: arm64: Use different pointer authentication keys for pKVM 2023-06-14 15:17:32 +00:00
hyp-init.S Merge branch kvm-arm64/misc into kvmarm/next 2023-06-15 13:09:43 +00:00
hyp-main.c Merge branch kvm-arm64/hvhe into kvmarm/next 2023-06-15 13:02:49 +00:00
hyp-smp.c KVM: arm64: Unmap 'kvm_arm_hyp_percpu_base' from the host 2022-11-11 17:19:35 +00:00
hyp.lds.S KVM: arm64: Introduce a BSS section for use at Hyp 2021-03-19 12:01:20 +00:00
list_debug.c list: Introduce CONFIG_LIST_HARDENED 2023-08-15 14:57:25 -07:00
mem_protect.c KVM/arm64 updates for 6.5 2023-07-01 07:04:29 -04:00
mm.c Merge branch kvm-arm64/pkvm-vcpu-state into kvmarm-master/next 2022-12-05 14:37:23 +00:00
page_alloc.c mm, treewide: redefine MAX_ORDER sanely 2023-04-05 19:42:46 -07:00
pkvm.c KVM: arm64: Force HCR_E2H in guest context when ARM64_KVM_HVHE is set 2023-06-12 23:17:24 +00:00
psci-relay.c KVM: arm64: Log source when panicking from nVHE hyp 2021-04-01 09:54:37 +01:00
setup.c KVM: arm64: Allocate pages for hypervisor FF-A mailboxes 2023-06-01 21:34:50 +00:00
stacktrace.c arm64: stacktrace: track hyp stacks in unwinder's address space 2022-09-09 12:30:08 +01:00
switch.c KVM/arm64 updates for 6.5 2023-07-01 07:04:29 -04:00
sys_regs.c KVM: arm64: Advertise ID_AA64PFR0_EL1.CSV2/3 to protected VMs 2023-04-04 15:52:06 +00:00
sysreg-sr.c KVM: arm64: Simplify __kvm_enable_ssbs() 2020-11-27 11:32:44 +00:00
timer-sr.c KVM: arm64: Program the timer traps with VHE layout in hVHE mode 2023-06-12 23:17:24 +00:00
tlb.c KVM: arm64: Use local TLBI on permission relaxation 2023-05-16 17:39:19 +00:00