linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>
Subject: Re: [PATCH] tpm: of: avoid __va() translation for event log address
Date: Fri, 25 Sep 2020 08:56:26 +0300	[thread overview]
Message-ID: <20200925055626.GC165011@linux.intel.com> (raw)
In-Reply-To: <20200922094128.26245-1-ardb@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 <peterhuewe@gmx.de>
> Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  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 <linux/slab.h>
> +#include <linux/io.h>
>  #include <linux/of.h>
>  #include <linux/tpm_eventlog.h>
>  
> @@ -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

  reply	other threads:[~2020-09-25  5:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  9:41 [PATCH] tpm: of: avoid __va() translation for event log address Ard Biesheuvel
2020-09-25  5:56 ` Jarkko Sakkinen [this message]
2020-09-25  5:57   ` Jarkko Sakkinen
2020-09-25  7:00   ` Ard Biesheuvel
2020-09-25 10:29     ` Jarkko Sakkinen
2020-09-25 12:00       ` Jason Gunthorpe
2020-09-27 23:44         ` Jarkko Sakkinen
2020-09-28  5:56           ` Christophe Leroy
2020-09-28  6:20             ` Ard Biesheuvel
2020-09-28 14:09               ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200925055626.GC165011@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=ardb@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).