All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] kexec-tools: Truncate PE file if it is signed
@ 2024-12-06  2:44 Pingfan Liu
  2024-12-06  2:44 ` [PATCH 1/2] PE: Extract get_pehdr_offset() for reuse Pingfan Liu
  2024-12-06  2:44 ` [PATCH 2/2] pe-zboot: Truncate the trailing zero if Image is signed Pingfan Liu
  0 siblings, 2 replies; 5+ messages in thread
From: Pingfan Liu @ 2024-12-06  2:44 UTC (permalink / raw)
  To: kexec; +Cc: Pingfan Liu, Simon Horman

Note: This series is compatible with the ongoing kernel patches '[PATCH
0/2] Kexec: Sign Image before packing into EFI STUB' [1]. It ensures
functionality when kexec_file_load enforces signature verification on
arm64, LoongArch, and RISC-V.


*** Issue ***
In the linux kernel drivers/firmware/efi/libstub/Makefile.zboot, the
original Image is padded with zero, using the following instruction:
        truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@

Hence pe-zboot.c decomopresses and gets Image plus trailing zeroes.

These trailing zeroes don't affect loading the original PE file. But
they do raise an issue during the signature verfication. The root cause is
that the kernel function:
        static int pefile_digest_pe_contents(const void *pebuf, unsigned int pelen,
                                             struct pefile_context *ctx,
                                             struct shash_desc *desc)
treats [pebuf, pebuf+pelen] as valid payload, which includes the
trailing zeroes. But that is not the truth.

*** Solution ***
In pratice, the table of attribute certificates come at the end of a
PE file. This patch utilizes that fact and truncates at the boundary of the
certificate table to get the original Image.

[1]: https://lore.kernel.org/linux-efi/20241206021000.8953-1-piliu@redhat.com/T/#t

Cc: Simon Horman <horms@kernel.org>
To: kexec@lists.infradead.org

Pingfan Liu (2):
  PE: Extract get_pehdr_offset() for reuse
  pe-zboot: Truncate the trailing zero if Image is signed

 include/pe.h           | 47 ++++++++++++++++++++++++++++++++++++++++++
 kexec/kexec-pe-zboot.c | 25 +++++++++++++++++++---
 kexec/kexec-uki.c      | 17 ---------------
 3 files changed, 69 insertions(+), 20 deletions(-)

-- 
2.41.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-12-13 12:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-06  2:44 [PATCH 0/2] kexec-tools: Truncate PE file if it is signed Pingfan Liu
2024-12-06  2:44 ` [PATCH 1/2] PE: Extract get_pehdr_offset() for reuse Pingfan Liu
2024-12-13 12:43   ` Simon Horman
2024-12-06  2:44 ` [PATCH 2/2] pe-zboot: Truncate the trailing zero if Image is signed Pingfan Liu
2024-12-13 12:43   ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.