linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] KVM: arm64: UBSAN at EL2
@ 2025-04-30 16:27 Mostafa Saleh
  2025-04-30 16:27 ` [PATCH v2 1/4] arm64: Introduce esr_is_ubsan_brk() Mostafa Saleh
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Mostafa Saleh @ 2025-04-30 16:27 UTC (permalink / raw)
  To: kvmarm, kasan-dev, linux-hardening, linux-kbuild, linux-kernel,
	linux-arm-kernel
  Cc: will, maz, oliver.upton, broonie, catalin.marinas, tglx, mingo,
	bp, dave.hansen, x86, hpa, kees, elver, andreyknvl, ryabinin.a.a,
	akpm, yuzenghui, suzuki.poulose, joey.gouly, masahiroy, nathan,
	nicolas.schier, Mostafa Saleh

Many of the sanitizers the kernel supports are disabled when running
in EL2 with nvhe/hvhe/proctected modes, some of those are easier
(and makes more sense) to integrate than others.
Last year, kCFI support was added in [1]

This patchset adds support for UBSAN in EL2.
UBSAN can run in 2 modes:
  1) “Normal” (CONFIG_UBSAN_TRAP=n): In this mode the compiler will
  do the UBSAN checks and insert some function calls in case of
  failures, it can provide more information(ex: what is the value of
  the out of bound) about the failures through those function arguments,
  and those functions(implemented in lib/ubsan.c) will print a report with
  such errors.

  2) Trap (CONFIG_UBSAN_TRAP=y): This is a minimal mode, where similarly,
  the compiler will do the checks, but instead of doing function calls,
  it would do a “brk #imm” (for ARM64) with a unique code with the failure
  type, but without any extra information (ex: only print the out-bound line
  but not the index)

For nvhe/hvhe/proctected modes, #2 would be suitable, as there is no way to
print reports from EL2, so similarly to kCFI(even with permissive) it would
cause the hypervisor to panic.

But that means that for EL2 we need to compile the code with the same options
as used by “CONFIG_UBSAN_TRAP” independently from the kernel config.

This patch series adds a new KCONFIG for ARM64 to choose to enable UBSAN
separately for the modes mentioned.

The same logic decoding the kernel UBSAN is reused, so the messages from
the hypervisor will look similar as:
[   29.215332] kvm [190]: nVHE hyp UBSAN: array index out of bounds at: [<ffff8000811f2344>] __kvm_nvhe_handle___pkvm_init_vm+0xa8/0xac!

In this patch set, the same UBSAN options(for check types) are used for both
EL1/EL2, although a case can be made to have separate options (leading to
totally separate CFLAGS) if we want EL2 to be compiled with stricter checks
for something as protected mode.
However, re-using the current flags, makes code re-use easier for
report_ubsan_failure() and  Makefile.ubsan

[1] https://lore.kernel.org/all/20240610063244.2828978-1-ptosi@google.com/

Changes from v1:
- https://lore.kernel.org/all/20250416180440.231949-1-smostafa@google.com/
- Collected Kees Acked-By
- Rename CFLAGS flag to CFLAGS_UBSAN_TRAP
- Small comment fix

Mostafa Saleh (4):
  arm64: Introduce esr_is_ubsan_brk()
  ubsan: Remove regs from report_ubsan_failure()
  KVM: arm64: Introduce CONFIG_UBSAN_KVM_EL2
  KVM: arm64: Handle UBSAN faults

 arch/arm64/include/asm/esr.h     | 5 +++++
 arch/arm64/kernel/traps.c        | 4 ++--
 arch/arm64/kvm/handle_exit.c     | 6 ++++++
 arch/arm64/kvm/hyp/nvhe/Makefile | 6 ++++++
 arch/x86/kernel/traps.c          | 2 +-
 include/linux/ubsan.h            | 6 +++---
 lib/Kconfig.ubsan                | 9 +++++++++
 lib/ubsan.c                      | 8 +++++---
 scripts/Makefile.ubsan           | 5 ++++-
 9 files changed, 41 insertions(+), 10 deletions(-)

-- 
2.49.0.967.g6a0df3ecc3-goog


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

end of thread, other threads:[~2025-05-08 16:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 16:27 [PATCH v2 0/4] KVM: arm64: UBSAN at EL2 Mostafa Saleh
2025-04-30 16:27 ` [PATCH v2 1/4] arm64: Introduce esr_is_ubsan_brk() Mostafa Saleh
2025-04-30 18:30   ` Kees Cook
2025-04-30 16:27 ` [PATCH v2 2/4] ubsan: Remove regs from report_ubsan_failure() Mostafa Saleh
2025-04-30 16:27 ` [PATCH v2 3/4] KVM: arm64: Introduce CONFIG_UBSAN_KVM_EL2 Mostafa Saleh
2025-04-30 18:30   ` Kees Cook
2025-04-30 16:27 ` [PATCH v2 4/4] KVM: arm64: Handle UBSAN faults Mostafa Saleh
2025-04-30 18:31   ` Kees Cook
2025-04-30 18:32 ` [PATCH v2 0/4] KVM: arm64: UBSAN at EL2 Kees Cook
2025-05-06  8:36   ` Marc Zyngier
2025-05-07 10:35   ` Marc Zyngier
2025-05-08 16:29     ` Kees Cook
2025-05-07 10:35 ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).