Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp863099pxk; Thu, 24 Sep 2020 23:00:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNW71K78T9QOhfredPU+HivXXZkppEQVXwG5clH4PKvLFKJSKlHNROoZWynkgvkRbXbR4s X-Received: by 2002:a17:906:4a81:: with SMTP id x1mr1142527eju.541.1601013607255; Thu, 24 Sep 2020 23:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601013607; cv=none; d=google.com; s=arc-20160816; b=TDzxlYtn/FDi2/GE0UXe7tcmgCF65HmyIW6SE+Q8mO3SnIOPHf/1QabAE0qho71dnY 8f3X+WwMbSERgSrzl4aR7jhPC9osi/sBbzu9usGNFk6o99S2nNofTBOLub6nzcTucMmA YJysryWe72gCIOsWmonsbfTqW2dp5b4DOr/Uk7NbYCa0m+azhI7Ff/nVJMGEkgxKWink JbYPWFcqkcR4rgQI8sn2sAfuiAwth5Yw0f6Z75i/9oPrLIhULd9SO0xumHlhLkCYstwQ wjcczAFyaXIXIojlDHtj1OykxT9EfWdBHraycRfBehCVyEGaFuwZX49wFA2jsmdFU4Qn aIhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=h1jJoti6+yOcJDgMWxBmC12YXKhGIEW3T4AlTP1qvS0=; b=bP/Yv4m2qaGutuVpVBWWyKTr4zPbUPhMsVECMWp8unFdh6y/chKd4MJi32uzpUNqYF xu3PaTki97imO3MjJ/CtN8JsAVhSStmK+Wjfkc5Da6tGESZLc5FWjM6bt+wUSSLKXA3Y 4LKXo01d1vq6Un7TB/j0SjYMGcsD+OOhHSEbOhkaid4BHeSx/nBpPWe/gbCd/Abe2X6c BJ/yldOwyw64wKJUjwh8HtI+QDdTV1wRCBrCxImSqEHbrWHsxn8nHb57d0x7GCzcXNRV HM7HS4Ea1S2mnyFJDQsbdJYuoQa+Ysf/5GzKHFCzbSE4dZGqLAKQrJbaiPd8xu1nW4X2 fgDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id g24si1194303edu.262.2020.09.24.22.59.43; Thu, 24 Sep 2020 23:00:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727072AbgIYF4a (ORCPT + 99 others); Fri, 25 Sep 2020 01:56:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:41493 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726925AbgIYF4a (ORCPT ); Fri, 25 Sep 2020 01:56:30 -0400 IronPort-SDR: sVPH6mAot7GIq0Bd4Z2wMCrYja4tpUSefJXQZoBEm44GF1Ijlx+xizGBtGuk+vKTJqTZ52GYOZ r4wHrFaTWjUw== X-IronPort-AV: E=McAfee;i="6000,8403,9754"; a="162346411" X-IronPort-AV: E=Sophos;i="5.77,300,1596524400"; d="scan'208";a="162346411" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2020 22:56:29 -0700 IronPort-SDR: CucfpYDGRDGLHDVYU+H5Nlz2kcPRy0f7CTiAsGWKeAPlPYzzjNKxnDVnHAc25kMTb0+Fn6oy5W ztmh5xT7nDNg== X-IronPort-AV: E=Sophos;i="5.77,300,1596524400"; d="scan'208";a="487322318" Received: from erybin-mobl.ccr.corp.intel.com (HELO localhost) ([10.249.47.248]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2020 22:56:28 -0700 Date: Fri, 25 Sep 2020 08:56:26 +0300 From: Jarkko Sakkinen To: Ard Biesheuvel Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Huewe , Jason Gunthorpe Subject: Re: [PATCH] tpm: of: avoid __va() translation for event log address Message-ID: <20200925055626.GC165011@linux.intel.com> References: <20200922094128.26245-1-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922094128.26245-1-ardb@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 11:41:28AM +0200, Ard Biesheuvel wrote: > The TPM event log is provided to the OS by the firmware, by loading > it into an area in memory and passing the physical address via a node > in the device tree. > > Currently, we use __va() to access the memory via the kernel's linear > map: however, it is not guaranteed that the linear map covers this > particular address, as we may be running under HIGHMEM on a 32-bit > architecture, or running firmware that uses a memory type for the > event log that is omitted from the linear map (such as EfiReserved). Makes perfect sense to the level that I wonder if this should have a fixes tag and/or needs to be backported to the stable kernels? > So instead, use memremap(), which will reuse the linear mapping if > it is valid, or create another mapping otherwise. > > Cc: Peter Huewe > Cc: Jarkko Sakkinen > Cc: Jason Gunthorpe > Signed-off-by: Ard Biesheuvel > --- > drivers/char/tpm/eventlog/of.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c > index a9ce66d09a75..9178547589a3 100644 > --- a/drivers/char/tpm/eventlog/of.c > +++ b/drivers/char/tpm/eventlog/of.c > @@ -11,6 +11,7 @@ > */ > > #include > +#include > #include > #include > > @@ -25,6 +26,7 @@ int tpm_read_log_of(struct tpm_chip *chip) > struct tpm_bios_log *log; > u32 size; > u64 base; > + void *p; I'd just use 'ptr' for readability sake. > log = &chip->log; > if (chip->dev.parent && chip->dev.parent->of_node) > @@ -65,7 +67,11 @@ int tpm_read_log_of(struct tpm_chip *chip) > return -EIO; > } > > - log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); > + p = memremap(base, size, MEMREMAP_WB); > + if (!p) > + return -ENOMEM; > + log->bios_event_log = kmemdup(p, size, GFP_KERNEL); > + memunmap(p); > if (!log->bios_event_log) > return -ENOMEM; > > -- > 2.17.1 > This is a really great catch! I'm a bit late of my PR a bit because of SGX upstreaming madness (sending v39 soon). If you can answer to my question above, I can do that nitpick change to patch and get it to my v5.10 PR. PS. Just so that you know, once I've applied it, it will be available here: git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git I'll include MAINTAINERS update to that PR. /Jarkko