From patchwork Fri Sep 6 09:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Snehal Koukuntla X-Patchwork-Id: 13793774 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 D8610CE7AF9 for ; Fri, 6 Sep 2024 09:39:39 +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=NL51OiKKXYrcwrjtHOrpmmV+PQMlb7GKuARQtOGoLlU=; b=0QnTMA0f+e5Vd5NN6WFTAE0mWV z2CKI5tWHPjXmKcFcplzKZP2EhM/HaKpoXpA0VIYT8J5G51TqtetYk1uE9SCDMmjx9GJIoUf04iGl sOiyzmWvH64LJPKFSsxq+bMuN+QNHWUw4VMQSAJHqkZC/wGv9TsV8oEIxO/9gyCvmZ5Wp8xSv6RR4 eH7mrjTjNzUZTrDssBQeN1YPEwymTV7xe4rkL7Z6EINkKX/OSLpgVw4mlcKi8bpu7XbOLjqcUPNU0 1pIyXWCgnxBttuWFuUzpD/xnIJg1c+3CfkBwtUHFrXQbOJkhiAVYKwmIPjN7xce0i1CfFqrImOuh8 ljmiV0qQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smVR8-0000000BY2p-3PK1; Fri, 06 Sep 2024 09:39:26 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smVG7-0000000BVUj-3aB9 for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 09:28:06 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e1159159528so7295989276.1 for ; Fri, 06 Sep 2024 02:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725614882; x=1726219682; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=NL51OiKKXYrcwrjtHOrpmmV+PQMlb7GKuARQtOGoLlU=; b=JjmXE4lY4Ny6ZjijSX1mDWzvIOItomKG8R3NvkfQ/qGlSPhGKdJpbb/lAGKpg60d4K 8RxDoyeXUKhurt3A5bJPYdHHlwweCKnTiHJ+I1JfFqxzFf9DqYVOAdsaUFMZpZjdhraq q84xvc7MLE/y9vByhQOKOscEgHv8RD738cCBHkreJ3guUANzUrSKr7nYAlDmPuWZ/iwg NU4SBdaOYDZfDrEtx0SASctK+TV61GhOrJN/TQue7dcm/ljGBt9a2Ca3AZIqxdGMa9Du dB3PyH+KNoGqTpvDSbc6xQz9+IfVjyleBt9UnElH3kgMHSWMrIvwLGDfPfpROnhYqwWi yO0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725614882; x=1726219682; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NL51OiKKXYrcwrjtHOrpmmV+PQMlb7GKuARQtOGoLlU=; b=pTlaxDxr4bd8M8SF8Db4WNWLOyfbJKs9QZ5Ia7pafpGpMLueAs06VWBkLnrG7KvWYp DPEHN+aXIN6Ejl42twX11aDlhOrhbVPrAumQmzKU3aOKxY2/Z/fkXDMzKXuEUaI5a3oX RfSD9Lm6Yty5xDthAoqqpTr+pVS0hY1IMzwmLU5ABrCLy0Po16syGZhYuYQLw0WTXHm3 BQIobTFMYHKM/FKn+6wtNIl0+SMvinJfFxhmwTsWgTgTAtKJldes8C/BXWyavZVUyaA7 Pt12lNLYJvu3M0F8E85hSorXJ5rYNFvMrj3XSsKrkHsVPJu2Nerhv+ivf/+daXocd6Tn Tvig== X-Forwarded-Encrypted: i=1; AJvYcCVx+AujGuxITKsX28TQ2kw0CXN37hmj3L+1OMPHbklEUb+Ood7E//qPEfzE446ze1ZXeb5KWCLrKlNLLRK+TkuQ@lists.infradead.org X-Gm-Message-State: AOJu0Ywaei375jvL0sB8KDStYuoFdTT4FNFiCRONGARregNGB8fmDEZL LAc4iugd0sHYdbpaAd9Tws7/yTr7G18r/69xcMnKzOv/oqUvai0ecHPYqxp4HzCNA3MgIjq60Nt V/uDaw6VN5V+CGbgtoR3AjQ== X-Google-Smtp-Source: AGHT+IETQ552AARnKz58C7KCw8wpKdRMaB3Kp2FZFfwlE+pb0fqKNxnYrW28FK9E2Bv9ErnO1UiOPc6M5jWgsKuFYQ== X-Received: from snehalreddy-1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:c1f]) (user=snehalreddy job=sendgmr) by 2002:a05:6902:2d43:b0:e11:593b:b8e7 with SMTP id 3f1490d57ef6-e1d3463e2d7mr11298276.3.1725614882036; Fri, 06 Sep 2024 02:28:02 -0700 (PDT) Date: Fri, 6 Sep 2024 09:27:32 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240906092732.113152-1-snehalreddy@google.com> Subject: [PATCH] KVM: arm64: Add memory length checks before it is xfered 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_022804_315566_24CE0BC6 X-CRM114-Status: GOOD ( 10.13 ) 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 From: Snehal Check size during allocation to fix discrepancy in memory reclaim path. Currently only happens during memory reclaim, inconsistent with mem_xfer Signed-off-by: Snehal Koukuntla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index e715c157c2c4..e9223cc4f913 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -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);