]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: hisilicon/hpre - fix dma unmap sequence
authorZhiqi Song <songzhiqi1@huawei.com>
Fri, 18 Jul 2025 10:05:01 +0000 (18:05 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:25:59 +0000 (16:25 +0200)
[ Upstream commit 982fd1a74de63c388c060e4fa6f7fbd088d6d02e ]

Perform DMA unmapping operations before processing data.
Otherwise, there may be unsynchronized data accessed by
the CPU when the SWIOTLB is enabled.

Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/hisilicon/hpre/hpre_crypto.c

index ef02dadd6217098fe963416973e82a00db3970c4..541f5eb76b6e895c53554e37897e87701899414d 100644 (file)
@@ -1461,11 +1461,13 @@ static void hpre_ecdh_cb(struct hpre_ctx *ctx, void *resp)
        if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld))
                atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value);
 
+       /* Do unmap before data processing */
+       hpre_ecdh_hw_data_clr_all(ctx, req, areq->dst, areq->src);
+
        p = sg_virt(areq->dst);
        memmove(p, p + ctx->key_sz - curve_sz, curve_sz);
        memmove(p + curve_sz, p + areq->dst_len - curve_sz, curve_sz);
 
-       hpre_ecdh_hw_data_clr_all(ctx, req, areq->dst, areq->src);
        kpp_request_complete(areq, ret);
 
        atomic64_inc(&dfx[HPRE_RECV_CNT].value);
@@ -1769,9 +1771,11 @@ static void hpre_curve25519_cb(struct hpre_ctx *ctx, void *resp)
        if (overtime_thrhld && hpre_is_bd_timeout(req, overtime_thrhld))
                atomic64_inc(&dfx[HPRE_OVER_THRHLD_CNT].value);
 
+       /* Do unmap before data processing */
+       hpre_curve25519_hw_data_clr_all(ctx, req, areq->dst, areq->src);
+
        hpre_key_to_big_end(sg_virt(areq->dst), CURVE25519_KEY_SIZE);
 
-       hpre_curve25519_hw_data_clr_all(ctx, req, areq->dst, areq->src);
        kpp_request_complete(areq, ret);
 
        atomic64_inc(&dfx[HPRE_RECV_CNT].value);