From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 915DB3376A5; Tue, 26 Aug 2025 13:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756215815; cv=none; b=g/13Nf+zmUhayoOu3O+HaYwMSp/qNzHCHaqBp1Q/n8r6QWs4vhCNeWHhU5EPfNWeovvSi9NBdmH4C3Z/ZDVvGEoQXCHE7ZYM53lM/As3GQX0s4jN3bN3RyrEcHeVyzuxJl5S60YvNSzM/zQHrltC+beUSk8uW7CIBsOQLSoUZyE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756215815; c=relaxed/simple; bh=lwMN57oOtWMFEeag5pbs7heaI1U+NUCfhRb8K1RCpHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uzVe2Sh/tP46pplGfyzzraTDzMld6jgH8tfKulzhbl3LmE20T5TH70Ce7acj+7wzriULGOgSZ+F91cVFOAwtXBnK8VqSRLso0afir4MZ6u++reJX3tjCKuDpbMXoTv/3tKXJ+/e7uWSeXZY/aJwLsP3Ov4YuAcfZtmtdR3KA1ZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rIEnuGm5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rIEnuGm5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26C84C4CEF1; Tue, 26 Aug 2025 13:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756215815; bh=lwMN57oOtWMFEeag5pbs7heaI1U+NUCfhRb8K1RCpHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rIEnuGm5eYiYk73Fs0xRwPgYbEXWjwZQImmjRjXbR00QpOFhRbvmV9UMIHfdHPPBo 2TjIUuDHqtGmP418V+OrrPrJ14nU0P85aLs8Q2em758/R21/4D6ObpPWV2ZEYYi910 32ek0h4TSYLQC7CCZB/si37tyR5z5KpzbKMywbVQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thomas Fourier , Antoine Tenart , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 177/644] crypto: inside-secure - Fix `dma_unmap_sg()` nents value Date: Tue, 26 Aug 2025 13:04:28 +0200 Message-ID: <20250826110950.856186425@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110946.507083938@linuxfoundation.org> References: <20250826110946.507083938@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Fourier [ Upstream commit cb7fa6b6fc71e0c801e271aa498e2f19e6df2931 ] The `dma_unmap_sg()` functions should be called with the same nents as the `dma_map_sg()`, not the value the map function returned. Fixes: c957f8b3e2e5 ("crypto: inside-secure - avoid unmapping DMA memory that was not mapped") Signed-off-by: Thomas Fourier Reviewed-by: Antoine Tenart Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/inside-secure/safexcel_hash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c index 2124416742f8..de0a093d8f50 100644 --- a/drivers/crypto/inside-secure/safexcel_hash.c +++ b/drivers/crypto/inside-secure/safexcel_hash.c @@ -249,7 +249,9 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, safexcel_complete(priv, ring); if (sreq->nents) { - dma_unmap_sg(priv->dev, areq->src, sreq->nents, DMA_TO_DEVICE); + dma_unmap_sg(priv->dev, areq->src, + sg_nents_for_len(areq->src, areq->nbytes), + DMA_TO_DEVICE); sreq->nents = 0; } @@ -497,7 +499,9 @@ static int safexcel_ahash_send_req(struct crypto_async_request *async, int ring, DMA_FROM_DEVICE); unmap_sg: if (req->nents) { - dma_unmap_sg(priv->dev, areq->src, req->nents, DMA_TO_DEVICE); + dma_unmap_sg(priv->dev, areq->src, + sg_nents_for_len(areq->src, areq->nbytes), + DMA_TO_DEVICE); req->nents = 0; } cdesc_rollback: -- 2.39.5