Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp671530img; Fri, 22 Mar 2019 06:18:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJbeA9xn6sy8W9bAH//EGJzsQ2SENOpARCxTU2V5svV+6GozPi7+j1pd8JubnCKWX7T47r X-Received: by 2002:a17:902:f209:: with SMTP id gn9mr9574767plb.50.1553260696204; Fri, 22 Mar 2019 06:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553260696; cv=none; d=google.com; s=arc-20160816; b=yCRAPm88jH20gMMjlYa/Rzbh5S/jbNxEXerDWB+5QLVuoNXe9dgsIaFhks2kmjUlKZ ZmKOTQ+snCY9LeWBtGYPbLMvFkpXz0w0PdsrLhP0OWt0s77GxcWPYnnby8wGWs6lxayW pVCAPMgVKAOpt8vgzF1yzPgObze3XRT9J7TvTC8iz2KA87NM+gMdkS69sWLyEjsvdqdV 4U1dP4BlDyucHB28MLJGDJWJwOkMOJ7rIQpa7On/XLXM7EMYQMBVVBE6jmfF9e8g/VoM KlQ45T30WhyLQvSMYszrlaXW+acQlsZYIXMWAXoR25//N4zuIplbCLveAkh0oBTxDg9c /wog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DuobSGIWk7uy0/0FoqloWDL7SyQjEORQF6sj+FLibNQ=; b=J0QHAiA8Yh4ANIT3xTANYPydpIcgAY6PHJ9zZumVItNxQWE2SCdiqUYlxe2BU0IKCl cB/DMjsYsb6kPDMv2G0J5TlIYurh59i4RlQOz77wITUki4NNiryAP5uth0icIMdfKndd uKeF3q2z1ExNaVhDlP5VT9DIdiJaVhffxR0OnEECPUTGwlif9HoFukw7LdV/sZWviKIx GUv+pToqO9L8Gx3pK0aUBK9q1ItCYjKAdx8f3nF8ybZdnbqoWPbA0DZUGI/ubV5VvZVP x5P4KLGqRibh31+phkle6JF/bGySA8ZIAVSfOUMVQDRZum4BG5Hu07Mu9QBGp55C1cUl F9vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U9LzRwNn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b18si3885310pgj.500.2019.03.22.06.18.01; Fri, 22 Mar 2019 06:18:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U9LzRwNn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729291AbfCVLZb (ORCPT + 99 others); Fri, 22 Mar 2019 07:25:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:52836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729286AbfCVLZ2 (ORCPT ); Fri, 22 Mar 2019 07:25:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8865D218A2; Fri, 22 Mar 2019 11:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253928; bh=rx7udbyzE2256/Dc/+4SnG69HLGNw5YVwkUKIImvPAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9LzRwNnuZB3YLtAlvs5M4EADNzspbWU7hKmGSI+Gn3kjulglomG89yxWH+XgESaZ 5BChnovrxXOeHnDJH/PDvvnuO/yzW36Dr3wAwWDcpQBQB48dnrf8GUWV6HSmjRRwzz vGQkvmPrxPd30e7qjURwVO0hyqwyS2nKwWKeDWM4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Herbert Xu Subject: [PATCH 3.18 097/134] crypto: ahash - fix another early termination in hash walk Date: Fri, 22 Mar 2019 12:15:10 +0100 Message-Id: <20190322111217.186866547@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 77568e535af7c4f97eaef1e555bf0af83772456c upstream. Hash algorithms with an alignmask set, e.g. "xcbc(aes-aesni)" and "michael_mic", fail the improved hash tests because they sometimes produce the wrong digest. The bug is that in the case where a scatterlist element crosses pages, not all the data is actually hashed because the scatterlist walk terminates too early. This happens because the 'nbytes' variable in crypto_hash_walk_done() is assigned the number of bytes remaining in the page, then later interpreted as the number of bytes remaining in the scatterlist element. Fix it. Fixes: 900a081f6912 ("crypto: ahash - Fix early termination in hash walk") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/ahash.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -84,17 +84,17 @@ static int hash_walk_new_entry(struct cr int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err) { unsigned int alignmask = walk->alignmask; - unsigned int nbytes = walk->entrylen; walk->data -= walk->offset; - if (nbytes && walk->offset & alignmask && !err) { - walk->offset = ALIGN(walk->offset, alignmask + 1); - nbytes = min(nbytes, - ((unsigned int)(PAGE_SIZE)) - walk->offset); - walk->entrylen -= nbytes; + if (walk->entrylen && (walk->offset & alignmask) && !err) { + unsigned int nbytes; + walk->offset = ALIGN(walk->offset, alignmask + 1); + nbytes = min(walk->entrylen, + (unsigned int)(PAGE_SIZE - walk->offset)); if (nbytes) { + walk->entrylen -= nbytes; walk->data += walk->offset; return nbytes; } @@ -114,7 +114,7 @@ int crypto_hash_walk_done(struct crypto_ if (err) return err; - if (nbytes) { + if (walk->entrylen) { walk->offset = 0; walk->pg++; return hash_walk_next(walk);