From patchwork Mon Jul 12 06:03:53 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: 472943 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2666902jao; Mon, 12 Jul 2021 00:00:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyX9DATANjE5BumxEa0EcKvBPNk34kBKJDXWvAyeWKYcvlaf0/XGJWKiPr7xpBx2XdYvpSM X-Received: by 2002:a92:dcc5:: with SMTP id b5mr1578562ilr.234.1626073224485; Mon, 12 Jul 2021 00:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626073224; cv=none; d=google.com; s=arc-20160816; b=BZziYzlkT5mksj0jVv30ZW8EEF9jDMxKBdzdkk/J3ly0/2scS/7tQeG4Hl59zEp27m bUn9lm29yRsMLvRZdqbjRXPo7VxsCDx37MfoOJ3NkZm6nOCDJn9wtO49ZJsyUJF6tBTg U5gsdD6Y+/2QFPm1huizyYyC2I6reZy2i49Rt3vfRyKRjPJo3zkRkOyG9HxYowEwlEWf O1SYNoicqB50HVa3pjnvMa4nISGnjtmAp9Nv47ZRYT5KssPEGzSl3jR6iUtP/4xMGrwa LPqpr2XMQhwMzv20DmPIClDivHxl1THvIUvCXQmdyJvDAuC69z5wlsTzB67hB03m9Bfa LdUA== 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=W9vJ0SMZiCskZnQ5TJR01HGuV593Tbhvi3ZGY6NouR8=; b=P1v+s8x9qiXL99wYdWM76MUwxeEXlhCCE0V97Au1NRxZgihpxdR66esUAlQwNYS07D 7qVBwz6EdlMecWfa7F2wjSGxJYKBveHcwyNCF4vPv0xxA5ZUAca/xTqOBVy9dFV+9l7n AKdTijxBU9uw0O88vEfqZgspGKHsqt90BuTIGTNm42wmaeseeVuNENKccTKAZzp8Ka5Y oWaZFLu0EsqK0LCs/dbiWiB8sxCzRkdamrMn9kgj7LM7SppaVoLM3rfER0SF/5UjJPpk JIrsBGHgcXwNC2c++wRICx9cPdaFymJ5V8xfi5u2BqveVbdXbahjuLGu6tvTv4eooKbO Fqfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BDKwPYIS; 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 n2si18122085jaj.36.2021.07.12.00.00.24; Mon, 12 Jul 2021 00:00:24 -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=BDKwPYIS; 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 S236955AbhGLHDK (ORCPT + 12 others); Mon, 12 Jul 2021 03:03:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:36860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240917AbhGLHCY (ORCPT ); Mon, 12 Jul 2021 03:02:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 441EE610A6; Mon, 12 Jul 2021 06:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626073172; bh=6qvfVHz8Ivbu+S8FtkH8bJH6LL/dj1fkRbuXihqrtqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDKwPYISSypLjfx6HnaS46U6pc8z2xg99iaKwKkl/3lwr2MsqVSMd9I6sGg1v9s3X qkAg2ycVk9/vVgbzZT5fm4DmmjDW/Mf8xqBXyZe2BjxgxrPaeUxzfNcwZkjxn5I61G 7b7mvptUTf8u2SqRDgucWJKT0HB8jXlxFCiplqf0= 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.12 150/700] crypto: qce: skcipher: Fix incorrect sg count for dma transfers Date: Mon, 12 Jul 2021 08:03:53 +0200 Message-Id: <20210712060946.768254239@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@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 a2d3da0ad95f..5a6559131eac 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -71,7 +71,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); @@ -122,21 +122,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;