nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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