From: Simon Horman <horms@kernel.org>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: devicetree@vger.kernel.org, Coiby Xu <coxu@redhat.com>,
Frank Rowand <frowand.list@gmail.com>,
Nageswara R Sastry <rnsastry@linux.ibm.com>,
nayna@linux.ibm.com, kexec@lists.infradead.org,
linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
nasastry@in.ibm.com, Eric Biederman <ebiederm@xmission.com>,
linux-integrity@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
Rob Herring <robh@kernel.org>
Subject: Re: [PATCH v9 4/4] tpm/kexec: Duplicate TPM measurement log in of-tree for kexec
Date: Tue, 18 Apr 2023 19:52:09 +0200 [thread overview]
Message-ID: <ZD7YybmnioAs0yKR@kernel.org> (raw)
In-Reply-To: <20230418134409.177485-5-stefanb@linux.ibm.com>
On Tue, Apr 18, 2023 at 09:44:09AM -0400, Stefan Berger wrote:
> The memory area of the TPM measurement log is currently not properly
> duplicated for carrying it across kexec when an Open Firmware
> Devicetree is used. Therefore, the contents of the log get corrupted.
> Fix this for the kexec_file_load() syscall by allocating a buffer and
> copying the contents of the existing log into it. The new buffer is
> preserved across the kexec and a pointer to it is available when the new
> kernel is started. To achieve this, store the allocated buffer's address
> in the flattened device tree (fdt) under the name linux,tpm-kexec-buffer
> and search for this entry early in the kernel startup before the TPM
> subsystem starts up. Adjust the pointer in the of-tree stored under
> linux,sml-base to point to this buffer holding the preserved log. The TPM
> driver can then read the base address from this entry when making the log
> available. Invalidate the log by removing 'linux,sml-base' from the
> devicetree if anything goes wrong with updating the buffer.
>
> Use subsys_initcall() to call the function to restore the buffer even if
> the TPM subsystem or driver are not used. This allows the buffer to be
> carried across the next kexec without involvement of the TPM subsystem
> and ensures a valid buffer pointed to by the of-tree.
Hi Stefan,
some minor feedback from my side.
> Use the subsys_initcall(), rather than an ealier initcall, since
nit via checkpatch.pl --codespell: s/ealier/earlier/
> page_is_ram() in get_kexec_buffer() only starts working at this stage.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> Cc: Eric Biederman <ebiederm@xmission.com>
> Tested-by: Nageswara R Sastry <rnsastry@linux.ibm.com>
> Tested-by: Coiby Xu <coxu@redhat.com>
> Reviewed-by: Rob Herring <robh@kernel.org>
...
> +void tpm_add_kexec_buffer(struct kimage *image)
> +{
> + struct kexec_buf kbuf = { .image = image, .buf_align = 1,
> + .buf_min = 0, .buf_max = ULONG_MAX,
> + .top_down = true };
> + struct device_node *np;
> + void *buffer;
> + u32 size;
> + u64 base;
> + int ret;
> +
> + if (!IS_ENABLED(CONFIG_PPC64))
> + return;
> +
> + np = of_find_node_by_name(NULL, "vtpm");
> + if (!np)
> + return;
> +
> + if (of_tpm_get_sml_parameters(np, &base, &size) < 0)
> + return;
> +
> + buffer = vmalloc(size);
> + if (!buffer)
> + return;
> + memcpy(buffer, __va(base), size);
> +
> + kbuf.buffer = buffer;
> + kbuf.bufsz = size;
> + kbuf.memsz = size;
> + ret = kexec_add_buffer(&kbuf);
> + if (ret) {
> + pr_err("Error passing over kexec TPM measurement log buffer: %d\n",
> + ret);
Does buffer need to be freed here?
> + return;
> + }
> +
> + image->tpm_buffer = buffer;
> + image->tpm_buffer_addr = kbuf.mem;
> + image->tpm_buffer_size = size;
> +}
next prev parent reply other threads:[~2023-04-19 11:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 13:44 [PATCH v9 0/4] tpm: Preserve TPM measurement log across kexec (ppc64) Stefan Berger
2023-04-18 13:44 ` [PATCH v9 1/4] drivers: of: kexec ima: Support 32-bit platforms Stefan Berger
2023-05-24 22:56 ` Jerry Snitselaar
2023-04-18 13:44 ` [PATCH v9 2/4] tpm: of: Make of-tree specific function commonly available Stefan Berger
2023-05-24 22:56 ` Jerry Snitselaar
2023-06-09 18:18 ` Jarkko Sakkinen
2023-06-09 18:49 ` Stefan Berger
2023-06-10 9:25 ` Jarkko Sakkinen
2023-06-28 23:07 ` Jarkko Sakkinen
2023-04-18 13:44 ` [PATCH v9 3/4] of: kexec: Refactor IMA buffer related functions to make them reusable Stefan Berger
2023-05-24 23:16 ` Jerry Snitselaar
2023-05-25 0:23 ` Stefan Berger
2023-04-18 13:44 ` [PATCH v9 4/4] tpm/kexec: Duplicate TPM measurement log in of-tree for kexec Stefan Berger
2023-04-18 17:49 ` kernel test robot
2023-04-18 17:52 ` Simon Horman [this message]
2023-04-18 19:12 ` kernel test robot
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=ZD7YybmnioAs0yKR@kernel.org \
--to=horms@kernel.org \
--cc=coxu@redhat.com \
--cc=devicetree@vger.kernel.org \
--cc=ebiederm@xmission.com \
--cc=frowand.list@gmail.com \
--cc=kexec@lists.infradead.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=nasastry@in.ibm.com \
--cc=nayna@linux.ibm.com \
--cc=rnsastry@linux.ibm.com \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=stefanb@linux.ibm.com \
/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).