linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: boot: Fix EFI stub alignment
@ 2018-09-16 15:22 Ben Hutchings
  2018-09-18 22:04 ` Ard Biesheuvel
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Hutchings @ 2018-09-16 15:22 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, linux-efi

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

We currently align the end of the compressed image to a multiple of
16.  However the PE-COFF header included in the EFI stub says that the
file alignment is 32 bytes, and when adding an EFI signature to the
file it must first be padded to this alignment.

sbsigntool commands warn about this:

    warning: file-aligned section .text extends beyond end of file
    warning: checksum areas are greater than image size. Invalid section table?

Worse, pesign-at least when creating a detached signature—uses the
hash of the unpadded file, resulting in an invalid signature if
padding is required.

Avoid both these problems by increasing alignment to 32 bytes when
CONFIG_EFI_STUB is enabled.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -391,6 +391,13 @@ int main(int argc, char ** argv)
 		die("Unable to mmap '%s': %m", argv[2]);
 	/* Number of 16-byte paragraphs, including space for a 4-byte CRC */
 	sys_size = (sz + 15 + 4) / 16;
+#ifdef CONFIG_EFI_STUB
+	/*
+	 * COFF requires minimum 32-byte alignment of sections, and
+	 * adding a signature is problematic without that alignment.
+	 */
+	sys_size = (sys_size + 1) & ~1;
+#endif
 
 	/* Patch the setup code with the appropriate size parameters */
 	buf[0x1f1] = setup_sectors-1;

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

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

* Re: [PATCH] x86: boot: Fix EFI stub alignment
  2018-09-16 15:22 [PATCH] x86: boot: Fix EFI stub alignment Ben Hutchings
@ 2018-09-18 22:04 ` Ard Biesheuvel
  0 siblings, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2018-09-18 22:04 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: the arch/x86 maintainers, Linux Kernel Mailing List, linux-efi

On 16 September 2018 at 08:22, Ben Hutchings <ben@decadent.org.uk> wrote:
> We currently align the end of the compressed image to a multiple of
> 16.  However the PE-COFF header included in the EFI stub says that the
> file alignment is 32 bytes, and when adding an EFI signature to the
> file it must first be padded to this alignment.
>
> sbsigntool commands warn about this:
>
>     warning: file-aligned section .text extends beyond end of file
>     warning: checksum areas are greater than image size. Invalid section table?
>
> Worse, pesign-at least when creating a detached signature—uses the
> hash of the unpadded file, resulting in an invalid signature if
> padding is required.
>
> Avoid both these problems by increasing alignment to 32 bytes when
> CONFIG_EFI_STUB is enabled.
>
> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> ---

Thanks, queued in efi/next.


> --- a/arch/x86/boot/tools/build.c
> +++ b/arch/x86/boot/tools/build.c
> @@ -391,6 +391,13 @@ int main(int argc, char ** argv)
>                 die("Unable to mmap '%s': %m", argv[2]);
>         /* Number of 16-byte paragraphs, including space for a 4-byte CRC */
>         sys_size = (sz + 15 + 4) / 16;
> +#ifdef CONFIG_EFI_STUB
> +       /*
> +        * COFF requires minimum 32-byte alignment of sections, and
> +        * adding a signature is problematic without that alignment.
> +        */
> +       sys_size = (sys_size + 1) & ~1;
> +#endif
>
>         /* Patch the setup code with the appropriate size parameters */
>         buf[0x1f1] = setup_sectors-1;

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

end of thread, other threads:[~2018-09-18 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-16 15:22 [PATCH] x86: boot: Fix EFI stub alignment Ben Hutchings
2018-09-18 22:04 ` Ard Biesheuvel

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).