From: Jonathan McDowell <noodles@fb.com>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: Mimi Zohar <zohar@linux.ibm.com>,
"kexec@lists.infradead.org" <kexec@lists.infradead.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-integrity@vger.kernel.org"
<linux-integrity@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"nayna@linux.ibm.com" <nayna@linux.ibm.com>,
"nasastry@in.ibm.com" <nasastry@in.ibm.com>,
"mpe@ellerman.id.au" <mpe@ellerman.id.au>,
Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>,
Borislav Petkov <bp@suse.de>
Subject: Re: [PATCH v4 4/5] of: kexec: Refactor IMA buffer related functions to make them reusable
Date: Wed, 6 Jul 2022 14:00:44 +0000 [thread overview]
Message-ID: <YsWVfbMu85Cmwdgm@noodles-fedora.dhcp.thefacebook.com> (raw)
In-Reply-To: <47256afac54d68c23f0bdec257ffa26ddf1eb25d.camel@linux.ibm.com>
On Tue, Jul 05, 2022 at 06:46:54PM -0400, Mimi Zohar wrote:
> [Cc'ing Borislav Petkov <bp@suse.de>, Jonathan McDowell <noodles@fb.com
> >]
>
> Hi Stefan,
>
> On Thu, 2022-06-30 at 22:26 -0400, Stefan Berger wrote:
> > Refactor IMA buffer related functions to make them reusable for carrying
> > TPM logs across kexec.
> >
> > Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: Frank Rowand <frowand.list@gmail.com>
> > Cc: Mimi Zohar <zohar@linux.ibm.com>
>
> Refactoring the ima_get_kexec_buffer sounds good, but there's a merge
> conflict with Jonathan McDowell's commit "b69a2afd5afc x86/kexec: Carry
> forward IMA measurement log on kexec".
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/of/kexec.c
None of this looks difficult to re-do on top of my changes that are in
-next; the only thing to watch out for is a couple of functions have
moved into the __init section but that looks appropriate for your TPM
log carry-over too.
> > ---
> > v4:
> > - Move debug output into setup_buffer()
> > ---
> > drivers/of/kexec.c | 131 ++++++++++++++++++++++++++-------------------
> > 1 file changed, 76 insertions(+), 55 deletions(-)
> >
> > diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
> > index c4f9b6655a2e..0710703acfb0 100644
> > --- a/drivers/of/kexec.c
> > +++ b/drivers/of/kexec.c
> > @@ -115,48 +115,59 @@ static int do_get_kexec_buffer(const void *prop, int len, unsigned long *addr,
> > return 0;
> > }
> >
> > -/**
> > - * ima_get_kexec_buffer - get IMA buffer from the previous kernel
> > - * @addr: On successful return, set to point to the buffer contents.
> > - * @size: On successful return, set to the buffer size.
> > - *
> > - * Return: 0 on success, negative errno on error.
> > - */
> > -int ima_get_kexec_buffer(void **addr, size_t *size)
> > +static int get_kexec_buffer(const char *name, unsigned long *addr, size_t *size)
> > {
> > int ret, len;
> > - unsigned long tmp_addr;
> > unsigned long start_pfn, end_pfn;
> > - size_t tmp_size;
> > const void *prop;
> >
> > - if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
> > - return -ENOTSUPP;
> > -
> > - prop = of_get_property(of_chosen, "linux,ima-kexec-buffer", &len);
> > + prop = of_get_property(of_chosen, name, &len);
> > if (!prop)
> > return -ENOENT;
> >
> > - ret = do_get_kexec_buffer(prop, len, &tmp_addr, &tmp_size);
> > + ret = do_get_kexec_buffer(prop, len, addr, size);
> > if (ret)
> > return ret;
> >
> > - /* Do some sanity on the returned size for the ima-kexec buffer */
> > - if (!tmp_size)
> > + /* Do some sanity on the returned size for the kexec buffer */
> > + if (!*size)
> > return -ENOENT;
> >
> > /*
> > * Calculate the PFNs for the buffer and ensure
> > * they are with in addressable memory.
> > */
> > - start_pfn = PHYS_PFN(tmp_addr);
> > - end_pfn = PHYS_PFN(tmp_addr + tmp_size - 1);
> > + start_pfn = PHYS_PFN(*addr);
> > + end_pfn = PHYS_PFN(*addr + *size - 1);
> > if (!page_is_ram(start_pfn) || !page_is_ram(end_pfn)) {
> > - pr_warn("IMA buffer at 0x%lx, size = 0x%zx beyond memory\n",
> > - tmp_addr, tmp_size);
> > + pr_warn("%s buffer at 0x%lx, size = 0x%zx beyond memory\n",
> > + name, *addr, *size);
> > return -EINVAL;
> > }
> >
> > + return 0;
> > +}
> > +
> > +/**
> > + * ima_get_kexec_buffer - get IMA buffer from the previous kernel
> > + * @addr: On successful return, set to point to the buffer contents.
> > + * @size: On successful return, set to the buffer size.
> > + *
> > + * Return: 0 on success, negative errno on error.
> > + */
> > +int ima_get_kexec_buffer(void **addr, size_t *size)
> > +{
> > + int ret;
> > + unsigned long tmp_addr;
> > + size_t tmp_size;
> > +
> > + if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
> > + return -ENOTSUPP;
> > +
> > + ret = get_kexec_buffer("linux,ima-kexec-buffer", &tmp_addr, &tmp_size);
> > + if (ret)
> > + return ret;
> > +
> > *addr = __va(tmp_addr);
> > *size = tmp_size;
> >
> > @@ -191,72 +202,82 @@ int ima_free_kexec_buffer(void)
> > return memblock_phys_free(addr, size);
> > }
> >
> > -/**
> > - * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt
> > - *
> > - * @fdt: Flattened Device Tree to update
> > - * @chosen_node: Offset to the chosen node in the device tree
> > - *
> > - * The IMA measurement buffer is of no use to a subsequent kernel, so we always
> > - * remove it from the device tree.
> > - */
> > -static void remove_ima_buffer(void *fdt, int chosen_node)
> > +static int remove_buffer(void *fdt, int chosen_node, const char *name)
> > {
> > int ret, len;
> > unsigned long addr;
> > size_t size;
> > const void *prop;
> >
> > - if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
> > - return;
> > -
> > - prop = fdt_getprop(fdt, chosen_node, "linux,ima-kexec-buffer", &len);
> > + prop = fdt_getprop(fdt, chosen_node, name, &len);
> > if (!prop)
> > - return;
> > + return -ENOENT;
> >
> > ret = do_get_kexec_buffer(prop, len, &addr, &size);
> > - fdt_delprop(fdt, chosen_node, "linux,ima-kexec-buffer");
> > + fdt_delprop(fdt, chosen_node, name);
> > if (ret)
> > - return;
> > + return ret;
> >
> > ret = fdt_find_and_del_mem_rsv(fdt, addr, size);
> > if (!ret)
> > - pr_debug("Removed old IMA buffer reservation.\n");
> > + pr_debug("Remove old %s buffer reserveration", name);
> > + return ret;
> > }
> >
> > -#ifdef CONFIG_IMA_KEXEC
> > /**
> > - * setup_ima_buffer - add IMA buffer information to the fdt
> > - * @image: kexec image being loaded.
> > - * @fdt: Flattened device tree for the next kernel.
> > - * @chosen_node: Offset to the chosen node.
> > + * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt
> > *
> > - * Return: 0 on success, or negative errno on error.
> > + * @fdt: Flattened Device Tree to update
> > + * @chosen_node: Offset to the chosen node in the device tree
> > + *
> > + * The IMA measurement buffer is of no use to a subsequent kernel, so we always
> > + * remove it from the device tree.
> > */
> > -static int setup_ima_buffer(const struct kimage *image, void *fdt,
> > - int chosen_node)
> > +static void remove_ima_buffer(void *fdt, int chosen_node)
> > +{
> > + if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
> > + return;
> > +
> > + remove_buffer(fdt, chosen_node, "linux,ima-kexec-buffer");
> > +}
> > +
> > +#ifdef CONFIG_IMA_KEXEC
> > +static int setup_buffer(void *fdt, int chosen_node, const char *name,
> > + phys_addr_t addr, size_t size)
> > {
> > int ret;
> >
> > - if (!image->ima_buffer_size)
> > + if (!size)
> > return 0;
> >
> > ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
> > - "linux,ima-kexec-buffer",
> > - image->ima_buffer_addr,
> > - image->ima_buffer_size);
> > + name, addr, size);
> > if (ret < 0)
> > return -EINVAL;
> >
> > - ret = fdt_add_mem_rsv(fdt, image->ima_buffer_addr,
> > - image->ima_buffer_size);
> > + ret = fdt_add_mem_rsv(fdt, addr, size);
> > if (ret)
> > return -EINVAL;
> >
> > - pr_debug("IMA buffer at 0x%pa, size = 0x%zx\n",
> > - &image->ima_buffer_addr, image->ima_buffer_size);
> > + pr_debug("%s at 0x%pa, size = 0x%zx\n", name, &addr, size);
> >
> > return 0;
> > +
> > +}
> > +
> > +/**
> > + * setup_ima_buffer - add IMA buffer information to the fdt
> > + * @image: kexec image being loaded.
> > + * @fdt: Flattened device tree for the next kernel.
> > + * @chosen_node: Offset to the chosen node.
> > + *
> > + * Return: 0 on success, or negative errno on error.
> > + */
> > +static int setup_ima_buffer(const struct kimage *image, void *fdt,
> > + int chosen_node)
> > +{
> > + return setup_buffer(fdt, chosen_node, "linux,ima-kexec-buffer",
> > + image->ima_buffer_addr, image->ima_buffer_size);
> > }
> > #else /* CONFIG_IMA_KEXEC */
> > static inline int setup_ima_buffer(const struct kimage *image, void *fdt,
next prev parent reply other threads:[~2022-07-06 14:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-01 2:25 [PATCH v4 0/5] tpm: Preserve TPM measurement log across kexec (ppc64) Stefan Berger
2022-07-01 2:25 ` [PATCH v4 1/5] of: check previous kernel's ima-kexec-buffer against memory bounds Stefan Berger
2022-07-01 2:26 ` [PATCH v4 2/5] drivers: of: kexec ima: Support 32-bit platforms Stefan Berger
2022-07-01 2:26 ` [PATCH v4 3/5] tpm: of: Make of-tree specific function commonly available Stefan Berger
2022-07-11 0:01 ` Jarkko Sakkinen
2022-07-01 2:26 ` [PATCH v4 4/5] of: kexec: Refactor IMA buffer related functions to make them reusable Stefan Berger
2022-07-05 22:46 ` Mimi Zohar
2022-07-06 14:00 ` Jonathan McDowell [this message]
2022-07-06 15:06 ` Stefan Berger
2022-07-01 2:26 ` [PATCH v4 5/5] tpm/kexec: Duplicate TPM measurement log in of-tree for kexec Stefan Berger
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=YsWVfbMu85Cmwdgm@noodles-fedora.dhcp.thefacebook.com \
--to=noodles@fb.com \
--cc=bp@suse.de \
--cc=devicetree@vger.kernel.org \
--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=mpe@ellerman.id.au \
--cc=nasastry@in.ibm.com \
--cc=nayna@linux.ibm.com \
--cc=robh+dt@kernel.org \
--cc=stefanb@linux.ibm.com \
--cc=zohar@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
all inboxes | Powered by JetHome®