From patchwork Tue May 12 08:28:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Horia_Geant=C4=83?= X-Patchwork-Id: 6386371 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 9B1FC9F32E for ; Tue, 12 May 2015 08:28:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C3A62203FB for ; Tue, 12 May 2015 08:28:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE40D203F7 for ; Tue, 12 May 2015 08:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932260AbbELI2f (ORCPT ); Tue, 12 May 2015 04:28:35 -0400 Received: from mail-bn1bon0116.outbound.protection.outlook.com ([157.56.111.116]:53174 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752810AbbELI2P (ORCPT ); Tue, 12 May 2015 04:28:15 -0400 Received: from BY2PR03CA059.namprd03.prod.outlook.com (10.141.249.32) by DM2PR0301MB1312.namprd03.prod.outlook.com (10.160.222.17) with Microsoft SMTP Server (TLS) id 15.1.154.19; Tue, 12 May 2015 08:28:14 +0000 Received: from BY2FFO11FD050.protection.gbl (2a01:111:f400:7c0c::142) by BY2PR03CA059.outlook.office365.com (2a01:111:e400:2c5d::32) with Microsoft SMTP Server (TLS) id 15.1.160.19 via Frontend Transport; Tue, 12 May 2015 08:28:13 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; davemloft.net; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD050.mail.protection.outlook.com (10.1.15.187) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Tue, 12 May 2015 08:28:12 +0000 Received: from enigma.ea.freescale.net (enigma.ea.freescale.net [10.171.77.120]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t4C8S97q014026; Tue, 12 May 2015 01:28:10 -0700 From: Horia Geanta To: Herbert Xu CC: , "David S. Miller" Subject: [PATCH 3/4] crypto: talitos - avoid out of bound scatterlist iterator Date: Tue, 12 May 2015 11:28:05 +0300 Message-ID: <1431419285-9014-1-git-send-email-horia.geanta@freescale.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1431363804-2331-1-git-send-email-horia.geanta@freescale.com> References: <1431363804-2331-1-git-send-email-horia.geanta@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD050; 1:2FGkeQikSF+PkqEbRdgAH+G9gUrhTAw7SWt33tgkcrtwAWctP4iQavK/tVrf/SxCnN44a3cc1IHjYEanqqmJiAsi2jVLMDq5GGclvUyXhYXuELFlb8SjeWD3jCv4aXfaeugT7Jt0hS0Qrl4At2HnsYk4g1CT3OEj/qakZiun1slwFl90ZNTo1x2/J1uO/NV7geg1XcMDI4fgYdlMuduirVgJfFOQlkl46RaPDz3eDNyppOjz4Qt4x9Wz8xKtHCgKuZ5iEODwICfSb802XYLfwUVrsJ7jRZjgUTxYUTcLXXRmSGg3l23IBSDOhKSpb4qD X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(106466001)(6806004)(229853001)(50466002)(47776003)(19580405001)(87936001)(105606002)(104016003)(36756003)(48376002)(50986999)(76176999)(46102003)(85426001)(189998001)(5001960100002)(2950100001)(86362001)(50226001)(92566002)(33646002)(110136002)(77096005)(62966003)(19580395003)(77156002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1312; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1312; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:DM2PR0301MB1312; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1312; X-Forefront-PRVS: 0574D4712B X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2015 08:28:12.8430 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1312 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Check return value of scatterlist_sg_next(), i.e. don't rely solely on number of bytes to be processed or number of scatterlist entries. Signed-off-by: Horia Geanta --- drivers/crypto/talitos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index 6b19b3dca616..7367f6cba2ed 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -1065,7 +1065,7 @@ static int sg_to_link_tbl(struct scatterlist *sg, int sg_count, { int n_sg = sg_count; - while (n_sg--) { + while (sg && n_sg--) { to_talitos_ptr(link_tbl_ptr, sg_dma_address(sg), 0); link_tbl_ptr->len = cpu_to_be16(sg_dma_len(sg)); link_tbl_ptr->j_extent = 0; @@ -1254,7 +1254,7 @@ static int sg_count(struct scatterlist *sg_list, int nbytes, bool *chained) int sg_nents = 0; *chained = false; - while (nbytes > 0) { + while (nbytes > 0 && sg) { sg_nents++; nbytes -= sg->length; if (!sg_is_last(sg) && (sg + 1)->length == 0)