[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/15] grub_dl_load_segments(): page-align the tramp/GOT areas to
From: |
Mate Kukri |
Subject: |
[PATCH 09/15] grub_dl_load_segments(): page-align the tramp/GOT areas too |
Date: |
Fri, 24 May 2024 12:03:56 +0100 |
From: Laszlo Ersek <lersek@redhat.com>
The tramp/GOT write-protection in grub_dl_set_mem_attrs() requires that
the tramp/GOT areas of the module image *not* share a page with any other
memory allocations. Page-align the tramp/GOT areas, while satisfying their
intrinsic alignment requirements too.
Fixes: 887f1d8fa976 (modules: load module sections at page-aligned addresses)
Fixes: ad1b904d325b (nx: set page permissions for loaded modules.)
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit c3569e4a245c21a3806ca122ee88da7c91d3d454)
Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
Conflicts:
grub-core/kern/dl.c (obvious)
Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
---
grub-core/kern/dl.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
index 2784fae7a..9f31ad3b9 100644
--- a/grub-core/kern/dl.c
+++ b/grub-core/kern/dl.c
@@ -228,7 +228,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \
!defined (__loongarch__)
grub_size_t tramp;
+ grub_size_t tramp_align;
grub_size_t got;
+ grub_size_t got_align;
grub_err_t err;
#endif
char *ptr;
@@ -260,12 +262,18 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
err = grub_arch_dl_get_tramp_got_size (e, &tramp, &got);
if (err)
return err;
- tsize += ALIGN_UP (tramp, GRUB_ARCH_DL_TRAMP_ALIGN);
- if (talign < GRUB_ARCH_DL_TRAMP_ALIGN)
- talign = GRUB_ARCH_DL_TRAMP_ALIGN;
- tsize += ALIGN_UP (got, GRUB_ARCH_DL_GOT_ALIGN);
- if (talign < GRUB_ARCH_DL_GOT_ALIGN)
- talign = GRUB_ARCH_DL_GOT_ALIGN;
+ tramp_align = GRUB_ARCH_DL_TRAMP_ALIGN;
+ if (tramp_align < arch_addralign)
+ tramp_align = arch_addralign;
+ tsize += ALIGN_UP (tramp, tramp_align);
+ if (talign < tramp_align)
+ talign = tramp_align;
+ got_align = GRUB_ARCH_DL_GOT_ALIGN;
+ if (got_align < arch_addralign)
+ got_align = arch_addralign;
+ tsize += ALIGN_UP (got, got_align);
+ if (talign < got_align)
+ talign = got_align;
#endif
#ifdef GRUB_MACHINE_EMU
@@ -326,11 +334,11 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
}
#if !defined (__i386__) && !defined (__x86_64__) && !defined(__riscv) && \
!defined (__loongarch__)
- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN);
+ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, tramp_align);
mod->tramp = ptr;
mod->trampptr = ptr;
ptr += tramp;
- ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_GOT_ALIGN);
+ ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, got_align);
mod->got = ptr;
mod->gotptr = ptr;
ptr += got;
--
2.39.2
- [PATCH 00/15] UEFI NX support and NX Linux loader using shim loader protocol, Mate Kukri, 2024/05/24
- [PATCH 05/15] modules: load module sections at page-aligned addresses, Mate Kukri, 2024/05/24
- [PATCH 04/15] pe: add the DOS header struct and fix some bad naming., Mate Kukri, 2024/05/24
- [PATCH 06/15] nx: add memory attribute get/set API, Mate Kukri, 2024/05/24
- [PATCH 10/15] grub_dl_set_mem_attrs(): add self-check for the tramp/GOT sizes, Mate Kukri, 2024/05/24
- [PATCH 11/15] grub_dl_set_mem_attrs(): fix format string, Mate Kukri, 2024/05/24
- [PATCH 09/15] grub_dl_load_segments(): page-align the tramp/GOT areas too,
Mate Kukri <=
- [PATCH 01/15] modules: make .module_license read-only, Mate Kukri, 2024/05/24
- [PATCH 13/15] efi: Provide wrappers for load_image, start_image, unload_image, Mate Kukri, 2024/05/24
- [PATCH 03/15] modules: Don't allocate space for non-allocable sections., Mate Kukri, 2024/05/24
- [PATCH 15/15] efi: Disallow fallback to legacy Linux loader when shim says NX is required., Mate Kukri, 2024/05/24
- [PATCH 14/15] efi: Use shim's loader protocol for EFI image verification and loading, Mate Kukri, 2024/05/24
- [PATCH 12/15] mm: Fixup bogus assumptions about types sizes in format strings, Mate Kukri, 2024/05/24