Received: by 10.223.176.5 with SMTP id f5csp1045307wra; Fri, 2 Feb 2018 10:12:51 -0800 (PST) X-Google-Smtp-Source: AH8x226WXMtrwlFT0dQUc4Mhw3uQDmPLSgRETIboh/Jlt+J2W877sWjOZZVl+4hcvyAU4GZyvSwm X-Received: by 10.99.67.66 with SMTP id q63mr2440866pga.175.1517595171868; Fri, 02 Feb 2018 10:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517595171; cv=none; d=google.com; s=arc-20160816; b=g2+ORM0yzVzSJtUh1KX6Jh+0ts+r3TeHd+fc+Db/+zBCxUr50fd/wW9sBcuIDoQB+E Bwid/+YP/3pNbp5OSlUFruyAGWwimy0YFTw9POmhMV9cwiWQZ7eWldLUz978x8A1iDCR 8pcXPnYa13PObBvV9RhWHm6G1/Jp2vex4RXgxVkz3Ais3qUrW7XM93A5tMMZlc9TtBTg 4LmQwXfxc/tJUfrlZ3qbEZUd8R82jUgiVakT5iZz3bKHHfTDxjk37Q6l/yP1+9RyY7ub ZNs+ceE6Ag7MqZUzfThDUqD0O/uxs3nN3Z4x/6Zptb1zrZMAN/wZUbEAR9Z4rZcg87P9 /tjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=59BO1eBgvf6ErkGAG3tT1gipt5haK8F/OkqIMyLLVfc=; b=Lmh1nKyEBa5YQDdViIsCYA3jqnFER4A8X1m+uV7V6eeoWaX0ZIGQEWGWaQavevtRED Bavx23t7T2w/Sbjk3ghoMSiCcUYHx7jJfp1gdbrYYns2LC8yBzhQWekS9MqtjqjFYVIG BAm/a7PPGEMcwCnK07xFtppb9wTagUH4i1S9C+3T3Depkrp/YvgfnxPp6Zwu0Ttfyi9t zdFlA4uCVBOra/zJLarI9fUYxXWRC4yXIeZNbqg02Qz2xBGPXGSVfAPJDYjJpqTyLk9M mfQj4Grb8gCJEMvnCDZiD8kM5nMzPin4jQJ3Bc1ATtaS11VVUUHlr3TBEm/rw5ZPIPH9 QBvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v184si18595pgb.832.2018.02.02.10.12.37; Fri, 02 Feb 2018 10:12:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753250AbeBBSKa (ORCPT + 99 others); Fri, 2 Feb 2018 13:10:30 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37042 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753035AbeBBRHa (ORCPT ); Fri, 2 Feb 2018 12:07:30 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 800D1EDB; Fri, 2 Feb 2018 17:07:29 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Antoine Tenart , Herbert Xu Subject: [PATCH 4.14 016/156] crypto: inside-secure - fix hash when length is a multiple of a block Date: Fri, 2 Feb 2018 17:56:37 +0100 Message-Id: <20180202140841.044638657@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Antoine Tenart commit 809778e02cd45d0625439fee67688f655627bb3c upstream. This patch fixes the hash support in the SafeXcel driver when the update size is a multiple of a block size, and when a final call is made just after with a size of 0. In such cases the driver should cache the last block from the update to avoid handling 0 length data on the final call (that's a hardware limitation). Fixes: 1b44c5a60c13 ("crypto: inside-secure - add SafeXcel EIP197 crypto engine driver") Signed-off-by: Antoine Tenart Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/inside-secure/safexcel_hash.c | 34 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) --- a/drivers/crypto/inside-secure/safexcel_hash.c +++ b/drivers/crypto/inside-secure/safexcel_hash.c @@ -185,17 +185,31 @@ static int safexcel_ahash_send(struct cr else cache_len = queued - areq->nbytes; - /* - * If this is not the last request and the queued data does not fit - * into full blocks, cache it for the next send() call. - */ - extra = queued & (crypto_ahash_blocksize(ahash) - 1); - if (!req->last_req && extra) { - sg_pcopy_to_buffer(areq->src, sg_nents(areq->src), - req->cache_next, extra, areq->nbytes - extra); + if (!req->last_req) { + /* If this is not the last request and the queued data does not + * fit into full blocks, cache it for the next send() call. + */ + extra = queued & (crypto_ahash_blocksize(ahash) - 1); + if (!extra) + /* If this is not the last request and the queued data + * is a multiple of a block, cache the last one for now. + */ + extra = queued - crypto_ahash_blocksize(ahash); - queued -= extra; - len -= extra; + if (extra) { + sg_pcopy_to_buffer(areq->src, sg_nents(areq->src), + req->cache_next, extra, + areq->nbytes - extra); + + queued -= extra; + len -= extra; + + if (!queued) { + *commands = 0; + *results = 0; + return 0; + } + } } spin_lock_bh(&priv->ring[ring].egress_lock);