Received: by 10.223.176.5 with SMTP id f5csp998047wra; Fri, 2 Feb 2018 09:27:32 -0800 (PST) X-Google-Smtp-Source: AH8x224WyeNJoLpp0hhrCMTkcoQarb/WOaddaBwpmCVOxpL1r6YchskepH/pHhvuLBWZ3dAD5iMy X-Received: by 10.98.144.79 with SMTP id a76mr40493122pfe.15.1517592452413; Fri, 02 Feb 2018 09:27:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517592452; cv=none; d=google.com; s=arc-20160816; b=F8UBX8lWqGSONcU9Ap/52uS/LwVIsqvJfVhpRYobV3uOnG5JOek19hidi22AwOpV/s jw97OFTbPHgASLiiGUZ10Mqkqjxw8RdNGNSvOBObK9ZFBrW8uXdkggyJ8I2C/4o0aDlY i+d3aW7VCdgg4Tpx7cnCEiQ/3d2DYgtpIfbCXdLO8NeUtOFdKX1+mG9kNjS0JCl2pcdA hU9mEAIB/mS5jXjhTPUuaHwB/9DKRFOuWYGav1gWQKlD9rIEcdEpTUyKYkOOKlQOMCSQ b6G/fCLgPNZYU7xQfR03Ul3CfV2U4QnmOMHTEZ1nk4kW1KxkHHruRdiLTJlVUPVc32al Fa4w== 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=K/OgMpl3hkkqriqrczTvVieEaw857sCy7UcxAkMp02Q=; b=A+xzgA0Wsg/9sWRnIq2NBJEbPpcli41Ejb6QJBIK9p0H7qLZHnHrjPGR8DX/GHHvxu xZ/AqJ9Jys+iZVldhd+Un2JWAIxeaYsD9eb4M3A+7U24YZhjXisxhzC9aLgz/IpATW4z BkprzCPY0u9tEse83gxQ4pXpkBMBne13sxNb5yRQDOr5pSZaJ/iIhwRKAcifYGTXdFJ9 XWLI6quwVWXaYZpHSsAI753CXhZCLsJMJNyRAmvmS4I2WC9h3UQyZPkcmWc687JowTr8 5UexohrOM+dl8rVEgJyWUoXGqCnAYuUEJ6ChD1iIhA9Aa2EkAmdgWQVY0bPGSfNoNMU1 t09A== 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 h12-v6si78702plt.241.2018.02.02.09.27.17; Fri, 02 Feb 2018 09:27:32 -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 S1752488AbeBBRZH (ORCPT + 99 others); Fri, 2 Feb 2018 12:25:07 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40612 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753684AbeBBROx (ORCPT ); Fri, 2 Feb 2018 12:14:53 -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 1E54EAD8; Fri, 2 Feb 2018 17:14:51 +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.15 12/55] crypto: inside-secure - fix hash when length is a multiple of a block Date: Fri, 2 Feb 2018 17:58:30 +0100 Message-Id: <20180202140827.168066257@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140826.117602411@linuxfoundation.org> References: <20180202140826.117602411@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.15-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 @@ -186,17 +186,31 @@ static int safexcel_ahash_send_req(struc 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);