Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4441989ybi; Mon, 3 Jun 2019 10:55:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyF0LlMlP36yBizzCSf01Om1PjidUWl33cgjvM43pRiTWIX7afYKko/XozgRmlbD1lKFzwf X-Received: by 2002:a63:5462:: with SMTP id e34mr24146291pgm.400.1559584537958; Mon, 03 Jun 2019 10:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559584537; cv=none; d=google.com; s=arc-20160816; b=Pv9veS6fGoosmLvRCKpUljQ2D3GN+wBD0bLlzGqXi1Il60Ii7c6P0LhxT9DMuL3Shp pLm96bM+o4z9uSZ/CKTJrDIoobG3ZpYrMr3O3gpzaMH/eO4X6dsr2e/t6FerR7DLR9FZ uyICqFaE7bNHtSJfQa7NibJMwilgIinzBJEPCYGC5zvZdGXz99sCRrktI5rMyn6Fbr0q Kp4vgYwJInpZWtyfpX1DHPR7LEDjsH1hveBOevbu2vL6ywPZuphWujWEwf8Okk7LqLpU hzBjNObDq0N2nRUsVWzocTc+562eCP8bTy2t1FjNrhnYZTHOQlj0tmweXwv3Cq8+13nk Akaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0egZsMTcvZMJ0crgLoZdAMHjjqkOGHK9oVQTQujUuuU=; b=V19jtS5xzy4aecsQcnMn9a4Rz3NzgX/qjI8d7cIQZYEqCN/tByET+YztBNtRVpJl60 3YaAmDy9ukaAjcxxsKDHfiOyQ6FxbAZwhpFZM55LTRR9Fxl1B1eCrrr3+wjp25B1wL/7 hFLEJq7v20zUkBTgM/TMH62KP+BxMu2ftAIPYQBfwu0mTkNgKbEzgZX+7tyOx9elBPG+ XuKKUKda1ai8B3cJXEYiZ1Gkh89hqSAI2Qhnrq6o8F8ims6hnWLCPzPLR+rQ3nhTymQ7 XsD5LgMUWrnBFUf9Hs9leKCn9LnAn+jhlAbkEZ6iAf6+6Hg/IvBUUmQvQcSoS2Y2QI28 LKQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Qtp2a/6x"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 y62si19077661pgy.362.2019.06.03.10.55.18; Mon, 03 Jun 2019 10:55:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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="Qtp2a/6x"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 S1727170AbfFCRbe (ORCPT + 99 others); Mon, 3 Jun 2019 13:31:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:45350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726805AbfFCRbe (ORCPT ); Mon, 3 Jun 2019 13:31:34 -0400 Received: from gmail.com (unknown [104.132.1.77]) (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 DCD0126D87; Mon, 3 Jun 2019 17:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559583094; bh=ef4z7eIvFCgptVOwhdxrknQEusVHxKBjNcgPZL7xjwM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qtp2a/6xnsWe0YzsE1p3a6RJ4UhAkMhH/cvtVt2NYNKzbFDNwYHZApJ84LoiuQVJF XgGPJDNd/C89Mug6ldKVOPF2s3rqmXP/inTecxEBqK9SjdZa5hCb0IZVfz/58Tn6mb GJ6AbQHaAB0pOVD3d6n+POGFs88MMudq88uWaWZU= Date: Mon, 3 Jun 2019 10:31:32 -0700 From: Eric Biggers To: Christophe Leroy Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peter Robinson , stable@vger.kernel.org Subject: Re: [PATCH] crypto: ghash - fix unaligned memory access in ghash_setkey() Message-ID: <20190603173131.GA240519@gmail.com> References: <20190530175039.195574-1-ebiggers@kernel.org> <0f7e6d3d-aa27-30c3-5c82-67d484bf667c@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0f7e6d3d-aa27-30c3-5c82-67d484bf667c@c-s.fr> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, Jun 03, 2019 at 09:27:24AM +0200, Christophe Leroy wrote: > > > Le 30/05/2019 ? 19:50, Eric Biggers a ?crit?: > > From: Eric Biggers > > > > Changing ghash_mod_init() to be subsys_initcall made it start running > > before the alignment fault handler has been installed on ARM. In kernel > > builds where the keys in the ghash test vectors happened to be > > misaligned in the kernel image, this exposed the longstanding bug that > > ghash_setkey() is incorrectly casting the key buffer (which can have any > > alignment) to be128 for passing to gf128mul_init_4k_lle(). > > > > Fix this by memcpy()ing the key to a temporary buffer. > > Shouldn't we make it dependent on CONFIG_HAVE_64BIT_ALIGNED_ACCESS No, because the buffer can have as little as 1-byte alignment. > or !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ? I don't think that's a good idea because two code paths are harder to test than one, and also CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS only means that the CPU allows "regular" loads and stores to be misaligned. On some architectures the compiler can still generate load and store instructions that require alignment, e.g. 'ldrd' or 'ldm' on ARM. We could change gf128mul_init_4k_lle() to take a byte array and make it use get_unaligned_be64(). But since it has to allocate and initialize a 4 KiB multiplication table anyway, that microoptimization would be lost in the noise. - Eric