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