Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4888640ima; Tue, 5 Feb 2019 03:01:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IYkTRPvvh2NT3ZuTDpczu/I0WuO8cVgpgHHQqWUJYevE1L8xCxOkuLnt+rNDT3GNVMaTyKC X-Received: by 2002:a62:f5da:: with SMTP id b87mr4422315pfm.253.1549364502495; Tue, 05 Feb 2019 03:01:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549364502; cv=none; d=google.com; s=arc-20160816; b=T4NPepnJjTYVjhhzUHb+CheXPDkB0Ow3n9SjrmPQwFBXX370k2guyac9DskL27CBft Kzk4/PDbZm2aUW4VOCEa/AFZ5x8wrRv+a2KCLGHIevv72DkwdXGxsjsxdk+4JzSMMXpA 6RV+Fyr/cSO+uoQsTBAoirFgzV18OOAOfQxqtqJkZZp27mtxKCdMwkP2ppdQgNyIvGMl +AiSI3r0r5NOt3rqTgswKrv5VBF65GSOdJ85nN3rzZzuXEXdLMcs5jm/FP/44jE0OUrM bBt+8XNkPA+CNT27YmlvzrJikqMsUrT2hvB1MxLeMG6PjZvsj/ivPjeiQs0CT9fwlYzG M6KQ== 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=zb0AwO2hfR+FvpH+lN7xpBJxmt4D2pN7Xe7Jbdlz6w0=; b=mN9HSK9cL9pR4B3ZcE86fOTHFff77vYh+Rrgi6A1wksLychLaur6UZFDVVa0WGVclP vGq7Vg6lYayzZ/j6ZeXTDLlpmB53rPyEbquA9FcLcbGQd1DzmxdgfIqDsv+5sucUfGlu oUwLt2Ogxva45RLMGd2q7LbgOfgWLhnBboiQb800MtyJ+lfWYdjcjjVj7edJE8N95I4C 3ELwGOOegrp4HstxBz1gr94wTGZZMrVRfsJwWgADSWkv1TtCIxqhsscma6KY4qPH1kTs oXlb9tmnb7xwevRXr8fvW2U43EjPCrIvGsX8h3YIQ/HYqnjCNaxMs3j7pP5cTGbm8RrF v9/Q== 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 x191si1656791pfd.220.2019.02.05.03.01.24; Tue, 05 Feb 2019 03:01:42 -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 S1727671AbfBEKry (ORCPT + 99 others); Tue, 5 Feb 2019 05:47:54 -0500 Received: from mga01.intel.com ([192.55.52.88]:20030 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfBEKry (ORCPT ); Tue, 5 Feb 2019 05:47:54 -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 fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 02:47:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,563,1539673200"; d="scan'208";a="144297225" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.172]) by fmsmga001.fm.intel.com with ESMTP; 05 Feb 2019 02:47:51 -0800 Date: Tue, 5 Feb 2019 12:47:47 +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: <20190205104747.GB1823@linux.intel.com> References: <20190201111949.14881-1-jarkko.sakkinen@linux.intel.com> <0446c899270a4b128a6d05e62d63e704@AcuMS.aculab.com> <20190205104406.GA1823@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190205104406.GA1823@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: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. /jarkko