Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp59854ybm; Mon, 20 May 2019 11:51:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqy10av+hHP1vS1fIIoouxTWFKpBRIdTzSdIBKU06h+Jj3Lisoh4kh+nRthP7IVxZTD/AAEJ X-Received: by 2002:a17:902:bd06:: with SMTP id p6mr3805227pls.112.1558378295047; Mon, 20 May 2019 11:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558378295; cv=none; d=google.com; s=arc-20160816; b=inV09Tfa4EJxW/RDecQlUVj5uNS+p/z7yxeRRTXeIRf0qLBzqVXeBfTEN2v9iiF/DQ 4IKbhOAE/ihN5dJbt5hV8NCb9biVfaF5+mOSIDmrHXPHXrReV0gK8kBfQ9AOBzcb4vyj k2WrsH/PeOk5FzQuKpEd3EnsEjS5eHlmRC2aNu75Xu+zNnwu/AEp/X4ZlgdWyJ1PFAAS TZ21sum/sxFc6iFdnLBfeosNUwGfhJdr7IKWgXkH4CFWjBlZKfhufg43mfTLu6nPJSHv Iv1f8d2DlDAC99nrlfC6Wm0DaWKmqFeSfuItqqKT15G0RpcWKn/1u7w6x4l1RVXV9cAX aAiA== 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=shM2T5Ef6HDA3vh/Px7+wgLaLI44O7bBwv31LbuTl70=; b=ZnNSxHtex6urb7hceIxozERDS6nMBlc3bOmLSnk94n0XvrvmFFMucOtScKhFo6Th8A WxLd6ykb7rJqeacjia0rEE3J5NYs17ffDe/bq+hk5DVvbtovfCAGXY7F5ZTCN/mAqpfm gWIYnEXeoUAVTI3xMxjy+KQO8ZDCi6CCKm9QmA0RE7gJzBVoQw1GEoE1AwR6/k05SP5o tRg7HcDSjFBk/3dm6uGdmxXXvm4mcUMRSUfuhExLmAk7cMjshu3qXX0Wi9NszF8GyUnP lUUJ3qJjwVSvh/N7jE04/1kUeaDG4aGCg3lBxcLwBv7Ug6u/8lHJvvcwku3Q2AIWlwam ytPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gwE5ZEfR; 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 m189si20871364pfb.74.2019.05.20.11.51.18; Mon, 20 May 2019 11:51:35 -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=gwE5ZEfR; 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 S2391477AbfETMph (ORCPT + 99 others); Mon, 20 May 2019 08:45:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:42100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388645AbfETM0j (ORCPT ); Mon, 20 May 2019 08:26:39 -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 B29E9214AE; Mon, 20 May 2019 12:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355199; bh=XvtAsDLEUGLG/5JAIEZjsWSHoExQuKV9bR/WUi5O0OI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gwE5ZEfRuv9EuxJdoFSJMtYMJ1RDDogBRt1YdYGrIRbFoKtoS1yXANHjRjFdLjZdj yGtGMmRq5gODDmWFU1JvCKoAtG3JaxuIV/TtGZlxEmZY4XGskcOCpyvyZChSkEi60A w0xDM4Bfv7LKtAib5sOGJ93Yr7ADm5SW3t/vx+9w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Ard Biesheuvel , Herbert Xu Subject: [PATCH 5.0 029/123] crypto: chacha-generic - fix use as arm64 no-NEON fallback Date: Mon, 20 May 2019 14:13:29 +0200 Message-Id: <20190520115246.715655463@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115245.439864225@linuxfoundation.org> References: <20190520115245.439864225@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Eric Biggers commit 7aceaaef04eaaf6019ca159bc354d800559bba1d upstream. The arm64 implementations of ChaCha and XChaCha are failing the extra crypto self-tests following my patches to test the !may_use_simd() code paths, which previously were untested. The problem is as follows: When !may_use_simd(), the arm64 NEON implementations fall back to the generic implementation, which uses the skcipher_walk API to iterate through the src/dst scatterlists. Due to how the skcipher_walk API works, walk.stride is set from the skcipher_alg actually being used, which in this case is the arm64 NEON algorithm. Thus walk.stride is 5*CHACHA_BLOCK_SIZE, not CHACHA_BLOCK_SIZE. This unnecessarily large stride shouldn't cause an actual problem. However, the generic implementation computes round_down(nbytes, walk.stride). round_down() assumes the round amount is a power of 2, which 5*CHACHA_BLOCK_SIZE is not, so it gives the wrong result. This causes the following case in skcipher_walk_done() to be hit, causing a WARN() and failing the encryption operation: if (WARN_ON(err)) { /* unexpected case; didn't process all bytes */ err = -EINVAL; goto finish; } Fix it by rounding down to CHACHA_BLOCK_SIZE instead of walk.stride. (Or we could replace round_down() with rounddown(), but that would add a slow division operation every time, which I think we should avoid.) Fixes: 2fe55987b262 ("crypto: arm64/chacha - use combined SIMD/ALU routine for more speed") Cc: # v5.0+ Signed-off-by: Eric Biggers Reviewed-by: Ard Biesheuvel Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/chacha_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/crypto/chacha_generic.c +++ b/crypto/chacha_generic.c @@ -52,7 +52,7 @@ static int chacha_stream_xor(struct skci unsigned int nbytes = walk.nbytes; if (nbytes < walk.total) - nbytes = round_down(nbytes, walk.stride); + nbytes = round_down(nbytes, CHACHA_BLOCK_SIZE); chacha_docrypt(state, walk.dst.virt.addr, walk.src.virt.addr, nbytes, ctx->nrounds);