From patchwork Wed Nov 4 20:13:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 7553001 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9411BBEEA4 for ; Wed, 4 Nov 2015 20:14:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B977E20571 for ; Wed, 4 Nov 2015 20:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E06592053F for ; Wed, 4 Nov 2015 20:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932352AbbKDUOZ (ORCPT ); Wed, 4 Nov 2015 15:14:25 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37801 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756273AbbKDUOZ (ORCPT ); Wed, 4 Nov 2015 15:14:25 -0500 Received: by wmll128 with SMTP id l128so1347666wml.0; Wed, 04 Nov 2015 12:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=3K9g3erPoWdiBSE6foBYgHNXPiavqM6gZl4xHlvEOc8=; b=l84JkWPqe8xAkSrcs5JVme1cV2Ah9iJ20GH0T5erfdUhlJQmDsrsziybjgOaHLO60J UqQK/0EOV2RB6tVnbEqTRHcO8UVu7cSOSXgcst0aPhB0kBhinUlhlX8dABgmYf/gv572 YEekHyH5xIMh1kUrWr9+N+y8325Ng3MINRdhVfMsUesIqo/Ok+tQMvqkijVhegn3XnXS VIX5KW1yTeYZydZEKFjdhHBgT6pS4zRomA0E1F0ptv5lCyeh5PTqBQbQl9sD/JwGy5iX Hm4xXxN//LgrOBddgbuEZFTPHrmEsthlAdFquckxsEldsOvD4EiZhrnnGe3DYSK0sZRq QDQw== X-Received: by 10.28.229.212 with SMTP id c203mr26323249wmh.11.1446668063628; Wed, 04 Nov 2015 12:14:23 -0800 (PST) Received: from Red.local (ANice-651-1-289-62.w83-201.abo.wanadoo.fr. [83.201.177.62]) by smtp.googlemail.com with ESMTPSA id 77sm4702051wml.20.2015.11.04.12.14.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 12:14:23 -0800 (PST) From: LABBE Corentin To: arno@natisbad.org, boris.brezillon@free-electrons.com, clabbe.montjoie@gmail.com, davem@davemloft.net, herbert@gondor.apana.org.au, thomas.petazzoni@free-electrons.com Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] crypto: marvell: check return value of sg_nents_for_len Date: Wed, 4 Nov 2015 21:13:33 +0100 Message-Id: <1446668045-8620-1-git-send-email-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.4.10 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The sg_nents_for_len() function could fail, this patch add a check for its return value. Signed-off-by: LABBE Corentin --- drivers/crypto/marvell/cipher.c | 8 ++++++++ drivers/crypto/marvell/hash.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/drivers/crypto/marvell/cipher.c b/drivers/crypto/marvell/cipher.c index 3df2f4e..78cf6f9 100644 --- a/drivers/crypto/marvell/cipher.c +++ b/drivers/crypto/marvell/cipher.c @@ -400,7 +400,15 @@ static int mv_cesa_ablkcipher_req_init(struct ablkcipher_request *req, return -EINVAL; creq->src_nents = sg_nents_for_len(req->src, req->nbytes); + if (creq->src_nents < 0) { + dev_err(cesa_dev->dev, "Invalid number of src SG"); + return creq->src_nents; + } creq->dst_nents = sg_nents_for_len(req->dst, req->nbytes); + if (creq->dst_nents < 0) { + dev_err(cesa_dev->dev, "Invalid number of dst SG"); + return creq->dst_nents; + } mv_cesa_update_op_cfg(tmpl, CESA_SA_DESC_CFG_OP_CRYPT_ONLY, CESA_SA_DESC_CFG_OP_MSK); diff --git a/drivers/crypto/marvell/hash.c b/drivers/crypto/marvell/hash.c index e8d0d71..250c6e5 100644 --- a/drivers/crypto/marvell/hash.c +++ b/drivers/crypto/marvell/hash.c @@ -710,6 +710,10 @@ static int mv_cesa_ahash_req_init(struct ahash_request *req, bool *cached) creq->req.base.type = CESA_STD_REQ; creq->src_nents = sg_nents_for_len(req->src, req->nbytes); + if (creq->src_nents < 0) { + dev_err(cesa_dev->dev, "Invalid number of src SG"); + return creq->src_nents; + } ret = mv_cesa_ahash_cache_req(req, cached); if (ret)