Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4881688ima; Tue, 5 Feb 2019 02:53:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbT6pwt/YXr3lb/+BPvigjgIu58U2vXHAMzDadxd/S/NBpr3KpV9p3feY3VATKrbZb2r92S X-Received: by 2002:a17:902:34a:: with SMTP id 68mr4543016pld.268.1549363993774; Tue, 05 Feb 2019 02:53:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549363993; cv=none; d=google.com; s=arc-20160816; b=QQvZqor7PBB0kw7LBYF0cSStsK/xZHjPpqkR4tnVnzJnx8fuF1RYKqsBcMEmI5YPuc X7gVYGsqXkSmqe5FRJZZapkYYM5fC8v6aMZkogr3xCmGe1QbtKC+KpU4Lm7JtLrw7D9C jDnCbWDCNEGu6zshfjwBDQpMxlfMn3bANxBfo4cTCgrmKsUNH9LSZuu+TlvHVLaMGpbI 55dSbO/bo12FETP9obbgcTAAjdTn9a++90dafOfFxdw+qNWad17Wk8cXynWn/pkfX2py FUoBxlvDM0qy0Tyn3HPRBJGfCG5dzWCKXqQnQMLnwpdCIKJKJ37HVcwWmq+4WGm5F353 2qrw== 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=k0fWTt0AlPvDxvTFXYsUH0aeHw8ehr0gt7873wWBv6E=; b=XOpAhu1GtwwcXiwo5rEy6FqIF8tb45UUuQoVhUWsMuhXi89/HxvcKfsS0JJgeRLGt5 86dCovkSNgDTbSbq4Vha6Fkc+d83p84O0GbNpHiA3XsVLN9t1kDWPpfuXRXjUGoggg36 17rqgXVWtUaNq8BnaMX22/XSCoBBKcASl7EUj8BXsFhhwRgDq7ihsCXzfox05dLaM4AJ /MJ9Vl/kKkpiZmz09SDcZa2wylhnoSb8QTPsgv+u9Yh9v6hcP3MkiRB69il1QBOQlr2k 23Svi+X0cB/h3ca+BLXKup1JK8j5LOpdcxEtw6373c82jZ7eQGmKjpiXOy6XAITWGyw3 M/kA== 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 x34si2666440pgl.491.2019.02.05.02.52.44; Tue, 05 Feb 2019 02:53:13 -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 S1726943AbfBEKoO (ORCPT + 99 others); Tue, 5 Feb 2019 05:44:14 -0500 Received: from mga05.intel.com ([192.55.52.43]:56726 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfBEKoN (ORCPT ); Tue, 5 Feb 2019 05:44:13 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 02:44:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,563,1539673200"; d="scan'208";a="140797692" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.172]) by fmsmga002.fm.intel.com with ESMTP; 05 Feb 2019 02:44:10 -0800 Date: Tue, 5 Feb 2019 12:44:06 +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: <20190205104406.GA1823@linux.intel.com> References: <20190201111949.14881-1-jarkko.sakkinen@linux.intel.com> <0446c899270a4b128a6d05e62d63e704@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0446c899270a4b128a6d05e62d63e704@AcuMS.aculab.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 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. /Jarkko