public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: James Bottomley <James.Bottomley@hansenpartnership.com>,
	 Breno Leitao <leitao@debian.org>,
	 Usama Arif <usamaarif642@gmail.com>,
	linux-efi@vger.kernel.org,  kexec@lists.infradead.org,
	 bhe@redhat.com, vgoyal@redhat.com,  tglx@linutronix.de,
	 dave.hansen@linux.intel.com, x86@kernel.org,
	 linux-kernel@vger.kernel.org,  rmikey@meta.com,
	gourry@gourry.net
Subject: Re: [RFC] efi/tpm: add efi.tpm_log as a reserved region in 820_table_firmware
Date: Tue, 17 Sep 2024 10:24:14 -0500	[thread overview]
Message-ID: <874j6e482p.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <CAMj1kXF7EohKai9nyxSnvu32KNdUcNZxxP69Sz-vUZ-6nmvekg@mail.gmail.com> (Ard Biesheuvel's message of "Tue, 17 Sep 2024 08:45:44 +0200")

Ard Biesheuvel <ardb@kernel.org> writes:

> Hi Eric,
>
> Thanks for chiming in.

It just looked like after James gave some expert input the
conversation got stuck, so I am just trying to move it along.

I don't think anyone knows what this whole elephant looks like,
which makes solving the problem tricky.

> On Mon, 16 Sept 2024 at 22:21, Eric W. Biederman <ebiederm@xmission.com> wrote:
>>
>> James Bottomley <James.Bottomley@HansenPartnership.com> writes:
>>
>> > On Fri, 2024-09-13 at 04:57 -0700, Breno Leitao wrote:
>> >> Hello James,
>> >>
>> >> On Thu, Sep 12, 2024 at 12:22:01PM -0400, James Bottomley wrote:
>> >> > On Thu, 2024-09-12 at 06:03 -0700, Breno Leitao wrote:
>> >> > > Hello Ard,
>> >> > >
>> >> > > On Thu, Sep 12, 2024 at 12:51:57PM +0200, Ard Biesheuvel wrote:
>> >> > > > I don't see how this could be an EFI bug, given that it does
>> >> > > > not deal with E820 tables at all.
>> >> > >
>> >> > > I want to back up a little bit and make sure I am following the
>> >> > > discussion.
>> >> > >
>> >> > > From what I understand from previous discussion, we have an EFI
>> >> > > bug as the root cause of this issue.
>> >> > >
>> >> > > This happens because the EFI does NOT mark the EFI TPM event log
>> >> > > memory region as reserved (EFI_RESERVED_TYPE). Not having an
>> >> > > entry for the event table memory in EFI memory mapped, then
>> >> > > libstub will ignore it completely (the TPM event log memory
>> >> > > range) and not populate e820 table with it.
>> >> >
>> >> > Wait, that's not correct.  The TPM log is in memory that doesn't
>> >> > survive ExitBootServices (by design in case the OS doesn't care
>> >> > about it).  So the EFI stub actually copies it over to a new
>> >> > configuration table that is in reserved memory before it calls
>> >> > ExitBootServices.  This new copy should be in kernel reserved
>> >> > memory regardless of its e820 map status.
>> >>
>> >> First of all, thanks for clarifying some points here.
>> >>
>> >> How should the TPM log table be passed to the next kernel when
>> >> kexecing() since it didn't surive ExitBootServices?
>> >
>> > I've no idea.  I'm assuming you don't elaborately reconstruct the EFI
>> > boot services, so you can't enter the EFI boot stub before
>> > ExitBootServices is called?  So I'd guess you want to preserve the EFI
>> > table that copied the TPM data in to kernel memory.
>>
>> This leaves two practical questions if I have been following everything
>> correctly.
>>
>> 1) How to get kexec to avoid picking that memory for the new kernel to
>>    run in before it initializes itself. (AKA the getting stomped by
>>    relocate kernel problem).
>>
>> 2) How to point the new kernel to preserved tpm_log.
>>
>>
>> This recommendation is from memory so it may be a bit off but
>> the general structure should work.  The idea is as follows.
>>
>> - Pass the information between kernels.
>>
>>   It is probably simplest for the kernel to have a command line option
>>   that tells the kernel the address and size of the tpm_log.
>>
>>   We have a couple of mechanisms here.  Assuming you are loading a
>>   bzImage with kexec_file_load you should be able to have the in kernel
>>   loader to add those arguments to the kernel command line.
>>
>
> This shouldn't be necessary, and I think it is actively harmful to
> keep inventing special ways for the kexec kernel to learn about these
> things that deviate from the methods used by the first kernel. This is
> how we ended up with 5 sources of truth for the physical memory map
> (EFI memory map, memblock and 3 different versions of the e820 memory
> map).
>
> We should try very hard to make kexec idempotent, and reuse the
> existing methods where possible. In this case, the EFI configuration
> table is already being exposed to the kexec kernel, which describes
> the base of the allocation. The size of the allocation can be derived
> from the table header.
>
>> - Ensure that when the loader is finding an address to load the new
>>   kernel it treats the address of the tpm_log as unavailable.
>>
>
> The TPM log is a table created by the EFI stub loader, which is part
> of the kernel. So if we need to tweak this for kexec's benefit, I'd
> prefer changing it in a way that can accommodate the first kernel too.
> However, I think the current method already has that property so I
> don't think we need to do anything (modulo fixing the bug)

