From: "Pierre-Clément Tosi" <ptosi@google.com>
To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org
Cc: "Pierre-Clément Tosi" <ptosi@google.com>,
"Marc Zyngier" <maz@kernel.org>,
"Oliver Upton" <oliver.upton@linux.dev>,
"Suzuki K Poulose" <suzuki.poulose@arm.com>,
"Vincent Donnefort" <vdonnefort@google.com>
Subject: [PATCH v4 00/13] KVM: arm64: Add support for hypervisor kCFI
Date: Wed, 29 May 2024 13:12:06 +0100 [thread overview]
Message-ID: <20240529121251.1993135-1-ptosi@google.com> (raw)
CONFIG_CFI_CLANG ("kernel Control Flow Integrity") makes the compiler inject
runtime type checks before any indirect function call. On AArch64, it generates
a BRK instruction to be executed on type mismatch and encodes the indices of the
registers holding the branch target and expected type in the immediate of the
instruction. As a result, a synchronous exception gets triggered on kCFI failure
and the fault handler can retrieve the immediate (and indices) from ESR_ELx.
This feature has been supported at EL1 ("host") since it was introduced by
b26e484b8bb3 ("arm64: Add CFI error handling"), where cfi_handler() decodes
ESR_EL1, giving informative panic messages such as
[ 21.885179] CFI failure at lkdtm_indirect_call+0x2c/0x44 [lkdtm]
(target: lkdtm_increment_int+0x0/0x1c [lkdtm]; expected type: 0x7e0c52a)
[ 21.886593] Internal error: Oops - CFI: 0 [#1] PREEMPT SMP
However, it is not or only partially supported at EL2: in nVHE (or pKVM),
CONFIG_CFI_CLANG gets filtered out at build time, preventing the compiler from
injecting the checks. In VHE, EL2 code gets compiled with the checks but the
handlers in VBAR_EL2 are not aware of kCFI and will produce a generic and
not-so-helpful panic message such as
[ 36.456088][ T200] Kernel panic - not syncing: HYP panic:
[ 36.456088][ T200] PS:204003c9 PC:ffffffc080092310 ESR:f2008228
[ 36.456088][ T200] FAR:0000000081a50000 HPFAR:000000000081a500 PAR:1de7ec7edbadc0de
[ 36.456088][ T200] VCPU:00000000e189c7cf
To address this,
- [01/13] fixes an existing bug where the ELR_EL2 was getting clobbered on
synchronous exceptions, causing the wrong "PC" to be reported by
nvhe_hyp_panic_handler() or __hyp_call_panic(). This is particularly limiting
for kCFI, as it would mask the location of the failed type check.
- [02/13] fixes a minor C/asm ABI mismatch which would trigger a kCFI failure
- [03/13] to [09/13] prepare nVHE for CONFIG_CFI_CLANG and [10/13] enables it
- [11/13] improves kCFI error messages by saving then parsing the CPU context
- [12/13] adds a kCFI test module for VHE and [13/13] extends it to nVHE & pKVM
As a result, an informative kCFI panic message is printed by or on behalf of EL2
giving the expected type and target address (possibly resolved to a symbol) for
VHE, nVHE, and pKVM (iff CONFIG_NVHE_EL2_DEBUG=y).
Note that kCFI errors remain fatal at EL2, even when CONFIG_CFI_PERMISSIVE=y.
Changes in v4:
- Addressed Will's comments on v3:
- Removed save/restore of x0-x1 & used __guest_exit_panic ABI for new routines
- Reworked __pkvm_init_switch_pgd new API with separate args
- Moved cosmetic changes (renaming to __hyp_panic) into dedicated commit
- Further clarified the commit message regarding R_AARCH64_ABS32
- early_brk64() uses esr_is_cfi_brk() (now introduced along esr_brk_comment())
- Added helper to display nvHE panic banner
- Moved the test module to the end of the series
Pierre-Clément Tosi (13):
KVM: arm64: Fix clobbered ELR in sync abort/SError
KVM: arm64: Fix __pkvm_init_switch_pgd call ABI
KVM: arm64: nVHE: Simplify __guest_exit_panic path
KVM: arm64: nVHE: Add EL2h sync exception handler
KVM: arm64: Rename __guest_exit_panic __hyp_panic
KVM: arm64: nVHE: gen-hyprel: Skip R_AARCH64_ABS32
KVM: arm64: VHE: Mark __hyp_call_panic __noreturn
arm64: Introduce esr_comment() & esr_is_cfi_brk()
KVM: arm64: Introduce print_nvhe_hyp_panic helper
KVM: arm64: nVHE: Support CONFIG_CFI_CLANG at EL2
KVM: arm64: Improve CONFIG_CFI_CLANG error message
KVM: arm64: VHE: Add test module for hyp kCFI
KVM: arm64: nVHE: Support test module for hyp kCFI
arch/arm64/include/asm/esr.h | 11 ++
arch/arm64/include/asm/kvm_asm.h | 3 +
arch/arm64/include/asm/kvm_cfi.h | 38 +++++++
arch/arm64/include/asm/kvm_hyp.h | 3 +-
arch/arm64/kernel/asm-offsets.c | 1 +
arch/arm64/kernel/debug-monitors.c | 4 +-
arch/arm64/kernel/traps.c | 8 +-
arch/arm64/kvm/Kconfig | 20 ++++
arch/arm64/kvm/Makefile | 3 +
arch/arm64/kvm/handle_exit.c | 50 ++++++++-
arch/arm64/kvm/hyp/cfi.c | 37 +++++++
arch/arm64/kvm/hyp/entry.S | 34 +++++-
arch/arm64/kvm/hyp/hyp-entry.S | 4 +-
arch/arm64/kvm/hyp/include/hyp/cfi.h | 47 +++++++++
arch/arm64/kvm/hyp/include/hyp/switch.h | 5 +-
arch/arm64/kvm/hyp/nvhe/Makefile | 7 +-
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 6 ++
arch/arm64/kvm/hyp/nvhe/host.S | 21 ++--
arch/arm64/kvm/hyp/nvhe/hyp-init.S | 23 ++--
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 19 ++++
arch/arm64/kvm/hyp/nvhe/setup.c | 4 +-
arch/arm64/kvm/hyp/nvhe/switch.c | 7 ++
arch/arm64/kvm/hyp/vhe/Makefile | 1 +
arch/arm64/kvm/hyp/vhe/switch.c | 34 +++++-
arch/arm64/kvm/hyp_cfi_test.c | 75 +++++++++++++
arch/arm64/kvm/hyp_cfi_test_module.c | 135 ++++++++++++++++++++++++
26 files changed, 553 insertions(+), 47 deletions(-)
create mode 100644 arch/arm64/include/asm/kvm_cfi.h
create mode 100644 arch/arm64/kvm/hyp/cfi.c
create mode 100644 arch/arm64/kvm/hyp/include/hyp/cfi.h
create mode 100644 arch/arm64/kvm/hyp_cfi_test.c
create mode 100644 arch/arm64/kvm/hyp_cfi_test_module.c
--
2.45.1.288.g0e0cd299f1-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2024-05-29 12:13 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 12:12 Pierre-Clément Tosi [this message]
2024-05-29 12:12 ` [PATCH v4 01/13] KVM: arm64: Fix clobbered ELR in sync abort/SError Pierre-Clément Tosi
2024-06-03 14:05 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 02/13] KVM: arm64: Fix __pkvm_init_switch_pgd call ABI Pierre-Clément Tosi
2024-06-03 14:22 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 03/13] KVM: arm64: nVHE: Simplify __guest_exit_panic path Pierre-Clément Tosi
2024-06-03 14:30 ` Will Deacon
2024-06-04 15:48 ` Pierre-Clément Tosi
2024-06-05 16:02 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 04/13] KVM: arm64: nVHE: Add EL2h sync exception handler Pierre-Clément Tosi
2024-06-03 14:32 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 05/13] KVM: arm64: Rename __guest_exit_panic __hyp_panic Pierre-Clément Tosi
2024-06-03 14:34 ` Will Deacon
2024-06-04 15:51 ` Pierre-Clément Tosi
2024-06-05 16:10 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 06/13] KVM: arm64: nVHE: gen-hyprel: Skip R_AARCH64_ABS32 Pierre-Clément Tosi
2024-06-03 14:35 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 07/13] KVM: arm64: VHE: Mark __hyp_call_panic __noreturn Pierre-Clément Tosi
2024-06-03 14:36 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 08/13] arm64: Introduce esr_comment() & esr_is_cfi_brk() Pierre-Clément Tosi
2024-06-03 14:42 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 09/13] KVM: arm64: Introduce print_nvhe_hyp_panic helper Pierre-Clément Tosi
2024-06-03 14:43 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 10/13] KVM: arm64: nVHE: Support CONFIG_CFI_CLANG at EL2 Pierre-Clément Tosi
2024-06-03 14:45 ` Will Deacon
2024-06-04 16:04 ` Pierre-Clément Tosi
2024-06-05 16:11 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 11/13] KVM: arm64: Improve CONFIG_CFI_CLANG error message Pierre-Clément Tosi
2024-06-03 14:48 ` Will Deacon
2024-06-04 16:05 ` Pierre-Clément Tosi
2024-06-06 16:22 ` Will Deacon
2024-05-29 12:12 ` [PATCH v4 12/13] KVM: arm64: VHE: Add test module for hyp kCFI Pierre-Clément Tosi
2024-05-29 12:12 ` [PATCH v4 13/13] KVM: arm64: nVHE: Support " Pierre-Clément Tosi
2024-06-03 13:59 ` [PATCH v4 00/13] KVM: arm64: Add support for hypervisor kCFI Will Deacon
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=20240529121251.1993135-1-ptosi@google.com \
--to=ptosi@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=vdonnefort@google.com \
/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