From nobody Fri Apr 3 01:24:08 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D5293AE1BC for ; Wed, 25 Mar 2026 11:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438306; cv=none; b=t28apRGGJJg844OWV8uiqjJPnWVpcNU52A68ywRjuyTlqPFfasDlWxAeJwGKpteJQyZlvFyzX/0suGFx3AbgDk2Z6G6e13Z8vFqqU8m2GF4onIIfxc/06PllfIItg8SEdlEiDFmsXuR0yNgzBxadK3K07O25y0MgQK/B+x3vEFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774438306; c=relaxed/simple; bh=ngPogGvQ/oHYmBLGmymSGcjEabQ6C2DPBCFrZroAAKU=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=SlhQOLUJaja2+OwN6qZrhxlFQh03zL+lorbyBJ0SZhU/dmF6K1dMsuCUz6o9SrQn2LZyHlPS07JvB665P+BQaekFZh20g4uIocvaqZXMvQ1WRClCjAL2xJmdLj3tGUDfs+mCzH5P/BZ1tLrCK/i4eq0rrtKSyMtc0SXQf0oaBA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hp4kwh0s; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hp4kwh0s" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4853a9467c5so42276195e9.2 for ; Wed, 25 Mar 2026 04:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774438303; x=1775043103; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=p84lLdIepUZTxV4B3SNssiaMT7UBerhqgF3wniuKFK8=; b=hp4kwh0sFlx/xlB/z3T1h7nnoDNWNasnfyfKJc2HiReqQsHMXqwEOviBgXYcBr8fUu XkF18ZIGCajgVK0KTMZo258itHrAyMbcF1vklMaPRIwKoahCuHfc2nVOruflCrCa+ZXl yghj5zw2LC3ZisSj3n6DgtpVzFC+/jGdhWj+C0ItJ+j8qaf49FRf8pkX2HesQUKyN1Om +RqVvDLecZyfLQUHWhvqAkRV/DhQ7CPMB2s86Igt7ehgUg6Vf+RvpZzU3/VKFz6LhSeU AM58qC3MHWhx92u2RUxf7QxVbhH4DsHl+cB585GhPlu/9PiCXHh5scSE58WYOB5za+vP AiwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774438303; x=1775043103; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=p84lLdIepUZTxV4B3SNssiaMT7UBerhqgF3wniuKFK8=; b=mUs/g70U04uVrCKUTeksdtUJIvsYYFtzLcezna/e5RdLr2DwkUg/iV/fNbY/qgY6D+ NMSTDdmGa0P13P3oRb1dLPu8OuwaOqQ7B5UJ1CzE4V+u1abkA/xdqB+aSy7wGHHVAIsB L7EcWN1N7T5EKO8Al87oPjO30ubc7tXCKJALbfwdzUbVUoLUEZmiPmR+qO5FlYWKnpbh /8ztDVaaFT8X0W5k+elGAaVlDJqnifSI04VVxi5aMQ/f7VGPOPvEkDj9x35Vvys+49yH d5qCbmlZrIAOAkKwFJfKpHRK/jue9jeUW+MMzQgdgtZuI2z6wzkZVOE6dZQpRu+Knd43 TKTQ== X-Forwarded-Encrypted: i=1; AJvYcCWPISAzCF5bJ0is2lLodcjbU3LW5RiBESaCuuBuJsJYn/CaUEmwqEaZUfsvZ9YqRHAgt0nzhoPg4X5PK8E=@vger.kernel.org X-Gm-Message-State: AOJu0YwLI3AJKY8j6nQbZWDjdekKGl0l86UxGg4QPrCUdZIRpxx3YgmR okXUK/v78zTqJtsxvaXXFr9SElZtGa5KX3uPbK21y4TgnvmrCxDjcT3Hj/go4byGPVUb9TJxhLC v/X/+HI/Ea9SbIR1CnZkjVuFaZooiEg== X-Received: from wruc11.prod.google.com ([2002:a5d:4f0b:0:b0:43b:42a9:2db1]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4692:b0:485:3812:36f6 with SMTP id 5b1f17b1804b1-48716046ee1mr47372355e9.21.1774438303323; Wed, 25 Mar 2026 04:31:43 -0700 (PDT) Date: Wed, 25 Mar 2026 11:31:38 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.1018.g2bb0e51243-goog Message-ID: <20260325113138.4171430-1-sebastianene@google.com> Subject: [PATCH v2] KVM: arm64: Prevent the host from using an smc with imm16 != 0 From: Sebastian Ene To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, android-kvm@google.com Cc: catalin.marinas@arm.com, joey.gouly@arm.com, mark.rutland@arm.com, maz@kernel.org, oupton@kernel.org, sebastianene@google.com, suzuki.poulose@arm.com, tabba@google.com, vdonnefort@google.com, will@kernel.org, yuzenghui@huawei.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 !=3D 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/h= yp-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) =3D SMCCC_RET_NOT_SUPPORTED; + kvm_skip_host_instr(); + break; + } + handle_host_smc(host_ctxt); break; case ESR_ELx_EC_IABT_LOW: --=20 2.53.0.1018.g2bb0e51243-goog