From patchwork Thu Apr 18 08:17:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 10906629 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A13A8161F for ; Thu, 18 Apr 2019 08:18:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87D2328C38 for ; Thu, 18 Apr 2019 08:18:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B1BD28C21; Thu, 18 Apr 2019 08:18:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 691A928C34 for ; Thu, 18 Apr 2019 08:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388293AbfDRIR6 (ORCPT ); Thu, 18 Apr 2019 04:17:58 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51744 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388279AbfDRIRy (ORCPT ); Thu, 18 Apr 2019 04:17:54 -0400 Received: by mail-wm1-f66.google.com with SMTP id 4so1728852wmf.1; Thu, 18 Apr 2019 01:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z5FqXHUkkOxiPqY9isBq9yK5Qx1B2t+uIrpEWzqHhn4=; b=ScQFT3IFvQa3euQsJP1/Jz+BGtaJxiOW7DbwNa0GEW0uzJdXZjsVsr1ixuuH+SDaof C3Nlzbc13LL7Z6bDjxnnceYseWsGmSGaKuVBmfTnCTsp5tm1TrPtTSruQIRKFPJFFpCL yCJEGWXHfNbvUEOzMnnTYF7box5TzYUHuZL2itCwVP7NWbVUUBab1aNxQK9uwLBJpKxF pyNbKowIkgsmzRaYpMP3J8XRL3+QvYX74O+trtA//jC81NVb6i2TqC7Jtqe9xtDij4lt YpfxXiwQ1ieUgyC30tX5zTCFsbTkfxqjrVcnRCvkyZdfjXKbV5u5Fj1T+e/pF7l5jgYV zkfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z5FqXHUkkOxiPqY9isBq9yK5Qx1B2t+uIrpEWzqHhn4=; b=atiwMCFbjjHFPJjkvrvyrO7b5vNHp4j2cUJkm2w12ZrmzNBk5dzqxtR3SEBljmbbVN 0MsjV0+TRQIuuPzcmRqUaCxxCC0/USKBpyBcvLDpUc7jT3FQrpS9wCV81dkun7MEs1XZ m0TWv+VSYUx0KccNGd5zJTjFnJPRo3/YnEP2CXjg3pvOJ2vyN8XPxWwJtOYLupJLx63E b0WTjoSuM5KM5ljANiBpC7JLbmCvuU6aGYBOySJGJn01b4lZ9Ydf6D9pLeEGknHdTYXo TKRJ3D57MA+N3irwm8zDIKE9zNJhJpNLOyEA/mybuKH4HhZtyaL8KttXofaMixN/eEHK cRFw== X-Gm-Message-State: APjAAAXx5evgNzYs+YtqeINWAsz8VWMXUHzcVcvM/pYf++j4tJiDIGSg P8cEU7+JU04l1rrODcnR8Xw= X-Google-Smtp-Source: APXvYqxOJJGqvqm8GMhlQeF9XODmg5oHOxr6NI3SDMdQJl+Z8fVYcMK2cP6yM7YiAKz9TiRU4RLGxw== X-Received: by 2002:a1c:4602:: with SMTP id t2mr1991850wma.120.1555575472351; Thu, 18 Apr 2019 01:17:52 -0700 (PDT) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id w11sm2350619wre.15.2019.04.18.01.17.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 01:17:51 -0700 (PDT) From: Corentin Labbe To: davem@davemloft.net, herbert@gondor.apana.org.au, maxime.ripard@bootlin.com, wens@csie.org Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, ebiggers@kernel.org, Corentin Labbe Subject: [PATCH 3/4] crypto: sun4i-ss: Fix invalid calculation of hash end Date: Thu, 18 Apr 2019 10:17:34 +0200 Message-Id: <20190418081735.19002-4-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418081735.19002-1-clabbe.montjoie@gmail.com> References: <20190418081735.19002-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When nbytes < 4, end is wronlgy set to a negative value which, due to uint, is then interpreted to a large value leading to a deadlock in the following code. This patch fix this problem. Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") Signed-off-by: Corentin Labbe --- drivers/crypto/sunxi-ss/sun4i-ss-hash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c index a4b5ff2b72f8..f6936bb3b7be 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c @@ -240,7 +240,10 @@ static int sun4i_hash(struct ahash_request *areq) } } else { /* Since we have the flag final, we can go up to modulo 4 */ - end = ((areq->nbytes + op->len) / 4) * 4 - op->len; + if (areq->nbytes < 4) + end = 0; + else + end = ((areq->nbytes + op->len) / 4) * 4 - op->len; } /* TODO if SGlen % 4 and !op->len then DMA */