Re: [PATCH] Carry forward IMA measurement log on kexec on x86_64

From: Mimi Zohar
Date: Thu Apr 28 2022 - 08:26:32 EST


On Thu, 2022-04-28 at 10:40 +0000, Jonathan McDowell wrote:
> On Tue, Apr 26, 2022 at 02:10:58PM -0400, Mimi Zohar wrote:
> > On Tue, 2022-04-26 at 16:48 +0000, Jonathan McDowell wrote:
> > > Also there's an issue about the fact that we measure the kexec pieces
> > > even if we don't actually do the kexec; there's no marker that confirms
> > > the kexec took place. It's separate to this patch (in that it affects
> > > the device tree kexec infrastructure too) but it's conceivable that an
> > > attacker could measure in the new kernel details and not actually do the
> > > kexec, and that's not distinguishable from the kexec happening.
> > >
> > > One approach might be to add a marker in the kexec ima buffer such that
> > > if it's not present we know the kexec hasn't happened, but I need to
> > > think through that a bit more.
> >
> > I'm not quite sure what you mean by "we measure the kexec pieces". The
> > kexec file load syscall calls kernel_read_file_from_fd() to read the
> > kernel image into a buffer. The measurement record included in the IMA
> > measurement list a hash of the buffer data, which is exactly the same
> > as the hash of the kernel image.
> >
> > The kernel kexec self tests only do the kexec load, not the execute.
> > For each kexec execute you'll see an additional "boot_aggregate" record
> > in the IMA measurement list. At least for the moment I don't see a
> > need for additional marker.
>
> You're right, of course. I'd missed the fact we measure the
> boot_aggregate into IMA_MEASURE_PCR_IDX on boot, so although we'll
> update PCRs related to the kexec on load the IMA PCR won't get updated
> until we've actually done the reboot. So no need for anything extra.

To clarify, after the kexec load, the IMA measurement list contains the
kexec'ed kernel image measurement. The TPM was also extended with that
measurement. Nothing prevents verifying the IMA measurement list at
this point, before the kexec execute, though depending on policy it
might result in additional measurements.

The IMA "pcr=" policy rule option allows specifying a different PCR
than the default IMA_MEASURE_PCR_IDX.

To summarize, with CONFIG_IMA_ARCH_POLICY enabled, both measurements -
kexec'ed kernel image, boot_aggregate - are being added to the IMA
measurement list and extended into the default TPM PCR. Measuring the
kexec'ed kernel image and extending the TPM with the measurement
happens at some point before the system is rebooted. The
"boot_aggregate" is the first measurement after boot/soft boot.

thanks,

Mimi