From patchwork Wed Nov 4 20:13:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 7553071 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 EA50BBEEA4 for ; Wed, 4 Nov 2015 20:16:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 18EA52053F for ; Wed, 4 Nov 2015 20:16:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EA3920532 for ; Wed, 4 Nov 2015 20:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030659AbbKDUOt (ORCPT ); Wed, 4 Nov 2015 15:14:49 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:37349 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030775AbbKDUOr (ORCPT ); Wed, 4 Nov 2015 15:14:47 -0500 Received: by wicfv8 with SMTP id fv8so39616028wic.0; Wed, 04 Nov 2015 12:14:46 -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=Sue6+/W/M9HZNbiGzQtiwwTL6E9C01ZnMq2t8dNdVtQ=; b=JoGjfT2xd6ZxowXVE2wTdLKr/5YtrQQozGmVbhhQA/Fiom6xSrVLaGbh6xWou8xkmj /l7RhLWTlVvwVHLeDptxVXCJ0UD7SV7BmYc73WwDh3+5MAi7zPRE5Dwv4zgfsh0HPc0D oH03fehebAPii5aPPA2tEKNSLvQ7onggllSCUTKsXbj5OphbDj0sQs8AMzHpwOYjCn8w JzlPd9shl24ZmnFuMLQVBcn5nz6V82FE0JjUAihsB4yfeuGIvWxUgNSpGYu4y68cZyQS 2eIj8gG3eiI2+Fd6ChJSW/1uCQ0S9lO9oUA3459tWE18iObMqINPkNFXpYHZUdQGDtU/ oJCA== X-Received: by 10.194.22.40 with SMTP id a8mr3850869wjf.109.1446668086130; Wed, 04 Nov 2015 12:14:46 -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.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 12:14:45 -0800 (PST) From: LABBE Corentin To: clabbe.montjoie@gmail.com, davem@davemloft.net, herbert@gondor.apana.org.au, horia.geanta@freescale.com, steve.cornelius@freescale.com, vicki.milhoan@freescale.com, yanjiang.jin@windriver.com Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] crypto: caam: check return value of sg_nents_for_len Date: Wed, 4 Nov 2015 21:13:38 +0100 Message-Id: <1446668045-8620-6-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=-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=unavailable 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. We do the same for sg_count since it use sg_nents_for_len(). Signed-off-by: LABBE Corentin --- drivers/crypto/caam/caamhash.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 9609f66..b894ce3 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -794,6 +794,10 @@ static int ahash_update_ctx(struct ahash_request *req) if (to_hash) { src_nents = sg_nents_for_len(req->src, req->nbytes - (*next_buflen)); + if (src_nents < 0) { + dev_err(jrdev, "Invalid number of src SG.\n"); + return src_nents; + } sec4_sg_src_index = 1 + (*buflen ? 1 : 0); sec4_sg_bytes = (sec4_sg_src_index + src_nents) * sizeof(struct sec4_sg_entry); @@ -993,6 +997,10 @@ static int ahash_finup_ctx(struct ahash_request *req) int sh_len; src_nents = sg_nents_for_len(req->src, req->nbytes); + if (src_nents < 0) { + dev_err(jrdev, "Invalid number of src SG.\n"); + return src_nents; + } sec4_sg_src_index = 1 + (buflen ? 1 : 0); sec4_sg_bytes = (sec4_sg_src_index + src_nents) * sizeof(struct sec4_sg_entry); @@ -1077,6 +1085,10 @@ static int ahash_digest(struct ahash_request *req) int sh_len; src_nents = sg_count(req->src, req->nbytes); + if (src_nents < 0) { + dev_err(jrdev, "Invalid number of src SG.\n"); + return src_nents; + } dma_map_sg(jrdev, req->src, src_nents ? : 1, DMA_TO_DEVICE); sec4_sg_bytes = src_nents * sizeof(struct sec4_sg_entry); @@ -1225,6 +1237,10 @@ static int ahash_update_no_ctx(struct ahash_request *req) if (to_hash) { src_nents = sg_nents_for_len(req->src, req->nbytes - (*next_buflen)); + if (src_nents < 0) { + dev_err(jrdev, "Invalid number of src SG.\n"); + return src_nents; + } sec4_sg_bytes = (1 + src_nents) * sizeof(struct sec4_sg_entry); @@ -1333,6 +1349,10 @@ static int ahash_finup_no_ctx(struct ahash_request *req) int ret = 0; src_nents = sg_nents_for_len(req->src, req->nbytes); + if (src_nents < 0) { + dev_err(jrdev, "Invalid number of src SG.\n"); + return src_nents; + } sec4_sg_src_index = 2; sec4_sg_bytes = (sec4_sg_src_index + src_nents) * sizeof(struct sec4_sg_entry); @@ -1421,6 +1441,10 @@ static int ahash_update_first(struct ahash_request *req) if (to_hash) { src_nents = sg_count(req->src, req->nbytes - (*next_buflen)); + if (src_nents < 0) { + dev_err(jrdev, "Invalid number of src SG.\n"); + return src_nents; + } dma_map_sg(jrdev, req->src, src_nents ? : 1, DMA_TO_DEVICE); sec4_sg_bytes = src_nents * sizeof(struct sec4_sg_entry);