nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0546-modules-Don-t-allocate-space-for-non-allocable-secti.patch

bf0270
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
bf0270
From: Peter Jones <pjones@redhat.com>
bf0270
Date: Mon, 21 Mar 2022 16:56:10 -0400
bf0270
Subject: [PATCH] modules: Don't allocate space for non-allocable sections.
bf0270
bf0270
Currently when loading grub modules, we allocate space for all sections,
bf0270
including those without SHF_ALLOC set.  We then copy the sections that
bf0270
/do/ have SHF_ALLOC set into the allocated memory, leaving some of our
bf0270
allocation untouched forever.  Additionally, on platforms with GOT
bf0270
fixups and trampolines, we currently compute alignment round-ups for the
bf0270
sections and sections with sh_size = 0.
bf0270
bf0270
This patch removes the extra space from the allocation computation, and
bf0270
makes the allocation computation loop skip empty sections as the loading
bf0270
loop does.
bf0270
bf0270
Signed-off-by: Peter Jones <pjones@redhat.com>
bf0270
(cherry picked from commit 03215e342f552396ab08125ea769b1e166417ec1)
bf0270
(cherry picked from commit 91518751b9bcba078e3f4385f4b2f6c39cab49cd)
bf0270
---
bf0270
 grub-core/kern/dl.c | 3 +++
bf0270
 1 file changed, 3 insertions(+)
bf0270
bf0270
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
bf0270
index 520126beab..ba1b33c20b 100644
bf0270
--- a/grub-core/kern/dl.c
bf0270
+++ b/grub-core/kern/dl.c
bf0270
@@ -290,6 +290,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
bf0270
        i < e->e_shnum;
bf0270
        i++, s = (const Elf_Shdr *)((const char *) s + e->e_shentsize))
bf0270
     {
bf0270
+      if (s->sh_size == 0 || !(s->sh_flags & SHF_ALLOC))
bf0270
+	continue;
bf0270
+
bf0270
       tsize = ALIGN_UP (tsize, s->sh_addralign) + s->sh_size;
bf0270
       if (talign < s->sh_addralign)
bf0270
 	talign = s->sh_addralign;