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

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