From patchwork Wed Nov 4 20:13:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 7553091 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D08AB9F36A for ; Wed, 4 Nov 2015 20:17:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6E862053F for ; Wed, 4 Nov 2015 20:17:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FD4220532 for ; Wed, 4 Nov 2015 20:17:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030671AbbKDUOk (ORCPT ); Wed, 4 Nov 2015 15:14:40 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:36896 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030659AbbKDUOj (ORCPT ); Wed, 4 Nov 2015 15:14:39 -0500 Received: by wmll128 with SMTP id l128so1352267wml.0; Wed, 04 Nov 2015 12:14:37 -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:in-reply-to:references; bh=VQj6Z6iIjUmiA3NK2YCDnwwWSFGb4QL8B80HXH3T9VI=; b=BlbFYufxP0REgo+uHRTLvbxcZCOwsYXX9IwDGpjVNU5lNN8INHt64Z+HU3MIEfNBfs OYvV24uN8+iY1zA+p/2MCktyFkYOqxmbkE2P8av1d4R0FFVNbFfunKGpNxpR+6/MYKcx oarVwkeY2i5LUabqsHLxD304U7Ic+oSq3L5Z89JlNE3E+2vnjo6w85yB1OefAQwff2Q9 S9Sfhst4UvYi1/6pt/3DbmoZIoJRwt+pxtTpcXhJvXZzJhT2kGUg3HZJHB4G2Vhrgdbe HfM3OIUMbF2//B9iTeF/JlMkdrrFM0rvJ20LuNj+HnbDIh98FR23XM9ctkk2X3jZOm8G DZMg== X-Received: by 10.28.11.207 with SMTP id 198mr27212239wml.47.1446668077793; Wed, 04 Nov 2015 12:14:37 -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.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 12:14:37 -0800 (PST) From: LABBE Corentin To: axboe@fb.com, clabbe.montjoie@gmail.com, cristian.stoica@freescale.com, dan.j.williams@intel.com, davem@davemloft.net, herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] crypto: qce: check return value of sg_nents_for_len Date: Wed, 4 Nov 2015 21:13:36 +0100 Message-Id: <1446668045-8620-4-git-send-email-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1446668045-8620-1-git-send-email-clabbe.montjoie@gmail.com> References: <1446668045-8620-1-git-send-email-clabbe.montjoie@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, SORTED_RECIPS, 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/qce/ablkcipher.c | 8 ++++++++ drivers/crypto/qce/sha.c | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/drivers/crypto/qce/ablkcipher.c b/drivers/crypto/qce/ablkcipher.c index 2c0d63d..dbcbbe2 100644 --- a/drivers/crypto/qce/ablkcipher.c +++ b/drivers/crypto/qce/ablkcipher.c @@ -83,6 +83,14 @@ qce_ablkcipher_async_req_handle(struct crypto_async_request *async_req) rctx->dst_nents = sg_nents_for_len(req->dst, req->nbytes); else rctx->dst_nents = rctx->src_nents; + if (rctx->src_nents < 0) { + dev_err(qce->dev, "Invalid numbers of src SG.\n"); + return rctx->src_nents; + } + if (rctx->dst_nents < 0) { + dev_err(qce->dev, "Invalid numbers of dst SG.\n"); + return -rctx->dst_nents; + } rctx->dst_nents += 1; diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c index 0c9973e..47e114a 100644 --- a/drivers/crypto/qce/sha.c +++ b/drivers/crypto/qce/sha.c @@ -92,6 +92,11 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req) } rctx->src_nents = sg_nents_for_len(req->src, req->nbytes); + if (rctx->src_nents < 0) { + dev_err(qce->dev, "Invalid numbers of src SG.\n"); + return rctx->src_nents; + } + ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE); if (ret < 0) return ret;