Skip to content

Conversation

@vathpela
Copy link
Member

In UEFI Mantis 2549, ARM proposes to recommend 64kB section alignment in
UEFI binaries. The reason for this is that some machines may be
configured to have no pages smaller than 64kB for performance reasons,
and in such a scenario things like W^X will be impossible to correctly
implement on binaries where one section ends and another begins on the
same 64kB page.

This change makes aarch64 binaries use a 64kB rather than 4kB section
alignment. Note that this only actually changes virtual addresses, not
file addresses, so the size is unchanged.

FWIW I ran this by ardb and he said it looks sane to him.

This fixes a case where we're not handling getopt_long()'s return value
properly.

Signed-off-by: Peter Jones <pjones@redhat.com>
This moves FileAlignment from being a local in load_pe() to being in the
PE context header, so that later functions can more easily access it.

Signed-off-by: Peter Jones <pjones@redhat.com>
This adds some debug information and a test that FileAlignment is
compatible with PAGE_SIZE to the validate_nx_compat() function.

Signed-off-by: Peter Jones <pjones@redhat.com>
In validate_nx_compat() we're testing SectionAlignment against our 4kB
page size, but the requirement is actually only that it should be a
multiple of it.

This tests for that instead.

Signed-off-by: Peter Jones <pjones@redhat.com>
This adds a test to verify_nx_compat() to check if section VMAs are
aligned with our PE header's SectionAlignment.

Signed-off-by: Peter Jones <pjones@redhat.com>
This changes our linking to have a per-arch section alignment and apply
it when we link.  Note that this will produce incorrect results if the
alignment used in the linker scripts do not match.

Signed-off-by: Peter Jones <pjones@redhat.com>
In UEFI Mantis 2549, ARM proposes to recommend 64kB section alignment in
UEFI binaries.  The reason for this is that some machines may be
configured to have no pages smaller than 64kB for performance reasons,
and in such a scenario things like W^X will be impossible to correctly
implement on binaries where one section ends and another begins on the
same 64kB page.

This change makes aarch64 binaries use a 64kB rather than 4kB section
alignment.  Note that this only actually changes virtual addresses, not
file addresses, so the size is unchanged:

Before:
SectionAlignment	00001000
FileAlignment		00001000

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .eh_frame     00018c64  0000000000005000  0000000000005000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .text         0006bd9c  000000000001e000  000000000001e000  0001a000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .reloc        0000000a  000000000008a000  000000000008a000  00086000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .data.ident   00000088  000000000008c000  000000000008c000  00087000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .sbatlevel    0000006c  000000000008d000  000000000008d000  00088000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .data         0002f268  000000000008e000  000000000008e000  00089000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .vendor_cert  00000010  00000000000be000  00000000000be000  000b9000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .dynamic      000000f0  00000000000bf000  00000000000bf000  000ba000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  8 .rela         0001d760  00000000000c0000  00000000000c0000  000bb000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  9 .sbat         00000083  00000000000de000  00000000000de000  000d9000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

$ /bin/ls -l shimaa64.efi
-rwxr-xr-x. 1 pjones pjones 1036357 Oct 28 13:34 shimaa64.efi

After:

SectionAlignment	00010000
FileAlignment		00001000

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .eh_frame     00018c64  0000000000010000  0000000000010000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .text         0006bd9c  0000000000030000  0000000000030000  0001a000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .reloc        0000000a  00000000000a0000  00000000000a0000  00086000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .data.ident   00000088  00000000000c0000  00000000000c0000  00087000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .sbatlevel    0000006c  00000000000d0000  00000000000d0000  00088000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .data         0002f268  00000000000e0000  00000000000e0000  00089000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  6 .vendor_cert  00000010  0000000000110000  0000000000110000  000b9000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  7 .dynamic      000000f0  0000000000120000  0000000000120000  000ba000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  8 .rela         0001d760  0000000000130000  0000000000130000  000bb000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  9 .sbat         00000083  0000000000150000  0000000000150000  000d9000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

$ /bin/ls -l shimaa64.efi
-rwxr-xr-x. 1 pjones pjones 1036357 Oct 28 13:18 shimaa64.efi

On my test machine, that changes the text and data load addresses (both
physical and virtual, we're still on a 1:1 map) as follows:
Before: _text:0x0000000092FF7000 _data:0x0000000093067000
After:  _text:0x0000000092F80000 _data:0x0000000093030000

Signed-off-by: Peter Jones <pjones@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant