Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1320873imu; Wed, 23 Jan 2019 14:55:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN4tFqkYOP2KPk+aQsMHCYNy5H4Dipp3z5Wz8Hi/ci07DrdUALhgTubbQ0seGOHX9eMiwjZj X-Received: by 2002:aa7:80d7:: with SMTP id a23mr3881068pfn.86.1548284157748; Wed, 23 Jan 2019 14:55:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548284157; cv=none; d=google.com; s=arc-20160816; b=sviWIzoZrsxnwfweEbgNMD1wCj0E4f3Vl9jrelwM1V2heLTJ4RX6xQ5UzCO14yFqu5 HqhyOMSr/S9hKcOZ60UPobKmS8WgAugX1SVN69l/d0kdj6Ie+HmU4Yjy/owEnVLWOtrk X9RAmC5zdn8R5+x63NUJ0AsIfi0xlsoPZmmxN6B/dFuGt3j0UKHjg8c61QVnBj4ZkOeY N8BcWXk7Sh44oy9MfOY6NtrGmdIvkKZNTKFcs7U7FgokuJLx7GWxfQ0rX7Gi0z5GNm4G LXt8CHmTM2P4X+A0EaXO5Re//tTlhd9nlGyK6ng9HWYbxfOCVKYv+yNpmCvWOx+HjATk 58+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CDsSqf3L+hlJh97jtij8dvEmo9gl1TtKUYDziKdIPwg=; b=sYwGVnfb0ObnkafFTYUXr1HbwUPJ+GmP2/g2F+GrVIaWDJDReMzQXibVokXoSQxKM+ otX1oVk9p2xVjq757kENTjCxEBNMGdo/sQ8rofVdM5KZosGS5xCQ/ljM9puq4bSWxbVI w3OGFNb1V19RqHmSpREZ5eQ67cFVg4HdqV283UL/YkI7ro/0wLz8oFIbMLrrqlhTlsKa Ycwr2l5wC5XNmqK9Q0UTuiDIJLBdMFHtketd5MmtT0m6ySsnj431lpPRegaPdN7PCZio EaFxsO4NmVkhY2sp3kyvmbSvqJ1lNGpWfzSwsDYPgeu1l84TztfpchAZL4XIF6p+rtxu qtOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yfsgeMR0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z17si22622484pgc.364.2019.01.23.14.55.42; Wed, 23 Jan 2019 14:55:57 -0800 (PST) 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=yfsgeMR0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbfAWWxx (ORCPT + 99 others); Wed, 23 Jan 2019 17:53:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:50142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfAWWwd (ORCPT ); Wed, 23 Jan 2019 17:52:33 -0500 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 039CE218AD; Wed, 23 Jan 2019 22:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548283953; bh=ufxoBm2hTwA/uh3MG++DT4zHTGEbfgFZcifD2C0Ye2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yfsgeMR0HtM/jmbeXlKpSWqp47+vF9FhpxQ+JynVSTnb+6zyC9LZXH90k+MW/yYaI iYT4v5kYsrsEOgs4kC6k0NQP3ceQ179sBdcuMG3e99DADJmk0mQLMDxQqvBN3CQc2f W3o9bl6Nrhl/r8LSklURXNkeVMecgmf/YkTGWQeg= From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: linux-kernel@vger.kernel.org, "Jason A . Donenfeld" , stable@vger.kernel.org Subject: [RFC/RFT PATCH 06/15] crypto: ahash - fix another early termination in hash walk Date: Wed, 23 Jan 2019 14:49:17 -0800 Message-Id: <20190123224926.250525-7-ebiggers@kernel.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123224926.250525-1-ebiggers@kernel.org> References: <20190123224926.250525-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers 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 --- crypto/ahash.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crypto/ahash.c b/crypto/ahash.c index ca0d3e281fef..81e2767e2164 100644 --- a/crypto/ahash.c +++ b/crypto/ahash.c @@ -86,17 +86,17 @@ static int hash_walk_new_entry(struct crypto_hash_walk *walk) 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; } @@ -116,7 +116,7 @@ int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err) if (err) return err; - if (nbytes) { + if (walk->entrylen) { walk->offset = 0; walk->pg++; return hash_walk_next(walk); -- 2.20.1.321.g9e740568ce-goog