]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Handle UBSAN faults
authorMostafa Saleh <smostafa@google.com>
Wed, 30 Apr 2025 16:27:11 +0000 (16:27 +0000)
committerMarc Zyngier <maz@kernel.org>
Wed, 7 May 2025 10:21:35 +0000 (11:21 +0100)
As now UBSAN can be enabled, handle brk64 exits from UBSAN.
Re-use the decoding code from the kernel, and panic with
UBSAN message.

Signed-off-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/20250430162713.1997569-5-smostafa@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/handle_exit.c

index b73dc26bc44b410903e2423551d61d4e65fd7e1e..5c49540883e3d5b125b0e3b6ff1d78c97a653aa9 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/kvm.h>
 #include <linux/kvm_host.h>
+#include <linux/ubsan.h>
 
 #include <asm/esr.h>
 #include <asm/exception.h>
@@ -474,6 +475,11 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
                        print_nvhe_hyp_panic("BUG", panic_addr);
        } else if (IS_ENABLED(CONFIG_CFI_CLANG) && esr_is_cfi_brk(esr)) {
                kvm_nvhe_report_cfi_failure(panic_addr);
+       } else if (IS_ENABLED(CONFIG_UBSAN_KVM_EL2) &&
+                  ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
+                  esr_is_ubsan_brk(esr)) {
+               print_nvhe_hyp_panic(report_ubsan_failure(esr & UBSAN_BRK_MASK),
+                                    panic_addr);
        } else {
                print_nvhe_hyp_panic("panic", panic_addr);
        }