public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: arm64: Prevent the host from using an smc with imm16 != 0
@ 2026-03-25 11:31 Sebastian Ene
  2026-03-25 11:35 ` Vincent Donnefort
  2026-03-25 13:28 ` Mark Rutland
  0 siblings, 2 replies; 13+ messages in thread
From: Sebastian Ene @ 2026-03-25 11:31 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, linux-kernel, android-kvm
  Cc: catalin.marinas, joey.gouly, mark.rutland, maz, oupton,
	sebastianene, suzuki.poulose, tabba, vdonnefort, will, yuzenghui

The ARM Service Calling Convention (SMCCC) specifies that the function
identifier and parameters should be passed in registers, leaving the
16-bit immediate field of the SMC instruction un-handled.
Currently, our pKVM handler ignores the immediate value, which could lead
to non-compliant software relying on implementation-defined behavior.
Enforce the host kernel running under pKVM to use an immediate value
of 0 by decoding the ISS from the ESR_EL2 and return a not supported
error code back to the caller.

Signed-off-by: Sebastian Ene <sebastianene@google.com>
---
v1 -> v2:

 - Dropped injecting an UNDEF and return an error instead
   (SMCCC_RET_NOT_SUPPORTED)
 - Used the mask ESR_ELx_xVC_IMM_MASK instead of masking with U16_MAX
 - Updated the title of the commit message from:
   "[PATCH] KVM: arm64: Inject UNDEF when host is executing an
    smc with imm16 != 0"
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index e7790097db93..4ffe30fd8707 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -762,6 +762,12 @@ void handle_trap(struct kvm_cpu_context *host_ctxt)
 		handle_host_hcall(host_ctxt);
 		break;
 	case ESR_ELx_EC_SMC64:
+		if (ESR_ELx_xVC_IMM_MASK & esr) {
+			cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED;
+			kvm_skip_host_instr();
+			break;
+		}
+
 		handle_host_smc(host_ctxt);
 		break;
 	case ESR_ELx_EC_IABT_LOW:
-- 
2.53.0.1018.g2bb0e51243-goog


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

end of thread, other threads:[~2026-03-25 16:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25 11:31 [PATCH v2] KVM: arm64: Prevent the host from using an smc with imm16 != 0 Sebastian Ene
2026-03-25 11:35 ` Vincent Donnefort
2026-03-25 11:41   ` Sebastian Ene
2026-03-25 11:58     ` Marc Zyngier
2026-03-25 12:16     ` Fuad Tabba
2026-03-25 13:16       ` Sebastian Ene
2026-03-25 11:46   ` Marc Zyngier
2026-03-25 12:12     ` Will Deacon
2026-03-25 13:33       ` Mark Rutland
2026-03-25 13:15     ` Sebastian Ene
2026-03-25 13:28 ` Mark Rutland
2026-03-25 14:33   ` Marc Zyngier
2026-03-25 16:02   ` Sebastian Ene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox