From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752591AbbJRWFq (ORCPT ); Sun, 18 Oct 2015 18:05:46 -0400 Received: from mail.eperm.de ([89.247.134.16]:34364 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752485AbbJRWFn (ORCPT ); Sun, 18 Oct 2015 18:05:43 -0400 From: Stephan Mueller To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v2 1/5] MPI: fix off by one in mpi_read_raw_from_sgl Date: Sun, 18 Oct 2015 12:45:18 +0200 Message-ID: <3192672.E3TvJmsW94@myon.chronox.de> User-Agent: KMail/4.14.10 (Linux/4.2.3-300.fc23.x86_64; KDE/4.14.11; x86_64; ; ) In-Reply-To: <1831785.BBs8Hj3CxY@myon.chronox.de> References: <1831785.BBs8Hj3CxY@myon.chronox.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch fixes the analysis of the input data which contains an off by one. The issue is visible when the SGL contains one byte per SG entry. The code for checking for zero bytes does not operate on the data byte. Signed-off-by: Stephan Mueller --- lib/mpi/mpicoder.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index c20ef27..c7e0a70 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c @@ -446,8 +446,11 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int len) const u8 *buff = sg_virt(sg); int len = sg->length; - while (len-- && !*buff++) + while (len && !*buff) { lzeros++; + len--; + buff++; + } if (len && *buff) break; -- 2.5.0