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>,
"Will Deacon" <will@kernel.org>, "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 v5 0/8] KVM: arm64: Add support for hypervisor kCFI
Date: Mon, 10 Jun 2024 07:32:29 +0100 [thread overview]
Message-ID: <20240610063244.2828978-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 supported at EL2 in nVHE (or pKVM), as CONFIG_CFI_CLANG gets
filtered out at build time, preventing the compiler from injecting the checks.
To address this,
- [1/8] 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.
- [2/8] fixes a minor C/asm ABI mismatch which would trigger a kCFI failure
- [3/8]-[7/8] prepare nVHE for CONFIG_CFI_CLANG and [8/8] enables it
Note that kCFI errors remain fatal at EL2, even when CONFIG_CFI_PERMISSIVE=y.
Changes in v5 (addressed Will's comments on v4):
- Dropped the patch making the handlers report the kCFI target & expected type
- Dropped the hypervisor kCFI test module
- Dropped the patch introducing handler for EL2h sync exceptions
- Dropped the patch renaming __guest_exit_panic
- Made invalid_host_el2_vect branch unconditionally to hyp_panic
- Changed SP type in __pkvm_init_switch_pgd signature to unsigned long
- Changed which registers __pkvm_init_switch_pgd used for intermediates
- Fixed typo in commit message about esr_brk_comment()
- Fixed mistake in commit message about context of invalid_host_el2_vect
Pierre-Clément Tosi (8):
KVM: arm64: Fix clobbered ELR in sync abort/SError
KVM: arm64: Fix __pkvm_init_switch_pgd call ABI
KVM: arm64: nVHE: Simplify invalid_host_el2_vect
KVM: arm64: nVHE: gen-hyprel: Skip R_AARCH64_ABS32
KVM: arm64: VHE: Mark __hyp_call_panic __noreturn
arm64: Introduce esr_brk_comment, esr_is_cfi_brk
KVM: arm64: Introduce print_nvhe_hyp_panic helper
KVM: arm64: nVHE: Support CONFIG_CFI_CLANG at EL2
arch/arm64/include/asm/esr.h | 11 +++++++++
arch/arm64/include/asm/kvm_hyp.h | 4 ++--
arch/arm64/kernel/asm-offsets.c | 1 +
arch/arm64/kernel/debug-monitors.c | 4 +---
arch/arm64/kernel/traps.c | 8 +++----
arch/arm64/kvm/handle_exit.c | 24 +++++++++++++++-----
arch/arm64/kvm/hyp/entry.S | 8 +++++++
arch/arm64/kvm/hyp/include/hyp/switch.h | 5 +++--
arch/arm64/kvm/hyp/nvhe/Makefile | 6 ++---
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 6 +++++
arch/arm64/kvm/hyp/nvhe/host.S | 6 -----
arch/arm64/kvm/hyp/nvhe/hyp-init.S | 30 +++++++++++++++----------
arch/arm64/kvm/hyp/nvhe/setup.c | 4 ++--
arch/arm64/kvm/hyp/vhe/switch.c | 3 +--
14 files changed, 78 insertions(+), 42 deletions(-)
--
2.45.2.505.gda0bf45e8d-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-06-10 6:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 6:32 Pierre-Clément Tosi [this message]
2024-06-10 6:32 ` [PATCH v5 1/8] KVM: arm64: Fix clobbered ELR in sync abort/SError Pierre-Clément Tosi
2024-06-10 6:32 ` [PATCH v5 2/8] KVM: arm64: Fix __pkvm_init_switch_pgd call ABI Pierre-Clément Tosi
2024-06-20 11:37 ` Will Deacon
2024-06-10 6:32 ` [PATCH v5 3/8] KVM: arm64: nVHE: Simplify invalid_host_el2_vect Pierre-Clément Tosi
2024-06-20 11:35 ` Will Deacon
2024-06-10 6:32 ` [PATCH v5 4/8] KVM: arm64: nVHE: gen-hyprel: Skip R_AARCH64_ABS32 Pierre-Clément Tosi
2024-06-10 6:32 ` [PATCH v5 5/8] KVM: arm64: VHE: Mark __hyp_call_panic __noreturn Pierre-Clément Tosi
2024-06-10 6:32 ` [PATCH v5 6/8] arm64: Introduce esr_brk_comment, esr_is_cfi_brk Pierre-Clément Tosi
2024-06-10 6:32 ` [PATCH v5 7/8] KVM: arm64: Introduce print_nvhe_hyp_panic helper Pierre-Clément Tosi
2024-06-10 6:32 ` [PATCH v5 8/8] KVM: arm64: nVHE: Support CONFIG_CFI_CLANG at EL2 Pierre-Clément Tosi
2024-06-20 17:56 ` [PATCH v5 0/8] KVM: arm64: Add support for hypervisor kCFI Oliver Upton
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=20240610063244.2828978-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 \
--cc=will@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