From patchwork Mon Sep 9 18:01:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Snehal Koukuntla X-Patchwork-Id: 13797384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE167ECE577 for ; Mon, 9 Sep 2024 18:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=4GzdOAnXsu8VayoX45huUrzJ6QMBoTAjQVvSrXaAbFE=; b=hb3Ld7PXyKTtgW3r267qfW2p0b m+rYx3omWgdFw9wW6MIvmtYou/23iQffiZLnotTvJWSinzy7SjwbKDWaCtQWnuOqoh+MqsFUunRGj ey1Q9zBn5GfNiYBgWtADuG8WRwxkkAjWrHHyMcZrkao8ZctjgvrCfd9mjrtvzHpdeMaC9fVJiq45T ERvEhG1qKo8cBJM9XrB8qJUE+SqaXsR4dD9JfPjJWS0kgUHxvVS0xhMZfSQ2zN+Ptgg9qIkkOkD26 wV6cEWD32Hnkoqcb+0ljkzBlMgbwqH3XN5nIlSGXh9gEwgsz8SfMAbHlTcVS/JIavbA23oJObnd3U 2xMznYtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snijT-00000002vdm-2sCI; Mon, 09 Sep 2024 18:03:23 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sniiT-00000002vVH-1Zcl for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 18:02:22 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e1cfb9d655eso9632531276.0 for ; Mon, 09 Sep 2024 11:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725904939; x=1726509739; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4GzdOAnXsu8VayoX45huUrzJ6QMBoTAjQVvSrXaAbFE=; b=LQFF5wFTvX5HLdKBJ3zTgzwB7xxg9Yl+xTWvf7c62v63meMwO/NPuSo+c7s+OxgEEX 5tGDSbzISQKM9pggXkhe0tAgCn97UY64ifWAuRqNkOiPUFLOQPdTRzjLQvEbg1DSHgrU RfiO1+Z6833CmWGE/wV/hCyVyzrd3QnwXYdkQ+zW9ToLeSLkKvRkTm1KHF9ZKueMYQdy KWYLb0jdu9HC5PdzKh7zb1eZV/WmW0IIFyRbhh6NgTaMRJTeI0bCXNVUAK7odJjP9iLu f3rAnl+8bQCk4fHxg7M1W8ZU1zznYn2K0zV9lYsAL43bEFpfVTSlUq3Ub1GMcw8fGmJO v1JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725904939; x=1726509739; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4GzdOAnXsu8VayoX45huUrzJ6QMBoTAjQVvSrXaAbFE=; b=Fmjk+DpGnVI6vLRh+xNUHkH9Uc3HJkJd5KtTY4IVSfeldXV49lKhp/SqRYoi+Ka8iy Eiu70Iw7YpynDB09m7Oi2i804KzwF8DM1zDDUr2MDxEH3ok6p4ppYyjOVT6pf28vusJ7 3W0UcMgTHsx5rnola6+BIyJgaQ5wdBLpSw/Wjc/AfHh4IT9FqYOXuZCzKnxkpe7HRzFa m7KSZM8IIIZacXVMXnsTFoX7U1RoCPvCXpbBxPHiBIX3QK14IQ93FAm+x9iyPZ0T+C5E MovwSiYfjnqIaExMTbu/Z9eoo25pz/CTtqYBpT6V7Wm2U/Wi2HoEjU6pGETc9bykt3Dj my9A== X-Forwarded-Encrypted: i=1; AJvYcCVxbZPbXN9HZ3n3BtC/BsE6nWC82ksY8+weM6qB/pIDke2BXTgBrq2Fm2GPU0q1+5jioQAMEsGOmNH+lZL7FqCk@lists.infradead.org X-Gm-Message-State: AOJu0YzgmyqjJhJZnjWFRM7a2Vl5nrEe/N0LZYyNS5wZIO+7930sRpTx 1m+bJlp57pBfQKgTsv0Hh5CSb3bVQbbEzoSvOb4/lmZAg28gy8atf9M5BAbLZWXJLbj5V0HWNTB PrUZ8QQoV28KbPj7clpHD2A== X-Google-Smtp-Source: AGHT+IFAuTEL+1ahwEy/aM3fSi5ne7wxws+pnvSGN+IlqZz9OjmkUToSqSs13gvLLdON+5TO44ygwJ2bXIpXxfgvnA== X-Received: from snehalreddy-1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:c1f]) (user=snehalreddy job=sendgmr) by 2002:a25:680b:0:b0:e0b:958a:3344 with SMTP id 3f1490d57ef6-e1d34a3abb7mr28584276.10.1725904939453; Mon, 09 Sep 2024 11:02:19 -0700 (PDT) Date: Mon, 9 Sep 2024 18:01:54 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240909180154.3267939-1-snehalreddy@google.com> Subject: [PATCH v3] KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer From: Snehal Koukuntla To: Marc Zyngier , Oliver Upton Cc: James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla , Sebastian Ene , Vincent Donnefort , Snehal , Jean-Philippe Brucker , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_110221_454537_F837D6AC X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory. To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf. Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing. Also do_ffa_mem_xfer() does not need __always_inline Fixes: 634d90cf0ac65 ("KVM: arm64: Handle FFA_MEM_LEND calls from the host") Cc: stable@vger.kernel.org Reviewed-by: Sebastian Ene Signed-off-by: Snehal Koukuntla Reviewed-by: Oliver Upton Reported-by: Wei-Lin Chang Signed-off-by: Oliver Upton Reviewed-by: Oliver Upton --- arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index e715c157c2c4..637425f63fd1 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, return; } -static __always_inline void do_ffa_mem_xfer(const u64 func_id, +static void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res, struct kvm_cpu_context *ctxt) { @@ -461,6 +461,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id, goto out_unlock; } + if (len > ffa_desc_buf.len) { + ret = FFA_RET_NO_MEMORY; + goto out_unlock; + } + buf = hyp_buffers.tx; memcpy(buf, host_buffers.tx, fraglen);