:: commit c98101c9945b4b916d626ce3c68de4c7e10c5d2f

Mintsuki <mintsuki@protonmail.com> — 2026-02-08 17:48

parents: 2b2d1d7be0

protos/multiboot2: Validate section_entry_size against expected struct size

diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index a8e84fa8..23c56a98 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -521,6 +521,11 @@ reloc_fail:
 
         int bits = elf_bits(kernel);
 
+        if ((bits == 64 && section_hdr_info.section_entry_size < sizeof(struct elf64_shdr)) ||
+            (bits == 32 && section_hdr_info.section_entry_size < sizeof(struct elf32_shdr))) {
+            panic(true, "multiboot2: ELF section entry size too small");
+        }
+
         for (size_t i = 0; i < section_hdr_info.num; i++) {
             if (bits == 64)  {
                 struct elf64_shdr *shdr = (void *)tag->sections + i * section_hdr_info.section_entry_size;
tab: 248 wrap: offon