From patchwork Wed Nov 4 20:13:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 7553181 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 730339F36A for ; Wed, 4 Nov 2015 20:22:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1D0320614 for ; Wed, 4 Nov 2015 20:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A503D2060F for ; Wed, 4 Nov 2015 20:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965362AbbKDUWf (ORCPT ); Wed, 4 Nov 2015 15:22:35 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34141 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965161AbbKDUWe (ORCPT ); Wed, 4 Nov 2015 15:22:34 -0500 Received: by wmeg8 with SMTP id g8so8382361wme.1 for ; Wed, 04 Nov 2015 12:22:33 -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=/fP+waecGSxG5hFDCilCYG1bdoF1T+5+USVZplniXHY=; b=RrG3t+O+pOKVniHacJKHcY1dX0YgCj/C76ecwr5mjgvszSVBoGeAl0wqmbZt18Nimn U7AXBAL1Lefi1ddHIO5v29WKQCu9xp8y1KMedHrlSxr4s3+n0En8ZfxTzwDduVDg5Vy5 j/l7WuoWFTndIdSn/J427swxYWF3EpFHRh1uDmaJQLdOM6ZnFt3D2j2ysd4VcF4dVsh3 oG4N6G7eP8w/POa2HoazgMh+PNT1C6nm2tJ2b7gr7Cg6Pq6aPPaYWv01iwwUJoS+Qi7j BqXQe+WluJmGO4LEVxStWkKZw17yCboyx4enn3uJtRB/QEoo6QifivGrKziE4sRQVNeP 0vvA== X-Received: by 10.28.18.21 with SMTP id 21mr5863564wms.34.1446668066957; Wed, 04 Nov 2015 12:14:26 -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.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 12:14:26 -0800 (PST) From: LABBE Corentin To: davem@davemloft.net, herbert@gondor.apana.org.au Cc: LABBE Corentin , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] crypto: sahara: check return value of sg_nents_for_len Date: Wed, 4 Nov 2015 21:13:35 +0100 Message-Id: <1446668045-8620-3-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=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/sahara.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c index f68c24a..ea9f56a 100644 --- a/drivers/crypto/sahara.c +++ b/drivers/crypto/sahara.c @@ -477,7 +477,15 @@ static int sahara_hw_descriptor_create(struct sahara_dev *dev) } dev->nb_in_sg = sg_nents_for_len(dev->in_sg, dev->total); + if (dev->nb_in_sg < 0) { + dev_err(dev->device, "Invalid numbers of src SG.\n"); + return dev->nb_in_sg; + } dev->nb_out_sg = sg_nents_for_len(dev->out_sg, dev->total); + if (dev->nb_out_sg < 0) { + dev_err(dev->device, "Invalid numbers of dst SG.\n"); + return dev->nb_out_sg; + } if ((dev->nb_in_sg + dev->nb_out_sg) > SAHARA_MAX_HW_LINK) { dev_err(dev->device, "not enough hw links (%d)\n", dev->nb_in_sg + dev->nb_out_sg); @@ -793,6 +801,10 @@ static int sahara_sha_hw_links_create(struct sahara_dev *dev, dev->in_sg = rctx->in_sg; dev->nb_in_sg = sg_nents_for_len(dev->in_sg, rctx->total); + if (dev->nb_in_sg < 0) { + dev_err(dev->device, "Invalid numbers of src SG.\n"); + return dev->nb_in_sg; + } if ((dev->nb_in_sg) > SAHARA_MAX_HW_LINK) { dev_err(dev->device, "not enough hw links (%d)\n", dev->nb_in_sg + dev->nb_out_sg);