From mboxrd@z Thu Jan 1 00:00:00 1970 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 06C1E42EED9 for ; Tue, 16 Jun 2026 10:54:25 +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=1781607267; cv=none; b=bDJvQV/X3chJsJyVMCYZEAMIf5T2oL9vQcVPjXBee4I3ei5OWyDWHZPVdke0wUXIgQFRrEsHpwLg10F48gSxEJu6Bv/LgbQY5grwgGCtQ10rllIu11ltmYQRQAC7j1hv9wNDXCHoSocNC9Iw7Lexu4BwfaeJAaQC/uiIqDikn8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781607267; c=relaxed/simple; bh=aLy1aqQg9uKPDRV0yIlbf5EWWuvfUKXrVYINVrPNTmc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=d7OQHErdZP4EWW23aqfIOn3fSIO1oqtI9SmejfLdApyVe3knG3YroZowCWGEK5rig56jUKOPI1x4lbDbIo1sCbil2RVxT0U1I0zF6V5DlCapUHiocF+WU2xn/8c42yY6hyNz7V/MRfuI5k95RjeNjwU5sZ192vjyDY2xkNGtzEk= 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=McXQ88QO; 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="McXQ88QO" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-490b79e6b94so41273895e9.2 for ; Tue, 16 Jun 2026 03:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781607264; x=1782212064; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=b9YtP4kly16nC//zfpWqwF2dbg0H1K+4KeRXQuDtzJU=; b=McXQ88QO5S0rAPKZ3eZuMXaI6uzHdO8JJ0rC3zLcVZMP5iZ4oPX7+YNxNE1aTAUFyC Azagt2H1uU/+XHl24IAUXEDfyhDdx0EEgt/4z3kzqLeUrMoTyMypWRSHL3hYC4uVgOqf 4hW46TmQnCgJ3zNHPv/kv10V9hCSeN7hAbMcCnJabOodn8IQ24uANErTOOwSloJsDt3z 07KOYf1tfRTRtiRL2BLkDqODNrN9ijDeEZnzbU5LORDJk4HRm54/B5DQXRmMvhfeRSqr m5ZfC5m9Kn60+EqZNkdRVpp/+anWN3jqUxcGcBOQYZWJkQCwFDfc9lzzPAQlyRax6uOm g3Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781607264; x=1782212064; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=b9YtP4kly16nC//zfpWqwF2dbg0H1K+4KeRXQuDtzJU=; b=M5cgckIBQmWJI3N4Sy0dGBYN2S1CkbDAfgpUpoNKyHgKsZDbj6T5QH18XR8pJoADLi qj6FH9lIkWbQFRH4aDROSWMjQuliON3lBWMUqmktgS6LVD2shUcZmMQLhvZRnSNU4ueA 49rY66hA4zQNhIbPX/mej03LwQivyFVkvorXJX3DAoHdbXBgoStw03AhPAx4w1LkWI8G JSx37XeLWcrg3A9plARbtgPmAA4edCnCQoVEQP8/uWEDUK2jWCwxegSksl2MNYwqeuwP 1ulzzv8OPEgxdV7jT9OEy/F93V9iuxzYmFsgIJ0KFYOQkhELWZhVB6I+8Z8LXljlRmpd YTlw== X-Forwarded-Encrypted: i=1; AFNElJ9ED8NDZJbwyC+gGZrd8l2J6W4fA0WjqwnYuECuPwof5ncJQ/og4xLO9oVP9pSGSAhZnT+3p1wv87VqFFo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8tx1xiAbpTcKaT3JXrOVkm3/rHxcJBBCLwvLwpskR8+fXD/gP Li5/fFra6MHOU/GBr1axMKKH4aYM9xveMOlexxUpQjl9EgQAKvyHem1HvhPWSZKMSB7FH40VM3S 3vmlyhTrsAQSHG9mCYb9LNbzm/kZPAA== X-Received: from wmaw25.prod.google.com ([2002:a05:600c:6d59:b0:48a:5334:11e]) (user=sebastianene job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3f18:b0:490:c2a2:e91f with SMTP id 5b1f17b1804b1-4922ffc05f0mr43580905e9.35.1781607264086; Tue, 16 Jun 2026 03:54:24 -0700 (PDT) Date: Tue, 16 Jun 2026 10:54:08 +0000 In-Reply-To: <20260616105417.2578670-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260616105417.2578670-1-sebastianene@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260616105417.2578670-2-sebastianene@google.com> Subject: [PATCH v3 1/7] KVM: arm64: Enforce strict SBZ checks in the FF-A proxy From: Sebastian Ene To: catalin.marinas@arm.com, maz@kernel.org, oupton@kernel.org, will@kernel.org Cc: joey.gouly@arm.com, korneld@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, android-kvm@google.com, mrigendra.chaubey@gmail.com, perlarsen@google.com, sebastianene@google.com, suzuki.poulose@arm.com, vdonnefort@google.com, yuzenghui@huawei.com Content-Type: text/plain; charset="UTF-8" Introduce a helper method ffa_check_unused_args_sbz to enforce strict arguments checking when the hypervisor acts as a relayer between the host and Trustzone. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/hyp/nvhe/ffa.c | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 1af722771178..c723a21006aa 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -71,6 +71,18 @@ static u32 hyp_ffa_version; static bool has_version_negotiated; static hyp_spinlock_t version_lock; +static bool ffa_check_unused_args_sbz(struct kvm_cpu_context *ctxt, int first_reg) +{ + int reg; + + for (reg = first_reg; reg < 17; reg++) { + if (cpu_reg(ctxt, reg)) + return true; + } + + return false; +} + static void ffa_to_smccc_error(struct arm_smccc_1_2_regs *res, u64 ffa_errno) { *res = (struct arm_smccc_1_2_regs) { @@ -239,6 +251,11 @@ static void do_ffa_rxtx_map(struct arm_smccc_1_2_regs *res, int ret = 0; void *rx_virt, *tx_virt; + if (ffa_check_unused_args_sbz(ctxt, 4)) { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + if (npages != (KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) / FFA_PAGE_SIZE) { ret = FFA_RET_INVALID_PARAMETERS; goto out; @@ -315,6 +332,11 @@ static void do_ffa_rxtx_unmap(struct arm_smccc_1_2_regs *res, DECLARE_REG(u32, id, ctxt, 1); int ret = 0; + if (ffa_check_unused_args_sbz(ctxt, 2)) { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + if (id != HOST_FFA_ID) { ret = FFA_RET_INVALID_PARAMETERS; goto out; @@ -421,6 +443,11 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_1_2_regs *res, int ret = FFA_RET_INVALID_PARAMETERS; u32 nr_ranges; + if (ffa_check_unused_args_sbz(ctxt, 5)) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + if (fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) goto out; @@ -482,6 +509,11 @@ static void __do_ffa_mem_xfer(const u64 func_id, u32 offset, nr_ranges, checked_offset; int ret = 0; + if (ffa_check_unused_args_sbz(ctxt, 5)) { + ret = FFA_RET_INVALID_PARAMETERS; + goto out; + } + if (addr_mbz || npages_mbz || fraglen > len || fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) { ret = FFA_RET_INVALID_PARAMETERS; @@ -581,6 +613,11 @@ static void do_ffa_mem_reclaim(struct arm_smccc_1_2_regs *res, int ret = 0; u64 handle; + if (ffa_check_unused_args_sbz(ctxt, 4)) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + handle = PACK_HANDLE(handle_lo, handle_hi); hyp_spin_lock(&host_buffers.lock); @@ -769,6 +806,11 @@ static void do_ffa_version(struct arm_smccc_1_2_regs *res, { DECLARE_REG(u32, ffa_req_version, ctxt, 1); + if (ffa_check_unused_args_sbz(ctxt, 2)) { + res->a0 = FFA_RET_NOT_SUPPORTED; + return; + } + if (FFA_MAJOR_VERSION(ffa_req_version) != 1) { res->a0 = FFA_RET_NOT_SUPPORTED; return; @@ -818,6 +860,11 @@ static void do_ffa_part_get(struct arm_smccc_1_2_regs *res, DECLARE_REG(u32, flags, ctxt, 5); u32 count, partition_sz, copy_sz; + if (ffa_check_unused_args_sbz(ctxt, 6)) { + ffa_to_smccc_res(res, FFA_RET_INVALID_PARAMETERS); + return; + } + hyp_spin_lock(&host_buffers.lock); if (!host_buffers.rx) { ffa_to_smccc_res(res, FFA_RET_BUSY); -- 2.54.0.1136.gdb2ca164c4-goog