From patchwork Mon Jul 12 06:03:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 473007 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2696299jao; Mon, 12 Jul 2021 00:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZsdPWcbYeoHHdMzvuPDCGf3qDxvUecFOLxG3PwxSx/+pHoVn0sYl4Hfxf4xaQAKWeKyS3 X-Received: by 2002:a17:907:1c98:: with SMTP id nb24mr52601993ejc.316.1626075863918; Mon, 12 Jul 2021 00:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626075863; cv=none; d=google.com; s=arc-20160816; b=VQNvz82ge4Iqi8Sd1+RY/g+hcthzh/MqrdKQxEJAxI/K1JFKHWcnBktCMq2Lv1zVj3 H1d4rvcUzFXaEoc3E+jZGGxWOi1zRdmN8v8BmMSgueosmqhrEtYJkmqkXwE7RgjxEieI 93sbFErAJR73srqbx66ak9Bb1UoC/PJODdNI26LAPXWX+YqZ3LAVVrkMFKBxUvPHhQ6d 4vrCZv9/7SrYERXdRfC/7d1ccb0ucCZCFt8Nn96tZTVEzh/5oyQP3n6mJmhjXW4xZ4by VwJgXasN36ho539eCzbgAXDWAhMUgRXO5K9wLcaBQVX6rHJQZ1HNnWTRP+xTZpbg/49C CwZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=l9PSIHi7thUv8JjCqmiAFncr3wDSSPDgvDUvt5cxKkE=; b=BQT1l07SsDQqLyvPIVXZJWCo5qE9Y5xa29ZiUrQ0cfFLJQ1rYR+ECRoutOkrqGlNb3 o+g26U2MQ9EaBdRQWOrP58Or65blP2ANb9ksleZHLyXTzXUqY5bp9FXA4GwYRnMaT6xc vQd18awtclhsRmfixDLCMxVXNE4uxeSH8sCu0MD6w5GFw+SdYi4V3lk9kwHokIk34Hsz 8h8zOFuil12qZh3lXuCW3jL8bRfGQOBGeF1bDzYsgSUxwZK+Ir2Zp4LMT/AiHRXFI7pf WsxrJQ5O0z857tfpgwWVdYgH/AuJzf50g+EUXmg5ZMswK+LCnCohzdm4Dy7jM5IiwJly pvJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WGHTh3Ly; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si13642925eda.13.2021.07.12.00.44.23; Mon, 12 Jul 2021 00:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WGHTh3Ly; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349854AbhGLHot (ORCPT + 12 others); Mon, 12 Jul 2021 03:44:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:46796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347815AbhGLHkN (ORCPT ); Mon, 12 Jul 2021 03:40:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CFBCF61629; Mon, 12 Jul 2021 07:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626075380; bh=sFpWLh59XEW/L2ThVMuQX65C/0NRjUggW0zKEKMo3Nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGHTh3Lyf/MXRF6X/Uj7sR8I9tPR61DNKSTu4sODqHCGQ4nHWn/Wb52dSqvvt9Y1Q VK7cclfbfXo/4//VR+E7bnkGwacC6a7owttH350i+uUCzy0xHEOYzn/vpYcwkol+p4 o0S4AFbLZEmZ+XaiZdVy9ELpN4Gw87TEAhpfn8yE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thara Gopinath , Herbert Xu , Sasha Levin Subject: [PATCH 5.13 158/800] crypto: qce: skcipher: Fix incorrect sg count for dma transfers Date: Mon, 12 Jul 2021 08:03:01 +0200 Message-Id: <20210712060935.217000443@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060912.995381202@linuxfoundation.org> References: <20210712060912.995381202@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thara Gopinath [ Upstream commit 1339a7c3ba05137a2d2fe75f602311bbfc6fab33 ] Use the sg count returned by dma_map_sg to call into dmaengine_prep_slave_sg rather than using the original sg count. dma_map_sg can merge consecutive sglist entries, thus making the original sg count wrong. This is a fix for memory coruption issues observed while testing encryption/decryption of large messages using libkcapi framework. Patch has been tested further by running full suite of tcrypt.ko tests including fuzz tests. Signed-off-by: Thara Gopinath Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/qce/skcipher.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.30.2 diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index c0a0d8c4fce1..259418479227 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -72,7 +72,7 @@ qce_skcipher_async_req_handle(struct crypto_async_request *async_req) struct scatterlist *sg; bool diff_dst; gfp_t gfp; - int ret; + int dst_nents, src_nents, ret; rctx->iv = req->iv; rctx->ivsize = crypto_skcipher_ivsize(skcipher); @@ -123,21 +123,22 @@ qce_skcipher_async_req_handle(struct crypto_async_request *async_req) sg_mark_end(sg); rctx->dst_sg = rctx->dst_tbl.sgl; - ret = dma_map_sg(qce->dev, rctx->dst_sg, rctx->dst_nents, dir_dst); - if (ret < 0) + dst_nents = dma_map_sg(qce->dev, rctx->dst_sg, rctx->dst_nents, dir_dst); + if (dst_nents < 0) goto error_free; if (diff_dst) { - ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, dir_src); - if (ret < 0) + src_nents = dma_map_sg(qce->dev, req->src, rctx->src_nents, dir_src); + if (src_nents < 0) goto error_unmap_dst; rctx->src_sg = req->src; } else { rctx->src_sg = rctx->dst_sg; + src_nents = dst_nents - 1; } - ret = qce_dma_prep_sgs(&qce->dma, rctx->src_sg, rctx->src_nents, - rctx->dst_sg, rctx->dst_nents, + ret = qce_dma_prep_sgs(&qce->dma, rctx->src_sg, src_nents, + rctx->dst_sg, dst_nents, qce_skcipher_done, async_req); if (ret) goto error_unmap_src;