Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4890919ima; Tue, 5 Feb 2019 03:03:56 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia1pGae16gTmSl4sEpruvgEG5mQUMevvdfY8Fo6wMxzKDJokMQ+JyHIeYGh4sJj5+z5c0Xv X-Received: by 2002:a63:e302:: with SMTP id f2mr4046608pgh.320.1549364635916; Tue, 05 Feb 2019 03:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549364635; cv=none; d=google.com; s=arc-20160816; b=J8dgS/3hOPJV4kIBgmHNWQV9ztpSbVH4na0De/XtctHZqBH6q26B15nnh73asKyoxU cGPT3jxrTzkiG1W8PhdRF23kCrsRklRFpRXdRIVfIJyrZvxYTu7JfMO1rLuP3PWCO4m9 lHlbMiJhppoPiouwFlNy2GW2NM6YCGIvXMDpkwbxTV2ztrDVsz2Oz2RLkq8cMY5gkUd4 chUsVi+4/frfopFxrzlYzNgIIWLk+5W1k3aKF3mmGMX58ihmx1qr0qVGHexKiBo5ciNm TFjbZfapRPJbsUUWkyulYRWkFZQyFC4x3WeydQQDKWNm3HfYlA99SXvo4RHZki7cJYgr OWdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=APq7YYAv/XAHdsqnDxKdD+qJ0NR71fQwnm5ifliz03Q=; b=Y5Alm/3yY823z4fybRyjPLSRWcxI8oooWS3g6ZnKw1U0ET2hnybmoE+7EYcreODUVT XpCoWnLnDJ655xMTuntN+RKOd1ZC0vVIhoOVR/hl6B9zs5QS7Tx8hy3I7i+P1YwWf4d6 RBOVYvesctYgaQSE5PtuTEjMH669kkPQs31Cnup9X1DDeRGPj3/QlcAYspe9ongMrLya SfXMgPQ/qqhxWpelJMcHlHtGE2FtQX0E4Ul01a+zYaQF4gsfHM/niLpOtKZq6Mi/k+SV m5OwA83XZ4vQq5HEQafmaYhfciEmbTqX1Bw0bsnbupJYzJYpI4/L2KpxZlGv51IJpm/U fg6w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si2779796pfh.138.2019.02.05.03.03.39; Tue, 05 Feb 2019 03:03:55 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbfBEKtS (ORCPT + 99 others); Tue, 5 Feb 2019 05:49:18 -0500 Received: from mga11.intel.com ([192.55.52.93]:38183 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfBEKtR (ORCPT ); Tue, 5 Feb 2019 05:49:17 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 02:49:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,563,1539673200"; d="scan'208";a="144297414" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.172]) by fmsmga001.fm.intel.com with ESMTP; 05 Feb 2019 02:49:14 -0800 Date: Tue, 5 Feb 2019 12:49:10 +0200 From: Jarkko Sakkinen To: David Laight Cc: "linux-kernel@vger.kernel.org" , "linux-integrity@vger.kernel.org" , "linux-security-module@vger.kernel.org" , "stable@vger.kernel.org" , Linus Torvalds , James Morris , Tomas Winkler , Jerry Snitselaar Subject: Re: [PATCH] tpm/tpm_crb: Avoid unaligned reads in crb_recv(): Message-ID: <20190205104910.GC1823@linux.intel.com> References: <20190201111949.14881-1-jarkko.sakkinen@linux.intel.com> <0446c899270a4b128a6d05e62d63e704@AcuMS.aculab.com> <20190205104406.GA1823@linux.intel.com> <20190205104747.GB1823@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190205104747.GB1823@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 05, 2019 at 12:47:47PM +0200, Jarkko Sakkinen wrote: > On Tue, Feb 05, 2019 at 12:44:06PM +0200, Jarkko Sakkinen wrote: > > On Mon, Feb 04, 2019 at 12:17:43PM +0000, David Laight wrote: > > > From: Jarkko Sakkinen > > > > Sent: 01 February 2019 11:20 > > > > The current approach to read first 6 bytes from the response and then tail > > > > of the response, can cause the 2nd memcpy_fromio() to do an unaligned read > > > > (e.g. read 32-bit word from address aligned to a 16-bits), depending on how > > > > memcpy_fromio() is implemented. If this happens, the read will fail and the > > > > memory controller will fill the read with 1's. > > > > > > To my mind memcpy_to/fromio() should only be used on IO addresses that are > > > adequately like memory, and should be implemented in a way that that won't > > > generate invalid bus cycles. > > > Also memcpy_fromio() should also be allowed to do 'aligned' accesses that > > > go beyond the ends of the required memory area. > > > > > > ... > > > > > > > > - memcpy_fromio(buf, priv->rsp, 6); > > > > + memcpy_fromio(buf, priv->rsp, 8); > > > > expected = be32_to_cpup((__be32 *) &buf[2]); > > > > - if (expected > count || expected < 6) > > > > + if (expected > count || expected < 8) > > > > return -EIO; > > > > > > > > - memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6); > > > > + memcpy_fromio(&buf[8], &priv->rsp[8], expected - 8); > > > > > > Why not just use readl() or readq() ? > > > > > > Bound to generate better code. > > > > For the first read can be done. The second read is of variable > > length. > > Neither can be done to the first one, because readq() does > le64_to_cpu(). Shoud not do any conversions, only raw read. > So I'll just stick it to what we have. ATM tmp_crb is only used in LE architectures (x86 and ARM64), but I still hate to have hidden extra byte order conversions, even if they get compiled as nil ops. It is more wrong than to use memcpy_fromio(). /Jarkko