I am fine with not inventing a new mechanism, but I think we need
to reuse whatever mechanism the stub loader uses to pass it's
table to the kernel.  Not the EFI table that disappears at
ExitBootServices().

> That said, I am doubtful that the kexec kernel can make meaningful use
> of the TPM log to begin with, given that the TPM will be out of sync
> at this point. But it is still better to keep it for symmetry, letting
> the higher level kexec/kdump logic running in user space reason about
> whether the TPM log has any value to it.

Someone seems to think so or there would not be a complaint that it is
getting corrupted.

This should not be the kexec-on-panic kernel as that runs in memory
that is reserved solely for it's own use.  So we are talking something
like using kexec as a bootloader.

Eric


  reply	other threads:[~2024-09-17 15:24 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 10:41 [RFC] efi/tpm: add efi.tpm_log as a reserved region in 820_table_firmware Usama Arif
2024-09-11 11:51 ` Ard Biesheuvel
2024-09-11 14:34   ` Usama Arif
2024-09-12 10:23   ` Usama Arif
2024-09-12 10:51     ` Ard Biesheuvel
2024-09-12 11:17       ` Usama Arif
2024-09-12 13:03       ` Breno Leitao
2024-09-12 13:10         ` Ard Biesheuvel
2024-09-12 13:54           ` Usama Arif
2024-09-12 14:05             ` Ard Biesheuvel
2024-09-12 14:14               ` Ard Biesheuvel
2024-09-13 10:56                 ` Dave Young
2024-09-13 11:06                   ` Usama Arif
2024-09-13 11:13                     ` Dave Young
2024-09-13 11:49                       ` Dave Young
2024-09-13 11:56                         ` Usama Arif
2024-09-13 12:52                           ` Dave Young
2024-09-14  6:46                   ` Dave Young
2024-09-14  8:31                     ` Ard Biesheuvel
2024-09-14  9:24                       ` Dave Young
2024-09-14  9:46                         ` Dave Young
2024-09-12 14:29           ` Breno Leitao
2024-09-12 15:21             ` Ard Biesheuvel
2024-09-12 15:35               ` Usama Arif
2024-09-12 15:45                 ` Ard Biesheuvel
2024-09-12 16:22         ` James Bottomley
2024-09-13 11:57           ` Breno Leitao
2024-09-13 12:07             ` James Bottomley
2024-09-16 20:20               ` Eric W. Biederman
2024-09-17  6:45                 ` Ard Biesheuvel
2024-09-17 15:24                   ` Eric W. Biederman [this message]
2024-09-17 15:35                     ` Ard Biesheuvel
2024-09-18  3:13                       ` Eric W. Biederman
2024-09-18  7:36                         ` Ard Biesheuvel
2024-10-09  9:10                           ` Jonathan McDowell
2024-10-09 10:46                             ` Breno Leitao
2024-10-09 14:05                               ` Jonathan McDowell

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=874j6e482p.fsf@email.froward.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=ardb@kernel.org \
    --cc=bhe@redhat.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=gourry@gourry.net \
    --cc=kexec@lists.infradead.org \
    --cc=leitao@debian.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmikey@meta.com \
    --cc=tglx@linutronix.de \
    --cc=usamaarif642@gmail.com \
    --cc=vgoyal@redhat.com \
    --cc=x86@kernel.org \
    /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